Hi,
I am writing a PID control loop for an inverted pendulum 2 wheel robot and am having some trouble getting it to balance.
I have a gyro, accelerometer and wheel encoders to use.
For the P (proportional) term I use the platform angle in degrees which is generated from the gyro and accelerometer.
For the I (integral) term I am not sure how to calculate this and also over what time to integrate the platform angle. Can I just use a running average for the platform angle for this?
For the D (derivative) term I use the gyro's rate output in degrees per second.
Once I calculate all 3 of the above variables (multiplying them each by their gain factors) do I just add them together and then use the result to set the motors dutycycle? So I would have:
motor_dutycycle = P*p_gain + I*i_gain + D*d_gain
Using various combinations of P and D terms, I have not been successful to balance it yet.
There are also wheel encoders that provide 1200 counts per wheel rotation. Would it help to use the wheel encoders for balancing? I would like to just get the robot balancing in one place as a start.
The way I generate the platform angle may be a problem I think: I integrate the gyroscope output and then use the accelerometer to slowly correct that integrated angle, up to a maximum of 2degrees/second of correction. The problem this has is the accelerometer is sensitive to the accelerations of the pendulum jerking back and forth while it tries to balance, so it may cause an error in the actual platform angle. Would a 2 state kalman filter help for this? Also I currently use only the horizontal axis of the accelerometer, if I used the vertical and horizontal axis' of the 2axis accelerometer (adxl202e) would that help? The gyroscope is an adxrs150 and both the gyro and accelerometer are filtered with first order 40Hz -3dB lowpass digital filters. the balancing loop runs at 30Hz currently.
cheers, Jamie