Make motors run the same speed using encoders

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

Im sorry but i don’t think i understand your question well enough. From what i got it sounds like your having problems with making the robot go straight even if the joystick is tilted in an off direction. If this is your problem then you can make a case structure hook up to the button your going to use to initiate this coding (im assuming a button) and in the true wire the x axis input on arcade drive (yet again more assumtions) to a 0 constant in the case structure and for false have the x axis output go through the case structure to the x axis input. It MUST go through the case structure.
in boolean algebra it would look something like this:
a = button;
Xinput = axis input;
Xoutput = plugged into the arcade drive;
equation.bmp (58.7 KB)

equation.bmp (58.7 KB)

equation.bmp (58.7 KB)

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.

Forget my idea, use Billbo’s
I like the fact that it corrects itself

The approach discussed here uses a gyro instead of encoders. It might give you some additional ideas.


ohhh… so you can use the change in x value in the gyro and make a simple algorithym that takes x value and creates a new x-value for the robot that would more than compensate for the new change in x-value from the gyro.

Billbo could you post a screen shot of the labview “code”?

I like your solution over mine however I don’t quite have feel of coding in Labview to get this done quickly.


WELCOME TO Chiefdelphi!
I would love nothing more than to help you out with this, but I have a problem.

This year I made a commitment to allow my team to do ALL of their own coding, without actually creating any myself. I help, advise, instruct but I don’t actually code, no matter how tempted I may get. As part of this commitment, I have decided to not install LabView on any PC I have access to. It would be too much of a temptation for me.

So, without access to Labview, I can’t show you how I would do it.
Hopefully someone else here on CD can help you out with your request. It really is quite simple and “should” only take a few minutes to create. Tuning the gain for straight driving might take 10 to 15 minutes, with lots of laughter as you see your robot swing wildly in odd directions until the gain is low enough. I would suggest a starting value of approximately .002. (Remember, with even a error of 1 bit difference, you would be giving a full range X value, therefore, the gain must be very low to get you close.)