From 187903a80f8763387578fe6b11e0abb851f6f101 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 6 Apr 2012 23:21:58 +0200 Subject: digital/ai/src/twi_master: support asserv without aux --- digital/ai/src/twi_master/asserv.c | 21 +++++++++++++++++++++ digital/ai/src/twi_master/asserv.h | 18 +++++++++++++++++- digital/io-hub/src/guybrush/avrconfig.h | 4 ++++ digital/io-hub/src/robospierre/avrconfig.h | 4 ++++ digital/io/src/avrconfig.h | 4 ++++ 5 files changed, 50 insertions(+), 1 deletion(-) (limited to 'digital') diff --git a/digital/ai/src/twi_master/asserv.c b/digital/ai/src/twi_master/asserv.c index 839b1d23..76b2eb15 100644 --- a/digital/ai/src/twi_master/asserv.c +++ b/digital/ai/src/twi_master/asserv.c @@ -45,6 +45,7 @@ enum asserv_status_flag_e asserv_status_flag_move_forward = 2, /** Bot is moving backward (linear speed smaller than 0). */ asserv_status_flag_move_backward = 3, +#if AC_ASSERV_AUX_NB /** Motor0 movement finished with success. */ asserv_status_flag_motor0_succeed = 4, /** Motor0 movement finished with failure. */ @@ -53,6 +54,7 @@ enum asserv_status_flag_e asserv_status_flag_motor1_succeed = 6, /** Motor1 movement finished with failure. */ asserv_status_flag_motor1_failed = 7, +#endif }; typedef enum asserv_status_flag_e asserv_status_flag_e; @@ -89,10 +91,12 @@ typedef struct asserv_struct_s uint8_t input_port; /** Bot position. */ asserv_position_t position; +#if AC_ASSERV_AUX_NB /** Motor0 position. */ uint16_t motor0_position; /** Motor1 position. */ uint16_t motor1_position; +#endif } asserv_struct_s; /** @@ -125,8 +129,10 @@ asserv_status_cb (uint8_t *status) asserv_status.position.x = v8_to_v32 (0, status[3], status[4], status[5]); asserv_status.position.y = v8_to_v32 (0, status[6], status[7], status[8]); asserv_status.position.a = v8_to_v16 (status[9], status[10]); +#if AC_ASSERV_AUX_NB asserv_status.motor0_position = v8_to_v16 (status[11], status[12]); asserv_status.motor1_position = v8_to_v16 (status[13], status[14]); +#endif /* Update moving direction. */ if (asserv_get_moving_direction () != 0) asserv_last_moving_direction = asserv_get_moving_direction (); @@ -145,6 +151,8 @@ asserv_move_cmd_status (void) return none; } +#if AC_ASSERV_AUX_NB + asserv_status_e asserv_motor0_cmd_status (void) { @@ -171,6 +179,8 @@ asserv_motor1_cmd_status (void) return none; } +#endif /* AC_ASSERV_AUX_NB */ + void asserv_get_position (position_t *current_position) { @@ -183,6 +193,8 @@ asserv_get_position (position_t *current_position) current_position->a = asserv_status.position.a; } +#if AC_ASSERV_AUX_NB + uint16_t asserv_get_motor0_position (void) { @@ -197,6 +209,8 @@ asserv_get_motor1_position (void) return asserv_status.motor1_position; } +#endif /* AC_ASSERV_AUX_NB */ + uint8_t asserv_get_moving_direction (void) { @@ -322,6 +336,8 @@ asserv_push_the_wall (uint8_t backward, uint32_t init_x, uint32_t init_y, twi_master_send_buffer (10); } +#if AC_ASSERV_AUX_NB + void asserv_move_motor0_absolute (uint16_t position, uint8_t speed) { @@ -344,6 +360,8 @@ asserv_move_motor1_absolute (uint16_t position, uint8_t speed) twi_master_send_buffer (4); } +#endif /* AC_ASSERV_AUX_NB */ + void asserv_set_x_position (int32_t x) { @@ -433,6 +451,8 @@ asserv_goto (uint32_t x, uint32_t y, uint8_t backward) twi_master_send_buffer (8); } +#if AC_ASSERV_AUX_NB + void asserv_motor0_zero_position (int8_t speed) { @@ -469,3 +489,4 @@ asserv_motor1_free (void) twi_master_send_buffer (2); } +#endif /* AC_ASSERV_AUX_NB */ diff --git a/digital/ai/src/twi_master/asserv.h b/digital/ai/src/twi_master/asserv.h index c9a52a11..90e3b785 100644 --- a/digital/ai/src/twi_master/asserv.h +++ b/digital/ai/src/twi_master/asserv.h @@ -39,7 +39,7 @@ #define ASSERV_TWI_ADDRESS 4 /** Length of the status buffer (not including CRC). */ -#define ASSERV_STATUS_LENGTH 15 +#define ASSERV_STATUS_LENGTH (11 + AC_ASSERV_AUX_NB * 2) /** Use backward movements. */ #define ASSERV_BACKWARD 1 @@ -79,6 +79,8 @@ typedef enum asserv_status_e asserv_status_e asserv_move_cmd_status (void); +#if AC_ASSERV_AUX_NB + /** * Is last motor0 class command has successfully ended? * This function is used to know the status of the last motor0 command. It @@ -97,6 +99,8 @@ asserv_motor0_cmd_status (void); asserv_status_e asserv_motor1_cmd_status (void); +#endif /* AC_ASSERV_AUX_NB */ + /** * Get the current position of the bot. * @param current_position the current position to update. @@ -104,6 +108,8 @@ asserv_motor1_cmd_status (void); void asserv_get_position (position_t *current_position); +#if AC_ASSERV_AUX_NB + /** * Get the motor0 position. * @return the position of the motor0 (in steps). @@ -118,6 +124,8 @@ asserv_get_motor0_position (void); uint16_t asserv_get_motor1_position (void); +#endif /* AC_ASSERV_AUX_NB */ + /** * Are we moving forward/backward? * @return @@ -204,6 +212,8 @@ void asserv_push_the_wall (uint8_t backward, uint32_t init_x, uint32_t init_y, uint16_t init_a); +#if AC_ASSERV_AUX_NB + /** * Move the motor0. * Motor0 class command. @@ -226,6 +236,8 @@ asserv_move_motor0_absolute (uint16_t position, uint8_t speed); void asserv_move_motor1_absolute (uint16_t position, uint8_t speed); +#endif /* AC_ASSERV_AUX_NB */ + /** * Set current X position. * Other class command. @@ -284,6 +296,8 @@ asserv_set_position (int32_t x, int32_t y, int16_t angle); void asserv_goto (uint32_t x, uint32_t y, uint8_t backward); +#if AC_ASSERV_AUX_NB + /** Reset the motor0 to the zero position. */ void asserv_motor0_zero_position (int8_t speed); @@ -300,4 +314,6 @@ asserv_motor0_free (void); void asserv_motor1_free (void); +#endif /* AC_ASSERV_AUX_NB */ + #endif /* asserv_h */ diff --git a/digital/io-hub/src/guybrush/avrconfig.h b/digital/io-hub/src/guybrush/avrconfig.h index ab581210..d41ac498 100644 --- a/digital/io-hub/src/guybrush/avrconfig.h +++ b/digital/io-hub/src/guybrush/avrconfig.h @@ -132,4 +132,8 @@ /** PWM setting. */ #undef AC_IOHUB_PWM +/* asserv. */ +/** Number of auxiliary motors. */ +#define AC_ASSERV_AUX_NB 2 + #endif /* avrconfig_h */ diff --git a/digital/io-hub/src/robospierre/avrconfig.h b/digital/io-hub/src/robospierre/avrconfig.h index 581fa136..fdd682d0 100644 --- a/digital/io-hub/src/robospierre/avrconfig.h +++ b/digital/io-hub/src/robospierre/avrconfig.h @@ -138,4 +138,8 @@ PWM (3, B, C, 5, C, 3) \ PWM (3, C, C, 4, C, 2) +/* asserv. */ +/** Number of auxiliary motors. */ +#define AC_ASSERV_AUX_NB 2 + #endif /* avrconfig_h */ diff --git a/digital/io/src/avrconfig.h b/digital/io/src/avrconfig.h index cb9061fd..2ad8c129 100644 --- a/digital/io/src/avrconfig.h +++ b/digital/io/src/avrconfig.h @@ -138,6 +138,10 @@ /** TWI address of the io board. */ #define AC_IO_TWI_ADDRESS 2 +/* asserv. */ +/** Number of auxiliary motors. */ +#define AC_ASSERV_AUX_NB 2 + /* spi - SPI module. */ /** Select driver: HARD, SOFT, or NONE. */ #define AC_SPI0_DRIVER HARD -- cgit v1.2.3