You are confusing me now. You are using Arduino IDE with OpenCR and I am assuming that you have installed the OpenCR board via the Board Manager - so why would you need to use the Arduino UNO + Shield? Also have you installed the Dynamixel2Arduino library? If you have done these 2 tasks, there should be a bunch of example sketches showing how to control the DXLs from OpenCR directly.
Below is a complete Arduino sketch testing some XL-430 with OpenCR-1 and the Dynamixel2Arduino library:
#include <Dynamixel2Arduino.h>
#define DXL_SERIAL Serial3 // for OpenCR
#define DEBUG_SERIAL Serial
const int DXL_DIR_PIN = 84; // OpenCR Board's DIR PIN.
const uint8_t DXL_ID = 1;
const float DXL_PROTOCOL_VERSION = 2.0; // 1.0 for AX-12
Dynamixel2Arduino dxl(DXL_SERIAL, DXL_DIR_PIN);
//This namespace is required to use Control table item names
using namespace ControlTableItem;
void setup() {
// put your setup code here, to run once:
// Use UART port of DYNAMIXEL Shield to debug.
DEBUG_SERIAL.begin(115200);
while(!DEBUG_SERIAL);
// Set Port baudrate to 1000000 bps. This has to match with DYNAMIXEL baudrate.
dxl.begin(1000000);
// Set Port Protocol Version. This has to match with DYNAMIXEL protocol version.
dxl.setPortProtocolVersion(DXL_PROTOCOL_VERSION);
// Get DYNAMIXEL information
dxl.ping(DXL_ID);
// Turn off torque when configuring items in EEPROM area
dxl.torqueOff(DXL_ID);
dxl.setOperatingMode(DXL_ID, OP_VELOCITY);
dxl.torqueOn(DXL_ID);
}
void loop() {
// Set Goal Velocity using RAW unit
dxl.setGoalVelocity(DXL_ID, 200);
delay(1000);
// Print present velocity
DEBUG_SERIAL.print("Present Velocity(raw) : ");
DEBUG_SERIAL.println(dxl.getPresentVelocity(DXL_ID));
delay(1000);
// Set Goal Velocity using RPM
dxl.setGoalVelocity(DXL_ID, 25.8, UNIT_RPM);
delay(1000);
DEBUG_SERIAL.print("Present Velocity(rpm) : ");
DEBUG_SERIAL.println(dxl.getPresentVelocity(DXL_ID, UNIT_RPM));
delay(1000);
// Set Goal Velocity using percentage (-100.0 [%] ~ 100.0 [%])
dxl.setGoalVelocity(DXL_ID, -10.2, UNIT_PERCENT);
delay(1000);
DEBUG_SERIAL.print("Present Velocity(ratio) : ");
DEBUG_SERIAL.println(dxl.getPresentVelocity(DXL_ID, UNIT_PERCENT));
delay(1000);
}
To make it work with AX-12s, all you have to do is to change DXL_PROTOCOL_VERSION = 1.0
Below is a picture of my physical setup:
And a video clip of a SyncWriteRead sketch (using 2XL430):