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:
- 4:fab65ad01ab4
- Parent:
- 3:a49ab9168fb2
- Child:
- 5:0f4204941604
--- a/calccomp.h Tue Jul 10 13:19:53 2018 +0000 +++ b/calccomp.h Thu Jul 12 13:53:55 2018 +0000 @@ -1,3 +1,5 @@ +// Coded by Erik van de Coevering + #include "mbed.h" DigitalOut led1(LED1); // for stick arming (leds are active low) @@ -15,9 +17,7 @@ float xcomp = 0; float ycomp = 0; int xcomp2 = 0; -// int ycomp2 = 0; float ruddercomp = 0; -// float ratio = 0.3; int rud = 0; int zcomp = 0; int throttle = 0; @@ -45,46 +45,35 @@ m3 = throttle; m4 = throttle; - // Current values used on a 250 size mini racer (still needs tuning): P: 1.55, I: 2.4, D: 0.4 + // Current values used on a 250 size mini racer (still needs tuning): P: 1.45, I: 1.5, D: 0.34 // Calc PID values and prevent integral windup on KIx KPx = (angles[0] - xcntrl) * Kp; KIx = KIx + ((angles[0] - xcntrl) * Ki * 0.001); - if(KIx > 30) KIx = 30; - if(KIx < -30) KIx = -30; + if(KIx > 50) KIx = 50; + if(KIx < -50) KIx = -50; KDx = (angles[3] + (angles[0] - xcntrl)) * Kd; xcomp = KPx + KIx + KDx; xcomp2 = xcomp*-1; - /* - //Calc aileron compensation and mix - xcomp = ((((angles[0])-xcntrl)*Kp) + ((angles[3]+((angles[0]-xcntrl)*1.0f))*Kd)); - xcomp2 = (xcomp*-1); - // xcomp2 = 0; - */ + //Mix aileron m1 = m1 - xcomp2; m2 = m2 + xcomp2; m3 = m3 + xcomp2; m4 = m4 - xcomp2; - // Calc PID values and prevent integral windup on KIx + // Calc PID values and prevent integral windup on KIy KPy = (angles[1] + ycntrl) * Kp; KIy = KIy + ((angles[1] + ycntrl) * Ki * 0.001); - if(KIy > 30) KIy = 30; - if(KIy < -30) KIy = -30; + if(KIy > 50) KIy = 50; + if(KIy < -50) KIy = -50; KDy = (angles[4] + (angles[1] + ycntrl)) * Kd; ycomp = KPy + KIy + KDy; ycomp = ycomp*-1; - /* - //ycntrl = ycntrl+5; - //Calc elevator compensation and mix - ycomp = ((((angles[1])+(ycntrl))*Kp) + ((angles[4]+((angles[1]+ycntrl)*1.0f))*Kd)); - ycomp = ycomp*-1; - // ycomp2 = 0; - */ + //Mix elevator m1 = m1 + ycomp; m2 = m2 + ycomp; @@ -103,12 +92,6 @@ m3 = m3 - zcomp; m4 = m4 + zcomp; - //Prevent motors from stalling -// if(m1 < 1075 && throttle > 1000) m1 = 1280; -// if(m2 < 1075 && throttle > 1000) m2 = 1280; -// if(m3 < 1075 && throttle > 1000) m3 = 1280; -// if(m4 < 1075 && throttle > 1000) m4 = 1280; - //When throttle down or if not armed, stop motors if(throttle < 1100 || armed == false) { m1=1000;