Saturday, July 19, 2008

NXTSegway Revision 0.4 Final: New Design (Again) and PID Controller!

This is the fourth public release of my NXTSegway, and I am quite pleased with the results. I re-re-designed the robot: Dean Hystad informed me on the NXTStep forums of the benefit that a higher center of gravity can give to a balancing robot like NXTSegway. He gave an excellent example: it is much easier to balance a golf club on your finger than a pen. Along with the bigger wheels, as the title says, I also implemented a PID motion control system that solved all my balance problems. The program uses three error components (kp, kd, and ki), multiplies them by three constants, adds them together to form the PID value, scales the PID value to fit in the motors' power range (-100 to 100), and sets the motor power equal to the scaled PID value. The three error components work like this: kp (proportional) changes proportionally to the error, kd (differential) changes proportionally to the rate of change of error, and ki (integral) changes proportionally to the sum of all previous error values; the constant multipliers weight these components based on need. For a complete, technical PID tutorial, check out this site. As you can see from the video below, this controller is highly effective in creating a stable inverted pendulum. Note: if you want to use my source code and have a working robot, you must use a very similar design and adjust the kp, kd, ki, adj, and scale values to fit your robot and its environment. My values (especially the kp value) are extremely high due to the fact that the batteries were low...once I replaced the batteries, there was WAY too much overshoot.

Annotated source code can be found here (4KB)

7 comments:

Anonymous said...

Is that all it does?

Anonymous said...

Dude,

That is a way cool implementation of PID Control!

Have you tried it with just PI control - you may find it is more robust.

If you want to try a different tuning technique based on an open loop step test you may get even better performance than 1 minute. Drop me a line thru the link above and I can send you the procedure and a tuning calculator in excel if u r keen...

Cammy said...

Matt's the best robot builder ever & will be the next Iron Man/Bill Gates!!!!!

Nik said...

Hey! thats a nice inverted pendulum there! i was wondering how did you assemble it as you stated there if others want to use your code, the design has to be the same as yours. i feel like trying it out myself. i don't really know much about assembling as i was just introduce to the NXT from my friends

MADMAN2 said...

Hey Nik...if you read this, drop me your email address so I can contact you. Thanks

nik said...

hey i was wondering did you recieve my email?

Nik said...

Hey.. i guess i'll just leave my email add here. =) nikky--@live.com