From my experience, two motors never drive the exact same speed. I need to make a robot that has 2 driving motors and 1 free spinning idle wheel drive in a straight line.Intelligent Robot Car Chassis Kits with Speed Encoder Battery Box I cant figure out a FAST way to do that. I can only tell how far each motor has gone, should I measure each ones distance, and if one gets more than X infront of the other, slow that fast motor down? I'm not a good programmer and I can't seem to wrap my head around this one. Thanks for the help!
That page mentioned a 'speed encoder'. I'm not sure what that is, but if it's a rotary encoder for each wheel then you can measure the distance that each wheel has traveled, subtract left from right to find the differential distance, slow down the motor which has traveled the furthest by an amount which is proportional to the difference in distance.
Hi there -
I found some useful info searching around the net, particularly the following, which after some trial and error gave me a motor speed offset for a pair of motors incorporated into a 2WD bot. The code is here in snippets, with value set to 0, as is drawn from a 4WD bot constructed of late, and seemingly, with four drive wheels, always traveled in a straight line. Lucky I suppose. I used the Adafruit motor shield library for a clone Adafruit V1 shield.
//...begin snippets
#include <AFMotor.h>
// ...
#define MAX_SPEED 200 // 200/255, about 85%
#define MAX_SPEED_OFFSET 0 // Set to compensate for uneven drive motors
// ...
AF_DCMotor motor1(1, MOTOR12_1KHZ); // LEFT FRONT-create motor #1 using M1 output on Motor Drive Shield, set to 1kHz PWM frequency
AF_DCMotor motor2(2, MOTOR12_1KHZ); // LEFT REAR-create motor #2, using M2 output, set to 1kHz PWM frequency
AF_DCMotor motor3(3, MOTOR34_1KHZ); // RIGHT REAR-create motor #3 using M3 output on Motor Drive Shield, set to 1kHz PWM frequency
AF_DCMotor motor4(4, MOTOR34_1KHZ); // RIGHT FRONT-create motor #4 using M4 output on Motor Drive Shield, set to 1kHz PWM frequency
//...
void setup () {
//...
}
void loop (){
//...
}
// MOTOR CONTROL
void moveForward() {
motorSet = "FORWARD";
motor1.run(FORWARD); // turn it on going forward
motor2.run(FORWARD); // turn it on going forward
motor3.run(FORWARD); // turn it on going forward
motor4.run(FORWARD); // turn it on going forward
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=1) // bring up speed, lowers draw on batts at startup
{
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet+MAX_SPEED_OFFSET);
motor3.setSpeed(speedSet);
motor4.setSpeed(speedSet+MAX_SPEED_OFFSET);
delay(5);
}
}
//...end snippets
I had wanted to incorporate the magnetometer from a 10DOF IMU breakout in concert with an analog feedback servo/ultrasound distance sensor to map obstructions and proceed accordingly, but was unable to shield the magnetometer sufficiently. Even with all the motors capped and wires twisted, it was a no go. Swinging the compass in the traditional manner seemed not to work either. The magnetometer would have also provided a new course heading for traveling in a straight line, and for governing amount of turn based on ping info. If by chance you endeavor for something like this, please share your successes.
Anyway, check around and see if you find something similar to above, and you should be on your way.
Mark