From 2679c6e885a36bfad76ecb04f5576cfd5f42e4d4 Mon Sep 17 00:00:00 2001 From: Boris Staletic Date: Mon, 24 Apr 2017 14:42:23 +0200 Subject: [PATCH] Retransmit AX12 command --- src/drivers/actuators/ax12/ax12.c | 72 ++++++++++++++++++++----------- src/drivers/actuators/ax12/ax12.h | 32 +++++++------- src/executors/revolver/revolver.c | 18 ++++---- src/executors/revolver/revolver.h | 16 +++---- 4 files changed, 80 insertions(+), 58 deletions(-) diff --git a/src/drivers/actuators/ax12/ax12.c b/src/drivers/actuators/ax12/ax12.c index d913067..c5268bf 100644 --- a/src/drivers/actuators/ax12/ax12.c +++ b/src/drivers/actuators/ax12/ax12.c @@ -1,6 +1,6 @@ #include "ax12.h" -uint8_t ax12_move(uint8_t id, uint16_t position) +void ax12_move(uint8_t id, uint16_t position) { uint8_t out_data[9], checksum; @@ -19,11 +19,14 @@ uint8_t ax12_move(uint8_t id, uint16_t position) out_data[8] = checksum; // Send data to AX12 - HAL_UART_Transmit(AX12_UART, out_data, 9, 9); - return ax12_read_response(); + do + { + HAL_UART_Transmit(AX12_UART, out_data, 9, 9); + } + while(ax12_read_response()); } -uint8_t ax12_move_speed(uint8_t id, uint16_t position, uint16_t speed) +void ax12_move_speed(uint8_t id, uint16_t position, uint16_t speed) { uint8_t out_data[11], checksum; @@ -45,11 +48,14 @@ uint8_t ax12_move_speed(uint8_t id, uint16_t position, uint16_t speed) out_data[10] = checksum; // Send data to AX12 - HAL_UART_Transmit(AX12_UART, out_data, 11, 11); - return ax12_read_response(); + do + { + HAL_UART_Transmit(AX12_UART, out_data, 11, 11); + } + while(ax12_read_response()); } -uint8_t ax12_set_speed(uint8_t id, uint16_t speed) +void ax12_set_speed(uint8_t id, uint16_t speed) { uint8_t out_data[9]; @@ -65,11 +71,14 @@ uint8_t ax12_set_speed(uint8_t id, uint16_t speed) out_data[7] = speed>>8; out_data[8] = checksum; - HAL_UART_Transmit(AX12_UART, out_data, 9, 0); - return ax12_read_response(); + do + { + HAL_UART_Transmit(AX12_UART, out_data, 9, 0); + } + while(ax12_read_response()); } -uint8_t ax12_factory_reset(uint8_t id) +void ax12_factory_reset(uint8_t id) { uint8_t out_data[6], checksum = ~(id + AX12_RESET_LENGTH + AX12_RESET); @@ -79,11 +88,14 @@ uint8_t ax12_factory_reset(uint8_t id) out_data[4] = AX12_RESET; out_data[5] = checksum; - HAL_UART_Transmit(AX12_UART, out_data, 6, 6); - return ax12_read_response(); + do + { + HAL_UART_Transmit(AX12_UART, out_data, 6, 6); + } + while(ax12_read_response()); } -uint8_t ax12_set_baudrate(uint8_t id, uint32_t baudrate) +void ax12_set_baudrate(uint8_t id, uint32_t baudrate) { uint8_t out_data[8], checksum = ~(id + AX12_BAUDRATE_LENGTH + AX12_WRITE_DATA + AX12_BAUDRATE + ((2000000/baudrate)-1)); @@ -96,11 +108,14 @@ uint8_t ax12_set_baudrate(uint8_t id, uint32_t baudrate) out_data[6] = (2000000/baudrate)-1; out_data[7] = checksum; - HAL_UART_Transmit(AX12_UART, out_data, 8, 8); - return ax12_read_response(); + do + { + HAL_UART_Transmit(AX12_UART, out_data, 8, 8); + } + while(ax12_read_response()); } -uint8_t ax12_set_id(uint8_t id, uint8_t new_id) +void ax12_set_id(uint8_t id, uint8_t new_id) { uint8_t out_data[8], checksum = ~(id + AX12_ID_LENGTH + AX12_WRITE_DATA + AX12_ID + new_id); @@ -113,11 +128,14 @@ uint8_t ax12_set_id(uint8_t id, uint8_t new_id) out_data[6] = new_id; out_data[7] = checksum; - HAL_UART_Transmit(AX12_UART, out_data, 8, 8); - return ax12_read_response(); + do + { + HAL_UART_Transmit(AX12_UART, out_data, 8, 8); + } + while(ax12_read_response()); } -uint8_t ax12_set_angle_limit(uint8_t id, uint16_t cw_limit, uint16_t ccw_limit) +void ax12_set_angle_limit(uint8_t id, uint16_t cw_limit, uint16_t ccw_limit) { uint8_t out_data[11], checksum = ~(id + AX12_AL_LENGTH + AX12_WRITE_DATA + AX12_ANGLE_LIMIT + (cw_limit&0xff) @@ -135,11 +153,14 @@ uint8_t ax12_set_angle_limit(uint8_t id, uint16_t cw_limit, uint16_t ccw_limit) out_data[9] = ccw_limit>>8; out_data[10] = checksum; - HAL_UART_Transmit(AX12_UART, out_data, 11, 11); - return ax12_read_response(); + do + { + HAL_UART_Transmit(AX12_UART, out_data, 11, 11); + } + while(ax12_read_response()); } -uint8_t ax12_read_moving_status(uint8_t id) +void ax12_read_moving_status(uint8_t id) { uint8_t out_data[8], checksum = ~(id + AX12_MOVING_LENGTH + AX12_READ_DATA + AX12_MOVING + AX12_BYTE_READ); @@ -152,8 +173,11 @@ uint8_t ax12_read_moving_status(uint8_t id) out_data[6] = AX12_BYTE_READ; out_data[7] = checksum; - HAL_UART_Transmit(AX12_UART, out_data, 8, 8); - return ax12_read_response(); + do + { + HAL_UART_Transmit(AX12_UART, out_data, 8, 8); + } + while(ax12_read_response()); } uint8_t ax12_read_response(void) diff --git a/src/drivers/actuators/ax12/ax12.h b/src/drivers/actuators/ax12/ax12.h index 886e100..02f386c 100644 --- a/src/drivers/actuators/ax12/ax12.h +++ b/src/drivers/actuators/ax12/ax12.h @@ -32,49 +32,49 @@ * AX12_UART function */ -/** \fn uint8_t ax12_move(uint8_t id, uint16_t position) +/** \fn void ax12_move(uint8_t id, uint16_t position) * \brief Rotates AX12_UART to specified position * * @param id [in] Uniquely identifies the AX12_UART. Possible values are [0,254] If id is 254 the command is broadcasted to all AX12 servo motors * @param position [in] Desired position of AX12_UART Possible values are [0,1023] */ -uint8_t ax12_move(uint8_t id, uint16_t position); -/** \fn uint8_t ax12_move_speed(uint8_t id, uint16_t position, uint16_t speed) +void ax12_move(uint8_t id, uint16_t position); +/** \fn void ax12_move_speed(uint8_t id, uint16_t position, uint16_t speed) * \brief Rotates AX12_UART to specified position at the specified speed * * @param id [in] Uniquely identifies the AX12_UART. Possible values are [0,254] If id is 254 the command is broadcasted to all AX12 servo motors * @param position [in] Desired position of AX12_UART Possible values are [0,1023] * @param speed [in] Rotate at desired speed Possible values are [0,255] */ -uint8_t ax12_move_speed(uint8_t id, uint16_t position, uint16_t speed); -/** \fn uint8_t ax12_set_speed(uint8_t id, uint16_t speed) +void ax12_move_speed(uint8_t id, uint16_t position, uint16_t speed); +/** \fn void ax12_set_speed(uint8_t id, uint16_t speed) * \brief Sets the speed of AX12_UART for future use * * @param id [in] Uniquely identifies the AX12_UART. Possible values are [0,254] If id is 254 the command is broadcasted to all AX12 servo motors * @param speed [in] Rotate at desired speed Possible values are [0,255] */ -uint8_t ax12_set_speed(uint8_t id, uint16_t speed); -/** \fn uint8_t ax12_factory_reset(uint8_t id) +void ax12_set_speed(uint8_t id, uint16_t speed); +/** \fn void ax12_factory_reset(uint8_t id) * \brief Restes the AX12_UART to factory defaults * * @param id [in] Uniquely identifies the AX12_UART. Possible values are [0,254] If id is 254 the command is broadcasted to all AX12 servo motors */ -uint8_t ax12_factory_reset(uint8_t id); -/** \fn uint8_t ax12_set_id(uint8_t id, uint8_t new_id) +void ax12_factory_reset(uint8_t id); +/** \fn void ax12_set_id(uint8_t id, uint8_t new_id) * \brief Sets the id of AX12_UART for future use * * @param id [in] Uniquely identifies the AX12_UART. Possible values are [0,254] If id is 254 the command is broadcasted to all AX12 servo motors * @param new_id [in] The desired new id of AX12_UART. */ -uint8_t ax12_set_id(uint8_t id, uint8_t new_id); -/** \fn uint8_t ax12_set_baudrate(uint8_t id, uint32_t baudrate) +void ax12_set_id(uint8_t id, uint8_t new_id); +/** \fn void ax12_set_baudrate(uint8_t id, uint32_t baudrate) * \brief Sets the baudrate of AX12_UART for future use * * @param id [in] Uniquely identifies the AX12_UART. Possible values are [0,254] If id is 254 the command is broadcasted to all AX12 servo motors * @param baudrate [in] Specifies the baudrate at which the AX12_UART communicates */ -uint8_t ax12_set_baudrate(uint8_t id, uint32_t baudrate); -/** \fn uint8_t ax12_set_angle_limit(uint8_t id, uint16_t cw_limit, uint16_t ccw_limit) +void ax12_set_baudrate(uint8_t id, uint32_t baudrate); +/** \fn void ax12_set_angle_limit(uint8_t id, uint16_t cw_limit, uint16_t ccw_limit) * \brief Sets the angle limits for rotating both clockwise and counter clockwise * * @param id [in] Uniquely identifies the AX12_UART. Possible values are [0,254] If id is 254 the command is broadcasted to all AX12 servo motors @@ -83,13 +83,13 @@ uint8_t ax12_set_baudrate(uint8_t id, uint32_t baudrate); * * If both angle limits are set to 0 AX12_UART is being used in wheel mode */ -uint8_t ax12_set_angle_limit(uint8_t id, uint16_t cw_limit, uint16_t ccw_limit); -/** \fn uint8_t ax12_read_moving_status(uint8_t id) +void ax12_set_angle_limit(uint8_t id, uint16_t cw_limit, uint16_t ccw_limit); +/** \fn void ax12_read_moving_status(uint8_t id) * \brief Read whether AX12_UART has finished moving * * @param id [in] Uniquely identifies the AX12_UART. Possible values are [0,254] If id is 254 the command is broadcasted to all AX12 servo motors */ -uint8_t ax12_read_moving_status(uint8_t id); +void ax12_read_moving_status(uint8_t id); /** \fn uint8_t ax12_read_response(void) * \brief Read response after sending a command to AX12 */ diff --git a/src/executors/revolver/revolver.c b/src/executors/revolver/revolver.c index 071a4ff..19261c8 100644 --- a/src/executors/revolver/revolver.c +++ b/src/executors/revolver/revolver.c @@ -1,24 +1,22 @@ #include "revolver.h" -int8_t revolver_init(void) +void revolver_init(void) { - return ax12_move(REVOLVER_AX12_ID, revolver_position); + ax12_move(REVOLVER_AX12_ID, revolver_position); } -int8_t revolver_go_to_position(uint16_t tube_number) +void revolver_go_to_position(uint16_t tube_number) { - return ax12_move(REVOLVER_AX12_ID, + ax12_move(REVOLVER_AX12_ID, revolver_position = tube_number * AX12_NEXT_POSITION_INC); } -int8_t revolver_next(void) +void revolver_next(void) { - return ax12_move(REVOLVER_AX12_ID, - revolver_position += AX12_NEXT_POSITION_INC); + ax12_move(REVOLVER_AX12_ID, revolver_position += AX12_NEXT_POSITION_INC); } -int8_t revolver_previous(void) +void revolver_previous(void) { - return ax12_move(REVOLVER_AX12_ID, - revolver_position -= AX12_NEXT_POSITION_INC); + ax12_move(REVOLVER_AX12_ID, revolver_position -= AX12_NEXT_POSITION_INC); } diff --git a/src/executors/revolver/revolver.h b/src/executors/revolver/revolver.h index 802b997..616a035 100644 --- a/src/executors/revolver/revolver.h +++ b/src/executors/revolver/revolver.h @@ -11,13 +11,13 @@ int16_t revolver_position = 0; /** - * \fn int8_t init(void) + * \fn void init(void) * \brief Set the executor in initial state */ -int8_t revolver_init(void); +void revolver_init(void); /** - * \fn int8_t go_to_position(uint8_t) + * \fn void go_to_position(uint8_t) * \brief Go to specified tube * * @param tube_number [in] the number of the tube @@ -26,18 +26,18 @@ int8_t revolver_init(void); * * Number of tubes - 8 */ -int8_t revolver_go_to_position(uint16_t tube_number); +void revolver_go_to_position(uint16_t tube_number); /** - * \fn int8_t next(void) + * \fn void next(void) * \brief Rotate to the next tube */ -int8_t revolver_next(void); +void revolver_next(void); /** - * \fn int8_t previous(void) + * \fn void previous(void) * \brief Rotate to the previous tube */ -int8_t revolver_previous(void); +void revolver_previous(void); #endif /* ifndef REVOLVER_EXECUTOR */