The attached project will help you get started with your own balancing code for your FEZ Cerbot. You will need the following for this project
FEZ Cerbot
Accelerometer - I used the Seeed module
Gyroscope - I used the Seeed module
Button module
Stand-offs or some other means of mounting the modules to the FEZ Cerbot
The button module is used to initiate the balancing code once everything is calibrated and the FEZ Cerbot is in the upright position.
Look at the photo of the FEZ Cerbot with the modules mounted, you will notice the Gyro and the Accelerometer are mounted at the bottom of the board. This is particularly important for the Accelerometer because it minimizes the effect of the whipping motion on the accelerometer readings. The location of the gyro is less important, but for symmetry I mounted it at the bottom as well.
The balancing algorithm uses a Complementary Filter to combine the readings from the Gyro and the Accelerometer to get an accurate enough reading on the current angle of the bot. Using this angle and it’s deviation from the intended angle (upright), the data is fed into a Proportional-Integral-Derivative (PID) controller which calculates the direction and velocity that the motors need to be run to adjust for the deviation from the target angle.
Thank you taylorzaKing ,
Very useful for me.
Even I am not the robot guy, the Complementary filter is useful for me.
How is the accurate for this algorithm compare to using Inclinometer?
Other question is the Torsion,the robot maybe has a Torsion, how Calculate it and correct it?
I would imagine using an Inclinometer rather than an Accelererometer would give much better accuracy, but I have never actually used an Inclinometer so I cannot confirm that.
I am not sure I understand the question, Torsion usually refers to some kind of twisting force or deformation which I do not think is a factor in the robot. If you are referring to the back and forth oscillation of the robot as it tries to balance, what I found was the following.
[ol]Place the accelerometer as close to the rotation axis as possible to minimize the impact of the horizontal acceleration.
Do not run the motors too fast[/ol]
@ Gus - there are two things
[ol]TargetAngle - tweak this angle to compensate for the forward motion due toe the weight distribution, beware it is very sensitive so increase it in very small increments.
When you start the device in the upright position have it leaning slightly (very slightly) backwards[/ol]
The second point is the most significant, if it is already tending backwards the motors can react quick enough. I just retested and the current values work well for my bot, but maybe the weight distribution varies between the bots.
That is an interesting idea, I will see if I can give that a try.
As is, my bot does not have any creep other than some rotational creep due to the differential between the two motors, but even that is minimal.
Here is a video I just took with the bot standing without any interruption, you can see it has minimal creep. It was standing for a few minutes before I switched it off.
I got it to work without changing the code. I first set the robot on am angle with something under the front caster. Let it calibrate then it works. Ideas?
@ Gus - So if I understand correctly, you let it go through the calibration sequence at startup with the bot at a slight angle and after calibration you lift it to the upright position and initiate the balancing?
If so, I would be interested to see what the readings are for the accelerometer when the device is level, maybe the skew is in the accelerometer readings. Did you use the Seeed accelerometer?
I was recently asked about having the FEZ Cerbot moving while balancing at the same time. I had a few ideas so I thought I would test one of them.
Here the FEZ Cerbot is balancing and at the same time avoiding obstacles that approach the reflector sensors. Each sensor is managed independently and the FEZ Cerbot will turn away from the on coming object.