I've got a wheeled robot that slows down on carpet. I'd like to maintain the same speed by bumping up the PWM to the motors when it slows. I've got one of those MPU6050 boards that I'd liked to use to accomplish this. I'm thinking I could monitor the horizontal g force along the direction of travel and then speed up the motors if it drops. I'm not sure how to record the original value as a constant that won't change. In other words, calculate it once as a constant and use it to measure against during the robot's run. Thoughts and suggestions are appreciated.
Hmmm...I think the g force gives you a measure of acceleration not speed.
In other words at steady speed your g-force should be Zero! When the robot slows down you will, momentarily, feel a g-force corresponding to the deceleration but, IMO, it will be hard to correlate that to a speed measurement.
A rotary encoder of some sort could be hacked up to give you a more definite measure of wheel rotations.
You're right about the physics but I read somewhere, or thought I did, that the MPU6050 can sense constant motion because when resting on a stable surface, it should measure 1g in the z axis. So if in constant motion, there should be a coresponding g force in the direction of the axis it is moving or a combination of two. If I'm wrong about that, then I'll need to get some wheel encoders.
Thanks for the reply.
You will need wheel encoders to measure the speed.
For constant motion in a straight line, acceleration is zero. So, your accelerometer will read 1 g.
If the robot momentarily speeds up or slows down, then there has to be some acceleration. If you integrate that acceleration you can estimate the robot's new velocity. But that is hard to do accurately because of the need to subtract off the force of gravity (which is counteracted by the upward force provided by the floor).
You’re right about the physics but I read somewhere, or thought I did, that the MPU6050 can sense constant motion because when resting on a stable surface, it should measure 1g in the z axis. So if in constant motion, there should be a coresponding g force in the direction of the axis it is moving or a combination of two. If I’m wrong about that, then I’ll need to get some wheel encoders.
Yes, you are wrong about that. The 1g reading on the Z axis is because the earth’s gravity is a ‘static’ acceleration, due to the mass of the earth, rather than a change in speed. If you were to drop that accelerometer from any height, with the Z axis in the direction of the fall, you would find that the Z axis will read as 0g, with perhaps a slight offset because of the slight resistance of air. Of course, it will read a large g value when it hits the ground, for a short time. In a way, the MP6050 can sense constant motion, in that it senses no change in the axis along the direction of travel. Any change in speed is sensed by a deviation from 0 (or from 1, in the case of the Z axis). You could integrate g value with time, and apply more speed to the motor, calculate g and a time period to bring it back to speed, but it’s complicated.
Your best bet is a rotary encoder, though it need not be an expensive one, You could put something on the axle or wheel itself that you can detect with a low-cost sensor, perhaps a Hall-effect sensor and some magnets, or an emitter/photocell looking at some reflective tape, and so on.
Thanks much. Wheel encoders will be ordered.