ライントレーサー制御用のプログラムです.

Dependencies:   mbed

Revision:
0:e9af471e2a2b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motor.cpp	Thu Nov 16 06:15:58 2017 +0000
@@ -0,0 +1,77 @@
+
+#include "motor.h"
+BusOut leftc(PTA1,PTA2);
+PwmOut leftp(PTD4);
+
+BusOut rightc(PTC0,PTC7);
+PwmOut rightp(PTA12);
+
+PwmOut handle(PTC9);
+
+//start code for servo
+void servoInit(){
+    handle.period(0.020);
+    handle.pulsewidth(0.00155);
+    wait(0.5);
+}
+
+
+void rotate(PwmOut servo,float ppulse,float *npulse){
+    if(ppulse > *npulse){
+        if(ppulse > 0.002){
+            ppulse = 0.002;
+        }
+        servo.pulsewidth(ppulse); // servo position determined by a pulsewidth between 1-2ms
+        wait(1000.0 * 0.06 * ((ppulse - (*npulse)) / 0.1));
+    }
+    else {
+        if(ppulse < 0.0011){
+            ppulse = 0.0011;
+        }
+        servo.pulsewidth(ppulse); // servo position determined by a pulsewidth between 1-2ms
+        wait(1000.0 * 0.06 * (((*npulse) - ppulse) / 0.1));
+    }
+    *npulse = ppulse;
+}
+
+/*
+float rotate(PwmOut servo,float ppulse){
+    static float npulse = 0.00155;
+    if(ppulse > npulse){
+        if(ppulse > 0.002){
+            ppulse = 0.002;
+        }
+        servo.pulsewidth(ppulse); // servo position determined by a pulsewidth between 1-2ms
+        wait(1000.0 * 0.06 * ((ppulse - (npulse)) / 0.1));
+    }
+    else {
+        if(ppulse < 0.0011){
+            ppulse = 0.0011;
+        }
+        servo.pulsewidth(ppulse); // servo position determined by a pulsewidth between 1-2ms
+        wait(1000.0 * 0.06 * (((npulse) - ppulse) / 0.1));
+    }
+    npulse = ppulse;
+    return npulse;
+}
+*/
+//end
+
+//start code for DCmotor
+void motorInit(){
+    leftc = 0;
+    leftp = 1.0f;
+    rightc = 0;
+    rightp = 1.0f;
+}
+
+void start(){
+    leftc = 1;
+    rightc = 1;
+}
+
+void stop(){
+    leftc = 0;
+    rightc = 0;
+}
+//end
\ No newline at end of file