ライブラリ化を行った後

Dependencies:   QEI accelerator bit_test cyclic_io cyclic_var cylinder event_var limit mbed mecanum motor_drive pid pid_encoder rs422_put sbdbt servo

Fork of 17robo_Practice1 by kusano kiyoshige

Revision:
0:bf96e953cdb8
diff -r 000000000000 -r bf96e953cdb8 motor_drive.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motor_drive.h	Mon Jun 26 09:59:14 2017 +0000
@@ -0,0 +1,51 @@
+/*
+MotorDrive Name(cw, ccw, pwm);
+
+setup(Frequency, DutyLimit)
+MotorDrive関数のセットアップ
+pwm周波数,pwmの最高値を決める
+
+output(duty)
+dutyを出力する
+*/
+
+class MotorDrive
+{
+public  :
+    MotorDrive (PinName Cw, PinName Ccw, PinName Pwm) : cw(Cw), ccw(Ccw), pwm(Pwm) {
+        cw      = 0;
+        ccw     = 0;
+        pwm     = 0;
+    }
+
+    void setup(float Frequency, float Dutylimit) {
+        float Period = 1 / Frequency;
+        pwm.period(Period);
+        limit = Dutylimit;
+    }
+
+    void output(float duty) {
+        if (duty > 0) {
+            ccw  = 0;
+            cw  = 1;
+            if (duty > limit) {
+                duty = limit;
+            }
+        } else {
+            cw  = 0;
+            ccw  = 1;
+            if (duty < -limit) {
+                duty = -limit;
+            }
+        }
+        
+        pwm = fabs(duty);
+    }
+
+private :
+    DigitalOut cw;
+    DigitalOut ccw;
+    PwmOut pwm;
+    
+    float limit;
+};
\ No newline at end of file