I have successfully counted the rotary encoders on the wheel of my robot so this is not a problem.
My problem is what to do with this number.
Basically, the bigger problem is that I need my robot to go straight and I want to do it using only two encoders (one on every wheel).
Even if I send the same amount of power to both motors the robot does not go straight. This is why I decided to use encoders, so no matter the power on the batteries, or the conditions of the motors; the robot will go straight.
So, now that I have successfully counted the "clicks" on the encoder I need to know what to do with the number to make sure the tow wheels are synchronized.
This is the code I am using (Arduino):
digitalWrite(dirMotO, HIGH);
digitalWrite(dirMotE, HIGH);
//digitalWrite(motO, HIGH);
analogWrite(motO, 150);
//digitalWrite(motE, HIGH);
analogWrite(motE, 150);
PololuWheelEncoders::getCountsAndResetM1();
PololuWheelEncoders::getCountsAndResetM2();
while(PololuWheelEncoders::getCountsM1()<clicks && PololuWheelEncoders::getCountsM1()<clicks){
if(PololuWheelEncoders::getCountsM1()>=clicks){
digitalWrite(motO, LOW);
}
if(PololuWheelEncoders::getCountsM2()>=clicks){
digitalWrite(motE, LOW);
}
}
I thought this code would make sure that if one wheel gets to counts before the other it would stop and wait for the other wheel but the robot does not go straight.
I would really appreciate some help on this.
Thank you!