Steven McConnon
Steven McConnon

Reputation: 2680

Balancing robot PID tuning

I'm trying to build a two-wheeled balancing robot for fun. I have all of the hardware built and put together, and I think I have it coded as well. I'm using an IMU with gyro and accelerometers to find my tilt angle with a complimentary filter for smoothing the signal. The input signal from the IMU seems pretty smooth, as in less than 0.7 variance + or - the actual tilt angle.

My IMU sampling rate is 50 Hz and I do a PID calculation at 50 Hz too, which I think should be fast enough.

Basically, I'm using the PID library found at PID Library .

When I set the P value to something low then the wheels go in the right direction.

When I set the P value to something large then I get an output like the graph.

Enter image description here

Upvotes: 3

Views: 3893

Answers (4)

Juan Gonzalez Burgos
Juan Gonzalez Burgos

Reputation: 982

There are many heuristic rules to PID tuning out there, but what most people fail to realize is that PID tuning should not be an heuristic process, but should based on math and science.

What @Sigurd V said is correct: "What a control engineer could do would be to make a mathematical model...", and this can get as complicated as you want. But now a days there are many software tools that can help you automate all the math stuff and get you your desired PID gains quite easily.

Assuming all your hardware is in good shape you can use a free online tool like PidTuner to input your data and get near to optimal PID gains. I have personally used it and achieved good results. Use these as an starting point and then tune manually if required.

Upvotes: 1

Sigurd V
Sigurd V

Reputation: 5107

As Praks Wrote, your system looks as if it is either unstable or at perhaps marginally stable.

Generally Two wheeled robots can be quite difficult to control as they are inherently unstable without a controller.

I would personally try A PD controller at first, and if you have problems with setpoint accuracy i would use a PID, but just remember that if you want to have a Differential gain in your controller (The D part) it is extremely important that you have a very smooth signal.

Also, the values of the controller greatly depends on your hardware setup (Weight and weight distribution of the robot, motor coefficients and voltage levels) and the units you use internally in your software for the control signals (eg. mV V, degrees/radians). This entails that it will almost be impossible for anybody to guess the correct parameters for you.

What a control engineer could do would be to make a mathematical model of the robot and analyse the pole/zero locations.

If you have any experience with control theory you can take a look at the following paper, and see if it makes sense to you.

http://dspace.mit.edu/bitstream/handle/1721.1/69500/775672333.pdf

Upvotes: 1

praks411
praks411

Reputation: 1992

From the graph it looks like your system is not stable. I hope you have tested each subsystem of your robot before directly going for tuning. Which means that both sensors and actuators are responding properly and with acceptable error. Once each subsytem is calibrated properly for external error. You can start tuning. Once this done is you can start with valid value of P may be (0.5) to first achieve proper response time, you will need to do some trials here, them increment I slowly to cut down steady state error if any and use D only when required(in case of oscillation). I would suggest to handle P,I and D one by one instead of tweaking all at one time. Also during the testing you will need to continuously monitor the your sensor and actuator data to see if they are in acceptable range.

Upvotes: 1

spring
spring

Reputation: 18487

If you haven't already, I'd suggest you do a search on the terms Arduino PID (obvious suggestion but lots of people have been down this road). I remember when that PID library was being written, the author posted quite a bit with tutorials, etc. (example). Also I came across this PIDAutotuneLibrary.

I wrote my own PID routines but also had a heck of a time tuning and never got it quite right.

Upvotes: 0

Related Questions