2 sec interval: rechtsom, linksom, pauze

Dependencies:   Encoder HIDScope MODSERIAL mbed-dsp mbed

Fork of BMT-M9_motorcontrol_groep3 by Aukie Hooglugt

Files at this revision

API Documentation at this revision

Comitter:
Hooglugt
Date:
Mon Oct 20 08:13:51 2014 +0000
Parent:
16:1869377fbb73
Commit message:
step function send to motor 1 and motor 2, (rotates right, left, then pauses)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 1869377fbb73 -r 055edbd6ba9d main.cpp
--- a/main.cpp	Fri Oct 17 10:57:44 2014 +0000
+++ b/main.cpp	Mon Oct 20 08:13:51 2014 +0000
@@ -6,8 +6,8 @@
 
 void clamp(float * in, float min, float max);
 volatile bool looptimerflag;
-HIDScope scope(2);
-float new_pwm = 2;
+HIDScope scope(3);
+float new_pwm = 0;
 
 void setlooptimerflag(void)
 {
@@ -21,28 +21,33 @@
 
 void looper()
 {
-    if (new_pwm==2) { // 2 en -2 om aan te tonen dat clamp function ook werkt
-        new_pwm = -2;
+    if (new_pwm==1) {
+        new_pwm = -1;
     } else {
-        new_pwm = 2;
+        if (new_pwm==-1) {
+            new_pwm = 0;
+        } else {
+            if (new_pwm==0) {
+                new_pwm = 1;
+            }
+        }
     }
 }
 
-
 int main()
 {
     //motor 1, 25D
     Encoder motor1(PTD3, PTD5);
     DigitalOut motor1dir(PTC9);
     PwmOut pwm_motor1(PTC8);
-    pwm_motor.period_us(100); //10kHz PWM frequency
+    pwm_motor1.period_us(100); //10kHz PWM frequency
 
     //motor 2, 25D
     Encoder motor2(PTD2,PTD0);
     DigitalOut motor2dir(PTA4);
     PwmOut pwm_motor2(PTA5);
+    pwm_motor2.period_us(100); //10kHz PWM frequency
 
-    pwm_motor.period_us(100); //10kHz PWM frequency
     Ticker looptimer;
     looptimer.attach(setlooptimerflag,TSAMP);
     Ticker flip_switch;
@@ -55,14 +60,21 @@
         clamp(&new_pwm, -1,1);
 
         scope.set(0, new_pwm);
-        scope.set(1, motor2.getPosition());
+        scope.set(1, motor1.getPosition());
+        scope.set(2, motor2.getPosition());
         scope.send();
 
         if(new_pwm > 0)
+            motor1dir = 0;
+        else
+            motor1dir = 1;
+
+        if(new_pwm > 0)
             motor2dir = 0;
         else
             motor2dir = 1;
 
+        pwm_motor1.write(abs(new_pwm));
         pwm_motor2.write(abs(new_pwm));
     }
 }
\ No newline at end of file