2017 hongo b team

Dependents:   CtrlMD 2017_Bteam_alpha_slave

Files at this revision

API Documentation at this revision

Comitter:
Komazawa_sun
Date:
Fri Sep 08 03:31:04 2017 +0000
Commit message:
????;

Changed in this revision

MD10c.cpp Show annotated file Show diff for this revision Revisions of this file
MD10c.h 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
TS120.cpp Show annotated file Show diff for this revision Revisions of this file
TS120.h Show annotated file Show diff for this revision Revisions of this file
ThrowData_MD.cpp Show annotated file Show diff for this revision Revisions of this file
ThrowData_MD.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r be058264e889 MD10c.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MD10c.cpp	Fri Sep 08 03:31:04 2017 +0000
@@ -0,0 +1,28 @@
+#include "MD10c.h"
+
+MD10c::MD10c(PinName dir_pin, PinName pwm_pin, bool _dir_flip)
+:   dir_out(dir_pin), 
+    pwm_out(pwm_pin)
+{
+    dir_flip = _dir_flip;
+}
+
+void MD10c::drive(double _pwm)
+{
+    bool dir = (dir_flip == false)?0 <= _pwm :0 >= _pwm;
+    double pwm = fabs(_pwm);
+    
+    dir_out.write(dir);
+    pwm_out.write(pwm);
+    
+}
+
+void MD10c::drive(signed int _pwm, unsigned int max_pwm_abs)
+{
+    bool dir = (dir_flip == false)?0 <= _pwm :0 >= _pwm;
+    double pwm = fabs((double)(max_pwm_abs / _pwm));
+    
+    dir_out.write(dir);
+    pwm_out.write(pwm);
+    
+}
\ No newline at end of file
diff -r 000000000000 -r be058264e889 MD10c.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MD10c.h	Fri Sep 08 03:31:04 2017 +0000
@@ -0,0 +1,19 @@
+#ifndef MOTOR_DRIVER_MD10C_H
+#define MOTOR_DRIVER_MD10C_H
+
+#include "mbed.h"
+#include "MotorDriver.h"
+
+class MD10c : public MotorDriver
+{
+    public:
+        MD10c(PinName dir_pin, PinName pwm_pin, bool _dir_flip = false);
+        virtual void drive(double _pwm);
+        virtual void drive(signed int _pwm, unsigned int max_pwm_abs = 127);
+    private:
+        bool dir_flip;
+        DigitalOut dir_out;
+        PwmOut pwm_out;
+};
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r be058264e889 MotorDriver.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MotorDriver.h	Fri Sep 08 03:31:04 2017 +0000
@@ -0,0 +1,11 @@
+#ifndef MOTOR_DRIVER_H
+#define MOTOR_DRIVER_H
+
+class MotorDriver
+{
+    public:
+        virtual void drive(double _pwm) = 0;
+        virtual void drive(signed int _pwm, unsigned int max_pwm_abs = 127) = 0;
+};
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r be058264e889 TS120.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TS120.cpp	Fri Sep 08 03:31:04 2017 +0000
@@ -0,0 +1,47 @@
+#include "TS120.h"
+
+TS120::TS120(PinName pwm_pin, bool _dir_flip, double _flont_range, double _back_range)
+:   pwm_out(pwm_pin)
+{
+    dir_flip = _dir_flip;
+    flont_range = _flont_range;
+    back_range = _back_range;
+    
+    drive(0);
+    wait_ms(100);
+}
+
+void TS120::drive(double _pwm)
+{
+    double pwm = _pwm;
+    
+    if(dir_flip == true)
+        pwm *= -1;
+        
+    if(_pwm > 0.0)
+        pwm *= flont_range;
+    else
+        pwm *= back_range;
+        
+    int pwm_us = (int)((pwm_max - pwm_min) / 2) * (pwm + 1) + pwm_min; 
+     
+    pwm_out.pulsewidth_us(pwm_us);  
+}
+
+void TS120::drive(signed int _pwm, unsigned int max_pwm_abs)
+{
+    
+    double pwm = (double)((1 / max_pwm_abs) * _pwm);
+    
+    if(dir_flip == true)
+        pwm *= -1;
+        
+    if(pwm > 0.0)
+        pwm *= flont_range;
+    else
+        pwm *= back_range;
+        
+    int pwm_us = (int)((pwm_max - pwm_min) / 2) * (pwm + 1) + pwm_min; 
+      
+    pwm_out.pulsewidth_us(pwm_us);
+}
\ No newline at end of file
diff -r 000000000000 -r be058264e889 TS120.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TS120.h	Fri Sep 08 03:31:04 2017 +0000
@@ -0,0 +1,22 @@
+#ifndef MOTOR_DRIVER_TS120_H
+#define MOTOR_DRIVER_TS120_H
+
+#include "mbed.h"
+#include "MotorDriver.h"
+
+class TS120 : public MotorDriver
+{
+    public:
+        TS120(PinName pwm_pin, bool _dir_flip = false, double _flont_range = 1, double _back_range = 1);
+        virtual void drive(double _pwm);
+        virtual void drive(signed int _pwm, unsigned int max_pwm_abs = 127);
+    private:
+        bool dir_flip;
+        double flont_range;
+        double back_range;
+        PwmOut pwm_out;
+        static const int pwm_max = 2000;
+        static const int pwm_min = 1000;
+};
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r be058264e889 ThrowData_MD.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ThrowData_MD.cpp	Fri Sep 08 03:31:04 2017 +0000
@@ -0,0 +1,20 @@
+#include "ThrowData_MD.h"
+
+ThrowData::ThrowData(int _max_dig, bool _dir_flip)
+:   max_dig(_max_dig), dir_flip(_dir_flip)
+{
+}
+
+void ThrowData::drive(double _pwm)
+{
+    _target_data = (int)max_dig * _pwm;
+}
+
+void ThrowData::drive(signed int _pwm, unsigned int max_pwm_abs)
+{
+    _target_data = _pwm;
+}
+
+int ThrowData::get_output(){
+    return _target_data;
+}
\ No newline at end of file
diff -r 000000000000 -r be058264e889 ThrowData_MD.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ThrowData_MD.h	Fri Sep 08 03:31:04 2017 +0000
@@ -0,0 +1,19 @@
+#ifndef THROW_DATA_H
+#define THROW_DATA_H
+
+#include "MotorDriver.h"
+
+class ThrowData : public MotorDriver
+{
+    public:
+        ThrowData(int _max_dig = 255, bool _dir_flip = false);
+        virtual void drive(double _pwm);
+        virtual void drive(signed int _pwm, unsigned int max_pwm_abs = 0);
+        int get_output();
+    private:
+        int max_dig;
+        bool dir_flip;
+        int _target_data;
+};
+
+#endif
\ No newline at end of file