Latest version of my quadcopter controller with an LPC1768 and MPU9250.
Currently running on a custom PCB with 30.5 x 30.5mm mounts. There are also 2 PC apps that go with the software; one to set up the PID controller and one to balance the motors and props. If anyone is interested, send me a message and I'll upload them.
Diff: calccomp.h
- Revision:
- 2:61ad38ea550d
- Parent:
- 0:0929d3d566cf
- Child:
- 3:a49ab9168fb2
--- a/calccomp.h Mon Jul 09 16:37:24 2018 +0000 +++ b/calccomp.h Mon Jul 09 19:18:20 2018 +0000 @@ -28,11 +28,7 @@ static bool armed = false; float xcntrl = 0; float ycntrl = 0; - -// float KPx, KDx, KPy, KDy; -// static float KIx = 0; -// static float KIy = 0; - + //Scale rx channels rud = (((float)(ctrl[0] - ruddercenter))/2.5); ycntrl = ((float)(ctrl[3] - elevcenter))/8; @@ -49,12 +45,12 @@ m4 = throttle; /* // Calc PID values and prevent integral windup on KIx - KPx = (angles[0] + xcntrl) * 1.05f; - KIx = KIx + ((angles[0] + xcntrl) * 0.001f); + KPx = (angles[0] + xcntrl) * Kp; + KIx = KIx + ((angles[0] + xcntrl) * Kd); if(KIx > 30) KIx = 30; if(KIx < -30) KIx = -30; - KDx = (angles[3] + (angles[0] + xcntrl)*0.8f) * 0.45f; + KDx = (angles[3] + (angles[0] + xcntrl)) Kd; xcomp = KPx + KIx + KDx; xcomp2 = xcomp*-1; @@ -71,12 +67,12 @@ m4 = m4 - xcomp2; /* // Calc PID values and prevent integral windup on KIx - KPy = (angles[1] + ycntrl) * 1.05f; - KIy = KIx + ((angles[1] + ycntrl) * 0.001f); + KPy = (angles[1] + ycntrl) * Kd; + KIy = KIx + ((angles[1] + ycntrl) * Ki); if(KIy > 30) KIy = 30; if(KIy < -30) KIy = -30; - KDx = (angles[4] + (angles[1] + ycntrl)*0.8f) * 0.45f; + KDx = (angles[4] + (angles[1] + ycntrl)) * Kd; ycomp = KPy + KIy + KDy; */ @@ -136,4 +132,3 @@ motor[2] = m3; motor[3] = m4; } -