Author: jaguarondi
Date: 2008-08-26 11:23:32 +0200 (Tue, 26 Aug 2008)
New Revision: 1587

Modified:
   firmware/tuxcore/trunk/motors.c
Log:
* Added a timeout protection on each motor.


Modified: firmware/tuxcore/trunk/motors.c
===================================================================
--- firmware/tuxcore/trunk/motors.c     2008-08-26 08:32:36 UTC (rev 1586)
+++ firmware/tuxcore/trunk/motors.c     2008-08-26 09:23:32 UTC (rev 1587)
@@ -44,19 +44,25 @@
 /** Delay during which the motor is inverted when braking the eyes to stop them
  * in the close position. There's no need to brake the motor when opening the
  * eyes with this gearbox design. */
-#define EYES_BRAKING_DLY 4
+#define EYES_BRAKING_DLY 8
 /** Protection timeout for the eyes. */
 #define EYES_TIMEOUT 100
+/** Protection timeout for the mouth. */
+#define MOUTH_TIMEOUT 100
 /** Delay during which the motor is inverted when braking the mouth to stop it
  * in the open or close position. */
 #define MOUTH_BRAKING_DLY 8
 /** Delay during which the motor is inverted when braking the spinning. Braking
  * here is necessary to improve the accuracy of the absolute position. */
 #define SPIN_BRAKING_DLY 10
+/** Protection timeout for spinning. */
+#define SPIN_TIMEOUT 250
 /** Delay during which the motor is inverted when braking the flippers to stop
  * them either up or down. If we don't brake here, the flippers end up in a
  * medium position. */
 #define FLIPPERS_BRAKING_DLY 4
+/** Protection timeout for the flippers. */
+#define FLIPPERS_TIMEOUT 250
 /*! @} */
 /** Init value of the timer used to reset the flippers in the low position. */
 #define FLIP_TIMER_INIT 0xFF
@@ -90,9 +96,8 @@
  * positions. */
 uint8_t flippers_timer;
 /** Period taken by the previous movement of the flippers. */
-uint8_t flippers_revious_timer;
+uint8_t flippers_previous_timer;
 
-uint8_t flippers_stop_timeout;
 /** Number of periods remaining before stopping the rotation.
  * Normally used when braking, to stop the motor after a short period of
  * inversion. */
@@ -110,6 +115,17 @@
 /** Spinning direction */
 static uint8_t spin_direction;
 
+/** Flag byte to indicate if the movement is specified by duration or not */
+uint8_t duration_movement;
+/** Eyes bit in duration_movement */
+#define EYES_FLAG _BV(0)
+/** Mouth bit in duration_movement */
+#define MOUTH_FLAG _BV(1)
+/** Flippers bit in duration_movement */
+#define FLIPPERS_FLAG _BV(2)
+/** Spin bit in duration_movement */
+#define SPIN_FLAG _BV(3)
+
 /** PWM mask register applied on the motor port on a regular basis to drive the
  * flippers and spinning. */
 uint8_t portB_PWM_mask;
@@ -192,6 +208,7 @@
         if (param & 0x01)
         {
             eyes_stop_delay = value;
+            duration_movement |= EYES_FLAG;
             cnt = 0;
         }
         else
@@ -203,6 +220,7 @@
         if (param & 0x01)
         {
             mouth_stop_delay = value;
+            duration_movement |= MOUTH_FLAG;
             cnt = 0;
         }
         else
@@ -214,6 +232,7 @@
         if (param & 0x01)
         {
             flippers_stop_delay = value;
+            duration_movement |= FLIPPERS_FLAG;
             cnt = 0;
         }
         else
@@ -225,6 +244,7 @@
         if (param & 0x01)
         {
             spin_stop_delay = value;
+            duration_movement |= SPIN_FLAG;
             cnt = 0;
         }
         else
@@ -333,6 +353,7 @@
 {
     gStatus.mot &= ~GSTATUS_MOT_EYES;
     eyes_move_counter = 0;
+    duration_movement &= ~EYES_FLAG;
     stop_eyes_motor();
 }
 
@@ -351,7 +372,8 @@
 {
     gStatus.mot |= GSTATUS_MOT_EYES;
     eyes_move_counter = cnt;
-    eyes_stop_delay = EYES_TIMEOUT;
+    if (!(duration_movement & EYES_FLAG))
+        eyes_stop_delay = EYES_TIMEOUT;
     run_eyes_motor();
 }
 
@@ -446,11 +468,13 @@
     if (eyes_move_counter)
     {
         eyes_move_counter--;
-        eyes_stop_delay = EYES_TIMEOUT;
+        if (!(duration_movement & EYES_FLAG))
+            eyes_stop_delay = EYES_TIMEOUT;
         if (!eyes_move_counter)
         {
             stop_eyes_motor();
-            invert_eyes_motor();
+            if (!(PSW_EYES_PIN & PSW_EYES_C_MK))
+                invert_eyes_motor();
             eyes_stop_delay = EYES_BRAKING_DLY;
          }
     }
