![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Using HIDScope for P(I)D controller
Dependencies: FastPWM HIDScope MODSERIAL QEI biquadFilter mbed
Fork of PES_tutorial_5 by
Diff: main.cpp
- Revision:
- 6:bd73804c8cec
- Parent:
- 5:a1fb2d2fb2d0
- Child:
- 7:3b503177ff5c
diff -r a1fb2d2fb2d0 -r bd73804c8cec main.cpp --- a/main.cpp Mon Oct 15 09:42:17 2018 +0000 +++ b/main.cpp Mon Oct 15 10:20:24 2018 +0000 @@ -8,12 +8,14 @@ InterruptIn but2(D3); FastPWM motor1_pwm(D6); //FastPWM input, PES lecture 2 Ticker MotorInterrupt; -pc.baud(115200); +QEI Encoder (D12, D13, NC, 64, QEI::X4_ENCODING); void Motor() { // Aflezen Potentiometers voor PWM motor1_pwm = pot1.read(); // Aflezen PotMeter 1 (volatile omdat je altijd de potmeter wil blijven lezen) + pc.printf("%i\r\n", Encoder.getPulses()); + } void buttonpress() @@ -24,14 +26,31 @@ pc.printf("Velocity is %f \r\n", motor1_velocity); } +/*double GetReferenceVelocity() +{ + // Returns reference velocity in rad/s. + // Positive value means clockwise rotation. + // 60 rpm = 60*2*pi/60 = 6.28 ~ 6.2 rad/s + const float maxVelocity = 6.2; // in rad/s of course! + double referenceVelocity; // in rad/s + if (button2) { + // Clockwise rotation + referenceVelocity = potMeterIn * maxVelocity; + } + else + { + // Counterclockwise rotation + referenceVelocity = -1*potMeterIn * maxVelocity; + } + return referenceVelocity; +} */ + + int main() { + pc.baud(115200); motor1_pwm.period_us(60.0); // 60 microseconds PWM period, 16.7 kHz, defines all PWM pins (only needs to done once), FastPWM variabele MotorInterrupt.attach(Motor, 0.5); // Ticker die de functie Motor aanroept elke halve seconde, meer tijd is tragere respons op potmeter but2.rise(buttonpress); - int counts; - QEI Encoder (D12, D13, NC, 64, QEI::X4_ENCODING); - counts = Encoder.getPulses(); - pc.printf("%i\r\n", counts); while(true){} // Endless loop } \ No newline at end of file