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.

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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With