Script voor aansturen motoren

Dependencies:   Encoder HIDScope MODSERIAL mbed-dsp mbed

Revision:
9:18e7a0273106
Parent:
8:0bbbe93bd1c4
Child:
10:a2a2e7bfdc86
--- a/main.cpp	Mon Oct 27 13:13:01 2014 +0000
+++ b/main.cpp	Mon Oct 27 19:32:52 2014 +0000
@@ -1,8 +1,10 @@
 #include "mbed.h"
 #include "encoder.h"
 #include "HIDScope.h"
+#include "MODSERIAL.h"
 
-#define TSAMP 0.001
+
+#define TSAMP 0.01
 #define K_P (0.1)
 #define K_I (0.03  *TSAMP)
 #define K_D (0.001 /TSAMP)
@@ -17,15 +19,15 @@
 
 Serial pc(USBTX, USBRX);
 DigitalOut led1(LED_RED);
-HIDScope scope(3);
+HIDScope scope(4);
 
 //motor 25D
-Encoder motor1(PTD3,PTD5); //wit, geel
+Encoder motor1(PTD3,PTD5,true); //wit, geel
 PwmOut pwm_motor1(M2_PWM);
 DigitalOut motordir1(M2_DIR);
 
 //motor2 37D
-Encoder motor2(PTD2, PTD0); //wit, geel
+Encoder motor2(PTD2, PTD0,true); //wit, geel
 PwmOut pwm_motor2(M1_PWM);
 DigitalOut motordir2(M1_DIR);
 
@@ -39,10 +41,11 @@
 void looper()
 {
     motordir1=0;
-    pwm_motor1.write(0.06);
+    pwm_motor1.write(1);
     scope.set(0, motor1.getPosition());
     scope.set(1, motor1.getSpeed());
     scope.set(2, motor2.getPosition());
+    scope.set(3, motor2.getPosition());
     scope.send();
 }
 
@@ -66,7 +69,6 @@
 
 int main()
 {
-    wait(1);
     /*motordir1=0;
     pwm_motor1.period_us(100);
     pwm_motor1.write(1);
@@ -77,12 +79,16 @@
     pwm_motor1.write(1);
     wait(0.034);
     pwm_motor1.write(0);*/
+
+
     Ticker log_timer;
     Ticker timer;
     log_timer.attach(looper, TSAMP);
     timer.attach(&attime, 7);
 
+    pc.baud(115200);
     while(1) {
-
+        wait(0.2);
+        pc.printf("pos: %d, speed %f \r\n", motor1.getPosition(), motor1.getSpeed());
     }
 }