PAC: Avionics Team / Mbed 2 deprecated airbrake_motor

Dependencies:   mbed QEI

Fork of airbrake_motor by Zheyuan Xie

Files at this revision

API Documentation at this revision

Comitter:
zxie
Date:
Sat Jun 08 20:50:14 2019 +0000
Commit message:
publish

Changed in this revision

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Sat Jun 08 20:50:14 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/aberk/code/QEI/#5c2ad81551aa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jun 08 20:50:14 2019 +0000
@@ -0,0 +1,42 @@
+#include "QEI.h"
+
+Serial pc(USBTX, USBRX);
+RawSerial smc(PC_6, PA_12);
+//Use X2 encoding by default.
+QEI wheel (PC_8, PC_5, NC, 624);
+
+Ticker ctrl_tick;
+
+int tgt = 5000;
+
+void ctrl_event() {
+    static int rot = 0;
+    static int output = 0;
+    rot = wheel.getPulses();
+    pc.printf("Pulses is: %i\n\r", rot);
+    int err = tgt - rot;
+    if (err > 0) {
+        err = err;
+        output = (err * 0.1);
+        if (output > 127) output = 127;
+        smc.putc(0x8A);
+        smc.putc((uint8_t)output);
+    } else {
+        err =  -err;
+        output = (err * 0.1);
+        if (output > 127) output = 127;
+        smc.putc(0x89);
+        smc.putc(output);
+    }
+}
+ 
+int main() {
+    pc.baud(115200);
+    smc.baud(115200);
+    ctrl_tick.attach(&ctrl_event, 0.1);
+    while(1){
+        wait(5);
+        if (tgt != 0) tgt = 0;
+        else tgt = 5000;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Jun 08 20:50:14 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file