I can share part of the test code I used to identify the problem with the 2XC430. In this code, dxl1 and dxl2 is the 2XC430, and dxl3 is the XC430. Using this code, I’m able to control every motor in velocity mode, but I’m unable to control the 2XC430 in pwm mode. Note that I used the same code to control XM430 and XH430 motors in pwm mode also. In short the only motors that doesn’t work with this code are the 2XC430. I tested two different 2XC430 to make sure my problem was not related to a defective unit.
/***************************************************************************
Include headers :
***************************************************************************/
#include <Arduino.h>
#include <dynaUART.h>
unsigned long currentTime;
unsigned long previousTime;
/***************************************************************************
Function prototype :
***************************************************************************/
void toggleLed();
DynaUART dxl1 = DynaUART(0x01);
DynaUART dxl2 = DynaUART(0x02);
DynaUART dxl3 = DynaUART(0x03);
int16_t speed;
/****************************************************************************
Setup Program :
****************************************************************************/
void setup()
{
previousTime = 0;
speed = 300;
Serial2.begin(57600);
Serial2.setTimeout(5);
delay(1000);
dxl1.initMotor();
dxl2.initMotor();
dxl3.initMotor();
dxl1.setOperatingMode(PWM_MODE);
delay(1000);
dxl2.setOperatingMode(PWM_MODE);
delay(1000);
dxl3.setOperatingMode(PWM_MODE);
delay(1000);
}
/****************************************************************************
Main Program :
****************************************************************************/
void loop()
{
toggleLed();
delay(10);
}
/****************************************************************************
Function definition :
****************************************************************************/
void toggleLed()
{
if(millis()-previousTime > LED_INTERVAL)
{
dxl1.setPWMCommand(speed);
delay(100);
dxl2.setPWMCommand(speed);
delay(100);
dxl3.setPWMCommand(speed);
delay(100);
speed = -speed;
previousTime = millis();
}
}
void DynaUART::initMotor()
{
delay(10);
setTorque(OFF);
delay(10);
setShutdownCondition(ELECTRIC_ERROR | OVERHEATING_ERROR | INPUT_VOLTAGE_ERROR | ENCODER_ERROR | OVERLOAD_ERROR);
delay(10);
setOperatingMode(WHEEL_MODE);
delay(10);
}
void DynaUART::setOperatingMode(uint8_t mode)
{
setTorque(OFF);
delay(10);
instruction[0] = operatingMode;
instruction[1] = 0x00;
instruction[2] = mode;
preparePacket(WRITE, instruction, 3);
sendPacket();
delay(10);
setTorque(ON);
delay(10);
}
void DynaUART::setVelocityCommand(int32_t speed)
{
speed = constrain(speed, -MAX_SPEED, MAX_SPEED);
if(speed < 0)
{
speed = (~abs(speed)) + 1;
}
instruction[0] = goalVelocity;
instruction[1] = 0x00;
instruction[2] = speed & 0x000000FF;
instruction[3] = (speed >> 8) & 0x000000FF;
instruction[4] = (speed >> 16) & 0x000000FF;
instruction[5] = (speed >> 24) & 0x000000FF;
preparePacket(WRITE, instruction, 6);
sendPacket();
}
void DynaUART::setPWMCommand(int16_t pwm)
{
pwm = constrain(pwm, -MAX_PWM, MAX_PWM);
if(pwm < 0)
{
pwm = (~abs(pwm)) + 1;
}
instruction[0] = goalPWM;
instruction[1] = 0x00;
instruction[2] = pwm & 0x000000FF;
instruction[3] = (pwm >> 8) & 0x000000FF;
preparePacket(WRITE, instruction, 4);
sendPacket();
}
void DynaUART::setShutdownCondition(uint8_t condition)
{
instruction[0] = shutdown;
instruction[1] = 0x00;
instruction[2] = condition;
preparePacket(WRITE, instruction, 3);
sendPacket();
}