![](/media/cache/group/9e3cc099b3b04bca937a1cca1da81b19.jpg.50x50_q85.jpg)
Motor control
Dependencies: mbed QEI HIDScope biquadFilter MODSERIAL FastPWM
Diff: main.cpp
- Revision:
- 6:1c0b6e55e900
- Parent:
- 5:17aa878564d0
- Child:
- 7:20a802dfe664
diff -r 17aa878564d0 -r 1c0b6e55e900 main.cpp --- a/main.cpp Fri Oct 11 12:22:26 2019 +0000 +++ b/main.cpp Fri Oct 11 12:33:42 2019 +0000 @@ -5,11 +5,11 @@ #include "BiQuad.h" #include "FastPWM.h" -// Button and potmeter control +// Button and potmeter1 control InterruptIn button1(D11); InterruptIn button2(D10); -AnalogIn potmeter(A0); - +AnalogIn potmeter1(A0); +AnalogIn potmeter2(A1); // Encoder DigitalIn encA(D13); DigitalIn encB(D12); @@ -35,7 +35,7 @@ double potValue; double pi2= 6.283185; float e; //e = error -float Kp=17.5; +float Kp; float Ki=1; float Kd=21.5; float u_k; @@ -70,6 +70,7 @@ static BiQuad LowPassFilter(0.0640,0.1279,0.0640,-1.1683,0.4241); //Proportional part: + Kp=20*potmeter2.read(); u_k=Kp*e; //Integral part @@ -98,7 +99,7 @@ { angle = counts * factorin / gearratio; // Angle of motor shaft in rad omega = deltaCounts / Ts * factorin / gearratio; // Angular velocity of motor shaft in rad/s - potValue= potmeter.read(); + potValue= potmeter1.read(); u1= (potValue*2*pi2)-pi2; e=u1-angle; @@ -140,11 +141,12 @@ button2.fall(&toggleMotor); while (true) { - pc.printf("Potmeter: %d \r\n", potValue); + pc.printf("Potmeter: %d Kp: %f\r\n", potValue,Kp); pc.printf("Counts: %i DeltaCounts: %i\r\n", counts, deltaCounts); pc.printf("Angle: %f Omega: %f\r\n", angle, omega); pc.printf("U1: %f Error: %f \r\n",u1, e); + wait(0.5); } }