Quote:
Originally Posted by siggy2xc
does anyone have any ideas on how to use encoders to make the motors run at the same speed when going straight? I'm currently working on a code to make the robot go the same direction as you press the joystick no matter which way it is facing and this seems to be the biggest problem since the robot will drift left or right. I'm having a hard time with this since the motors shouldn't be running at the exact same speed when pressing slightly left or right.
(We will be using arcade drive)
Any help would be appreciated
Robot Casserole - Team 1736
|
If I understand what you are asking, you want to have the robot drive straight when a button is pressed, regardless of which direction the robot is facing. Is this correct?
Now, assuming it is correct....
According to your title, you have encoders connected to you drive train. Again assuming here, one on the left and one on the right.
Start with a case structure. Wire the Y channel bypass the structure. In the False state, the X will pass through the structure to the Arcade mode. When the "button" is pressed, switch the case structure. In the True state, the X channel will be replaced inside the case structure.
Here is where it gets a little complicated.
The first time through the loop after the button is pressed, initialize the counter for both encoders. From that point on, as long as the button remains pressed, the X value to the Arcade mode becomes
the difference between the counts of the left and right encoders. You will need to "GAIN" this value to maintain smooth and not over responsive control. You will also need to limit the output to the Arcade mode to between -1 and +1. You might also need to invert the sign so that the code corrects in the right direction.
The bottom line is, the correction to direction is based on the difference between the counts of the encoders.