I would like to use the servo in position control mode, but I would like to be able to set the PROFILE_VELOCITY flag to latch the speed of the movement because it’s too fast for my application right now. I wasn’t having any luck with this, and was even having difficulty writing other values in memory, so I finally gave up and had the motor read back every value from the control table it could, and found many default values that didn’t line up with their addresses in the manual. Is there another version or something I should be using?
Eventually I want to set PROFILE_VELOCITY but for now I’d like to be able to set or understand pretty much any value in the table. For example, the “velocity limit” has a default value of 445, and is supposed to appear at address position 44 (emanual/docs/en/dxl/x/xl330-m288.md at master · ROBOTIS-GIT/emanual · GitHub), but in my readback, I see the value 445 at address 17. I feel like I’m doing something very wrong and I haven’t been able to figure it out.
Thank you!
This is the code I just ran
int i = 0;
do {
var = dxl.readControlTableItem(i, DXL_ID);
Serial.print("Read ");
Serial.print(i);
Serial.print(" value: ");
Serial.println(var);delay(20);
i++;
} while (i < 256);
and this is the output I got up through address 85 - all the rest were zeros
In readControlTableItem(i, id), the number i is interpreted as an index of a predefined Control Table item, not a memory address. So using it this way is incorrect.
To read values properly, make sure to use either readControlTableItem(ITEM_NAME, ID) or dxl.read(ID, address, size).
Thanks! that’s absolutely my problem. I just tried to limp it along by counting IDs in the file you sent, but I’d much rather just use names like
var = dxl.readControlTableItem(PROFILE_VELOCITY, DXL_ID);
Unfortunately none of these names are recognized when I try to use them. am I missing an import?
This code is kind of a wreck because I’ve been adding stuff to debug, but you can see at the top I’ve manually tried to define constants for the various IDs. if I don’t do that, I get something like
Compilation error: ‘GOAL_POSITION’ was not declared in this scope
Thanks again!
#include <Dynamixel2Arduino.h>
#define DXL_SERIAL Serial1
#define DXL_DIR_PIN 2
Dynamixel2Arduino dxl(DXL_SERIAL, DXL_DIR_PIN);
const uint8_t DXL_ID = 1;
const float DXL_PROTOCOL_VERSION = 2.0;
#define GOAL_POSITION 39
#define PROFILE_VELOCITY 38
#define PROFILE_ACCELERATION 37
void setup() {
Serial.begin(115200);
while (!Serial);
DXL_SERIAL.begin(57600);
dxl.begin();
dxl.setPortProtocolVersion(DXL_PROTOCOL_VERSION);
dxl.torqueOff(DXL_ID); // Torque must be OFF before mode or profile changes
uint32_t var = dxl.readControlTableItem(PROFILE_VELOCITY, DXL_ID);
Serial.print("Read PROFILE_VELOCITY: ");
Serial.println(var);
uint32_t newvel = 100;
dxl.writeControlTableItem(PROFILE_VELOCITY, DXL_ID, newvel); // Set high speed
var = dxl.readControlTableItem(PROFILE_VELOCITY, DXL_ID);
Serial.print("Read PROFILE_VELOCITY: ");
Serial.println(var);
//dxl.writeControlTableItem(DRIVE_MODE, DXL_ID, 0x00); // Velocity-based profile
dxl.setOperatingMode(DXL_ID, OP_POSITION); // Position control mode
newvel = 10;
uint32_t newacc = 10;
dxl.writeControlTableItem(PROFILE_ACCELERATION, DXL_ID, newacc); // Optional, smoother accel
dxl.writeControlTableItem(PROFILE_VELOCITY, DXL_ID, newvel); // Set high speed
uint32_t vel = dxl.readControlTableItem(PROFILE_VELOCITY, DXL_ID);
Serial.print("Read profile velocity: ");
Serial.println(vel);
dxl.torqueOn(DXL_ID);
}
void loop() {
uint32_t var=5;
int i = 0;
// do {
// var = dxl.readControlTableItem(i, DXL_ID);
// Serial.print("Read ");
// Serial.print(i);
// Serial.print(" value: ");
// Serial.println(var);delay(20);
// i++;
// } while (i < 256);
Serial.print("Read GOAL_POSITION: ");
Serial.println(var);
dxl.setGoalPosition(DXL_ID, 512); // Move to 45°
var = dxl.readControlTableItem(GOAL_POSITION, DXL_ID);
Serial.print("Read GOAL_POSITION: ");
Serial.println(var);
delay(2000);
dxl.setGoalPosition(DXL_ID, 1536); // Move to 135°
var = dxl.readControlTableItem(GOAL_POSITION, DXL_ID);
Serial.print("Read GOAL_POSITION: ");
Serial.println(var);
delay(2000);
//delay(1000000);
}
These are already defined inside the Dynamixel2Arduino library, so you should delete these lines from your code to avoid conflicts and redundancy.
Instead, just add the following line at the top of your code:
using namespace ControlTableItem;
This allows you to use symbolic names like GOAL_POSITION, PROFILE_VELOCITY, and PROFILE_ACCELERATION directly without redefining them. It keeps your code cleaner and safer.
Tip: You can also check the official examples in the Arduino IDE:
File → Examples → Dynamixel2Arduino → basic
For instance, the position_mode or profile_velocity_acceleration examples show exactly how to use these control table items properly using their symbolic names.
These examples are a great reference for setting up and using the library correctly.