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:
- 4:91b583d4d8c4
- Parent:
- 3:e40763e01a80
- Child:
- 5:7fb05dfead4d
File content as of revision 4:91b583d4d8c4:
#include "mbed.h" #include "encoder.h" #include "HIDScope.h" HIDScope scope(4); 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 = 3; float dt1 = 0.01; float Kp1 = 1; float Ki1 = 0.5; float error1 = 0; float output1 = 0; float omrekenfactor = 4480.0/6.28; while(1) { error1 = setpoint1 - motor1.getSpeed()/omrekenfactor; // (omrekenfactor)/dt1; //motorpositie omgerekend naar rad/s integral1 = integral1 + error1*dt1; output1 = Kp1*error1 + Ki1*integral1; pwm_motor1.write(abs(output1)); wait(dt1); if(output1 > 0) { motor1dir = 0; } else { motor1dir = 1; } scope.set(0, error1); scope.set(1, output1); scope.set(2, motor1.getSpeed()/omrekenfactor); scope.set(3, motor1.getPosition()/(omrekenfactor)); scope.send(); } }