Robot Travel In Straight Line

Project: Arduino robot with motors equipped with hall effect quadrature encoders.

Hobbyist Situation: Good hardware/electronics skills, just learning how to program.

Challenge: Creating a sketch that will allow the bot to travel in a straight line for some distance, turnaround and travel back to the start point. Great precision is not needed for this challenge; therefore, limited tracking (drift) back and forth across the straight line path is acceptable.

Current situation: The bot has been tested and it goes forward, backwards, turns etc. However, as expected, the bot cannot travel in straight line.

Concept: Keep it simple by having one motor serve as the speed master and the other as a speed slave, where the master motor speed is held constant and the slave motor speed is varied so as to match the master motor speed. In this situation Error = speed_Master - speed_Slave

This concept was presented at the web page below which uses RobotC for programming. My limited programming experience/skills do not allow me to simply translate RobotC to an Arduino sketch C which I am currently learning.

http://www.robotc.net/wikiarchive/Tutor … e_straight

As explained at the above web page the difference between the master encoder and the slave encoder ticks can be used to determine error. Negative if slave has to slow down, positive if it has to speed up. If the motors moved at exactly the same speed, this value would be 0.

Another important aspect of the RobotC straight line code is it does not use floats or other data types that consume large amounts of microprocessor resources. It uses integers only and math that does not result in floats.

I have spent many hours on trying to come up with a way to get the bot to travel in a straight line using some aspect of PID that is not overly complex for this relatively simple task. It seems to me the concepts set out by the RobotC code offers the perfect solution.

Thank you for any advice or direction you may provide.

It looks like a good solution to me.

What doesn’t work?

If you are using integer math, is there any possibility that your pid loop is always returning zero because it is rounding down a fractional error signal.

I’m sure the principle works because I have done something very similar (pid velocity control on each wheel. Made mine do repeatable shapes)

Gareth

Sent from my iPhone using Tapatalk

Garteh - thank you for taking the time to respond.

I am still working on the code. Unfortunately, I did not do a good job explaining what I needed help with in my post.

What I was looking for was some advice on how to decipher the Vex RobotC code and turn it into ArduinoC or C++.

To that end I have made good progress understanding the Vex RobotC and have begun to write the needed functions and void loop code to accomplish my bot straight line travel goal.

Thanks again for taking the time to respond to my post.

Russell