Group 9 BioRobotics / Mbed 2 deprecated motor_encoder

Dependencies:   QEI mbed HIDScope

Revision:
2:cb7d7e31e30e
Parent:
1:ccb2f96c393a
Child:
3:e533800b2ef8
--- a/main.cpp	Fri Oct 12 08:31:16 2018 +0000
+++ b/main.cpp	Sun Oct 14 10:59:42 2018 +0000
@@ -4,45 +4,31 @@
 #define SERIAL_BAUD 115200
 
 Serial pc(USBTX,USBRX);
-int counts;
 
-//Kenneth was here
 DigitalOut dirpin(D4);
+DigitalOut dirpin_2(D6);
+
 PwmOut pwmpin(D5);
-AnalogIn pot_1(A1);
-DigitalOut dirpin_2(D6);
 PwmOut pwmpin_2(D7);
-AnalogIn pot_2(A2);
+
+AnalogIn pot_1(A1); //only using one potmeter for both motors, eventually just use a signal created by program or EMG-signals
 
- QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING);
+
+QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING);    //channel A=D12, channel B=D13
 
 int main()
 {
+    //float out_1=1.0f;                         //set potmeter signal as a predetermined digital signal
+    pc.baud(115200);                            //also set baudrate to 115200 in teraterm!
     pc.printf("start\r\n");
-    pc.baud(115200);
-   
-    pwmpin.period_us(60);
-    counts = Encoder.getPulses();
-
-    while(true){
-    //motor 1
-    float out_1 = pot_1 * 2.0f;
-    float out_2 = out_1 - 1.0f;
-    
-    dirpin.write(out_2 < 0);
+      
+    pwmpin.period_us(60);                       //???
     
-    pwmpin = fabs (out_2);
-    
-    // motor 2    
-    float out_3 = pot_2 * 2.0f;
-    float out_4 = out_3 - 1.0f;
-    
-    dirpin_2.write(out_4 < 0);
-    
-    pwmpin_2 = fabs (out_4);
-    
-    pc.printf("%i\r\n", counts);
-    
-    wait(0.01);   
+    while(1){
+    float out_1 = (pot_1 * 2.0f) - 1.0f;        //scales potmeter signal from 0 to 1 into -1 to 1
+    dirpin.write(out_1 < 0);                    //sets direction of motor? if negative =true (1), if positive =false (0)
+    pwmpin = fabs (out_1);                      //sets speed of motor?
+    pc.printf("%i\r\n", Encoder.getPulses());   //prints the amount of counts
+    wait(0.1);                                  //repeat loop every 0.01 sec
     } 
 }
\ No newline at end of file