Reading/Writing Dynamixel

The location of Dynamixel can be set and read.

(For more details check with Dynamixel SDK)

 

Things to Prepare

The controller and Dynamixel are connected.

This example is operated if the Dynamixel ID is 1.

 

Theory

Dynamixel can be controlled by transmitting designated packet. The location of Dynamixel can be controlled using provided library.

The microcontroller and Dynamixel comm are in USART channel 1

 

buffer.png

 

the diagram below show a circuit for Dynamixel comm for a half-duplex buffer.

Refer to controller’s port for port and pin number in 09 DXL READ_WRITE\APP\src\main.c

 

Source

int main(void)

{

/* System Clocks Configuration */

RCC_Configuration();

/* NVIC configuration */

NVIC_Configuration();

/* GPIO configuration */

GPIO_Configuration();

SysTick_Configuration();

dxl_initialize( 0, 1 );

USART_Configuration(USART_PC, Baudrate_PC);

TxDString("\n\nDynamixel Read/Write example for CM-530\n\n");

 

while(1)

{

bMoving = dxl_read_byte( id, P_MOVING );

CommStatus = dxl_get_result();

if( CommStatus == COMM_RXSUCCESS )

{

if( bMoving == 0 )

{

// Change goal position

if( INDEX == 0 )

INDEX = 1;

else

INDEX = 0;

// Write goal position

dxl_write_word( id, P_GOAL_POSITION_L, GoalPos[INDEX] );

}

PrintErrorCode();

// Read present position

wPresentPos = dxl_read_word( id, P_PRESENT_POSITION_L );

TxDWord16(GoalPos[INDEX]);

TxDString("   ");

TxDWord16(wPresentPos);

TxDByte_PC('\r');

TxDByte_PC('\n');

}

else

PrintCommStatus(CommStatus);

}

return 0;

}

 

 

Result

Dynamixel is moved back and forth in the disgnated location, and the current location is printed through terminal.