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

Revision:
1:c19fc63d555f
Parent:
0:2e33035d4e86
Child:
2:34c14fb36b5d
diff -r 2e33035d4e86 -r c19fc63d555f main.cpp
--- a/main.cpp	Mon Oct 15 08:15:14 2018 +0000
+++ b/main.cpp	Mon Oct 15 09:10:05 2018 +0000
@@ -2,34 +2,27 @@
 #include "FastPWM.h"    // FastPWM library
 //#include "MODSERIAL.h"
 //MODSERIAL pc(USBTX, USBRX);
-DigitalOut motor2_direction(D4);
 DigitalOut motor1_direction(D7);
 AnalogIn pot1(A4);
-AnalogIn pot2(A5);
-FastPWM motor2_pwm(D5);   //FastPWM input, PES lecture 2
-FastPWM motor1_pwm(D6);
+InterruptIn but2(D3);
+FastPWM motor1_pwm(D6); //FastPWM input, PES lecture 2
 Ticker MotorInterrupt;
-
+  
 void Motor()
 {
-    // Aflezen Potentiometers
-    volatile float pwm_pct1 = pot1.read(); // Aflezen PotMeter 1 (volatile omdat je altijd de potmeter wil blijven lezen)
-    volatile float pwm_pct2 = pot2.read(); // Aflezen PotMeter 2
-    // Interval van (0,1) scalen naar (-1,1)
-    volatile float a1 = (2.0*pwm_pct1)- 1; // POT1. pwm_pct1 wordt gescaled, en offset number -1 wordt erbij opgeteld.
-    volatile float a2 = (2.0*pwm_pct2)- 1; // POT2. Idem.
-    // Motor Direction bepalen
-    motor1_direction = a1 > 0; // Bool variable. Al gespecificeerd als direction pin, daarom hoeft er geen bool voor.
-    motor2_direction = a2 > 0; // Indien aX = 1, dan TRUE. Indien aX = -1, dan FALSE.
-    // Motor PWM 
-    motor1_pwm = fabs(a1); // Range van 0.0f tot 1.0f
-    motor2_pwm = fabs(a2);
+    // Aflezen Potentiometers voor PWM
+    motor1_pwm = pot1.read(); // Aflezen PotMeter 1 (volatile omdat je altijd de potmeter wil blijven lezen)
 }
-    
+   
+void buttonpress()
+{
+     motor1_direction = 1 - motor1_direction;
+}
 
 int main()
 {
     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);
     while(true){} // Endless loop  
 }
\ No newline at end of file