Robot's source code

Dependencies:   mbed

Revision:
40:83ce8d1072ef
Parent:
36:54f86bc6fd80
Child:
42:fcb48e2fc426
--- a/Asservissement/Motor.h	Mon Mar 16 21:46:12 2015 +0000
+++ b/Asservissement/Motor.h	Tue Mar 17 14:38:54 2015 +0000
@@ -6,8 +6,8 @@
 class Motor
 {
     private:
-        PwmOut* pwm;
-        DigitalOut* dir;
+        PwmOut pwm;
+        DigitalOut dir;
         bool inverse;
         float speed;
         
@@ -17,16 +17,16 @@
          * @param pwm Pin sur laquelle sort la PWM
          * @param dir Pin sur laquelle sort le bit de direction
          */
-        Motor(PwmOut* pwm, DigitalOut* dir)
+        Motor(PinName pin_pwm, PinName pin_dir): pwm(pin_pwm), dir(pin_dir)
         {
-            this->pwm = pwm;
-            this->dir = dir;
             inverse = false;
             speed = 0.0f;
-            this->pwm->period_us(10);    
+            pwm.period_us(10);  
+            pwm = 0.0f;  
             
         }
-        virtual ~Motor();
+        
+        virtual ~Motor(){}
 
         /** Fixe la vitesse du moteur
          *
@@ -34,16 +34,13 @@
          */
         void setSpeed(float s)
         {
-            if(s<= 1.0f && s >=-1.0f)
-            {
-                speed = fabs_(s);   
-                inverse = (s <= 0.0f);
-            }
+            float abs = fabs_(s);
+            speed = s;
+            pwm = abs;
+            if(s > 0)
+                dir = !inverse;
             else
-            {
-                speed = 0.0f;
-                inverse = false;
-            }    
+                dir = inverse;
         }
 
         /** Retourne la vitesse théorique du moteur
@@ -72,17 +69,6 @@
          *
          * @return True ou False
          */
-        bool setInverse(){return inverse;}    
+        bool getInverse(){return inverse;}    
         
-        void update(float s)
-        {
-            this->setSpeed(s);
-            
-            if(inverse)
-                dir->write(1);
-            else
-                dir->write(0);
-                
-            pwm->write(speed);   
-        }
 };
\ No newline at end of file