[tuxdroid-svn] r509 - firmware/tuxcore/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-09-11 14:30:23
|
Author: jaguarondi Date: 2007-09-11 16:29:55 +0200 (Tue, 11 Sep 2007) New Revision: 509 Modified: firmware/tuxcore/trunk/global.h firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/motors.h firmware/tuxcore/trunk/standalone.c Log: * Added doxygen comments on a couple of variables of the motor module. Some variables and macros have been renamed. * Fixed some indentation and removed a few lines of test code variables. Modified: firmware/tuxcore/trunk/global.h =================================================================== --- firmware/tuxcore/trunk/global.h 2007-09-11 14:07:55 UTC (rev 508) +++ firmware/tuxcore/trunk/global.h 2007-09-11 14:29:55 UTC (rev 509) @@ -29,17 +29,6 @@ #include <avr/io.h> #include "common/commands.h" -/* Control */ -#define EYES_OPEN_DLY 4 /* 4ms unit */ -#define EYES_ICLOSE_DLY 4 /* 4ms unit */ -#define MOUTH_OPEN_DLY 2 /* 4ms unit */ -#define MOUTH_ICLOSE_DLY 8 /* 4ms unit */ -#define SPIN_INTT_DLY 10 /* 4ms unit */ -#define SPIN_STOP_DLY 10 /* 4ms unit */ -#define WINGS_STOP_DLY 4 /* 4ms unit */ - -#define wingsPwmMask pwmMaskB -#define spinPwmMask pwmMaskB /* * -------------------------------------------------------- * STATUS @@ -67,7 +56,8 @@ * xxxxxxx0 === Wings lowered * xxxxxxx1 === Wings raised * xxxxxx0x === Motors stopped in a known position - * xxxxxx1x === Motors running or stopped in an unknown position. In this case, the previous bit means the last state the wings have passed in. */ + * xxxxxx1x === Motors running or stopped in an unknown position. In this + * case, the previous bit means the last state the wings have passed in. */ #define GSTATUS_POS_W0 0x01 #define GSTATUS_POS_W1 0x02 /* gStatus.mic:[3-2] Eyes position @@ -125,7 +115,8 @@ */ /* bits 5-0: - VTCCCCCC (C: RC5 6 bits command) */ -#define GSTATUS_IR_VALID _BV(7) /* V: set when RC5 data has been received */ +#define GSTATUS_IR_VALID _BV(7) /* V: set when RC5 data has been \ + received */ #define GSTATUS_IR_TOGGLE _BV(6) /* T: toggle bit of the RC5 code */ #define GSTATUS_IR_COMMAND 0x3F /* T: toggle bit of the RC5 code */ @@ -218,7 +209,9 @@ * TODO merge flags by categories in bitfields or bytes and masks */ -#define COND_RESET_NBR 9 /* number of flags that should be reset, change this according to the table below */ +/* Number of flags that should be reset, change this according to the table + * below. */ +#define COND_RESET_NBR 9 struct condition_table { /* flags reset by the COND_RESET_CMD */ @@ -239,13 +232,4 @@ extern struct condition_table cond_flags; -/* - * Test modes - */ - -#define sigout_set turnLeftLedOn -#define sigout_unset turnLeftLedOff -#define sigin_ini() {LED_PT &= ~LED_R_MK; LED_DDR &= ~LED_R_MK;} /* used as signal input */ -#define sigin (LED_PIN & LED_R_MK) /* wait for tester to be as pull up */ - #endif /* _GLOBAL_H_ */ Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-11 14:07:55 UTC (rev 508) +++ firmware/tuxcore/trunk/main.c 2007-09-11 14:29:55 UTC (rev 509) @@ -22,6 +22,7 @@ /** \file main.c \brief Tuxcore main functions */ + /** \mainpage Tuxcore firmware documentation of the Tux Droid open source robot \section SVN SVN repository @@ -276,11 +277,11 @@ FifoPut(statusFifo, PINC); FifoPut(statusFifo, PIND); FifoPut(statusFifo, STATUS_POSITION1_CMD); - FifoPut(statusFifo, eyesPosCnt); - FifoPut(statusFifo, mouthPosCnt); - FifoPut(statusFifo, wingsPosCnt); + FifoPut(statusFifo, eyes_move_counter); + FifoPut(statusFifo, mouth_move_counter); + FifoPut(statusFifo, flippers_move_counter); FifoPut(statusFifo, STATUS_POSITION2_CMD); - FifoPut(statusFifo, spinPosCnt); + FifoPut(statusFifo, spin_stop_delay); FifoPut(statusFifo, gStatus.pos); FifoPut(statusFifo, 0); if (light_f) /* send light measurement */ Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2007-09-11 14:07:55 UTC (rev 508) +++ firmware/tuxcore/trunk/motors.c 2007-09-11 14:29:55 UTC (rev 509) @@ -19,77 +19,139 @@ /* $Id$ */ +/** \file motors.c + \brief Motor module + \ingroup movements +*/ + #include <avr/interrupt.h> #include <avr/io.h> #include "global.h" #include "motors.h" -/* counter to stop eye/mouth at timer int */ -uint8_t wingsStpCnt, wingsPosCnt, wingsPwm = 5; -uint8_t wings_tim, wings_prev_tim; /* timer for absolute position of the wings */ -uint8_t eyesStpCnt, eyesPosCnt; //, eyesPwm; -uint8_t mouthStpCnt, mouthPosCnt, mouth_pos; //, mouthPwm; -uint8_t spinPosCnt, spinStpCnt, spinPwm = 5, spinDirection; +/** 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 +/** 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 +/** 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 +/** Init value of the timer used to reset the flippers in the low position. */ +#define FLIP_TIMER_INIT 0xFF +/** Minimum difference required between the period the flippers are moving from + * up to down and from down to up. */ +#define FLIPPERS_RESETTIMER_HYST 0x10 -/* pwm mask registers */ -uint8_t pwmMaskB; +/** Number of periods remaining before stopping the flippers. + * Normally used when braking, to stop the motor after a short period of + * inversion. */ +uint8_t flippers_stop_delay; +/** Number of movements remaining before stopping the flippers. */ +uint8_t flippers_move_counter; +/** PWM applied on the flippers motor. */ +uint8_t flippers_PWM = 5; +/** Timer used to measure the period the flippers take between the low and high + * positions. */ +uint8_t flippers_timer; +/** Period taken by the previous movement of the flippers. */ +uint8_t flippers_revious_timer; +/** Number of periods remaining before stopping the eyes. + * Normally used when braking, to stop the motor after a short period of + * inversion. */ +uint8_t eyes_stop_delay; +/** Number of movements remaining before stopping the flippers. */ +uint8_t eyes_move_counter; +/** Number of periods remaining before stopping the mouth. + * Normally used when braking, to stop the motor after a short period of + * inversion. */ +uint8_t mouth_stop_delay; +/** Number of movements remaining before stopping the mouth. */ +uint8_t mouth_move_counter; +/** Number of periods remaining before stopping the rotation. + * Normally used when braking, to stop the motor after a short period of + * inversion. */ +uint8_t spin_stop_delay; +/** Number of movements remaining before stopping the rotation. */ +uint8_t spin_move_counter; +/** PWM applied on the spinning motor. */ +uint8_t spin_PWM = 5; +/** Spinning direction */ +static uint8_t spin_direction; +uint8_t mouth_pos; /* XXX delete this */ + +/** PWM mask register applied on the port on a regular basis. */ +uint8_t portB_PWM_mask; + /** \brief Wings position interrupt \ingroup flippers - This interrupt stops the wings when the desired number of movements have been - executed. In order to stop the wings quickly and block the motor, we need to - invert the motor for a small duration. + This interrupt stops the flippers when the desired number of movements have + been executed. In order to stop the flippers quickly and block the motor, we + need to invert the motor for a small duration. When the signal is switching from high to low (switch pushed), the number of - movements is decreased and when null, the wings motor is switched backwards - and will be stopped by timer0 overflow after the WINGS_STOP_DLY period. - So we only count when the switch is pushed but not when it is released. As - the interrupt triggers on a signal change, we need to suppress the release - interrupt. + movements is decreased and when null, the flippers motor is switched + backwards and will be stopped by timer0 overflow after the + FLIPPERS_BRAKING_DLY period. So we only count when the switch is pushed but + not when it is released. As the interrupt triggers on a signal change, we + need to suppress the release interrupt. */ ISR(SIG_PIN_CHANGE1) { - if (~PSW_WINGS_PIN & PSW_WINGS_MK) /* we only count when the switch is pushed, not released */ + /* We only count when the switch is pushed, not released. */ + if (~PSW_WINGS_PIN & PSW_WINGS_MK) { - /* This test prevent the toggle when the wings are pushed. The wings - * motor must be switched on (wingsPwm <> 0) to toggle the position */ - if (wingsPwm) + /* This test prevents the toggle when the flippers are pushed. The + * flippers motor must be switched on (flippers_PWM <> 0) to toggle the + * position */ + if (flippers_PWM) gStatus.pos ^= GSTATUS_POS_W0; /* toggle wigs position */ - if (wings_tim) /* if we need to reposition the wings */ + if (flippers_timer) /* if we need to reposition the flippers */ { - if (wingsPosCnt == 1) + if (flippers_move_counter == 1) { - if ((wings_prev_tim) && (wings_tim < (wings_prev_tim - WINGS_TIM_DIFF))) /* wings are down */ + if ((flippers_revious_timer) && (flippers_timer < + (flippers_revious_timer - FLIPPERS_RESETTIMER_HYST))) { - /* Position reached so init gStatus.pos bit to lower position */ + /* flippers are down */ + /* Position reached so init gStatus.pos bit to lower + * position */ gStatus.pos &= ~GSTATUS_POS_W0; - wings_tim = 0; /* reset timers */ - wings_prev_tim = 0; + flippers_timer = 0; + flippers_revious_timer = 0; } - else /* continue */ + else /* continue */ { - /* Unknow position, execute another movement to determine it */ - wings_prev_tim = wings_tim; - wings_tim = WINGS_TIM_RESET; + /* Unknow position, execute another movement to determine + * it */ + flippers_revious_timer = flippers_timer; + flippers_timer = FLIP_TIMER_INIT; return; } } else - wings_tim = WINGS_TIM_RESET; + flippers_timer = FLIP_TIMER_INIT; } - if (wingsPosCnt) + if (flippers_move_counter) { - wingsPosCnt--; - if (!wingsPosCnt) + flippers_move_counter--; + if (!flippers_move_counter) { stopWings(); runWingsBw(); - wingsStpCnt = WINGS_STOP_DLY; + flippers_stop_delay = FLIPPERS_BRAKING_DLY; } } } @@ -111,9 +173,10 @@ So we count when the switch is pushed (eyes closed) and when the switch is released (eyes opened) to know the number of movements that occurs - The movement counter eyesPosCnt is decreased and when null, the head motor is + The movement counter eyes_move_counter is decreased and when null, the head + motor is switched backwards and will be stopped by timer0 overflow after the - EYES_ICLOSE_DLY period. + EYES_BRAKING_DLY period. */ ISR(SIG_PIN_CHANGE2) { @@ -122,14 +185,14 @@ else cond_flags.eyes_closed = 0; - if (eyesPosCnt) + if (eyes_move_counter) { - eyesPosCnt--; - if (!eyesPosCnt) + eyes_move_counter--; + if (!eyes_move_counter) { stopEyes(); runIEyes(); - eyesStpCnt = EYES_ICLOSE_DLY; + eyes_stop_delay = EYES_BRAKING_DLY; } } } @@ -138,22 +201,23 @@ \brief Mouth position interrupt \ingroup mouth - This interrupt stops the mouth when the desired number of movements have been - executed. In order to stop the mouth quickly and block the motor, we need to - invert the motor for a small duration. + This interrupt stops the mouth when the desired number of movements have + been executed. In order to stop the mouth quickly and block the motor, we + need to invert the motor for a small duration. There are 2 switches to detect the mouth poistion: mouth open and mouth closed. When any of the switches is pushed, a movement is counted. So we only count when the switch is pushed but not when it is released. As the interrupt triggers on a signal change, we need to suppress the release interrupt. - The movement counter mouthPosCnt is decreased and when null, the head motor - is switched backwards and will be stopped by timer0 overflow after the - MOUTH_ICLOSE_DLY period. + The movement counter mouth_move_counter is decreased and when null, the head + motor is switched backwards and will be stopped by timer0 overflow after the + MOUTH_BRAKING_DLY period. */ ISR(SIG_PIN_CHANGE0) { - if (~PSW_MOUTH_PIN & PSW_MOUTH_MK) /* we only count when the switch is pushed, not released */ + /* We only count when the switch is pushed, not released. */ + if (~PSW_MOUTH_PIN & PSW_MOUTH_MK) { if (~PSW_MOUTH_PIN & PSW_MOUTH_O_MK) if (mouth_pos == CLOSE) /* XXX can we delete this line? */ @@ -161,16 +225,14 @@ if (~PSW_MOUTH_PIN & PSW_MOUTH_C_MK) if (mouth_pos == OPEN) /* XXX can we delete this line? */ mouth_pos = CLOSE; - if (mouthPosCnt) + if (mouth_move_counter) { - mouthPosCnt--; - if (!mouthPosCnt) + mouth_move_counter--; + if (!mouth_move_counter) { - { - stopMouth(); - runIMouth(); - mouthStpCnt = MOUTH_ICLOSE_DLY; - } + stopMouth(); + runIMouth(); + mouth_stop_delay = MOUTH_BRAKING_DLY; } } } @@ -188,19 +250,19 @@ */ ISR(SIG_INTERRUPT1) { - if (spinPosCnt) + if (spin_stop_delay) { - spinPosCnt--; - - if (!spinPosCnt) + spin_stop_delay--; + + if (!spin_stop_delay) { - spinPwmMask &= ~MOT_SPIN_MK; + spin_PWM_mask &= ~MOT_SPIN_MK; stopSpinMot(); - spinStpCnt = SPIN_STOP_DLY; - if (spinDirection == LEFT) - spinPwmMask |= MOT_SPIN_R_MK; + spin_move_counter = SPIN_BRAKING_DLY; + if (spin_direction == LEFT) + spin_PWM_mask |= MOT_SPIN_R_MK; else - spinPwmMask |= MOT_SPIN_L_MK; + spin_PWM_mask |= MOT_SPIN_L_MK; } } } @@ -264,62 +326,65 @@ MOT_MOUTH_DDR |= MOT_MOUTH_MK; MOT_WINGS_FW_DDR |= MOT_WINGS_FW_MK; MOT_WINGS_BW_DDR |= MOT_WINGS_BW_MK; - MOT_SPIN_DDR |= MOT_SPIN_MK; /* both pins on the same port so we can use this mask */ + MOT_SPIN_DDR |= MOT_SPIN_MK; } /** - \brief Start waving the wings up and down \ingroup flippers \param cnt - number of movements before the wings will stop \param pwm pwm value between - 1 (slow) and 5 (fast) + \brief Start waving the flippers up and down \ingroup flippers \param cnt + number of movements before the flippers will stop \param pwm pwm value + between 1 (slow) and 5 (fast) - The wings will start waving until 'cnt' movements are executed. A movement - is raising or lowering the wings. 'cnt' can be up to 256. If 'cnt' is null, - waving will run indefinitely. pwm can be used to change the speed of the - motor although it's more directed to the power delivered to the motor. It's - possible that the smallest values won't deliver enough power to even start - the motor. + The flippers will start waving until 'cnt' movements are executed. A + movement is raising or lowering the flippers. 'cnt' can be up to 256. If + 'cnt' is null, waving will run indefinitely. pwm can be used to change the + speed of the motor although it's more directed to the power delivered to the + motor. It's possible that the smallest values won't deliver enough power to + even start the motor. */ void waveWings(uint8_t cnt, uint8_t pwm) { - wingsPosCnt = cnt; - wingsPwm = pwm; - wingsStpCnt = 0; + flippers_move_counter = cnt; + flippers_PWM = pwm; + flippers_stop_delay = 0; MOT_WINGS_BW_PT &= ~MOT_WINGS_BW_MK; - wingsPwmMask |= MOT_WINGS_FW_MK; + flippers_PWMMask |= MOT_WINGS_FW_MK; } /** - \brief Reset wings + \brief Reset flippers \ingroup flippers - This function reset the wings position. wings_tim is used to determine the - wings positions. Times needed to raise or lower the wings are not the same. - If two movements are executed, wings_tim allow to determine the shorter - time, and then to know if wings are up or low. + This function reset the flippers position. flippers_timer is used to + determine the flippers positions. Times needed to raise or lower the + flippers are not the same. + If two movements are executed, flippers_timer allow to determine the shorter + time, and then to know if flippers are up or low. */ void resetWings(void) { - wings_tim = WINGS_TIM_RESET; - waveWings(2, 5); /* the first movement is to be sure the timer doesn't start counting from any unknown poistion and that the motors are in regime */ + flippers_timer = FLIP_TIMER_INIT; + /* the first movement is to be sure the timer doesn't start counting from + * any unknown poistion and that the motors are in regime */ + waveWings(2, 5); } /** - \brief Raise wings \ingroup flippers + \brief Raise flippers \ingroup flippers - The condition to raise the wings is that they aren't already in the upper + The condition to raise the flippers is that they aren't already in the upper position. If this condition is respected, a single movement is executed by the waveWings function. - If the wings was in the higher position and has been lowered manually, the - wings can't be raised directly. They must pass by the low position + If the flippers was in the higher position and has been lowered manually, + the flippers can't be raised directly. They must pass by the low position (lowerWings function) before being able to be raised. - \note Implement conditions to be able to raise wings without pass by the low - position increase code size and complicate the code. This implementation - need to toggle the motor sense when two or more same commands are repeated. - The mecanical position when the motor is switched off is important. So, the - braking delay couldn't be the same in both sense. + \note Implement conditions to be able to raise flippers without pass by the + low position increase code size and complicate the code. This + implementation need to toggle the motor sense when two or more same commands + are repeated. The mecanical position when the motor is switched off is + important. So, the braking delay couldn't be the same in both sense. */ void raiseWings(void) @@ -330,18 +395,22 @@ /** - \brief Lower wings + \brief Lower flippers \ingroup flippers - The condition to lower the wings is that they aren't already in the lower position. - If this condition is respected, a single movement is executed by the waveWings function. + The condition to lower the flippers is that they aren't already in the lower + position. If this condition is respected, a single movement is executed by + the waveWings function. - If the wings was in the lower position and has been raised manually, the wings can't be lowered directly. They must pass by the high position + If the flippers was in the lower position and has been raised manually, the + flippers can't be lowered directly. They must pass by the high position (raiseWings function) before being able to be lowered. - \note Implement conditions to be able to lower wings without pass by the high position increase code size and complicate the code. This implementation - need to toggle the motor sense when two or more same commands are repeated. - The mecanical position when the motor is switched off is important. So, the braking delay couldn't be the same in both sense. + \note Implement conditions to be able to lower flippers without pass by the + high position increase code size and complicate the code. This + implementation need to toggle the motor sense when two or more same commands + are repeated. The mecanical position when the motor is switched off is + important. So, the braking delay couldn't be the same in both sense. */ void lowerWings(void) @@ -354,16 +423,17 @@ \brief Blink the eyes \ingroup eyes - \param cnt number of movements before the wings will stop + \param cnt number of movements before the flippers will stop \note Any mouth command is cancelled - The eyes will start blinking until 'cnt' movements are executed. A movement is - raising or lowering the eyelids. 'cnt' can be up to 256. If 'cnt' is null, waving will run indefinitely. + The eyes will start blinking until 'cnt' movements are executed. A movement + is raising or lowering the eyelids. 'cnt' can be up to 256. If 'cnt' is + null, waving will run indefinitely. */ void blinkEyes(uint8_t cnt) { - eyesPosCnt = cnt; - eyesStpCnt = 0; + eyes_move_counter = cnt; + eyes_stop_delay = 0; runEyes(); } @@ -373,19 +443,21 @@ Open the eyes if they are closed. - The eyes can be in three different states and should have a different behavior in all states. + The eyes can be in three different states and should have a different + behavior in all states. - Eyes opened - no movement is required. - Eyes closed - Just one movement is required to open the eyes. - indeterminated - two movements are required. To prevent that the motor can be activated when the eyes are opened and to stop the eyes in the open state by sending the open_eyes_cmd when they're - blinking, eyesPosCnt is initalised but the blinkEyes function isn't call. - If the motor is running, it will execute two movements before stop. If the motor - isn't switched on, nothing happens. + blinking, eyes_move_counter is initalised but the blinkEyes function isn't + call. + If the motor is running, it will execute two movements before stop. If the + motor isn't switched on, nothing happens. - \note XXX The computer side (API, daemon) must know than eyesPosCnt can be - not null with the motor switched off. + \note XXX The computer side (API, daemon) must know than eyes_move_counter + can be not null with the motor switched off. */ void openEyes(void) { @@ -396,7 +468,7 @@ blinkEyes(1); else - eyesPosCnt = 2; + eyes_move_counter = 2; } /** @@ -405,11 +477,11 @@ Close the eyes if they are opened. - When the close_eyes_cmd is received, if the eyes are closed, nothing happens. - But, when the eyes are blinking, this command must stop the eyes in the - closed position. To do this, eyesPosCnt is initialised, but the blinkEyes - function isn't call. So, if the command is received when the eyes are - blinking, two movements are executed before the motor is stopped. + When the close_eyes_cmd is received, if the eyes are closed, nothing + happens. But, when the eyes are blinking, this command must stop the eyes + in the closed position. To do this, eyes_move_counter is initialised, but + the blinkEyes function isn't call. So, if the command is received when the + eyes are blinking, two movements are executed before the motor is stopped. */ void closeEyes(void) { @@ -417,7 +489,7 @@ blinkEyes(1); else - eyesPosCnt = 2; + eyes_move_counter = 2; } /** @@ -426,13 +498,14 @@ \note Any eye command is cancelled \param cnt number of movements before the mouth will stop - The mouth will start blinking until 'cnt' movements are executed. A movement is - raising or lowering the eyelids. 'cnt' can be up to 256. If 'cnt' is null, waving will run indefinitely. + The mouth will start blinking until 'cnt' movements are executed. A movement + is raising or lowering the eyelids. 'cnt' can be up to 256. If 'cnt' is + null, waving will run indefinitely. */ void moveMouth(uint8_t cnt) { - mouthPosCnt = cnt; - mouthStpCnt = 0; + mouth_move_counter = cnt; + mouth_stop_delay = 0; runMouth(); } @@ -462,7 +535,7 @@ void stopSpin(void) { - spinPwmMask &= ~MOT_SPIN_MK; + spin_PWM_mask &= ~MOT_SPIN_MK; stopSpinMot(); } @@ -470,28 +543,28 @@ { /* Check if direction is changing and if pos. switch isn't push. Then, * increment angle value to prevent too short rotation */ - if (spinDirection == RIGHT && (PSW_SPIN_PIN & PSW_SPIN_MK)) + if (spin_direction == RIGHT && (PSW_SPIN_PIN & PSW_SPIN_MK)) { angle += 1; } - spinDirection = LEFT; - spinPosCnt = angle; - spinPwm = pwm; - spinPwmMask &= ~MOT_SPIN_R_MK; - spinPwmMask |= MOT_SPIN_L_MK; + spin_direction = LEFT; + spin_stop_delay = angle; + spin_PWM = pwm; + spin_PWM_mask &= ~MOT_SPIN_R_MK; + spin_PWM_mask |= MOT_SPIN_L_MK; } void spinRight(uint8_t angle, uint8_t pwm) { /* Check if direction is changing and if pos. switch isn't push. Then, * increment angle value to prevent too short rotation */ - if (spinDirection == LEFT && (PSW_SPIN_PIN & PSW_SPIN_MK)) + if (spin_direction == LEFT && (PSW_SPIN_PIN & PSW_SPIN_MK)) { angle += 1; } - spinDirection = RIGHT; - spinPosCnt = angle; - spinPwm = pwm; - spinPwmMask &= ~MOT_SPIN_L_MK; - spinPwmMask |= MOT_SPIN_R_MK; + spin_direction = RIGHT; + spin_stop_delay = angle; + spin_PWM = pwm; + spin_PWM_mask &= ~MOT_SPIN_L_MK; + spin_PWM_mask |= MOT_SPIN_R_MK; } Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2007-09-11 14:07:55 UTC (rev 508) +++ firmware/tuxcore/trunk/motors.h 2007-09-11 14:29:55 UTC (rev 509) @@ -19,9 +19,15 @@ /* $Id$ */ +/** \file motors.h + \brief Motor module interface + \ingroup movements +*/ + /** \defgroup movements Movements - The motor module contains all the functions necessery to control the movements of tux. + The motor module contains all the functions necessery to control the + movements of tux. */ /** \defgroup eyes Eyes @@ -48,34 +54,28 @@ This group contains all the functions to control the spinning. */ -/** \file motors.h - \ingroup movements -*/ - -/** \file motors.c - \ingroup movements -*/ #ifndef _MOTORS_H_ #define _MOTORS_H_ #include "hardware.h" -#define WINGS_TIM_RESET 0Xff -#define WINGS_TIM_DIFF 0x10 +#define flippers_PWMMask portB_PWM_mask +#define spin_PWM_mask portB_PWM_mask + enum mouth_pos_s { OPEN, CLOSE, UNDEFINED }; enum spin_direction { LEFT, RIGHT }; /* counters to stop eye/mouth and flippers at timer int */ -extern uint8_t wingsStpCnt, wingsPosCnt, wingsPwm; -extern uint8_t wings_tim, wings_prev_tim; -extern uint8_t eyesStpCnt, eyesPosCnt; -extern uint8_t mouthStpCnt, mouthPosCnt, mouth_pos; -extern uint8_t spinPosCnt, spinStpCnt, spinPwm; +extern uint8_t flippers_stop_delay, flippers_move_counter, flippers_PWM; +extern uint8_t flippers_timer, flippers_revious_timer; +extern uint8_t eyes_stop_delay, eyes_move_counter; +extern uint8_t mouth_stop_delay, mouth_move_counter, mouth_pos; +extern uint8_t spin_stop_delay, spin_move_counter, spin_PWM; /* pwm mask registers */ -extern uint8_t pwmMaskB; +extern uint8_t portB_PWM_mask; void initMotors(void); @@ -127,7 +127,8 @@ \brief Resets Tux's absolute turn reference \ingroup primitives - Compared to \c resetSpinOri(), this function only resets the turn count reference, not the angle. See gStatus.ori + Compared to \c resetSpinOri(), this function only resets the turn count + reference, not the angle. See gStatus.ori */ void resetSpinTurns(void); @@ -145,27 +146,31 @@ \brief Stop the eyes motor \ingroup eyes */ -#define stopEyes() (MOT_EYES_PT &= ~(MOT_EYES_MK | MOT_IEYES_MK)) +#define stopEyes() (MOT_EYES_PT &= ~(MOT_EYES_MK | MOT_IEYES_MK)) /** \brief Start the eyes motor \ingroup primitives */ -#define runEyes() {(MOT_EYES_PT &= ~MOT_IEYES_MK); (MOT_EYES_PT |= MOT_EYES_MK);} -#define runIEyes() {(MOT_EYES_PT &= ~MOT_EYES_MK); (MOT_EYES_PT |= MOT_IEYES_MK);} +#define runEyes() {(MOT_EYES_PT &= ~MOT_IEYES_MK); \ + (MOT_EYES_PT |= MOT_EYES_MK);} +#define runIEyes() {(MOT_EYES_PT &= ~MOT_EYES_MK); \ + (MOT_EYES_PT |= MOT_IEYES_MK);} /** - \brief Stop the mouth motor - \ingroup mouth - */ + \brief Stop the mouth motor + \ingroup mouth + */ #define stopMouth() (MOT_MOUTH_PT &= ~(MOT_MOUTH_MK | MOT_IMOUTH_MK)) /** \brief Start the mouth motor \ingroup primitives */ -#define runMouth() (MOT_MOUTH_PT &= ~MOT_IMOUTH_MK); (MOT_MOUTH_PT |= MOT_MOUTH_MK) -#define runIMouth() (MOT_MOUTH_PT &= ~MOT_MOUTH_MK); (MOT_MOUTH_PT |= MOT_IMOUTH_MK) +#define runMouth() (MOT_MOUTH_PT &= ~MOT_IMOUTH_MK); \ + (MOT_MOUTH_PT |= MOT_MOUTH_MK) +#define runIMouth() (MOT_MOUTH_PT &= ~MOT_MOUTH_MK);\ + (MOT_MOUTH_PT |= MOT_IMOUTH_MK) /** \brief Stop the flippers motor @@ -174,7 +179,7 @@ static inline void stopWings(void) __attribute__ ((always_inline)); void stopWings(void) { - wingsPwmMask &= ~MOT_WINGS_FW_MK; + flippers_PWMMask &= ~MOT_WINGS_FW_MK; MOT_WINGS_BW_PT &= ~MOT_WINGS_BW_MK; MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK; } @@ -185,8 +190,10 @@ Used to brake the flippers motor only */ -#define runWingsFw() {(MOT_WINGS_BW_PT &= ~MOT_WINGS_BW_MK); (MOT_WINGS_FW_PT |= MOT_WINGS_FW_MK);} -#define runWingsBw() {(MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK); (MOT_WINGS_BW_PT |= MOT_WINGS_BW_MK);} +#define runWingsFw() {(MOT_WINGS_BW_PT &= ~MOT_WINGS_BW_MK); \ + (MOT_WINGS_FW_PT |= MOT_WINGS_FW_MK);} +#define runWingsBw() {(MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK); \ + (MOT_WINGS_BW_PT |= MOT_WINGS_BW_MK);} /** \brief Stop the spinning motor @@ -195,20 +202,23 @@ static inline void stopSpinMot(void) __attribute__ ((always_inline)); void stopSpinMot(void) { - spinPwmMask &= ~MOT_SPIN_MK; + spin_PWM_mask &= ~MOT_SPIN_MK; MOT_SPIN_PT &= ~MOT_SPIN_MK; } /** \brief Start spinning to the left \ingroup primitives */ -#define runSpinLeft() (MOT_SPIN_R_PT &= ~MOT_SPIN_R_MK); (MOT_SPIN_L_PT |= MOT_SPIN_L_MK) +#define runSpinLeft() (MOT_SPIN_R_PT &= ~MOT_SPIN_R_MK); \ + (MOT_SPIN_L_PT |= MOT_SPIN_L_MK) /** \brief Start spinning to the right \ingroup primitives */ -#define runSpinRight() (MOT_SPIN_L_PT &= ~MOT_SPIN_L_MK); (MOT_SPIN_R_PT |= MOT_SPIN_R_MK) +#define runSpinRight() (MOT_SPIN_L_PT &= ~MOT_SPIN_L_MK); \ + (MOT_SPIN_R_PT |= MOT_SPIN_R_MK) + /** \brief Control the PWM of the spinning & flippers and motor braking. \ingroup primitives @@ -226,12 +236,12 @@ { /* Flippers PWM * Pulse is stopped here */ - if (pwm_tim == wingsPwm) + if (pwm_tim == flippers_PWM) MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK; /* Spin PWM * Pulse is stopped here */ - if (pwm_tim == spinPwm) + if (pwm_tim == spin_PWM) MOT_SPIN_PT &= ~MOT_SPIN_MK; /* PWM motor management @@ -241,57 +251,57 @@ if (pwm_tim++ == PWM_PERIOD) { pwm_tim = 0; - PORTB |= pwmMaskB; /* spin and flippers */ + PORTB |= portB_PWM_mask; /* spin and flippers */ } /* Flippers timer to stop the flippers in any position */ - if (wings_tim) + if (flippers_timer) { - wings_tim--; - if (!wings_tim) + flippers_timer--; + if (!flippers_timer) { stopWings(); } } /* Flippers braking (motor reversed) delay */ - if (wingsStpCnt) + if (flippers_stop_delay) { - wingsStpCnt--; - if (!wingsStpCnt) + flippers_stop_delay--; + if (!flippers_stop_delay) { stopWings(); - wingsPwm = 0; + flippers_PWM = 0; } } /* eyes braking (motor reversed) delay */ - if (eyesStpCnt) + if (eyes_stop_delay) { - eyesStpCnt--; - if (!eyesStpCnt) + eyes_stop_delay--; + if (!eyes_stop_delay) { stopEyes(); } } /* mouth braking (motor reversed) delay */ - if (mouthStpCnt) + if (mouth_stop_delay) { - mouthStpCnt--; - if (!mouthStpCnt) + mouth_stop_delay--; + if (!mouth_stop_delay) { stopMouth(); } } /* spin braking (motor reversed) delay */ - if (spinStpCnt) + if (spin_move_counter) { - spinStpCnt--; - if (!spinStpCnt) - { - stopSpinMot(); - } + spin_move_counter--; + if (!spin_move_counter) + { + stopSpinMot(); + } } } #endif /* _MOTORS_H_ */ Modified: firmware/tuxcore/trunk/standalone.c =================================================================== --- firmware/tuxcore/trunk/standalone.c 2007-09-11 14:07:55 UTC (rev 508) +++ firmware/tuxcore/trunk/standalone.c 2007-09-11 14:29:55 UTC (rev 509) @@ -209,7 +209,7 @@ if ((gStatus.sw & GSTATUS_POWERPLUGSW_MK)) { stopSpin(); /* flush the spinning commands */ - spinPosCnt = 0; + spin_stop_delay = 0; } if (remote_mode) @@ -228,7 +228,8 @@ } /* IR signal processing */ - if (gStatus.ir != ir_oldvalue) /* put here things that should be done only once when a button is pushed */ + /* put here things that should be done only once when a button is pushed */ + if (gStatus.ir != ir_oldvalue) { ir_command = gStatus.ir & GSTATUS_IR_COMMAND; ir_toggle = gStatus.ir & GSTATUS_IR_TOGGLE; @@ -252,7 +253,9 @@ } /* Alt key pressed - * Leave this test after the ALT KEYS otherwise alt_mode is reset before the other commands are processed when you push the second key */ + * Leave this test after the ALT KEYS otherwise alt_mode is reset + * before the other commands are processed when you push the second key + * */ if (ir_command == K_ALT) alt_mode = 1; else @@ -285,10 +288,10 @@ waveWings(mov_nbr, 5); break; case K_LEFT: - spinLeft(mov_nbr, spinPwm); + spinLeft(mov_nbr, spin_PWM); break; case K_RIGHT: - spinRight(mov_nbr, spinPwm); + spinRight(mov_nbr, spin_PWM); break; case K_STOP: stopSpin(); @@ -305,20 +308,20 @@ toggleLeftLed(); break; case K_FASTREWIND: - if (spinPwm) - spinPwm--; + if (spin_PWM) + spin_PWM--; break; case K_FASTFORWARD: - if (spinPwm < 5) - spinPwm++; + if (spin_PWM < 5) + spin_PWM++; break; case K_PREVIOUS: - if (wingsPwm) - wingsPwm--; + if (flippers_PWM) + flippers_PWM--; break; case K_NEXT: - if (wingsPwm < 5) - wingsPwm++; + if (flippers_PWM < 5) + flippers_PWM++; break; } } |