I have spent the last week or so considering
accelerometers and gyros. The team originally wanted to use a
gyroscope on our robot, but was advised that an accelerometer might
be a better choice because of the complexity of using a gyroscope and
the issue of drift.
I did some research and concluded that the
accelerometer can only measure tilt when it is sitting still or
moving at a constant rate. And I found no complaints anywhere about
drift with the gyro.
I did notice when we where experimenting with the
accelerometer that when it is reading no acceleration the sum of all
three axes is equal to about 200(the equivalent of 1G). I think
this means that it can tell when it is sitting still which means it
can check its position if it senses that it is not changing speed.
This is useful until you watch the robot and see how often it
accelerates and decelerates.
All this could change when we start testing the autonomous code. We
could probably pause long enough for the accelerometer to get a
reading before continuing on to the puck holders. I would assume that
it just needs about a fraction of a second of zero acceleration to
read the acceleration from gravity before it can continue on. However
for that to work, I think it would need to know what the axis
measurements mean and how it should respond once it has it. This
brings us back to why did we get it in the first place for a 30 second
autonomous program.
Having already made the decision to use an accelerometer, based on
previous advice and consideration, we concluded the accelerometer
will deliver the best results as long as the robot is still. The
suggestion from a mentor to use PID control –
proportional–integral–derivative – has been very helpful.
PID is three different variables, where P is the
proportional control, I is the sum of all the errors, and D is the difference between the current and previous error. A PID controller tries to correct the error
between a measured process variable and a desired set point by
subtracting a current position from the target position –
Target – Current = Error
P = error*KP
Now that we have the error we can tell what I is:
I = error + I * KI
It adds the latest error each time it goes threw the loop.
We can also now tell what D is.
D = current error – previous error * KD
So now we have:
P = Target – Current *KP
I = error + I *KI
D = current error – previous error * KD
Output = P+I+D
KP, KI, and KD are the constants that are determined by experimentation
You use the output to control your motor(s) or anything else you might be using it for.
Robot C has a built in version of a PID controller to control motors
with a rotation sensor. If you want to use PID with any other sensors
on the robot, you have to build the PID function yourself.
However, no matter what we use it for or if we use it at all, you
have to admit that both gyros and accelerometers are really cool
sensors.