Patrick Zieverink / Mbed 2 deprecated biorobotics_four_scorers

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

Revision:
7:78bc59c7753c
Parent:
6:354a6509405f
Child:
8:6f6a4dc12036
diff -r 354a6509405f -r 78bc59c7753c main.cpp
--- a/main.cpp	Thu Oct 03 11:02:02 2019 +0000
+++ b/main.cpp	Fri Oct 04 11:18:15 2019 +0000
@@ -3,24 +3,25 @@
 #include "FastPWM.h"
 #include "QEI.h"
 
-MODSERIAL pc(USBTX, USBRX);         //verbinden met pc
+Serial pc(USBTX, USBRX);         //verbinden met pc
 DigitalOut motor2_direction(D4);    //verbinden met motor 2 op board (altijd d4)
 FastPWM motor2_pwm(D5);             //verbinden met motor 2 pwm (altijd d5)
 Ticker loop_ticker;                 //used in main()
 InterruptIn button(D10);            //knop op birorobotics shield
+DigitalOut led1(D9);                // led op D9 aanzetten
 QEI encoder (D11, D12, NC, 8400, QEI::X4_ENCODING); //encoder gebruiken
 
 //variables
 enum States {idle, cw, ccw, end, failure};
-States current_state;
-class motor_state {
-    public:
+States current_state;               //wat gebeurd hier?
+class motor_state {                 // je maakt hier motor_state?
+    public:                         //wat gebeurd hier?
     float pwm1; //pwm of 1st motor
     float pwm2; //pwm of 2nd motor
     int dir1; //direction of 1st motor
     int dir2; //direction of 2nd motor
 };
-motor_state motor;
+motor_state motor;              //
 
 bool state_changed = false;
 volatile bool button_pressed = false;
@@ -28,27 +29,33 @@
 void measure_signals() {return;}
 
 void do_nothing() {
-    if (button_pressed) { //this moves the program from the idle to cw state
+    
+    
+    if (button_pressed == true) { //this moves the program from the idle to cw state
         current_state = cw;
+        led1 = 0;
         state_changed = true; //to show next state it can initialize
         pc.printf("Changed state from idle to cw\r\n");
         button_pressed = false; //reset button
     }
+    
 }
+
+
 void rotate_cw() {
     if (state_changed) {
         pc.printf("State changed to CW\r\n");
         state_changed = false; //reset this so it wont print next loop
     }
-    motor.dir2 = 1; //todo: check if this is actually clockwise
-    motor.pwm2 = 0.5f;
+    motor.dir2 = 1;             //todo: check if this is actually clockwise
+    
     if (!state_changed && button_pressed) { //state wasnt just changed, button has been pressed -> change state
         current_state = ccw;
         state_changed = true;
         button_pressed = false; //reset this
     }
 }
-
+ 
 void rotate_ccw() {
     //similar to rotate_cw()
     if (state_changed) {
@@ -56,7 +63,7 @@
         state_changed = false;
     }
     motor.dir2 = 0;
-    motor.pwm2 = 0.5f;
+
     if (!state_changed && button_pressed) { //state niet veranderd, button gepressd -> state verandert
         current_state = cw;
         state_changed = true;
@@ -75,7 +82,7 @@
     
     //run current state
     switch (current_state) {
-        case idle:
+        case idle:                  // hoezo de :?
             do_nothing();
             break;
         case cw:
@@ -107,8 +114,12 @@
     motor.pwm2 = 0;
     motor.dir1 = 0;
     motor.dir2 = 0;
+    
+    //motor.dir2 = 1;             //todo: check if this is actually clockwise
+    //motor.pwm2 = 0.5f;
+    
     button.fall(&button_interrupt);
-    loop_ticker.attach(&main_loop, 0.001f); //main loop at 1kHz
-    
+    loop_ticker.attach(&main_loop, 0.1f); //main loop at 1kHz
+    pc.printf("Iickerloop finished \n \r");
     while (true) {}
 }        
\ No newline at end of file