[tuxdroid-svn] r835 - in firmware: tuxcore/trunk tuxdefs
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2008-01-07 16:08:18
|
Author: Paul_R Date: 2008-01-07 17:08:17 +0100 (Mon, 07 Jan 2008) New Revision: 835 Modified: firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/motors.h firmware/tuxcore/trunk/parser.c firmware/tuxdefs/api.h firmware/tuxdefs/defines.h Log: * Added two new commands (OxD4 - MOTORS_RUN and 0x81 - MOTORS_CONFIG) to commands the motors. The motors can be configured with a number of movements, or with a duration. (time base : 4ms : max 255*4ms). Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2008-01-07 16:03:39 UTC (rev 834) +++ firmware/tuxcore/trunk/motors.c 2008-01-07 16:08:17 UTC (rev 835) @@ -30,6 +30,20 @@ #include "global.h" #include "motors.h" #include "common/defines.h" +/** + * \name Motors structures + * @{ */ +motors_t eyes_params; +motors_t mouth_params; +motors_t flippers_params = +{ + .pwm = 5, +}; +motors_t spin_params = +{ + .pwm = 5, +}; +/*! @} */ /** * \name Braking delays @@ -161,6 +175,107 @@ } /*! @} */ +/** + * \name Motors command parser + * These functions parse the received command, and call the specific motor + * function. + * @{ */ +/** \ingroup movements */ +/** + \brief Parse the MOTORS_SET_CMD to command a motor with a specific number of movements. + \param motor The motor to command + \param value The number of movements or/ the timeout valueto execute + \param params bit 0 & 1 : The final state; bit 2 : 0 for count, 1 for timeout + */ +void motors_run(uint8_t motor, uint8_t const value, uint8_t const param) +{ + uint8_t cnt; + if (motor == MOT_EYES) + { + if (param & 0x01) + { + eyes_params.delay = value; + eyes_stop_delay = value; + cnt = 0; + } + else + { + eyes_params.count = value; + cnt = value; + } + blink_eyes(cnt); + } + else if (motor == MOT_MOUTH) + { + if (param & 0x01) + { + mouth_params.delay = value; + mouth_stop_delay = value; + cnt = 0; + } + else + { + mouth_params.count = value; + cnt = value; + } + move_mouth(cnt); + } + else if (motor == MOT_FLIPPERS) + { + if (param & 0x01) + { + flippers_params.delay = value; + flippers_stop_delay = value; + cnt = 0; + } + else + { + flippers_params.count = value; + cnt = value; + } + wave_flippers(cnt, flippers_params.pwm); + } + else if (motor == (MOT_SPIN_L) || motor == (MOT_SPIN_R)) + { + if (param & 0x01) + { + spin_params.delay = value; + spin_stop_delay = value; + cnt = 0; + } + else + { + spin_params.count = value; + cnt = value; + } + if (motor == MOT_SPIN_L) + spin_left(value, spin_params.pwm); + else + spin_right(value, spin_params.pwm); + } +} + +/** + \brief Parse the MOTORS_SET_CMD to command a motor with a specific number of movements. + \param motor The motor to command + \param pwm The PWM value + + The PWM can be used only for the spinning and the flippers. + + */ +void motors_config(uint8_t const motor, uint8_t const pwm) +{ + if (motor == MOT_FLIPPERS) + { + flippers_params.pwm = pwm; + flippers_PWM = pwm; + } + else if (motor == (MOT_SPIN_L) || motor == (MOT_SPIN_R)) + { + spin_params.pwm = pwm; + spin_PWM = pwm; + } +} /** Counter for flipper interrupt suspend. */ uint8_t static suspend_flippers_delay = 0; @@ -255,7 +370,7 @@ { gStatus.mot |= GSTATUS_MOT_EYES; eyes_move_counter = cnt; - eyes_stop_delay = 0; + //eyes_stop_delay = 0; run_eyes_motor(); } @@ -414,7 +529,7 @@ { gStatus.mot |= GSTATUS_MOT_MOUTH; mouth_move_counter = cnt; - mouth_stop_delay = 0; + //mouth_stop_delay = 0; run_mouth_motor(); } @@ -551,7 +666,7 @@ gStatus.mot |= GSTATUS_MOT_WINGS; flippers_move_counter = cnt; flippers_PWM = pwm; - flippers_stop_delay = 0; + //flippers_stop_delay = 0; MOT_FLIPPERS_BW_PT &= ~MOT_FLIPPERS_BW_MK; flippers_PWMMask |= MOT_FLIPPERS_FW_MK; } Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2008-01-07 16:03:39 UTC (rev 834) +++ firmware/tuxcore/trunk/motors.h 2008-01-07 16:08:17 UTC (rev 835) @@ -76,6 +76,12 @@ void initMotors(void); /* + * Motors commands parser + */ +extern void motors_run(uint8_t const motor, uint8_t const value, uint8_t const param); +extern void motors_config(uint8_t const motor, uint8_t const pwm); + +/* * Movements */ extern void stop_eyes(void); @@ -100,4 +106,19 @@ */ extern void motor_control(void); +/* + * Motors status structure + */ +typedef struct motors_t +{ + uint8_t count; + uint8_t pwm; + uint8_t delay; +} motors_t; + +extern motors_t eyes_params; +extern motors_t mouth_params; +extern motors_t flippers_params; +extern motors_t spin_params; + #endif /* _MOTORS_H_ */ Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2008-01-07 16:03:39 UTC (rev 834) +++ firmware/tuxcore/trunk/parser.c 2008-01-07 16:08:17 UTC (rev 835) @@ -66,72 +66,15 @@ gStatus.audio_status = command[3]; return; } - - /* Moves */ - else if (command[0] == BLINK_EYES_CMD) + /* Move */ + else if (command[0] == MOTORS_SET_CMD) { - blink_eyes(command[1]); + motors_run(command[1], command[2], command[3]); } - else if (command[0] == STOP_EYES_CMD) + else if (command[0] == MOTORS_CONFIG_CMD) { - stop_eyes(); + motors_config(command[1], command[2]); } - else if (command[0] == OPEN_EYES_CMD) - { - open_eyes(); - } - else if (command[0] == CLOSE_EYES_CMD) - { - close_eyes(); - } - else if (command[0] == MOVE_MOUTH_CMD) - { - move_mouth(command[1]); - } - else if (command[0] == OPEN_MOUTH_CMD) - { - open_mouth(); - } - else if (command[0] == CLOSE_MOUTH_CMD) - { - close_mouth(); - } - else if (command[0] == STOP_MOUTH_CMD) - { - stop_mouth(); - } - else if (command[0] == WAVE_WINGS_CMD) - { - wave_flippers(command[1], command[2]); - } - else if (command[0] == RAISE_WINGS_CMD) - { - raise_flippers(); - } - else if (command[0] == LOWER_WINGS_CMD) - { - lower_flippers(); - } - else if (command[0] == RESET_WINGS_CMD) - { - reset_flippers(); - } - else if (command[0] == STOP_WINGS_CMD) - { - stop_flippers(); - } - else if (command[0] == SPIN_LEFT_CMD) - { - spin_left(command[1], command[2]); - } - else if (command[0] == SPIN_RIGHT_CMD) - { - spin_right(command[1], command[2]); - } - else if (command[0] == STOP_SPIN_CMD) - { - stop_spinning(); - } /* Leds */ else if (command[0] == LED_PULSE_RANGE_CMD) { @@ -245,6 +188,72 @@ { led_set_intensity(LED_RIGHT, 0x0); } + + /* Moves */ + else if (command[0] == BLINK_EYES_CMD) + { + blink_eyes(command[1]); + } + else if (command[0] == STOP_EYES_CMD) + { + stop_eyes(); + } + else if (command[0] == OPEN_EYES_CMD) + { + open_eyes(); + } + else if (command[0] == CLOSE_EYES_CMD) + { + close_eyes(); + } + else if (command[0] == MOVE_MOUTH_CMD) + { + move_mouth(command[1]); + } + else if (command[0] == OPEN_MOUTH_CMD) + { + open_mouth(); + } + else if (command[0] == CLOSE_MOUTH_CMD) + { + close_mouth(); + } + else if (command[0] == STOP_MOUTH_CMD) + { + stop_mouth(); + } + else if (command[0] == WAVE_WINGS_CMD) + { + wave_flippers(command[1], command[2]); + } + else if (command[0] == RAISE_WINGS_CMD) + { + raise_flippers(); + } + else if (command[0] == LOWER_WINGS_CMD) + { + lower_flippers(); + } + else if (command[0] == RESET_WINGS_CMD) + { + reset_flippers(); + } + else if (command[0] == STOP_WINGS_CMD) + { + stop_flippers(); + } + else if (command[0] == SPIN_LEFT_CMD) + { + spin_left(command[1], command[2]); + } + else if (command[0] == SPIN_RIGHT_CMD) + { + spin_right(command[1], command[2]); + } + else if (command[0] == STOP_SPIN_CMD) + { + stop_spinning(); + } /* Undefined commands */ else Modified: firmware/tuxdefs/api.h =================================================================== --- firmware/tuxdefs/api.h 2008-01-07 16:03:39 UTC (rev 834) +++ firmware/tuxdefs/api.h 2008-01-07 16:08:17 UTC (rev 835) @@ -277,8 +277,35 @@ /*! @} */ +/** \name Movement commands + * Theses commands are used to move Tux. + * @{ */ + +/** + * Execute a defined number of movements, with a specified final state. + * + * Parameters: + * - 1 : The motor to command + * - 2 : The count or/ timeout value + * - 3 : + * .0..1 : The final state + * .2 : 0 for count, 1 for timeout + */ +#define MOTORS_SET_CMD 0xD4 + +/** + * Execute a movement for a defined time and specify the PWM duty cycle. + * + * Parameters: + * - 1 : The motor to command + * - 2 : The PWM frequency + */ +#define MOTORS_CONFIG_CMD 0x81 /*! @} */ + +/*! @} */ + /** States of the audio recording (flash programming) process */ typedef enum audiorec_status { Modified: firmware/tuxdefs/defines.h =================================================================== --- firmware/tuxdefs/defines.h 2008-01-07 16:03:39 UTC (rev 834) +++ firmware/tuxdefs/defines.h 2008-01-07 16:08:17 UTC (rev 835) @@ -188,7 +188,6 @@ * \name Movements */ /*! @{ */ - /** * Type indicating the mouth position. */ @@ -199,6 +198,43 @@ MOUTH_CLOSED, } MOUTH_POSITION_t; +/** + * Type indicating the motor + */ +typedef enum +{ + MOT_EYES, + MOT_MOUTH, + MOT_FLIPPERS, + MOT_SPIN_L, + MOT_SPIN_R, +} MOTOR_TYPE_t; + +/** + * Type 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; + +/** + * Type indicating the status + */ +typedef enum +{ + STAT_STOPPED = 0, + STAT_OPEN = 1, + STAT_UP = 1, + STAT_CLOSE = 2, + STAT_DOWN = 2, + STAT_RUNNING = 3, +} MOT_STATUS_t; + /*! @} */ /** |