Motor

Dependents:   Nucleo_spi 2015_denziben_i2c_S2 Nucleo_Motor Nucleo_Motor ... more

Files at this revision

API Documentation at this revision

Comitter:
kikoaac
Date:
Sun Aug 07 12:45:33 2016 +0000
Parent:
4:56a1159c881c
Commit message:
motordrive IC;

Changed in this revision

Motor.cpp Show annotated file Show diff for this revision Revisions of this file
Motor.h Show annotated file Show diff for this revision Revisions of this file
diff -r 56a1159c881c -r 3b639d84a95d Motor.cpp
--- a/Motor.cpp	Fri Oct 30 12:47:35 2015 +0000
+++ b/Motor.cpp	Sun Aug 07 12:45:33 2016 +0000
@@ -3,7 +3,7 @@
  */
 #include "Motor.h"
 Motor::Motor(const Motor& m):
-    motor(m.Pin[0],m.Pin[1],m.Pin[2],m.Pin[3]),PwmPin(m.Pin[4])
+    mode(m.Pin[0],m.Pin[1]),PwmPin(m.Pin[2])
 {
     bias=0.0;
     max=m.max;
@@ -12,14 +12,12 @@
     run(Stop,1);
 }
 
-Motor::Motor(PinName _pin_h1, PinName _pin_g2, PinName _pin_g1, PinName _pin_h2,PinName _pwm) :
-    motor(_pin_h1,_pin_g2,_pin_g1,_pin_h2),PwmPin(_pwm)
+Motor::Motor(PinName _pin1, PinName _pin2,PinName _pwm) :
+    mode(_pin1,_pin2),PwmPin(_pwm)
 {
-     Pin[0] = _pin_h1;
-    Pin[1] = _pin_g2;
-    Pin[2] = _pin_g1;
-    Pin[3] = _pin_h2;
-    Pin[4] = _pwm;
+    Pin[0] = _pin1;
+    Pin[1] = _pin2;
+    Pin[2] = _pwm;
     max=1.0;
     //this
     PwmPin.period_ms(10);
@@ -33,17 +31,13 @@
     //if(state==i)return;
     PwmPin = Duty;
     if(state==i)return;
-    motor=0;
-    //wait_us(20);
-    /*t.start();
-    t.reset();
-    while(t.read_us()>=20);*/
-    wait_us(200);
-    if(i==Front) motor=0x01|0x04;
-    else if(i==Back) motor=0x02|0x08;
-    else if(i==Stop) motor=0x01|0x08;
-    else if(i==Free) motor=0x00|0x00;
-    else motor=0;
+    mode=0;
+    wait_us(20);
+    if(i==Free) mode=0x00;
+    else if(i==Back) mode=0x01|0x00;
+    else if(i==Front) mode=0x00|0x02;
+    else if(i==Stop) mode=0x01|0x02;
+    else mode=0x00;
     state=i;
 }
 
diff -r 56a1159c881c -r 3b639d84a95d Motor.h
--- a/Motor.h	Fri Oct 30 12:47:35 2015 +0000
+++ b/Motor.h	Sun Aug 07 12:45:33 2016 +0000
@@ -8,7 +8,7 @@
 #define Stop 3
 #define Free 4
 class Motor {
-protected : PinName Pin[5];
+protected : PinName Pin[3];
     float bias;
     Motor(const Motor& m);
     Motor& operator=(const Motor &m) {
@@ -16,17 +16,17 @@
     }
 public:
 
-    Motor(PinName _pin_h1, PinName _pin_g2, PinName _pin_g1, PinName _pin_h2,PinName _pwm);
+    Motor(PinName _pin1, PinName _pin2,PinName _pwm);
 
    
     Motor& operator= (float duty)
     {
-        if(duty<-0.1F)
+        if(duty<-0.01F)
         {
             duty*=-1;
             run(Back,duty);
         }
-        else if(float(duty)>0.1F)
+        else if(float(duty)>0.01F)
         {
             run(Front,duty);
         }
@@ -46,7 +46,7 @@
 private:
     int state;
     float Duty;
-    BusOut motor;
+    BusOut mode;
     PwmOut PwmPin;
 };