ROBOTIS e-Manual v1.13.01
The location of Dynamixel can be set and read.
The controller and Dynamixel are connected.
This example is operated if the Dynamixel ID is 1.
Dynamixel can be controlled by transmitting designated packet. The location of Dynamixel can be controlled using provided library.
|
unsigned short GoalPos[2] = {0, 1023}; //unsigned short wGoalPos[2] = {0, 4095}; // for EX series |
Like EX 106+, if an actuator belongs to the location range between 0 and 4095, notes are applied to the upper line but not applied to the lower line.
|
serial_initialize(57600); dxl_initialize( 0, DEFAULT_BAUDNUM ); // Not using device index sei(); // Interrupt Enable |
This part is for initialization to use serial communication. The serial initialization function is included in serial library, and the serial port is initialized if communication speed is transmitted by data.
In the case of sei(), it is an internal command makes users possible to use "Interrupt."
In the case of dxl_initialize() function, communication environemnt of the controller is initialized if device index and communication speed are transmitted by data.
DEFAULT_BAUDNUM is 1.
If there are no specific reasons, device index is 0.
|
// Check moving done 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 ); printf( "%d %d\n",GoalPos[index], wPresentPos ); } else PrintCommStatus(CommStatus); |
This part describes that Dynamixel is sent to certain location, and the current location is read at the same time.
First of all, if the current movement status has been read, and the motor is not moving, the movement command to the designated location can be carried on by dxl_write_word() function.
The data of dxl_write_word() function are respectively (the ID, address, and position values of connected Dynamixel).
Later, the current location is read and transmitted by serial communication.
Dynamixel is moved back and forth in the disgnated location, and the current location is printed through terminal.