BOE-Balancer Program
Carol Hazlett
Posts: 312
I am starting this thread because once again I am going to try to do something I don't know how to do! I designed a balancing BOE-Bot (though I bet I am not the first) that is going to be programmed in Blocklyprop and use a PID.
So I will be posting a lot of questions in a quest for help with this.
So I will be posting a lot of questions in a quest for help with this.
Comments
wonderful idea.
Enjoy!
Mike
It might be old hack for some, but I like it and plan to do the same soon.
Thanks for sharing this.
with it and want to learn how to use it for almost all my robotics.
It's a very healthy choice.
coded. Only fine tuning and adjusting was needed from me. So this will be a first for me and is a prelude to a bigger project, a robot that balances on a ball.
There are a lot of self balancers out there and plenty of code snippets but I want to do it in Blocklyprop so I am sort of breaking some new ground a little bit.
BTW, what the heck is that thing between the wheels and sticking out the back of your robot? I want to use the Ping to make this robot have some roaming behavior.
I believe the thing sticking out in the vid that erco posted is like a kick-stand to prevent the bot from falling completely over if it gets off balance. That way it is not smacking on the floor or table if it falls. just a guess though.
It has been hard but a lot of fun. I am really getting hooked on the Blocklyprop. I will show code too. Then you
can all tell me what could have been done better!
I may have damaged this PABWX when thrashing around. I am
testing it for trouble but I do have another PABWX to use if this
is broken. Did you make the BOE-Balancer in your video? Now I
know what that thing between its wheels is for! Keep it from
slamming on its face. I have the PID written and it seems to work
but the robot is just not stable enough. So I need to go through every
system to see what is wrong. I am hoping it is not because Blocklyprop
does not do floating point math. I don't know all the little work
around formulas people use to simulate floating point results.
I made this one a while back:
I am using the Parallax 9-axis IMU.
Have a look at this code: https://github.com/parallaxinc/Flight-Controller/blob/master/Helpers/ComplimentaryFilter/ComplimentaryFilterSample/Main.cs#L174
Specfifically at the function called UpdateComplimentaryFilter(). This code takes a gyro and accel sample from a Prop and does the computation on a PC, but it demonstrates the idea pretty solidly. That said, if Blockly doesn't let you use floats, this may be a little trickier.
I have printed it out for perusal.
I am ready for the big one now.
now back to work on the BOE-Balancer. I am not having much trouble with making a PID in Blocklyprop but
just can't dial in the robot enough at the beginning to make it stable. It is either not responsive enough or
overshooting. I have not found the sweet spot. You can not make it stable in the first stage of the PID but it
should be trying to stand. I have tried it with encoders, without encoders, with high speed servos and regular
CR servos. It is very close but not close enough. I will keep trying...............................Once again I am eating
something bigger than my head.
Who needs a biped robot, when you can have code like yours that makes a balancing robot so stable. Either one falls over when the battery gone though.
A setpoint is one of the parameters of your PID. It is essentially the balance point of your robot. Only in an ideal world is it ever at 0.
The sweet spot should be consistent, so once you've found "true level" through a calibration routine, that should work as your set point. It may require an offset because of weight imbalance on the craft, but that's typically handled by integral term in the PID.
I fused the accelerometer and gyro readings together to produce a more accurate and faster responding angular reading, and just used the raw gyro numbers for the rotation rate. I also found that the motor output required to balance isn't linear with angle - it's more like 1 / cos(Angle). When the bot is vertical, it's perpendicular to the floor, and that's the direction the wheels move, so all movement goes more or less directly into rotating the bot. If you're at 30 degrees, you need to move the motors farther to make a similar change in your angle - motor impulses at this point are cos(30) = 0.866 effective at rotating you.
This effect is amplified because the effect of gravity is affected by this as well, but inverted - When perfectly vertical, gravity has zero effect on your rotation. The further you are off center, the stronger the effect of gravity, in this case, it's sin(Angle).
So, cumulatively, if you're at zero, everything is peachy. If you're slightly off zero, gravity starts to accelerate you away from it, and your motors have to work harder to push you back to it, so you need to ramp your PID response based on your current angle to account for all of this.
I did merge both readings into one but my setpoint is a minus number and it seems to me to cause anomalies in reversing the motor
speeds from positive to negative. I have also tried dividing the gyro output by 360 or 180 to bring the numbers down to something the
motors can use. Am I barking up a wrong path there?