So I am building a differential drive robot and I want it to autonomously drive in a straight line on an uneven surface. I know I need a position and velocity PID. As of now, I am deciding on which sensors to buy. Should I use optical encoders, accelerometers, or something else?

I wanted to go with accelerometers due to the error encoders would face due to slippage, but I am not sure.

Some enlightenment would help!

  • 1
    $\begingroup$ Do you have any source of guide, e.g. are you following a line on the ground? Neither encoders nor accelerometers would be sufficient to follow a perfectly straight line without some sort of locating device. $\endgroup$ – Guy Sirton Apr 26 '14 at 6:04
  • $\begingroup$ My robot is moving down a straight path that has incline surfaces on each side. I am finding the distance to a point on the incline surface with ultrasonic (ping) sensors. What do you think? $\endgroup$ – mechaman Apr 26 '14 at 23:02

Get a good IMU you can communicate with over i2c. Make sure it has an accelerometer and a gyroscope. Use these two sensors to calculate your heading, and then correct accordingly to make sure you are heading straight.

Here's an example of a nice IMU: https://www.sparkfun.com/products/10121

Sparkfun has created an arduino library for that particular sensor that will make calculating heading easy peasy. Good luck!

  • $\begingroup$ Thank you nanogru! Sorry for the delayed response, but I have been able to produce something that works. Thanks :) $\endgroup$ – mechaman Jun 26 '14 at 0:59
  • $\begingroup$ gyro+accel is not enough for correct headings $\endgroup$ – holmeski Jul 16 '16 at 15:05

You will need BOTH. Use encoder sensors on the wheels one for each side. These will allow a PID controller to maintain wheel speed even with the variable mechanical loads on an uneven terrain.

The heading sensor (IMU) will need gyros too and maybe a magnetic compass to correct for drift in the gyros. You will need a PID controllerl that looks at the difference between commanded heading and the heading as measured by the IMU this PID will adjust the target speeds of the two wheel PIDs


nanogru is right, you will need definatley need an IMU, not just an accelerometer. The one he recommended looks pretty good.

Would also recommend going down the Ardiuno track, it will make life much easier and cheaper.

I normally use encoders too. There is a good Arduino library for encoders: http://www.pjrc.com/teensy/td_libs_Encoder.html

Have had good success with optical quadrature encoders. Can be read using digital or interrupt inputs. If you want the best performance, you will want to use at least a Mega to have enough interrupts.

You could also upgrade your robot with a laptop, Kinect, Linux, and ROS (if your robot can handle the payload).

This stuff is pretty easy to set up these days for 6DOF SLAM and autonomous navigation, especially with new tools like MoveIt: http://moveit.ros.org/robots/

What do you plan on doing with the position data? Is it for autonomous navigation?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.