@@ -495,6 +519,7 @@
 {
     gStatus.mot &= ~GSTATUS_MOT_MOUTH;
     mouth_move_counter = 0;
+    duration_movement &= ~MOUTH_FLAG;
     stop_mouth_motor();
 }
 
@@ -512,7 +537,8 @@
 {
     gStatus.mot |= GSTATUS_MOT_MOUTH;
     mouth_move_counter = cnt;
-    //mouth_stop_delay = 0;
+    if (!(duration_movement & MOUTH_FLAG))
+        mouth_stop_delay = MOUTH_TIMEOUT;
     run_mouth_motor();
 }
 
@@ -582,6 +608,8 @@
         if (mouth_move_counter)
         {
             mouth_move_counter--;
+            if (!(duration_movement & MOUTH_FLAG))
+                mouth_stop_delay = MOUTH_TIMEOUT;
             if (mouth_final_state != MOUTH_UNKNOWN)
             {
                 if ((mouth_final_state == MOUTH_OPEN) && !(PSW_MOUTH_PIN & 
PSW_MOUTH_O_MK))
@@ -641,6 +669,7 @@
 {
     gStatus.mot &= ~GSTATUS_MOT_WINGS;
     flippers_move_counter = 0;
+    duration_movement &= ~FLIPPERS_FLAG;
     stop_flippers_motor();
 }
 
@@ -662,7 +691,8 @@
     gStatus.mot |= GSTATUS_MOT_WINGS;
     flippers_move_counter = cnt;
     flippers_PWM = pwm;
-    //flippers_stop_delay = 0;
+    if (!(duration_movement & FLIPPERS_FLAG))
+        flippers_stop_delay = FLIPPERS_TIMEOUT;
     MOT_FLIPPERS_BW_PT &= ~MOT_FLIPPERS_BW_MK;
     flippers_PWMMask |= MOT_FLIPPERS_FW_MK;
     PORTB |= flippers_PWMMask;
@@ -770,21 +800,21 @@
         {
             if (flippers_move_counter == 1)
             {
-                if ((flippers_revious_timer) && (flippers_timer <
-                        (flippers_revious_timer - FLIPPERS_RESETTIMER_HYST)))
+                if ((flippers_previous_timer) && (flippers_timer <
+                        (flippers_previous_timer - FLIPPERS_RESETTIMER_HYST)))
                 {
                     /* flippers are down */
                     /* Position reached so init gStatus.pos bit to lower
                      * position */
                     gStatus.pos &= ~GSTATUS_POS_W0;
                     flippers_timer = 0;
-                    flippers_revious_timer = 0;
+                    flippers_previous_timer = 0;
                 }
                 else
                 {
                     /* Unknow position, execute another movement to determine
                      * it. */
-                    flippers_revious_timer = flippers_timer;
+                    flippers_previous_timer = flippers_timer;
                     flippers_timer = FLIP_TIMER_INIT;
                     return;
                 }
@@ -796,6 +826,8 @@
         if (flippers_move_counter)
         {
             flippers_move_counter--;
+            if (!(duration_movement & FLIPPERS_FLAG))
+                flippers_stop_delay = FLIPPERS_TIMEOUT;
             if (!flippers_move_counter)
             {
                 stop_flippers_motor();
@@ -825,6 +857,7 @@
 {
     gStatus.mot &= ~GSTATUS_MOT_SPIN_MK;
     spin_move_counter = 0;
+    duration_movement &= ~SPIN_FLAG;
     stop_spin_motor();
 }
 
@@ -846,6 +879,8 @@
         if (spin_move_counter)
             spin_move_counter++;
     spin_direction = LEFT;
+    if (!(duration_movement & SPIN_FLAG))
+        spin_stop_delay = SPIN_TIMEOUT;
     spin_PWM = pwm;
     spin_PWM_mask &= ~MOT_SPIN_R_MK;
     spin_PWM_mask |= MOT_SPIN_L_MK;
@@ -890,6 +925,8 @@
     {
         spin_move_counter--;
 
+        if (!(duration_movement & SPIN_FLAG))
+            spin_stop_delay = SPIN_TIMEOUT;
         if (!spin_move_counter)
         {
             spin_PWM_mask &= ~MOT_SPIN_MK;
@@ -951,7 +988,7 @@
         }
     }
 
-    /* Flippers braking (motor reversed) delay */
+    /* Flippers motor timeout */
     if (flippers_stop_delay)
     {
         flippers_stop_delay--;
@@ -962,7 +999,7 @@
         }
     }
 
-    /* eyes braking (motor reversed) delay */
+    /* eyes motor timeout */
     if (eyes_stop_delay)
     {
         eyes_stop_delay--;
@@ -972,7 +1009,7 @@
         }
     }
 
-    /* mouth braking (motor reversed) delay */
+    /* mouth motor timeout */
     if (mouth_stop_delay)
     {
         mouth_stop_delay--;
@@ -982,7 +1019,7 @@
         }
     }
 
-    /* spin braking (motor reversed) delay */
+    /* spin motor timeout */
     if (spin_stop_delay)
     {
         spin_stop_delay--;


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to