motordrive

Dependents:   MotorIdentification MotorPIcontrol Motor_P_PositionControl

Files at this revision

API Documentation at this revision

Comitter:
porizou3
Date:
Mon Mar 18 04:46:47 2019 +0000
Commit message:
commit;

Changed in this revision

motordriver.cpp Show annotated file Show diff for this revision Revisions of this file
motordriver.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motordriver.cpp	Mon Mar 18 04:46:47 2019 +0000
@@ -0,0 +1,28 @@
+#include "motordriver.h"
+
+Motor::Motor(PinName pwm , PinName fwd , PinName rev , float frequency):
+             pwm_(pwm) , fwd_(fwd) , rev_(rev) , frequency_(frequency) {
+
+    pwm_.period(1/frequency_); // PWM周期の設定
+    pwm_ = 0.0;
+
+    fwd_ = 0;
+    rev_ = 0;
+
+}
+
+void Motor::rotate(float speed) {
+    /* speedを-1.0~1.0の範囲に設定 */
+    if(speed > 1.0) speed =  1.0;
+    if(speed <-1.0) speed = -1.0;
+    
+    fwd_ = (speed > 0.0);
+    rev_ = (speed < 0.0);
+    pwm_ = fabs(speed);
+}
+
+void Motor::brake(void) {
+    fwd_ = 1;
+    rev_ = 1;
+    pwm_ =  1.0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motordriver.h	Mon Mar 18 04:46:47 2019 +0000
@@ -0,0 +1,113 @@
+#ifndef __motordriver_h
+#define __motordriver_h
+
+/**
+ * Includes
+ */
+#include "mbed.h"
+
+class Motor {
+
+public:
+    /*
+     * pwm --- PwmOut pin
+     * fwd --- DigitalOut pin モーター正転
+     * rev --- DigitalOut pin モーター逆転
+     */
+    Motor(PinName pwm , PinName fwd , PinName rev , float frequency);
+
+    /* --- モーター回転 --- */
+    void rotate(float speed);
+
+    /* --- モーターHブレーキ ---*/
+    void brake(void);
+
+private:
+    
+    PwmOut     pwm_;
+    DigitalOut fwd_;
+    DigitalOut rev_;
+    float frequency_; //PWM周波数
+
+};
+
+
+#endif /* __motordriver_h */
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+             #ifndef __motordriver_h
+#define __motordriver_h
+
+/**
+ * Includes
+ */
+#include "mbed.h"
+
+class Motor {
+
+public:
+    /*
+     * pwm --- PwmOut pin
+     * fwd --- DigitalOut pin モーター正転
+     * rev --- DigitalOut pin モーター逆転
+     */
+    Motor(PinName pwm , PinName fwd , PinName rev , float frequency);
+
+    /* --- モーター回転 --- */
+    void rotate(float speed);
+
+    /* --- モーターHブレーキ ---*/
+    void brake(void);
+
+private:
+    
+    PwmOut     pwm_;
+    DigitalOut fwd_;
+    DigitalOut rev_;
+    float frequency_; //PWM周波数
+
+};
+
+
+#endif /* __motordriver_h */
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+             
\ No newline at end of file