シリアル

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
e5115026
Date:
Tue Nov 28 10:01:32 2017 +0000
Commit message:
????

Changed in this revision

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 886eded5868a main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 28 10:01:32 2017 +0000
@@ -0,0 +1,44 @@
+//
+//  Sample "SaberTooth_serial"
+//  2012/10/06 created by matsuo@edu.teu.ac.jp
+//  2014/06/13 revised by matsuo@edu.teu.ac.jp
+
+#include "mbed.h"
+
+//AnalogIn aIn_1(p19);    // Command input 1(0.0 to 1.0).
+//AnalogIn aIn_2(p20);    // Command input 2(0.0 to 1.0).
+
+Serial pc(USBTX, USBRX); // tx, rx for PC terminal.
+Serial sabertooth(p28, p27);  // tx, rx for Sabertooth.
+double moterDeg;
+double deg[3];
+
+
+void getDeg()
+{
+    deg[0]=pc.getc()-48;
+    deg[1]=pc.getc()-48;
+    deg[2]=pc.getc()-48;
+    
+    moterDeg=deg[0]+deg[1]*0.1+deg[2]*0.01;
+    pc.printf("%lf\t",moterDeg);
+    }
+
+int main()
+{
+    sabertooth.baud(19200); // Set baudrate of serial port for Sabertooth.
+    int cmd_1=0;
+    sabertooth.putc(0);   // Send "Stop" to Motor 1 and 2.
+    pc.attach(getDeg,Serial::RxIrq);
+    while (1) {
+        cmd_1 = (int)(moterDeg * 126 + 1); // Convert aIn_1 from 0.0-1.0 to 1-127.
+        //cmd_2 = (int)(aIn_2*126+128); // Convert aIn_2 from 0.0-1.0 to 128-255.
+
+        sabertooth.putc(cmd_1);   // Output cmd_1 to Motor 1.
+        //sabertooth.putc(cmd_2);   // Output cmd_2 to Motor 2.
+
+        pc.printf("%d\t", cmd_1);
+
+        wait_ms(10);
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 886eded5868a mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Nov 28 10:01:32 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721
\ No newline at end of file