Script voor aansturen motoren

Dependencies:   Encoder HIDScope MODSERIAL mbed-dsp mbed

Revision:
7:697293226e5e
Parent:
6:f260176f704b
Child:
8:0bbbe93bd1c4
Child:
18:fb85c58a4106
diff -r f260176f704b -r 697293226e5e main.cpp
--- a/main.cpp	Thu Oct 23 10:26:25 2014 +0000
+++ b/main.cpp	Thu Oct 23 10:47:35 2014 +0000
@@ -8,70 +8,51 @@
 #define K_D (0.001 /TSAMP)
 #define I_LIMIT 1.
 
-#define M1_PWM PTC8 //blauw
-#define M1_DIR PTC9 //groen
-#define M2_PWM PTA5 //blauw
-#define M2_DIR PTA4 //groen
+#define M1_PWM PTC8
+#define M1_DIR PTC9
+#define M2_PWM PTA5
+#define M2_DIR PTA4
+
+//Groene kabel moet op de GROUND en blauw op de 3.3v aansluiting
 
 Serial pc(USBTX, USBRX);
 DigitalOut led1(LED_RED);
-
-
-void clamp(float * in, float min, float max);
-float pid(float setpoint, float measurement);
-volatile bool looptimerflag;
 HIDScope scope(2);
 
+//motor 25D
+Encoder motor1(PTD3,PTD5); //wit, geel
+PwmOut pwm_motor1(M2_PWM);
+DigitalOut motordir1(M2_DIR);
 
-void setlooptimerflag(void)
+//motor2 37D
+Encoder motor2(PTD2, PTD0); //wit, geel
+PwmOut pwm_motor2(M1_PWM);
+DigitalOut motordir2(M1_DIR);
+
+bool flip=false;
+
+void attime()
 {
-    looptimerflag = true;
+    flip = !flip;
 }
 
+void looper()
+{
+    motordir1=0;
+    pwm_motor1.write(1);
+    scope.set(0, motor1.getPosition());
+    scope.set(1, motor2.getPosition());
+    scope.send();
+}
 
 
 int main()
 {
-    //Let op dat de jumpers goed staan als het motortje niet wilt draaien. De E1 jumper moet onder de nummer 7 pin. De locatie van de M1 pin
-    //bepaalt of de motor CW of CCW draait.
-    //start Encoder-> first pin should be PTDx or PTAx, second pin doesn't matter
-
-    //motor 25D
-    Encoder motor1(PTD3,PTD5); //wit, geel
-    PwmOut pwm_motor1(M2_PWM); //
-    pwm_motor1.period_us(75); //10kHz PWM frequency
-    DigitalOut motordir1(M2_DIR);
-
-//motor2 37D
-    Encoder motor2(PTD2, PTD0); //wit, geel
-    PwmOut pwm_motor2(M1_PWM);
-    pwm_motor2.period_us(75);
-    DigitalOut motordir2(M1_DIR);
-
-    //char c ='0';
+    Ticker log_timer;
+    Ticker timer;
+    log_timer.attach(looper, TSAMP);
+    timer.attach(&attime, 7);
     while(1) {
-        wait(13);
-        pwm_motor1.write(1);
 
-
-
-
-        wait(0.01);
-        scope.set(0, motor1.getPosition());
-        scope.set(1, motor2.getPosition());
-        scope.send();
-        /*do {
-
-            if(pc.readable()) {
-                c = pc.getc();
-            }
-        } while((c !='1'));
-
-        c = '0';
-        pwm_motor1.write(0.5);
-        motordir1.write(0);
-        wait(3);
-
-        }*/
     }
 }