Balancing robots

Anyone out there with experience of building a balancing robot along the lines of nBot, LegWay or GyroBot?
I've built the hardware for such a robot but I always end up with it
oscillating unstably, even if I try to help it out with my hands (in which case my hands prevent it from falling but it still oscillates quite a bit about the equilibrium point hitting my hands).
If I scale down the torque on the wheels to the point that it doesn't fly back and forth unstably then the motor is too weak to actually respond to any kind of falling. The fact that it does swing back and forth suggests to me that I can be sure the motors (standard servos modified for continuous rotation and controlled by a PWM controller) are at least powerful enough to do the job but that instead it's the algorithm that's the problem.
I'm using a simple PID type controller with outputPWMPulseSize a*angularDisplacement+b*angularRate for various values of a and b.
The main thing that springs to mind is that the PWM pulse size doesn't directly control the torque on the motor because there is also a back EMF term proportional to the motor velocity. Funnily enough, nBot and GyroBot both use encoders to measure motor speed. Do you think it is essential to feed the motor speed into my PID equation? LegWay seems not to need feedback from the motor. I already have some Hamamatsu IR emitter/detector pairs on order to start building an encoder...
Looking at my robot in action it seems like it does respond to falling but too late. And outputPWMPulseSize is updated hundreds of times per second.
Any ideas anyone?
Thanks, -- Torquemada
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Something like this.
http://www.ctgnet.com/Robotics/ctg_robotics_home.htm
Ask Ted.
Jay
---------------------------------------------------------------------------- "I'm pullin' for you; we're all in this together", Red Green ---------------------------------------------------------------------------- . .

to
to
feedback
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

to
to
feedback
How do you sense angular displacement?
Regards, Bob Monsen
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

I expect there's all kinds of ways of doing it, but the most obvious one is a pendulum attached to a potentiometer or optical encoder, with damping matched to the differential equation of motion of the device under control so that the pendulum doesn't oscillate and end up making the whole machine resonate and fall over or anything like that.
Tom
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

is
I was actually asking how he was doing it :)
However, I think your solution would be incredibly complex to implement, particularly when you can buy a piezegyro (like those used on RC helicopters) for around $75.
However, the OP is using an optical distance measurement device on a stick. That makes sense, assuming its fast enough.
I don't know enough physics to determine whether a pendulum would be a good indicator for angular acceleration. I guess if its at a strange angle related to the rotation you want to measure, then it would act as a gyro, and so you could measure the fall speed based on perturbations of the thing. If the swing is in the same plane as the rotation you want to measure, it won't work, I think.
Regards, Bob Monsen
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

to
to
Those angularDisplacement and angularRate are coming from accelerometer/gyro, correct ? Gut feeling says that motor speed should be incorporated, and you seem to be missing an integral term which should help reduce oscillations ?
-kert
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

term which should help

The angular displacement is coming from a Sharp IR ranger mounted at the end of an arm and pointing downwards to measure displacement from the floor (going into a 10 bit ADC on an ATMega32). I do have a MEMS rotation sensor but I thought this approach would be easier to start with.
Besides outputPWMPulseSize = a*angularDisplacement+b*angularRate I've also tried outputPWMPulseSize += a*angularDisplacement+b*angularRate (note the += instead of =). In effect that's integrating. Much the same kind of results.

How strong is your gut feeling? Although the web page for the LegWay (http://perso.freelug.org/legway/LegWay.html ) says it reads the motor speed when I look at the code (http://home1.gte.net/res1g289/legway.c ) it appears not to do so. I'm wondering if anyone out there has built a balancing robot and tried removing the dependency on the motor speed. -- Dan
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

kind
[Zagan] Although I have experience in mechanical engineering, electronics, and software development, I still consider myself a newbie to robotics. I'd like to put in my 2 cents on the topic of this thread.
One idea that has occurred to me is to use a linear potentiometer with a weight hanging from the shaft to sense the angle or the robot. Since the potentiometer would act as a voltage divider, a voltage could be directed to an ADC input to determine the angle. The problems I see with this approach would be:
1) The inertia of the weight could give a false reading when the robot stops, and when it starts forward or backward motion.
2) The weight could produce a "pendulum" effect upon full stop.
The above problems could perhaps be conpensated for in software or by mechanical means.
I would be interested in hearing comments from others on this technique.
Thanks in advance,
// Jim
--
|| Free Science Fiction
|| "The Keepers of Forever"
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
An accelerometer and gyro are used.
The accelerometer is a long term value, It senses your orientation with respect to gravity. It is integrated so that low frequency impulses do not affect it.
The gyro is a rotary velocity device. It is the derrivitive of rotational position. Integrating it gives position, but gyroscopes are subject to drift, so you add the accelerometer.
AFAIK, the lego bot does not balence, it maintains a constant angle to the ground, by keeping the sensor a constant distance to the ground. If presented with a ramp, it would tip.
A pendulum could replace the accelerometer, by using dampening grease, but why bother.

