I have recently obtained an MP-6050 that I am integrating with an Arduino micro-controller to control a small robot. I am having difficulty changing the sensitivity of the accelerometer and obtaining data on linear velocity.
1-How do I change the sensitivity setting of the MPU-6050 on Arduino? I know there are settings from +2g to +16g but how can I choose the one I need? What code to I have to write?
2-Is there a way to obtained linear velocity from the accelerometer data? I am trying to know how fast my robot is moving.
If you have some guidance on this subject, don’t hesitate to share. Thank you for you time in reading this. I look forward to your replies.
2: Simply said: Assume the accelerator is not moving and speed is 0 OR it has some predetermined value along each axis. Sample the acceleration value of the axis as fast and frequently as possible. Then multiply the last acceleration sample value with the sampling time interval. This is a delta-V, or velocity change. Add this amount (positive or negative) to the current speed value. Repeat with the next acceleration sample. Do this for each axis individually.
Unfortunately it isn’t as simple as that. As no sample is a perfect measurement of the instantaneous acceleration in one axis, it always has some error in it. And if the sample rate is slow, then you are only adding up crude acceleration samples. Small variations in the accelerations are lost. Once you start to add up many small errors over time, the sum may eventually grow far away from the real speed. It may seem like it is moving, but it could still be there laying resting on a table. Or it may have a certain motion, but the calculated speed value is different because the errors have added up to one side. So over time you cannot be sure how fast it’s actual speed has become.
2b: If you want to know how fast your robot is moving, it may be more reliable to use wheel encoders (assuming your robot has wheels) and measure the rotation of the wheels per time interval. From that, and the wheel circumference you can infer wheel speed. If it has enough traction and doesn’t suffer from wheel slip then it likely has a better concept of how fast it is moving.