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.
Dependencies: Encoder HIDScope mbed
Diff: main.cpp
- Revision:
- 2:302174acdac7
- Parent:
- 0:c205dc094877
- Child:
- 3:e40763e01a80
diff -r f5b413a833d5 -r 302174acdac7 main.cpp --- a/main.cpp Thu Oct 23 12:01:26 2014 +0000 +++ b/main.cpp Thu Oct 23 12:05:16 2014 +0000 @@ -21,19 +21,22 @@ pwm_motor2.period_us(100); //10kHz PWM frequency - integral1 = 0; - setpoint1 = 9.5; - dt1 = 0.01; - Kp1 = 0.01; - Ki1 = 0.01; + float integral1 = 0; + float setpoint1 = 9.5; + float dt1 = 0.01; + float Kp1 = 0.01; + float Ki1 = 0.01; + float error1 = 0; + float output1 = 0; + while(1) { start: - error1 = setpoint1 - motor1.getposition/(4480*6.28)/dt1; //motorpositie omgerekend naar rad/s + float error1 = setpoint1 - motor1.getPosition/(4480*6.28)/dt1; //motorpositie omgerekend naar rad/s integral1 = integral1 + error1*dt1; output1 = Kp1*error1 + Ki1*integral1; - pwm_motor1.write(abs(output1); + pwm_motor1.write(abs(output1)); wait(dt1) - goto start + goto start; if(new_pwm > 0) { motor1dir = 0; @@ -41,9 +44,9 @@ motor1dir = 1; } - scope.set(0, new_pwm); + scope.set(0, output1); scope.set(1, motor1.getPosition()); - scope.set(2, motor1.getposition()/(4480*6.28)/dt1); + scope.set(2, motor1.getPosition()/(4480*6.28)/dt1); scope.send(); } } \ No newline at end of file