Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retransmit AX12 command #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 48 additions & 24 deletions src/drivers/actuators/ax12/ax12.c
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;

Expand All @@ -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];

Expand All @@ -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);

Expand All @@ -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));
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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)
Expand Down
32 changes: 16 additions & 16 deletions src/drivers/actuators/ax12/ax12.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*/
Expand Down
18 changes: 8 additions & 10 deletions src/executors/revolver/revolver.c
Original file line number Diff line number Diff line change
@@ -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);
}
16 changes: 8 additions & 8 deletions src/executors/revolver/revolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */