This function writes data to a specific memory address of DYNAMIXEL with a specific ID.
NOTE
DXL_MAX_NODE
: 16
DXL_MAX_NODE_BUFFER_SIZE
: 12
#include <Dynamixel2Arduino.h>
SoftwareSerial soft_serial(7, 8); //RX,TX
#define DXL_SERIAL Serial
#define DEBUG_SERIAL soft_serial //define proper serial debugging port for the board
const uint8_t RS485_DIR_PIN = 2; //DYNAMIXEL Shield
ParamForSyncReadInst_t sync_read_param;
RecvInfoFromStatusInst_t read_result;
const int DXL_DIR_PIN = 2;
int32_t recv_velocity[2];
Dynamixel2Arduino dxl(DXL_SERIAL, RS485_DIR_PIN);
void setup() {
DEBUG_SERIAL.begin(115200);
dxl.begin(1000000);
dxl.scan();
sync_read_param.addr = 128; //Present Velocity of DYNAMIXEL-X series
sync_read_param.length = 4;
sync_read_param.xel[0].id = 1;
sync_read_param.xel[1].id = 3;
sync_read_param.id_count = 2;
}
void loop() {
dxl.syncRead(sync_read_param, read_result);
DEBUG_SERIAL.println("======= Sync Read =======");
memcpy(&recv_velocity[0], read_result.xel[0].data, read_result.xel[0].length);
memcpy(&recv_velocity[1], read_result.xel[1].data, read_result.xel[1].length);
DEBUG_SERIAL.print("ID: ");DEBUG_SERIAL.print(read_result.xel[0].id);DEBUG_SERIAL.print(" ");
DEBUG_SERIAL.print(", Present Velocity: ");DEBUG_SERIAL.print(recv_velocity[0]);DEBUG_SERIAL.print(" ");
DEBUG_SERIAL.print(", Packet Error: ");DEBUG_SERIAL.print(read_result.xel[0].error);DEBUG_SERIAL.print(" ");
DEBUG_SERIAL.print(", Param Length: ");DEBUG_SERIAL.print(read_result.xel[0].length);DEBUG_SERIAL.print(" ");
DEBUG_SERIAL.println();
DEBUG_SERIAL.print("ID: ");DEBUG_SERIAL.print(read_result.xel[1].id);DEBUG_SERIAL.print(" ");
DEBUG_SERIAL.print(", Present Velocity: ");DEBUG_SERIAL.print(recv_velocity[1]);DEBUG_SERIAL.print(" ");
DEBUG_SERIAL.print(", Packet Error: ");DEBUG_SERIAL.print(read_result.xel[1].error);DEBUG_SERIAL.print(" ");
DEBUG_SERIAL.print(", Param Length: ");DEBUG_SERIAL.print(read_result.xel[1].length);DEBUG_SERIAL.print(" ");
DEBUG_SERIAL.println();
delay(100);
}