Motor testing program

Dependencies:   MODSERIAL QEI mbed

Files at this revision

API Documentation at this revision

Comitter:
kbruil
Date:
Tue Oct 18 11:09:46 2016 +0000
Commit message:
Motor test v1

Changed in this revision

MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
QEI.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 8030c143e37e MODSERIAL.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Tue Oct 18 11:09:46 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/MODSERIAL/#4737f8a5b018
diff -r 000000000000 -r 8030c143e37e QEI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Tue Oct 18 11:09:46 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
diff -r 000000000000 -r 8030c143e37e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 18 11:09:46 2016 +0000
@@ -0,0 +1,52 @@
+#include "mbed.h"
+#include "QEI.h"
+#include "MODSERIAL.h"
+
+
+MODSERIAL pc(USBTX, USBRX);
+DigitalOut motor1dir(D7);
+PwmOut motor1pwm(D6);
+
+void setmotor1(float val){
+    if (val>=0){
+        if (val > 1) {
+            val = 1.0f;
+        }
+        motor1dir.write(1);
+        motor1pwm.write(val);
+    }
+    else {
+        if (val < -1) {
+            val = -1.0f;
+        }
+        motor1dir.write(0);
+        motor1pwm.write(fabs(val));
+    }
+    printf("pwm: %.2f", fabs(val));
+}
+
+int main()
+{
+    float w = 0.05f;
+    
+    motor1pwm.period_us(1000);
+    pc.baud(115200);
+    while (true) {
+        for(float i=0;i<=1;i=i+0.1f){
+            printf("i: %.2f\n\r",i);
+            setmotor1(i);
+            wait(w);
+        }
+        for(float i=1;i>=-1;i=i-0.1f){
+            printf("i: %.2f\n\r",i);
+            setmotor1(i);
+            wait(w);
+        }
+        for(float i=-1;i<=0;i=i+0.1f){
+            printf("i: %.2f\n\r",i);
+            setmotor1(i);
+            wait(w);
+        }
+        
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 8030c143e37e mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Oct 18 11:09:46 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3
\ No newline at end of file