Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MPU6050_Driver_Balance by
Revision 2:3a7eb05dbc72, committed 2018-04-20
- Comitter:
- glintligo
- Date:
- Fri Apr 20 10:56:57 2018 +0000
- Parent:
- 1:f9658c7309ef
- Commit message:
- 2018.4.20;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Apr 20 08:27:50 2018 +0000 +++ b/main.cpp Fri Apr 20 10:56:57 2018 +0000 @@ -17,8 +17,8 @@ }; //0.00005 -//0.00015 -PID PID_Para={0.0,0.0,0.0005}; + +PID PID_Para={0.000085,0.0,-0.0002}; Ticker toggle_led_ticker; //声明一个 Ticker 对象 DigitalOut myled(PC_13); //Serial pc(PA_9, PA_10); @@ -29,21 +29,21 @@ PwmOut mypwm4(PB_1); float calculate(float input,float target); void make() { //中断子程序,在平衡车和无人机的项目中,控制算法就写在中断子程序中:获取陀螺仪数据,根据陀螺仪数据通过PID算法得到电机的控制量(占空比和方向),在输出到单片机管脚 - co = calculate(roll, 0.0); - // pc.printf("pitch: %.2f roll: %.2f yaw: %.2f co: %.2f\r\n", pitch,roll,yaw,co); + co = calculate(roll, 0.0); + // pc.printf("pitch: %.2f roll: %.2f yaw: %.2f co: %.2f\r\n", pitch,roll,yaw,co); // pc.printf("roll: %.2f co: %.2f\r\n",roll,co); if (co >=0) { - mypwm2.pulsewidth(co); - mypwm1.pulsewidth(0); - mypwm4.pulsewidth(co); - mypwm3.pulsewidth(0);} + mypwm1.pulsewidth(co); + mypwm2.pulsewidth(0); + mypwm3.pulsewidth(co); + mypwm4.pulsewidth(0);} else { - mypwm2.pulsewidth(0); - mypwm1.pulsewidth(-co); - mypwm4.pulsewidth(0); - mypwm3.pulsewidth(-co);} + mypwm1.pulsewidth(0); + mypwm2.pulsewidth(-co); + mypwm3.pulsewidth(0); + mypwm4.pulsewidth(-co);} } @@ -52,7 +52,6 @@ PID_Para.error=target-input; PID_Para.dif_error=PID_Para.error-PID_Para.last_error; PID_Para.last_error=PID_Para.error; - PID_Para.int_error+=PID_Para.error; if(PID_Para.int_error >= NTMAX) PID_Para.int_error = NTMAX;