One interesting thing with setups to do the firmware recovery.
The code will change baud rates at different times to do the recovery.
So your code needs to be able to detect when FTDI has been asked to change baud rates and then change the rate you try to talk to the servos at that baud rate.
I have done this in the past with simple program for OpenCM board and have done some code on Teensy 3.x, which also change baud rates.
But in both of these cases the actual processor has the USB support built in and the firmware knows when the USB has asked for different baud.
Example real simple Servo controller for OPenCM and OpenCR:
Code:
#include <DynamixelSDK.h>
//====================================================================================================
// Really basic Servo Controller...
// This version for Robotis OpenCM9.04
//====================================================================================================
//=============================================================================
// Options...
//=============================================================================
#define BAUDRATE 1000000
#define DEVICE 1
#if DEVICE || defined(__OPENCR__)
#define DEVICENAME "3" //DEVICENAME "1" -> Serial1(OpenCM9.04 DXL TTL Ports)
#define DXLSerial Serial3
#else
#define DEVICENAME "1" //DEVICENAME "1" -> Serial1(OpenCM9.04 DXL TTL Ports)
#define DXLSerial Serial1
#endif
#define BUFFER_SIZE 64
//=============================================================================
// Globals
//=============================================================================
dynamixel::PortHandler *portHandler = dynamixel::PortHandler::getPortHandler(DEVICENAME);
uint8_t buffer[BUFFER_SIZE];
int led_state = LOW;
uint32_t g_baud_rate = BAUDRATE;
//extern USBD_CDC_LineCodingTypeDef LineCoding;
//====================================================================================================
// Setup
//====================================================================================================
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial2.begin(115200);
Serial.begin(BAUDRATE); // Init to actual default baud
Serial2.println("Start Basic Servo Controller");
// Open Port handler
portHandler = dynamixel::PortHandler::getPortHandler(DEVICENAME);
if (!portHandler->openPort()) signal_abort(1);
if (!portHandler->setBaudRate(BAUDRATE)) signal_abort(2);
}
//====================================================================================================
// loop
//====================================================================================================
void loop() {
bool did_something = false;
int cb;
// First forward anything received from DXL
cb = portHandler->readPort(buffer, BUFFER_SIZE);
if (cb > 0) {
Serial.write(buffer, cb);
did_something = true;
}
// Now forward anything received on USB to DXL
cb = 0;
while (Serial.available()) {
buffer[cb++] = Serial.read();
}
if (cb) {
portHandler->writePort(buffer, cb);
did_something = true;
}
if (did_something) {
led_state = led_state ? LOW : HIGH;
digitalWrite(LED_BUILTIN, led_state);
}
// lets see if USB baudrate changed?
uint32_t new_baud_rate = Serial.getBaudRate();
//uint32_t new_baud_rate = LineCoding.bitrate;
if (new_baud_rate != g_baud_rate) {
DXLSerial.begin(new_baud_rate);
Serial2.print("New Baud Rate: ");
Serial2.println(new_baud_rate, DEC);
g_baud_rate = new_baud_rate;
}
}
//====================================================================================================
// Signal_Abort - Fatal error, show blink pattern of error number...
//====================================================================================================
void signal_abort(uint8_t error) {
for (;;) {
for (uint8_t i = 0; i < error; i++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
}
delay(500);
}
}
Don't remember if this one worked or not on OpenCM... But it shows how it changes baud rate...
Personally I would suggest you might try to get something that is known to work for cases like this. For several years I simply used the USB2AX by Xevel to talk to servos from a PC.. Not sure if still available. Robotis would probably suggest U2D2.
Or simply pick up an OpenCM9.04 board. $10 http://www.robotis.us/opencm9-04-a-n...ctors-onboard/
And servo connection set $6 http://www.robotis.us/opencm9-04-con...accessory-set/
And solder in the AX/MX style servos
Or the OpenCM9.04 with connections plus the OpenCM 485 expansion board which has power and both TTL as well as RS485 AX/MX type servo connectors...
Then you can simply reprogram the OpenCM board to default firmware and then it can recover servos...
Bookmarks