[tuxdroid-svn] r518 - firmware/tuxcore/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-09-12 14:20:22
|
Author: jaguarondi Date: 2007-09-12 16:20:13 +0200 (Wed, 12 Sep 2007) New Revision: 518 Modified: firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/motors.h firmware/tuxcore/trunk/parser.c firmware/tuxcore/trunk/standalone.c Log: * Reorganised the mouth functions. * Some more cleanup and comments. Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-12 14:07:02 UTC (rev 517) +++ firmware/tuxcore/trunk/main.c 2007-09-12 14:20:13 UTC (rev 518) @@ -357,7 +357,7 @@ closeIO(); closePosSwitches(); stopSpin(); - stopMouth(); + stop_mouth(); stopWings(); PRR_bak = PRR; PRR = _BV(PRTWI) | _BV(PRTIM2) | _BV(PRTIM0) | _BV(PRTIM1) | _BV(PRADC); Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2007-09-12 14:07:02 UTC (rev 517) +++ firmware/tuxcore/trunk/motors.c 2007-09-12 14:20:13 UTC (rev 518) @@ -30,7 +30,7 @@ #include "global.h" #include "motors.h" -/** +/** * \name Braking delays * These functions access the motor I/O port. * @{ */ @@ -94,7 +94,7 @@ /** PWM mask register applied on the port on a regular basis. */ uint8_t portB_PWM_mask; -/** +/** * \name Module configuration * These functions initialize the motors and switches I/O ports for normal and * sleep mode. @@ -147,7 +147,7 @@ } /*! @} */ -/** +/** * \name Eyes functions * @{ */ /** \brief Low level access to stop the eyes motor. */ @@ -161,20 +161,20 @@ static inline void run_eyes_motor(void) __attribute__ ((always_inline)); void run_eyes_motor(void) { - (MOT_EYES_PT &= ~MOT_IEYES_MK); - (MOT_EYES_PT |= MOT_EYES_MK); + MOT_EYES_PT &= ~MOT_IEYES_MK; + MOT_EYES_PT |= MOT_EYES_MK; } /** \brief Low level access to invert the eyes motor. */ static inline void invert_eyes_motor(void) __attribute__ ((always_inline)); void invert_eyes_motor(void) { - (MOT_EYES_PT &= ~MOT_EYES_MK); - (MOT_EYES_PT |= MOT_IEYES_MK); + MOT_EYES_PT &= ~MOT_EYES_MK; + MOT_EYES_PT |= MOT_IEYES_MK; } /** - \brief Stop the eyes + \brief Stop the eyes immediately. \ingroup eyes The eyes motor will stop immediately, even if the eyes are not in the open @@ -205,36 +205,41 @@ } /** - \brief Open the eyes + \brief Open the eyes. \ingroup eyes Open the eyes if they are closed. 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. + behavior in all states: + - opened - no movement is required; + - closed - just one movement is required to open the eyes; + - unknown - two movements are required as the eyes can only be stopped when + they are closing; a spring is used to open them. - 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 + We need to differentiate when the eyes are opened and stopped, and when + they are opened but blinking. In the first case, we don't need to do + anything. But in the second, we need to stop the eyes in the open position. + To stop the eyes in the open state by sending the open_eyes_cmd when they're blinking, eyes_move_counter is initalised but the blink_eyes 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. + called. + If the motor is running, it will execute two movements before stopping. If the + motor isn't switched on, nothing happens but eyes_move_counter is set to a + non zero value though they are no movements happening. - \note XXX The computer side (API, daemon) must know than eyes_move_counter - can be not null with the motor switched off. + \note The computer side (API, daemon) must be aware that the + eyes_move_counter can be non zero with the motor switched off. */ void open_eyes(void) { if ((PSW_EYES_PIN & PSW_EYES_O_MK) && (PSW_EYES_PIN & PSW_EYES_C_MK)) + /* Position unknown. */ blink_eyes(2); - else if (!(PSW_EYES_PIN & PSW_EYES_C_MK)) + /* Eyes are closed. */ blink_eyes(1); - else + /* Eyes are opened but possibly blinking. */ eyes_move_counter = 2; } @@ -247,21 +252,21 @@ 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 blink_eyes function isn't call. So, if the command is received when the + the blink_eyes function isn't called. If the command is received when the eyes are blinking, two movements are executed before the motor is stopped. */ void close_eyes(void) { if (PSW_EYES_PIN & PSW_EYES_C_MK) + /* Eyes are not closed. */ blink_eyes(1); - else + /* Eyes are closed but possibly blinking. */ eyes_move_counter = 2; } /** \brief Eyes position interrupt - \ingroup eyes This interrupt stops the eyes when the desired number of movements have been executed. In order to stop the eyes quickly and block the motor, we need to @@ -301,9 +306,88 @@ /*! @} */ /** - \brief Mouth position interrupt + * \name Mouth functions + * @{ */ +/** \brief Low level access to stop the mouth motor. */ +static inline void stop_mouth_motor(void) __attribute__ ((always_inline)); +void stop_mouth_motor(void) +{ + MOT_MOUTH_PT &= ~(MOT_MOUTH_MK | MOT_IMOUTH_MK); +} + +/** \brief Low level access to start the mouth motor. */ +static inline void run_mouth_motor(void) __attribute__ ((always_inline)); +void run_mouth_motor(void) +{ + MOT_MOUTH_PT &= ~MOT_IMOUTH_MK; + MOT_MOUTH_PT |= MOT_MOUTH_MK; +} + +/** \brief Low level access to invert the mouth motor. */ +static inline void invert_mouth_motor(void) __attribute__ ((always_inline)); +void invert_mouth_motor(void) +{ + MOT_MOUTH_PT &= ~MOT_MOUTH_MK; + MOT_MOUTH_PT |= MOT_IMOUTH_MK; +} + +/** + \brief Stop the mouth immediately. \ingroup mouth + The mouth motor will stop immediately, even if the mouth is not in the open + or close position. Use open_mouth or close_mouth instead if you want to stop + them in a given position. + */ +void stop_mouth(void) +{ + stop_mouth_motor(); +} + +/** + \brief Move the mouth + \ingroup mouth + \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. + */ +void move_mouth(uint8_t cnt) +{ + mouth_move_counter = cnt; + mouth_stop_delay = 0; + run_mouth_motor(); +} + +/** + \brief Open the mouth + \ingroup mouth + + Open the mouth if they are closed. + */ +void open_mouth(void) +{ + if (!(PSW_MOUTH_PIN & PSW_MOUTH_C_MK)) + move_mouth(1); +} + +/** + \brief Close the mouth + \ingroup mouth + + Close the mouth if they are opened. + */ +void close_mouth(void) +{ + if (!(PSW_MOUTH_PIN & PSW_MOUTH_O_MK)) + move_mouth(1); +} + +/** + \brief Mouth position interrupt + 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. @@ -327,13 +411,14 @@ mouth_move_counter--; if (!mouth_move_counter) { - stopMouth(); - runIMouth(); + stop_mouth_motor(); + invert_mouth_motor(); mouth_stop_delay = MOUTH_BRAKING_DLY; } } } } +/*! @} */ /** \brief Wings position interrupt @@ -425,7 +510,7 @@ if (spin_direction == LEFT) spin_PWM_mask |= MOT_SPIN_R_MK; else - spin_PWM_mask |= MOT_SPIN_L_MK; + spin_PWM_mask |= MOT_SPIN_L_MK; } } } @@ -453,7 +538,7 @@ /** \brief Reset flippers \ingroup flippers - + 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. @@ -472,7 +557,7 @@ /** \brief Raise flippers \ingroup flippers - + 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. @@ -489,10 +574,10 @@ */ void raiseWings(void) -{ +{ if (gStatus.pos == 0) waveWings(1,5); -} +} /** @@ -506,7 +591,7 @@ 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 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 @@ -515,53 +600,12 @@ */ void lowerWings(void) -{ +{ if (gStatus.pos == 1) waveWings(1,5); } /** - \brief Move the mouth - \ingroup mouth - \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. - */ -void moveMouth(uint8_t cnt) -{ - mouth_move_counter = cnt; - mouth_stop_delay = 0; - runMouth(); -} - -/** - \brief Open the mouth - \ingroup mouth - - Open the mouth if they are closed. - */ -void openMouth(void) -{ - if (!(PSW_MOUTH_PIN & PSW_MOUTH_C_MK)) - moveMouth(1); -} - -/** - \brief Close the mouth - \ingroup mouth - - Close the mouth if they are opened. - */ -void closeMouth(void) -{ - if (!(PSW_MOUTH_PIN & PSW_MOUTH_O_MK)) - moveMouth(1); -} - -/** \brief Stop the spinning motor \ingroup primitives */ @@ -685,7 +729,7 @@ mouth_stop_delay--; if (!mouth_stop_delay) { - stopMouth(); + stop_mouth_motor(); } } Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2007-09-12 14:07:02 UTC (rev 517) +++ firmware/tuxcore/trunk/motors.h 2007-09-12 14:20:13 UTC (rev 518) @@ -93,9 +93,10 @@ extern void blink_eyes(uint8_t cnt); extern void close_eyes(void); extern void open_eyes(void); -void moveMouth(uint8_t cnt); -void openMouth(void); -void closeMouth(void); +extern void stop_mouth(void); +extern void move_mouth(uint8_t cnt); +extern void open_mouth(void); +extern void close_mouth(void); void resetWings(void); void waveWings(uint8_t cnt, uint8_t pwm); void lowerWings(void); @@ -108,18 +109,8 @@ * Macro and inline functions definition */ -#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) - -/** \brief Stop the flippers motor \ingroup flippers */ Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2007-09-12 14:07:02 UTC (rev 517) +++ firmware/tuxcore/trunk/parser.c 2007-09-12 14:20:13 UTC (rev 518) @@ -86,19 +86,19 @@ } else if (command[0] == MOVE_MOUTH_CMD) { - moveMouth(command[1]); + move_mouth(command[1]); } else if (command[0] == OPEN_MOUTH_CMD) { - openMouth(); + open_mouth(); } else if (command[0] == CLOSE_MOUTH_CMD) { - closeMouth(); + close_mouth(); } else if (command[0] == STOP_MOUTH_CMD) { - stopMouth(); + stop_mouth(); } else if (command[0] == WAVE_WINGS_CMD) { Modified: firmware/tuxcore/trunk/standalone.c =================================================================== --- firmware/tuxcore/trunk/standalone.c 2007-09-12 14:07:02 UTC (rev 517) +++ firmware/tuxcore/trunk/standalone.c 2007-09-12 14:20:13 UTC (rev 518) @@ -282,7 +282,7 @@ blink_eyes(mov_nbr); break; case K_OK: - moveMouth(mov_nbr); + move_mouth(mov_nbr); break; case K_DOWN: waveWings(mov_nbr, 5); @@ -296,7 +296,7 @@ case K_STOP: stopSpin(); stopWings(); - stopMouth(); + stop_mouth(); break; case K_MUTE: tux_config.ir_feedback = !tux_config.ir_feedback; |