integral
like
to
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

oooh, that might not work, those sensors are pretty slow.

kind
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Interesting! My gut instinct from looking at this thing is that it's tipping because it's responding too slowly to its input. Why would such a sensor be slow? Oughtn't it be able to function in microseconds as it's optical?
Actually I just found another robot using the same approach as me and also using servos without encoders: http://home.earthlink.net/~botronics/index/balibot.html . Theirs is twice as tall as mine and has much larger wheels both of which make the task easier. -- Torque
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Are you using a GP2D120? That apparently only updates every 5ms.
How I know: I was using one as input to a comparator (on a PIC12F675) and it was totally noisy, perhaps causing oscillations in the internal comparator! However, a helpful poster on sci.electronics.design mentioned to me the 5ms thing, and by putting a cap to ground across the output, it quieted down enough for my project to work. If you are inputting it to a comparator, that might also be an issue for you. Put a 0.1uF cap from the output to ground before you feed it to the comparator/opamp.
Regards, Bob Monsen

tipping
be
as
easier.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
5ms? That can't be the source of my problems then. An object accelerating due to gravity, from rest, would travel about 1mm in that time. The centre of mass of my robot will start falling much more slowly than that because it will only see g*sin(theta) where theta is a small displacement. So my feeling is that there's not much time for something significant to happen in 5ms.
Hmmm...I think I'm just going to have to write some code to log the measurements, plot some graphs, and see if I can make sense of it! -- Torque

it
comparator!
5ms
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

I don't think that motor speed measurement is necessary.
Please forgive me my English, I hope everyone will understand what I mean.
Imagine a task similar to balancing, but done by man.
Imagine you driving a car and your friend driving another car at the lane next to you. He drives straight forward at certain speed and your task is to drive head to head with him. So the goal is that you have the same speed as your friend and your car's position relative to his car position should be zero. What you do is just measure (watch) your position relative to your friend, check if you are approaching or receding the goal and finally you adjust the gas pedal. Do you need a speedometer at all? I think you don't.
Best regards Marcin Sommer
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Marcin said:

to
But what happens when the acceleration of of the other car depends quite sensitively on your position and velocity relative to him? It's not so simple then. -- Torque
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Right, but in a balancing robot the balance point is always in the same place, operator can change it, when he wants robot to move, but it only depends on operator's will, not robot position.
Marcin

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

<snip>
Heres a good working example with details : http://www.tlb.org/scooter.html , scroll down to "Putting it all together" section with formulas.
-kert
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
This is a real nasty problem. First step, have you calculated the cente of gravity and moment of inertia of the machine about its pivot? With these, you should be able to form a differential equation describing the motion of the device. If you can then solve the differential equation (you may need to simplify and make approximations in order to make it solvable) you can use that to form the equation of the signals to send to the motors in order to produce the motion you want (or the lack of it, in this case).
And I doubt the equation of motion will be as simple as that of ordinary SHM, like a pendulum on a fixed point. An angular acceleration applied to the wheels will not only try to flip the machine over the other way by applying a reactive torque about the axis of the wheels, but will also try to roll along, producing a reactive force that will apply not only linear acceleration to the whole body, but a second torque about the centre of gravity of the device. I could be wrong, I'm just writing this as I think of it, and an accurate mechanical diagram and derived DE would be a better way to go about it, but I hope these ideas may still help.
Tom
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
He doesn't really need to solve any differential equations, I think. I've seen software for this that simply bounds the value he wants to keep it at, and hacks tweaked constants into the code to deal with starting the motors at the right time.
Actually, I've seen (on the internet) a double pendulum balancing system that was solved with a fuzzy logic approach! Now, the scheme described above is basically a fuzzy logic system, where the logic variables are 'tipping forward', 'balanced', and 'tipping backwards'. The actions are going to be something like
if tipping forward, V += something if tipping backward, V -= something if balanced, do nothing
Biasing for forward movement means hacking the 'balanced' rule. Turning means biasing for motion on one wheel or the other.
Using a PID controller, particularly one without an I component, makes the system react incredibly fast, probably too fast. PD controllers are, from what I've read, notoriously unstable.
Regards, Bob Monsen

of
of
order
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

these,
need
can
to
try
linear
think
better
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.