Hi,
I'm building a DIY Segway using a:
- RoboClaw 2x15A Motor Controller to drive 2 brush DC motors (http://www.orionrobotics.com/RoboClaw-2x15A-Motor-Controller_p_268.html),
- “IMU Digital Combo Board - 6 Degrees of Freedom ITG3200/ADXL345” to get gyro & accelerometer inputs (SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345 - SEN-10121 - SparkFun Electronics),
- and a Arduino Uno board.
When I combine both components in a simple test program (see below), the program works for a few loop and then goes into an uncontrolled state in which the Motor Controller still drives the motors (at undefined speeds) and has both status LED on green (data transmission and power), but no red error LED light on the RoboClaw board.
When I just control the IMU board all is fine, same when I just have the motor controller running. Problems start when I trie to operate both at the same time.
I've experimented with different program loop times (50, 100, 200, and 300ms) and the results are pretty much the same.
Please see the program code:
#include "BMSerial.h"
#include "RoboClaw.h"
#include <arduino.h>
#include <FreeSixIMU.h> // IMU_Digital_Combo_Board_6_Degrees include
#include <FIMU_ADXL345.h> // IMU_Digital_Combo_Board_6_Degrees include
#include <FIMU_ITG3200.h> // IMU_Digital_Combo_Board_6_Degrees include
#include <Wire.h> // IMU_Digital_Combo_Board_6_Degrees include
#define address 0x80 // Robo Claw address.
// RoboClaw is set to Mode 7 Packet Serial Mode - Address 0x80 , 9600 baud
bool valid; // Robo Claw status variable
float imu_q[4]; // IMU q values
FreeSixIMU my3IMU=FreeSixIMU(); // Set the FreeIMU object, connected to A0 and A1
RoboClaw roboclaw(5, 6); // Arduino Pin5 (Receive) to RobClaw S2 (Transmit)
// Arduino Pin6 (Transmit) to RobClaw S1 (Receive)
// Arduino GND to GND pin on S1
void setup() {
init(); // initialize the Arduino Uno
roboclaw.begin(38400); // initialize the RoboClaw serial communication
delay(100);
Serial.begin(57600); // initialize the terminal serial communication link
delay(100);
Wire.begin(); // initialize com link to IMU board
delay(100);
my3IMU.init(); // initialize the IMU board
}
void loop() {
uint8_t i, ctr=1;
unsigned long loop_time=100, execute_time, start_millis;
while(ctr) {
for (i = 27; i < 128; i+=20) {
start_millis = millis(); // initialize loop timer
my3IMU.getQ(imu_q); // get the IMU sensor data
roboclaw.ForwardM1(address, i); //start Motor1 forward at speed i
roboclaw.ForwardM2(address, i); //start Motor2 forward at speed i
execute_time = millis() - start_millis;
Serial.print(F("Motor Speed: "));
Serial.print(i);
Serial.print(F("\tExec Time: "));
Serial.print(execute_time);
Serial.print(F("\tClock: "));
Serial.print(millis());
Serial.print(F("\nIMU_Q: "));
Serial.print(imu_q[0], 5);
Serial.print(F("\tIMU_Q: "));
Serial.print(imu_q[1], 5);
Serial.print(F("\tIMU_Q: "));
Serial.print(imu_q[2], 5);
Serial.print(F("\tIMU_Q: "));
Serial.print(imu_q[3], 5);
Serial.print(F("\nBattery Power: "));
Serial.print((float)(roboclaw.ReadMainBatteryVoltage(address, &valid) / 10.0), 1);
Serial.println(" ");
execute_time = millis() - start_millis;
if (loop_time > execute_time) {
delay(loop_time-execute_time); // don't process more than once every "loop_time" milli-seconds
}
}
Serial.print(F("\n>>>>>>> End of loop "));
Serial.print(ctr);
Serial.print(F(" with loop-time "));
Serial.print(loop_time);
Serial.println(F(" <<<<<<<\n"));
roboclaw.ForwardM1(address, i/2); //slow down Motor1
roboclaw.ForwardM2(address, i/2); //slow down Motor2
delay(200);
roboclaw.ForwardM1(address, i/3); //slow down Motor1
roboclaw.ForwardM2(address, i/3); //slow down Motor2
delay(200);
roboclaw.ForwardM1(address, 0); //stop Motor1
roboclaw.ForwardM2(address, 0); //stop Motor2
delay(2000);
ctr++;
}
}
Please see attached the screenshot from the Serial Monitor.
Your help will be greatly appreciated.
Volker