[tuxdroid-svn] r840 - in firmware: tuxcore/trunk tuxdefs
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2008-01-11 09:08:11
|
Author: Paul_R Date: 2008-01-11 10:08:02 +0100 (Fri, 11 Jan 2008) New Revision: 840 Modified: firmware/tuxcore/trunk/motors.c firmware/tuxdefs/defines.h Log: * Fixed a bug with the PWM values of the wings and the spinning motors. * Fixed a bug with the final position on the open_mouth and close_mouth functions. Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2008-01-08 15:52:18 UTC (rev 839) +++ firmware/tuxcore/trunk/motors.c 2008-01-11 09:08:02 UTC (rev 840) @@ -513,30 +513,42 @@ \brief Open the mouth. \ingroup mouth - Open the mouth if they are closed. + This function open the mouth if it's not already open. + The command is sent only if the mouth is not open or if the motor is + running. + We don't know the absolute mouth position. So, a command is sent + with 2 movements, and a flag is set to specify the final position. When the + final position is reached, the mouth_move_counter is reinitialized, and the + motor will stop. */ void open_mouth(void) { - if (!(PSW_MOUTH_PIN & PSW_MOUTH_C_MK)) - move_mouth(1); - if (MOT_MOUTH_PT |= MOT_MOUTH_MK) - mouth_final_state = MOUTH_OPENED; + if (PSW_MOUTH_PIN & PSW_MOUTH_O_MK || MOT_MOUTH_PT & MOT_MOUTH_MK) + { move_mouth(2); + mouth_final_state = MOUTH_OPEN; + } } /** \brief Close the mouth. \ingroup mouth - Close the mouth if they are opened. + This function close the mouth if it's not already closed. + The command is sent only if the mouth is not closed or if the motor is + running. + We don't know the absolute mouth position. So, a command is sent + with 2 movements, and a flag is set to specify the final position. When the + final position is reached, the mouth_move_counter is reinitialized, and the + motor will stop. */ void close_mouth(void) { - if (!(PSW_MOUTH_PIN & PSW_MOUTH_O_MK)) - move_mouth(1); - if (MOT_MOUTH_PT |= MOT_MOUTH_MK) + if (PSW_MOUTH_PIN & PSW_MOUTH_C_MK || MOT_MOUTH_PT & MOT_MOUTH_MK) + { + move_mouth(2); mouth_final_state = MOUTH_CLOSED; - move_mouth(2); + } } /** @@ -565,7 +577,7 @@ mouth_move_counter--; if (mouth_final_state != MOUTH_UNKNOWN) { - if ((mouth_final_state == MOUTH_OPENED) && !(PSW_MOUTH_PIN & PSW_MOUTH_O_MK)) + if ((mouth_final_state == MOUTH_OPEN) && !(PSW_MOUTH_PIN & PSW_MOUTH_O_MK)) mouth_move_counter = 0; else if ((mouth_final_state == MOUTH_CLOSED) && !(PSW_MOUTH_PIN & PSW_MOUTH_C_MK)) mouth_move_counter = 0; @@ -645,6 +657,7 @@ //flippers_stop_delay = 0; MOT_FLIPPERS_BW_PT &= ~MOT_FLIPPERS_BW_MK; flippers_PWMMask |= MOT_FLIPPERS_FW_MK; + PORTB |= flippers_PWMMask; } /** @@ -828,6 +841,7 @@ spin_PWM = pwm; spin_PWM_mask &= ~MOT_SPIN_R_MK; spin_PWM_mask |= MOT_SPIN_L_MK; + PORTB |= portB_PWM_mask; } /** @@ -851,6 +865,7 @@ spin_PWM = pwm; spin_PWM_mask &= ~MOT_SPIN_L_MK; spin_PWM_mask |= MOT_SPIN_R_MK; + PORTB |= portB_PWM_mask; } /** \brief Spin position interrupt. Modified: firmware/tuxdefs/defines.h =================================================================== --- firmware/tuxdefs/defines.h 2008-01-08 15:52:18 UTC (rev 839) +++ firmware/tuxdefs/defines.h 2008-01-11 09:08:02 UTC (rev 840) @@ -194,10 +194,13 @@ typedef enum { MOUTH_UNKNOWN, - MOUTH_OPENED, + MOUTH_OPEN, MOUTH_CLOSED, } MOUTH_POSITION_t; +#define MOTORS_CMD_MASK 0x7F +#define MOTORS_VALUE_MASK 0x80 + /** * Type indicating the motor */ @@ -209,18 +212,18 @@ MOT_SPIN_L, MOT_SPIN_R, } MOTOR_TYPE_t; + + /** - * Type indicating the final position + * Defines indicating the final position */ -typedef enum -{ - FP_OPEN = 0, - FP_UP = 0, - FP_CLOSE = 1, - FP_DOWN = 1, - FP_UNDEFINED = 2, -} MOT_FINAL_POS_t; +#define FP_EYES_CLOSE 0x80 +#define FP_EYES_OPEN 0x40 +#define FP_MOUTH_CLOSE 0x10 +#define FP_MOUTH_OPEN 0x08 +#define FP_FLIPPERS_UP 0x04 +#define FP_FLIPPERS_DOWN 0x02 /** * Type indicating the status |