Using HIDScope for P(I)D controller

Dependencies:   FastPWM HIDScope MODSERIAL QEI biquadFilter mbed

Fork of PES_tutorial_5 by BMT Module 9 Group 4

Committer:
1856413
Date:
Mon Oct 15 09:22:59 2018 +0000
Revision:
2:34c14fb36b5d
Parent:
1:c19fc63d555f
Child:
3:ea819bcf667f
Printf added, velocity is printed when changing direction, but not when changing velocity. Velocity still not correct!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
1856413 0:2e33035d4e86 1 #include "mbed.h"
1856413 0:2e33035d4e86 2 #include "FastPWM.h" // FastPWM library
1856413 2:34c14fb36b5d 3 #include "MODSERIAL.h"
1856413 2:34c14fb36b5d 4 MODSERIAL pc(USBTX, USBRX);
1856413 0:2e33035d4e86 5 DigitalOut motor1_direction(D7);
1856413 0:2e33035d4e86 6 AnalogIn pot1(A4);
1856413 1:c19fc63d555f 7 InterruptIn but2(D3);
1856413 1:c19fc63d555f 8 FastPWM motor1_pwm(D6); //FastPWM input, PES lecture 2
1856413 0:2e33035d4e86 9 Ticker MotorInterrupt;
1856413 1:c19fc63d555f 10
1856413 0:2e33035d4e86 11 void Motor()
1856413 0:2e33035d4e86 12 {
1856413 1:c19fc63d555f 13 // Aflezen Potentiometers voor PWM
1856413 1:c19fc63d555f 14 motor1_pwm = pot1.read(); // Aflezen PotMeter 1 (volatile omdat je altijd de potmeter wil blijven lezen)
1856413 0:2e33035d4e86 15 }
1856413 1:c19fc63d555f 16
1856413 1:c19fc63d555f 17 void buttonpress()
1856413 1:c19fc63d555f 18 {
1856413 1:c19fc63d555f 19 motor1_direction = 1 - motor1_direction;
1856413 2:34c14fb36b5d 20 float motor1_velocity = pot1.read() *2.0;
1856413 2:34c14fb36b5d 21 pc.baud(115200);
1856413 2:34c14fb36b5d 22 pc.printf("Velocity is %f \n", motor1_velocity);
1856413 1:c19fc63d555f 23 }
1856413 0:2e33035d4e86 24
1856413 0:2e33035d4e86 25 int main()
1856413 0:2e33035d4e86 26 {
1856413 0:2e33035d4e86 27 motor1_pwm.period_us(60.0); // 60 microseconds PWM period, 16.7 kHz, defines all PWM pins (only needs to done once), FastPWM variabele
1856413 0:2e33035d4e86 28 MotorInterrupt.attach(Motor, 0.5); // Ticker die de functie Motor aanroept elke halve seconde, meer tijd is tragere respons op potmeter
1856413 1:c19fc63d555f 29 but2.rise(buttonpress);
1856413 2:34c14fb36b5d 30
1856413 2:34c14fb36b5d 31
1856413 0:2e33035d4e86 32 while(true){} // Endless loop
1856413 0:2e33035d4e86 33 }