I am using the 24V Devantech motor set, that comes with the Devantech MD49 motor controller. I am using the tx and rx of an Arduino uno to send control signals/receive information to/from the MD49.
I have the motor controller behaving as described in the specifications, however, it is exhibiting consistent buggy behavior on the first run of code. Basically, on the first run of the code after the 24V supply to the controller/ motors has been turned on, no matter what speed is written to the motors, the first time SET_SPEED1 or SET_SPEED2 is sent with a speed to the controller, the motors (or single motor if in mode 0 or 1) will spin at a high speed, independent of what speed is sent from the Arduino, and always at the same speed and direction (if in mode 2 or 3, they spin in opposite directions). This happens as long as signals are being sent to the controller (i.e. it will not change speed or direction) until the first 2 second timeout is allowed to happen; once this happens, behavior returns to normal.
I have tried many different combinations of writing the speed first within the setup or loop, clearing the serial buffer in different places, removing and inserting the Tx and Rx leads at different times in the uploading/ running process, as well as many other things, however I have not been able to figure out what is causing/ will stop this buggy behavior.
After the first buggy run, as I’ve said, the controller behaves perfectly, however it is extremely annoying, tedious, and time wasting to have to lift the powered wheels off the ground every time I turn on the robot, to make sure it doesn’t go careening into a nearby wall. I would really like to be able to solve this problem and have it run normally all the time.
I have uploaded a demonstrative video to Youtube at youtu.be/rPg6PwK8QJo. Here is the code I have uploaded to the Arduino in the video, demonstrating this behavior. It sets the speed in the setup, however, as I have already said, I have done this in other ways in different parts of the code, and the initial buggy behavior is the same. This is merely demonstrative:
Thanks for your help, I hope the problem can be solved.
#define CMD (byte)0x00
#define SET_MODE 0x34
#define SET_SPEED1 0x31
void setup() {
Serial.begin(9600);
// clear the serial buffer
while(Serial.available())
Serial.read();
// set mode
Serial.write(CMD);
Serial.write(SET_MODE);
Serial.write(3);
// set speed
Serial.write(CMD);
Serial.write(SET_SPEED1);
Serial.write(10);
delay(2000);
}
void loop() {
}