Hi @ishgupta
-
Below is my custom baudrate scanning and change code for DYNAMIXEL AX and MX series. What only to do, is to define BAUDRATE
in the line. --e.g, #define BAUDRATE 9600
-
Note: When I had tested this code today, I’ve found that the AX series with DYNAMIXEL Shield library has some comm issue on Some Baudrate (57600bps). The applicapable Baudrate in use of DynamixelShield library(v0.2.6) with DYNAMIXEL AX series is 9600, 115,200 and 1000000. If you are not using one of them, make sure to change it to one of the list.
-
DYNAMIXEL Shield has a UART Switch, which determines Upload Mode
and DYNAMIXEL control mode
. To do DYNAMIXEL, be sure to swtich it to Upload Mode
. (The reason is to avoid TX/RX packet collision with hardware serial pins)
#include <DynamixelShield.h>
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560)
#include <SoftwareSerial.h>
SoftwareSerial soft_serial(7, 8); // DYNAMIXELShield UART RX/TX
#define DEBUG_SERIAL soft_serial
#elif defined(ARDUINO_SAM_DUE) || defined(ARDUINO_SAM_ZERO)
#define DEBUG_SERIAL SerialUSB
#else
#define DEBUG_SERIAL Serial
#endif
//Please see eManual Control Table section of your DYNAMIXEL.
//This example is written for DYNAMIXEL AX & MX series with Protocol 1.0.
//For MX 2.0 with Protocol 2.0, refer to write_x.ino example.
#define CW_ANGLE_LIMIT_ADDR 6
#define CCW_ANGLE_LIMIT_ADDR 8
#define ANGLE_LIMIT_ADDR_LEN 2
#define OPERATING_MODE_ADDR_LEN 2
#define TORQUE_ENABLE_ADDR 24
#define TORQUE_ENABLE_ADDR_LEN 1
#define LED_ADDR 25
#define LED_ADDR_LEN 1
#define GOAL_POSITION_ADDR 30
#define GOAL_POSITION_ADDR_LEN 2
#define PRESENT_POSITION_ADDR 36
#define PRESENT_POSITION_ADDR_LEN 2
#define TIMEOUT 10 //default communication timeout 10ms
#define BAUDRATE 1000000 // Any Supported Protocol
DynamixelShield dxl;
const uint8_t DXL_ID = 1;
const float DXL_PROTOCOL_VERSION = 1.0;
uint8_t turn_on = 1;
uint8_t turn_off = 0;
const int32_t baud[10] = {2000000, 1000000, 500000, 400000, 250000, 200000, 115200, 57600, 19200, 9600};
const int8_t baud_len = 10;
int8_t index = 0;
uint8_t read_baudrate = 0;
void setup() {
// put your setup code here, to run once:
// For Uno, Nano, Mini, and Mega, use UART port of DYNAMIXEL Shield to debug.
DEBUG_SERIAL.begin(115200); //Set debugging port baudrate to 115200bps
while(!DEBUG_SERIAL); //Wait until the serial port for terminal is opened
// Set Port Protocol Version. This has to match with DYNAMIXEL protocol version.
dxl.setPortProtocolVersion(DXL_PROTOCOL_VERSION);
for(index = 0; index < baud_len; index++){
// Set Port baudrate.
DEBUG_SERIAL.print("SCAN BAUDRATE ");
DEBUG_SERIAL.println(baud[index]);
dxl.begin(baud[index]);
delay(100);
if(dxl.ping(DXL_ID)) {
DEBUG_SERIAL.print("ID : ");
DEBUG_SERIAL.print(DXL_ID);
DEBUG_SERIAL.println(", Ping Succeed");
DEBUG_SERIAL.print("Set New Baudrate:"); DEBUG_SERIAL.println(BAUDRATE);
dxl.setBaud(DXL_ID, BAUDRATE);
dxl.begin(BAUDRATE);
// dxl.setPortProtocolVersion(DXL_PROTOCOL_VERSION);
break;
}
}
}
void loop() {
// put your main code here, to run repeatedly:
// LED On
DEBUG_SERIAL.println("LED ON");
dxl.write(DXL_ID, LED_ADDR, (uint8_t*)&turn_on, LED_ADDR_LEN, TIMEOUT);
delay(500);
// LED Off
DEBUG_SERIAL.println("LED OFF");
dxl.write(DXL_ID, LED_ADDR, (uint8_t*)&turn_off, LED_ADDR_LEN, TIMEOUT);
delay(500);
}
This code only perfectly works with DYNAMIXEL Protocol 1.0 models such as AX-xx or MX-xx Series (Aside from MX-XX (2.0))