first

Dependents:   17robo_fuzi 17robo_tokyo_kaede

Files at this revision

API Documentation at this revision

Comitter:
echo_piyo
Date:
Sun Sep 24 05:24:19 2017 +0000
Commit message:
????2??

Changed in this revision

motor_drive.cpp Show annotated file Show diff for this revision Revisions of this file
motor_drive.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motor_drive.cpp	Sun Sep 24 05:24:19 2017 +0000
@@ -0,0 +1,36 @@
+#include "motor_drive.h"
+
+MotorDrive::MotorDrive (PinName Direction,PinName Pwm) : direction(Direction), pwm(Pwm){
+    direction = 0;
+    pwm    = 0;
+}
+
+void MotorDrive::setup(float frequency, float acceleration, float timerCycle){
+    float period = 1/frequency;
+    pwm.period(period);
+    a = acceleration*timerCycle;
+}
+
+void MotorDrive::output(float targetDuty){
+    if (fabs(targetDuty-duty) <= a) {
+        duty = targetDuty;
+    } else if (duty < targetDuty) {
+        duty = duty + a;
+    } else if (duty > targetDuty) {
+        duty = duty - a;
+    }
+    
+    if (duty < 0) {
+        direction  = 1;
+        if (duty > DUTY_LIMIT) {
+            duty = DUTY_LIMIT;
+        }
+    } else {
+        direction  = 0;
+        if (duty < -DUTY_LIMIT) {
+            duty = -DUTY_LIMIT;
+        }
+    }
+
+    pwm = fabs(duty);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motor_drive.h	Sun Sep 24 05:24:19 2017 +0000
@@ -0,0 +1,37 @@
+/*
+MotorDrive Name(cw_ccw, pwm);
+
+setup(float frequency, float acceleration, float timerCycle);
+MotorDrive関数のセットアップ
+frequency    : pwmの周波数[Hz]
+acceleration : 加速度[m/s^2]
+timerCycle   : outputを呼び出す周期[s]
+
+output(duty)
+dutyになるように出力する
+*/
+
+#ifndef MBED_MOTOR_DRIVE_H
+#define MBED_MOTOR_DRIVE_H
+
+#include "mbed.h"
+
+#define DUTY_LIMIT   0.95
+
+class MotorDrive
+{
+public  :
+    MotorDrive (PinName Direction,PinName Pwm);
+
+    void setup(float frequency, float acceleration, float timerCycle);
+
+    void output(float targetDuty);
+
+private :
+    DigitalOut direction;
+    PwmOut pwm;
+    float a;
+    float duty;
+};
+
+#endif
\ No newline at end of file