Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Gyro Autobalancing (http://www.chiefdelphi.com/forums/showthread.php?t=103930)

jutayo23 28-02-2012 16:18

Re: Gyro Autobalancing
 
Team 1124 has gotten autonomous bridge balancing to work very well. Here's a video of our previous year's robot with the balancing code on it (this was before this year's robot was completed) You'll notice the bridge in this video is easily tipped. Our bridge was too light, which made balancing harder to achieve. The code worked even better when we tried it with a competition bridge.

http://www.youtube.com/watch?v=z2RpnQAU1dY

If anyone's interested in our method:

We use both a gyro and accelerometer to balance our robot. The gyro is good at giving an accurate angular rate, but not absolute angle, while the accelerometer is good at giving an accurate absolute angle, but not angular rate. We decided to combine the best features of both these sensors to get the best control.

I don't want to release the entire code yet, but here's essentially how it works.
It uses a state machine to decide how to behave. The driver drives the robot slowly up the bridge until the gyro rate is greater than a certain amount in either direction, at which point the code takes control of driving. The robot then drives in the opposite direction until a second significant angular rate is detected. After this sequence, the accelerometer is read for an accurate angle reading. If it is determined that balancing failed, it restarts. If it determines it is balanced, it holds its position and waits for the gyro to return a significant rate allowing it to re-balance.
You should be able to see all of these steps from the video above.

We use closed loop control on the drive (with PID) to control the rate at which the robot drives up the ramp in order to keep consistency.

Our drivers have been very pleased with this feature. It has yet to fail. It almost always balances the robot on the first try. When it doesn't, it gets it on its second, as seen in the video. This method is much faster than when our drivers attempted it manually.

I'd be happy to answer any questions related to our method of balancing, PID, or the sensors we used. Good luck to anyone else attempting this!

DominickC 28-02-2012 16:29

Re: Gyro Autobalancing
 
Quote:

Originally Posted by Tom Line (Post 1136238)
I was not aware that the competition bridges are calibrated with springs. I was under the impression that they use their own considerable weight and the off-center position of their hinges to effect their self centering. Can you please point me to the documentation that led you to this conclusion?

In addition, I believed that the bridges needed to be within 5 degrees of level to be balanced. Where did the 15 degrees come from? That is a considerable angle.

Hmm, maybe I'm assuming too much. I presumed springs were used, but I was wrong :p It is, in fact, a double hinge.

Quote:

2.2.5 The Bridges
Robots traverse the center of the Court by crossing over either one of three Bridges or the 4 in. tall by 6 in. wide, smooth steel Barriers running between them. Each Alliance has one dedicated Bridge for their use at end of their Alley. An additional white Coopertition Bridge is located at the center of the Court. Each Bridge is 48 in. wide, 88 in. long (outside dimensions), and sits with the top platform 12 in. high off the ground when level. Each Bridge is mounted on a double-hinge that allows the Bridge to tip towards either end of Court. The top surface of each bridge includes an array of 15 small holes, details of which are included in the official field drawings.

A Bridge will count as Balanced if it is within 5° of horizontal and all Robots touching it are fully supported by it.
There's the rule stating when the bridge is balanced. It was 5, not 15. Memory fails me again! I'll be doing more research next time I try to 'help' someone out :p

Luiz12 28-02-2012 16:45

Re: Gyro Autobalancing
 
Did I end up getting the PID structure correct...

slijin 28-02-2012 21:16

Re: Gyro Autobalancing
 
Quote:

Originally Posted by Luiz12 (Post 1135993)
So from what I understand is that I have to have a set point, which I assume would be zero since when the angle reaches zero

Yes, but it's a bit more complicated than that. Keep in mind that the gyro measures yaw (change in angle) around an axis through the gyro itself, but your robot does not balance around this axis; it balances on the bridge. You may have issues because the yaw rate is not directly proportional to the bridge angle.

Quote:

Originally Posted by Luiz12 (Post 1135993)
basically from what I've read the only thing that I would need to tune would be the proportional gain.

As mentioned earlier, mechanical systems have momentum; for this reason, a proportional gain will almost always result in oscillation around the setpoint. Because of the double hinge setup for the bridge, however, it has a noticeable resistance to tipping, so an incredibly small P may allow you to successfully balance without tuning I or D, but your robot will be moving very slowly to the setpoint, which could possibly, depending on your wheels/drivetrain, be ineffective due to stalling or slipping. For a time-effective balancing mechanism, you will likely want to tune both P and I.

Searching the forums will yield a wealth of discussion on how to tune a PID loop; there are also a number of discussions about how to tune PI loops and ignore the D.

Luiz12 28-02-2012 21:25

Re: Gyro Autobalancing
 
Well my plan was to just get the robot on the bridge on regular control, then press the button to begin the balancing then just let go of the button when its sufficiently balanced. Now for mounting the gyro it would be mounted vertically, not laying flat parallel to the floor right?

Ziv 28-02-2012 21:41

Re: Gyro Autobalancing
 
Quote:

Originally Posted by Luiz12 (Post 1136468)
Well my plan was to just get the robot on the bridge on regular control, then press the button to begin the balancing then just let go of the button when its sufficiently balanced.

This is a good idea. It's good to give as much control as possible to the driver, making it his or her choice whether or not to use a particular feature in a particular situation. (For example, if another robot is pushing you up the ramp, you probably want to stay put.)

Quote:

Originally Posted by Luiz12 (Post 1136468)
Now for mounting the gyro it would be mounted vertically, not laying flat parallel to the floor right?

Correct. The axis of rotation of the KOP gyro is perpendicular to the chip. For balancing, you probably want this axis to be parallel to the axels of your wheels, which means mounting it vertically.

Luiz12 28-02-2012 22:23

Re: Gyro Autobalancing
 
Now from what I read, I know to tune the PID I must start with zero values on I and D and then adjust the PID until it begins to oscillate ( which I assumes means the robot) then divide it by half. (from what I read on wikipedia) but do I increase the P or decrease, and in what increments should increase by? It then says,"Then increase Ki until any offset is corrected in sufficient time for the process" which I really don't understand. Do I adjust this if I see any lag or what does it mean?

plnyyanks 28-02-2012 22:33

Re: Gyro Autobalancing
 
Quote:

Originally Posted by Ziv (Post 1136477)
This is a good idea. It's good to give as much control as possible to the driver, making it his or her choice whether or not to use a particular feature in a particular situation. (For example, if another robot is pushing you up the ramp, you probably want to stay put.)

I agree with this as well. With our method, we have the driver enable the balancing, but (while retaining driver control) the driver will drive the robot up the bridge until the robot senses a tip. Then, the robot will take control away from the driver and do the rest of the balancing itself.


Quote:

Originally Posted by Luiz12 (Post 1136508)
It then says,"Then increase Ki until any offset is corrected in sufficient time for the process" which I really don't understand. Do I adjust this if I see any lag or what does it mean?

Basically, when you have Ki at zero, the system might take longer (than you want) to reach its setpoint. You use Ki in order to reduce this time. Think of the error accumulating over time and getting factored in. Therefore, the longer the system has had a nonzero error, the bigger the value the Ki term acts on is.

With that base, I don't really use a set system to tune Ki. I just usually start with a very small value (like around 0.01) and test it out. From there, if you watch your system and how long it takes to reach its setpoint, and determine how Ki should be changed. I usually tweak numbers by a factor of 2 or by a factor of 10 (depending on how much I think needs to be adjusted) and go from there.

tl;dr: Tune PID constants by guessing and checking until you get something satisfactory.

Luiz12 28-02-2012 22:44

Re: Gyro Autobalancing
 
My P value by default is at 1. Should I leave it like this or start from .01. or should I start from 1 and then increase by .01.

slijin 28-02-2012 22:45

Re: Gyro Autobalancing
 
Quote:

Originally Posted by Luiz12 (Post 1136508)
Now from what I read, I know to tune the PID I must start with zero values on I and D and then adjust the PID until it begins to oscillate ( which I assumes means the robot) then divide it by half. (from what I read on wikipedia) but do I increase the P or decrease, and in what increments should increase by? It then says,"Then increase Ki until any offset is corrected in sufficient time for the process" which I really don't understand. Do I adjust this if I see any lag or what does it mean?

You may want to look into reading this paper instead of Wikipedia.

Ki is the integration coefficient; that is, the I function of the PID controller integrates, i.e. accumulates, your error (how far you are from the setpoint), and allows you to correct for error that has accumulated as a result of oscillation from tuning P alone.

-edit- There's no definitive answer; it's almost wholly experimental, especially because the return rate of the gyro doesn't directly correlate with the "wobbling" of the bridge as you try to balance.

plnyyanks 28-02-2012 22:55

Re: Gyro Autobalancing
 
Quote:

Originally Posted by Luiz12 (Post 1136531)
My P value by default is at 1. Should I leave it like this or start from .01. or should I start from 1 and then increase by .01.

This may come off as a terrible answer, but do what works. Start with the default values, and observe how they make your system react. Then, modify the values accordingly.
Do you need the system to correct more? Raise Kp.
Do you need the system to correct faster? Raise Ki.
Do you need the system to slow down as it approaches the setpoint? Raise Kd.
Those are some overly general descriptions, but they work well in a pinch (and they also work oppositely).

It will be very hard to give specifics on PID constants without knowing about the system it will be acting on, because sometimes small changes can have huge impacts. That's why PID tuning takes such a long time - it's a lot of guess and check work until it works in a way you like.

In the meantime, I suggest to you do some reading on PID controller theory/tuning theory. Also, try and understand how the math behind them works in as much depth as possible (look through source code - I know you can look through the PID VI in LabVIEW). If you can understand how and why a PID controller works, it becomes that much easier to make one do your bidding.

Some other links to read when you have time (in no particular order. I like this one because NI is awesome and does a great job with their tutorials and support).

uofifox 03-03-2012 10:39

Re: Gyro Autobalancing
 
I have a question about your use of PID. What are you using for error computation? I mean if you're using accelerometer and gyro, are you simply using them to determine change occurs and using hte accelerometer to determine if you're close or closer to being level to determine your error?


All times are GMT -5. The time now is 21:00.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi