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

Reply to
Torquemada
Loading thread data ...

Something like this.

formatting link
Ask Ted.

Jay

---------------------------------------------------------------------------- "I'm pullin' for you; we're all in this together", Red Green

Reply to
happyhobit

How do you sense angular displacement?

Regards, Bob Monsen

Reply to
Robert C Monsen

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

Reply to
Kaido Kert

Heres a good working example with details :

formatting link
scroll down to "Putting it all together" section with formulas.

-kert

Reply to
Kaido Kert

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

formatting link
it reads the motor speed when I look at the code
formatting link
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

Reply to
Torquemada

[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

Reply to
Zagan

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.

Reply to
Blueeyedpop

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

Reply to
Robert C Monsen

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:

formatting link
Theirs is twice as tall as mine and has much larger wheels both of which make the task easier.

-- Torque

Reply to
Torquemada

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

Reply to
Tom McEwan

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

Reply to
Tom McEwan

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

Reply to
Robert C Monsen

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

Reply to
Robert C Monsen

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

Reply to
Robert C Monsen
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

comparator!

Reply to
Torquemada

That may work, but it sounds like a very hacky solution to me. Finding the DE is always a good idea when you're working on such systems, because the solution could turn out to be very simple, and if it does, you'll save yourself a world of trouble trying to keep the approximated system going.

This system will be more difficult - as displacement gets larger, you need a larger restoring torque, because the moment of the centre of mass about the pivot increases. However, if you have force proportional to displacement, you've got SHM, so you need something morce complex.

Reply to
Tom McEwan

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

Reply to
Marcin Sommer

Hi,

This sounds like the problem may be that the gain is too high. Try reducing the values of a and b and see if that helps.

Good luck with this!

Paul

Reply to
Paul

There seems to be no in-between value. If the gains are too high it's clear that it wants to engage in unstable oscillatory motion. With the gains low it only makes feeble efforts to right itself. I've heard that there is an algorithm of sorts for tuning PID controllers if you can measure their response but I've no idea where to find it.

Luck does seem to play a role! I showed someone my attempt last night apologising for the fact that it's still incomplete. And what do you know? - it remained vertical for extended periods of time

- 5-10s at a time. But it won't do that now! (Usually it's the other way round isn't it? When you demo something it fails!)

-- Dan

Reply to
Torquemada

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.