PDA

View Full Version : How to get robot to drive straigth using shaft encoders

eccmaster
01-31-2008, 05:44 PM
Does any body know what is the best way to get the robot to drive straight using shaft encoders. We are using the same ones that are in the AndyMark super shifter, but they are on the tough box/ Thanks in advance

Alan Anderson
01-31-2008, 10:25 PM
I can't guarantee a "best" way to do it, but I can tell you a simple way. When you want to start going straight, set both the left and right encoder counts to zero. Every so often, perhaps in the Default_Routine() for convenience, read them both and compute the difference (or more likely the sum, as they will probably be counting in opposite directions). When the result is positive, tweak one side's motors to run a little slower and the other side a little faster than otherwise commanded. When the result is negative, do the opposite.

Chris_Elston
02-02-2008, 10:57 AM
As a suggestion....

We've tried encoders to drive straight and though it can be done. The EASIEST code to write and drive straight is using a GYRO. Our team's opinion so far in the past 4 years of working with sensors and trying different things.

I would upgrade to a 300 DPS (degree per second) gyro however, and NOT use the 80 DPS GRYO in the kit this year. You can pick up a 300 DPS gyro at sparkfun. The 2007 gyro works ok, it's a faster DPS than the 2008 gyro.

Just our experience. We've stablized a two wheel drive robot last year with a gyro. Carpet sliders on the front and back of bot with drive train in the middle.

eccmaster
02-02-2008, 08:04 PM
Hello
We did get the 300dps from spark fun to use for 90 degree turns. I did notice that when we use the gyro functions in easyC, instead of getting readings of 1/10th of a degree with the gyro that came in the kit of parts (90 degrees = 900) we got only steps of 1 degree (90 degrees = 90). Why is that so?

Chris_Elston
02-02-2008, 08:15 PM
Hello
We did get the 300dps from spark fun to use for 90 degree turns. I did notice that when we use the gyro functions in easyC, instead of getting readings of 1/10th of a degree with the gyro that came in the kit of parts (90 degrees = 900) we got only steps of 1 degree (90 degrees = 90). Why is that so?

Did you change the GYRO type? When you intialize the gyro, you have to set the gyro type to scale it correctly.

Also, if you are using the gyro to drive straight, do not use the gyro easyC function (which returns DEGREES), instead, read the raw analog value from the gyro. This will be the "rate" of turn. If your not turning, the analog will be ZERO. If you start to turn, the gyro will sense the rate of your turn and you can use that as a error to adjust your PWM outputs.

intellec7
02-02-2008, 10:50 PM
The best way I know of driving straight with encoders to ensure that the wheels not only maintain in sync, but if they get out of sync , the robot returns back to it's original line is:

During an equal period take the difference between the encoder counts

Integrate this difference.

The result of the integration should be used to offset the commanded wheel commands. See the pseudo code below:

current_difference = left_count - right_count
integrated_error = integrated_error + current_difference

Left_Drive = Commanded_Left_Drive + integrated_error
Right_Drive = Commanded_Left_Drive - integrated_error

Let me know if I should make it clearer