Project of tracking ball
Dependencies: mbed existing_references
Revision 1:26da8b1fd7f4, committed 2021-05-24
- Comitter:
- helenh
- Date:
- Mon May 24 09:02:42 2021 +0000
- Parent:
- 0:d8cd915552c0
- Commit message:
- Sharing
Changed in this revision
existing_references.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r d8cd915552c0 -r 26da8b1fd7f4 existing_references.lib --- a/existing_references.lib Sun May 16 12:22:32 2021 +0000 +++ b/existing_references.lib Mon May 24 09:02:42 2021 +0000 @@ -1,1 +1,1 @@ -existing_references#7f16c88e4047 +https://os.mbed.com/users/helenh/code/existing_references/#a668eb71516b
diff -r d8cd915552c0 -r 26da8b1fd7f4 main.cpp --- a/main.cpp Sun May 16 12:22:32 2021 +0000 +++ b/main.cpp Mon May 24 09:02:42 2021 +0000 @@ -1,26 +1,86 @@ #include "mbed.h" #include "Serial_Transport.h" - - - - +#include "PID_Controller.h" +#include "MOTOR_CONTROL_CLASS.h" +#define pid_p 100 +#define pid_i 10 +#define pid_d 1 +#define pid_k 10 +#define PWM_PERIOD 0.01f //10ms ,100Hz +#define PWM_WIDTH_RATIO 0.00f DigitalOut myled(LED1); -//Interruptin button(Do_Recv); - - - +//Serial pc(SERIAL_TX, SERIAL_RX); +unsigned char recv_buff[100]; +Serial pc(SERIAL_TX, SERIAL_RX); int main() { + + pc.baud(115200); + + //是否有新的预设置位置 + unsigned char hasrecv_position; + //预设置位置值 + unsigned int preset_value=0; + //实际位置值 + unsigned int actual_value=0; + + //PID输出值 + int controll_value=0; + + //串口屏通讯对象指针 + Serial_class * preset_Com; + //创建实例 + preset_Com=new Serial_class(D1,D0); + + //摄像头通讯对象 + Serial_class * pOpenmv_Com; + //创建实例 + pOpenmv_Com=new Serial_class(D5,D4); + + //声明并创建PID对象 + Ball_PID * ball_pid=new Ball_PID(pid_p,pid_i,pid_d,pid_k); + + //创建PWM对象 + Motor_Control_Class mypwmout(D10); + mypwmout.Set_Para(PWM_PERIOD,PWM_WIDTH_RATIO);//10ms ,100Hz + while(1) { // myled = 1; // wait(0.2); // myled = 0; // wait(0.2); - // Interruptinbutton(Do_Recv); - //openmv_port.attach(&Do_Recv,SerialBase::RxIrq); - openmv_init(); + //pc.printf("data is received succesfully"); + //读取串口屏对象接收的数据 + hasrecv_position=preset_Com->HasRecv(); + pc.printf("state=%d\n",hasrecv_position); + if(hasrecv_position==4) + { + //收到完整的信息,位置值 + preset_value=preset_Com->ReadInfor(); + pc.printf("value=%d",preset_value); + //pc.printf("data is received succesfully"); + } +// +// // +// //读取OPENMV对象接收的数据 +// hasrecv_position=pOpenmv_Com->HasRecv(); +// if(hasrecv_position==1) +// { +// //收到完整的信息,位置值 +// actual_value=pOpenmv_Com->ReadInfor(); +// +// } +// +// //交给PID模块处理,获得控制量 +// controll_value=ball_pid->PID_Calculation(preset_value,actual_value/2); +// +// //转换为占空比并输出 +// mypwmout.Set_Output(controll_value); +// // + wait(0.5); + } }