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
main.cpp
- Committer:
- wbuysman
- Date:
- 2014-10-23
- Revision:
- 2:302174acdac7
- Parent:
- 0:c205dc094877
- Child:
- 3:e40763e01a80
File content as of revision 2:302174acdac7:
#include "mbed.h" #include "encoder.h" #include "HIDScope.h" HIDScope scope(3); int main() { //motor 1, 25D Encoder motor1(PTD3, PTD5); DigitalOut motor1dir(PTC9); PwmOut pwm_motor1(PTC8); pwm_motor1.period_us(100); //10kHz PWM frequency //motor 2, 25D Encoder motor2(PTD2,PTD0); DigitalOut motor2dir(PTA4); PwmOut pwm_motor2(PTA5); pwm_motor2.period_us(100); //10kHz PWM frequency 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: 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)); wait(dt1) goto start; if(new_pwm > 0) { motor1dir = 0; } else { motor1dir = 1; } scope.set(0, output1); scope.set(1, motor1.getPosition()); scope.set(2, motor1.getPosition()/(4480*6.28)/dt1); scope.send(); } }