[tuxdroid-svn] r519 - firmware/tuxcore/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-09-12 14:53:32
|
Author: jaguarondi Date: 2007-09-12 16:53:05 +0200 (Wed, 12 Sep 2007) New Revision: 519 Modified: firmware/tuxcore/trunk/hardware.h 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: * Reorganized the flippers functions. Modified: firmware/tuxcore/trunk/hardware.h =================================================================== --- firmware/tuxcore/trunk/hardware.h 2007-09-12 14:20:13 UTC (rev 518) +++ firmware/tuxcore/trunk/hardware.h 2007-09-12 14:53:05 UTC (rev 519) @@ -202,17 +202,17 @@ * the motor driver won't burn and the motor will simply turn in one direction. * @{ */ /** Flippers backward motor PORT. */ -#define MOT_WINGS_BW_PT PORTD +#define MOT_FLIPPERS_BW_PT PORTD /** Flippers backward motor DDR. */ -#define MOT_WINGS_BW_DDR DDRD +#define MOT_FLIPPERS_BW_DDR DDRD /** Flippers backward motor mask. */ -#define MOT_WINGS_BW_MK _BV(PD4) +#define MOT_FLIPPERS_BW_MK _BV(PD4) /** Flippers forward motor PORT. */ -#define MOT_WINGS_FW_PT PORTB +#define MOT_FLIPPERS_FW_PT PORTB /** Flippers forward motor DDR. */ -#define MOT_WINGS_FW_DDR DDRB +#define MOT_FLIPPERS_FW_DDR DDRB /** Flippers forward motor mask. */ -#define MOT_WINGS_FW_MK _BV(PB0) +#define MOT_FLIPPERS_FW_MK _BV(PB0) /** Mouth motor PORT. */ #define MOT_MOUTH_PT PORTD /** Mouth motor DDR. */ Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-12 14:20:13 UTC (rev 518) +++ firmware/tuxcore/trunk/main.c 2007-09-12 14:53:05 UTC (rev 519) @@ -358,7 +358,7 @@ closePosSwitches(); stopSpin(); stop_mouth(); - stopWings(); + stop_flippers(); 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:20:13 UTC (rev 518) +++ firmware/tuxcore/trunk/motors.c 2007-09-12 14:53:05 UTC (rev 519) @@ -141,8 +141,8 @@ { MOT_EYES_DDR |= MOT_EYES_MK; MOT_MOUTH_DDR |= MOT_MOUTH_MK; - MOT_WINGS_FW_DDR |= MOT_WINGS_FW_MK; - MOT_WINGS_BW_DDR |= MOT_WINGS_BW_MK; + MOT_FLIPPERS_FW_DDR |= MOT_FLIPPERS_FW_MK; + MOT_FLIPPERS_BW_DDR |= MOT_FLIPPERS_BW_MK; MOT_SPIN_DDR |= MOT_SPIN_MK; } /*! @} */ @@ -250,7 +250,7 @@ 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 + 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 called. If the command is received when the eyes are blinking, two movements are executed before the motor is stopped. @@ -421,9 +421,133 @@ /*! @} */ /** - \brief Wings position interrupt + * \name Flippers functions + * @{ */ +/** \brief Low level access to stop the flippers motor. */ +static inline void stop_flippers_motor(void) __attribute__ ((always_inline)); +void stop_flippers_motor(void) +{ + flippers_PWMMask &= ~MOT_FLIPPERS_FW_MK; + MOT_FLIPPERS_BW_PT &= ~MOT_FLIPPERS_BW_MK; + MOT_FLIPPERS_FW_PT &= ~MOT_FLIPPERS_FW_MK; +} + +/** \brief Low level access to start the flippers motor. */ +static inline void run_flippers_motor(void) __attribute__ ((always_inline)); +void run_flippers_motor(void) +{ + MOT_FLIPPERS_BW_PT &= ~MOT_FLIPPERS_BW_MK; + MOT_FLIPPERS_FW_PT |= MOT_FLIPPERS_FW_MK; +} + +/** \brief Low level access to invert the flippers motor. */ +static inline void invert_flippers_motor(void) __attribute__ ((always_inline)); +void invert_flippers_motor(void) +{ + MOT_FLIPPERS_FW_PT &= ~MOT_FLIPPERS_FW_MK; + MOT_FLIPPERS_BW_PT |= MOT_FLIPPERS_BW_MK; +} + +/** + \brief Stop the flippers immediately. \ingroup flippers + The flippers motor will stop immediately, even if the flippers are not in + the up or down position. Use raise_flippers or lower_flippers instead if you + want to stop them in a given position. + */ +void stop_flippers(void) +{ + stop_flippers_motor(); +} + +/** + \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 flippers will start waving until 'cnt' movements have been 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 PWM values won't deliver enough power + to even start the motor. + */ +void wave_flippers(uint8_t cnt, uint8_t pwm) +{ + flippers_move_counter = cnt; + flippers_PWM = pwm; + flippers_stop_delay = 0; + MOT_FLIPPERS_BW_PT &= ~MOT_FLIPPERS_BW_MK; + flippers_PWMMask |= MOT_FLIPPERS_FW_MK; +} + +/** + \brief Reset flippers + \ingroup flippers + + This function resets 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 2 movements are executed (up - down - up), + flippers_timer allows to determine the shorter time, and get if the flippers + are up or low at the end. + */ +void reset_flippers(void) +{ + flippers_timer = FLIP_TIMER_INIT; + /* The first movement is to be sure the timer doesn't start counting from + * any unknown postion and that the motors are in regime. */ + wave_flippers(2, 5); +} + + +/** + \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 wave_flippers function. + + If the flippers were in the higher position and have been lowered manually, + the flippers can't be raised directly. They must pass by the low position + (lower_flippers function) before being able to be raised. + + \note If the flippers are in a medium position, it's possible that they'll + first move low before raising. Implementing conditions to be able to raise + the flippers immeditely is not trivial and increases the code size too much + compared to the benefit. This would require changing the motor direction + when two consecutive commands are identical. Furthermore the absolute + position when the motor is switched off is important. So, the braking delay + couldn't be the same in both directions. + */ +void raise_flippers(void) +{ + if (gStatus.pos == 0) + wave_flippers(1,5); +} + + +/** + \brief Lower flippers + \ingroup flippers + + 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 wave_flippers function. + + \note Has the same limitations as raise_flippers. + */ +void lower_flippers(void) +{ + if (gStatus.pos == 1) + wave_flippers(1,5); +} + +/** + \brief Wings position interrupt + 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. @@ -431,7 +555,7 @@ When the signal is switching from high to low (switch pushed), the number of 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 + 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. */ @@ -478,13 +602,14 @@ flippers_move_counter--; if (!flippers_move_counter) { - stopWings(); - runWingsBw(); + stop_flippers_motor(); + invert_flippers_motor(); flippers_stop_delay = FLIPPERS_BRAKING_DLY; } } } } +/*! @} */ /** \brief Spin position interrupt @@ -516,96 +641,6 @@ } /** - \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 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) -{ - flippers_move_counter = cnt; - flippers_PWM = pwm; - flippers_stop_delay = 0; - MOT_WINGS_BW_PT &= ~MOT_WINGS_BW_MK; - flippers_PWMMask |= MOT_WINGS_FW_MK; -} -/** - \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. - 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) -{ - 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 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. - - 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 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) -{ - if (gStatus.pos == 0) - waveWings(1,5); -} - - -/** - \brief Lower flippers - \ingroup flippers - - 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 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 - 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) -{ - if (gStatus.pos == 1) - waveWings(1,5); -} - -/** \brief Stop the spinning motor \ingroup primitives */ @@ -675,7 +710,7 @@ /* Flippers PWM * Pulse is stopped here */ if (pwm_tim == flippers_PWM) - MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK; + MOT_FLIPPERS_FW_PT &= ~MOT_FLIPPERS_FW_MK; /* Spin PWM * Pulse is stopped here */ @@ -698,7 +733,7 @@ flippers_timer--; if (!flippers_timer) { - stopWings(); + stop_flippers_motor(); } } @@ -708,7 +743,7 @@ flippers_stop_delay--; if (!flippers_stop_delay) { - stopWings(); + stop_flippers_motor(); flippers_PWM = 0; } } Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2007-09-12 14:20:13 UTC (rev 518) +++ firmware/tuxcore/trunk/motors.h 2007-09-12 14:53:05 UTC (rev 519) @@ -97,10 +97,11 @@ 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); -void raiseWings(void); +extern void stop_flippers(void); +extern void reset_flippers(void); +extern void wave_flippers(uint8_t cnt, uint8_t pwm); +extern void lower_flippers(void); +extern void raise_flippers(void); void stopSpin(void); void spinLeft(uint8_t angle, uint8_t pwm); void spinRight(uint8_t angle, uint8_t pwm); @@ -109,31 +110,7 @@ * Macro and inline functions definition */ - /** - \brief Stop the flippers motor - \ingroup flippers - */ -static inline void stopWings(void) __attribute__ ((always_inline)); -void stopWings(void) -{ - flippers_PWMMask &= ~MOT_WINGS_FW_MK; - MOT_WINGS_BW_PT &= ~MOT_WINGS_BW_MK; - MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK; -} - -/** - \brief Start wing motor backwards - \ingroup flippers - - 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);} - -/** \brief Stop the spinning motor \ingroup primitives */ Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2007-09-12 14:20:13 UTC (rev 518) +++ firmware/tuxcore/trunk/parser.c 2007-09-12 14:53:05 UTC (rev 519) @@ -102,23 +102,23 @@ } else if (command[0] == WAVE_WINGS_CMD) { - waveWings(command[1], command[2]); + wave_flippers(command[1], command[2]); } else if (command[0] == RAISE_WINGS_CMD) { - raiseWings(); + raise_flippers(); } else if (command[0] == LOWER_WINGS_CMD) { - lowerWings(); + lower_flippers(); } else if (command[0] == RESET_WINGS_CMD) { - resetWings(); + reset_flippers(); } else if (command[0] == STOP_WINGS_CMD) { - stopWings(); + stop_flippers(); } else if (command[0] == SPIN_LEFT_CMD) { Modified: firmware/tuxcore/trunk/standalone.c =================================================================== --- firmware/tuxcore/trunk/standalone.c 2007-09-12 14:20:13 UTC (rev 518) +++ firmware/tuxcore/trunk/standalone.c 2007-09-12 14:53:05 UTC (rev 519) @@ -285,7 +285,7 @@ move_mouth(mov_nbr); break; case K_DOWN: - waveWings(mov_nbr, 5); + wave_flippers(mov_nbr, 5); break; case K_LEFT: spinLeft(mov_nbr, spin_PWM); @@ -295,7 +295,7 @@ break; case K_STOP: stopSpin(); - stopWings(); + stop_flippers(); stop_mouth(); break; case K_MUTE: |