I finally have a working inverse pendulum robot (bbot as I call it).

It uses Vex motors , Vex parts and the following non Vex sensors:

5 DOF IMU from Spark (3 axis accelerometer and 2 axis rate gyro) $100

Absolute analog output encoders from US Digital MA3-A-B8. [MA3 | US Digital ($35 each) These are neat little magnetic encoders that can be read by a/d inputs rather that fooling with interrupts.

I programmed using MPLAB and also EasyC.

The bbot has a noticeable limit cycle about vertical because of the large nonlinearity in the motors due to friction and slop in the transmission of force between the motor and wheel. Both are significant contributors. The a/d sampling is too coarse for this IMU but I had it around and used it anyway. The LS Bit of the rate gyro represents about 2.5 deg/s and is difficult to integrate without some drift due to sampling errors. However, I blend the integrated pitch rate with fwd/aft accelerometer to get a better measure of vertical.

I used MATLAB control systems tool box to design the feedback gains using linear quadratic regulator optimization (LQR) in the discrete domain. They were pretty close to the final settings I used. The feedback command u=k1*angle_error +k2*angle_rate + k3*encoder_rate_symmetric + k4*encoder_pos.

Seems to work ok with k4=0. There is not a stable solution if k3=0. So those who try to use just a PD controller on angle will have some trouble if encoder rate is not included.

The angle_error and angle_rate are a blend of accelerometer derived tilt and rate gyro output combined in a complementary filter. The accelerometer is lagged with a time constant =1/k_filter and then blended with gyro_rate to eliminate the lags in the short term and retain accelerometer angle in the long term. In pseudo code it looks something like this:

angle_rate= (ax-angle_error)*k_filter + gyro_rate ;

angle_error=angle_error+ angle_rate *dt ;

Note the correction term to the gyro_rate based on the difference between the tilt angle derived from acceleration “ax” and the angle_error used by the system. This effectively converts gyro_rate drift into an angle_error offset rather than a increasing ramp angle_error. For example , if the gyro_rate had a bias of .1deg/sec without the filter blending, the expected error would be 1 deg in 10 seconds. With the filter, the error would only be .1 deg in 10 seconds assuming k_filter is 1. The second line is just the integration of the angle_rate with an update time of dt (=18.5ms)

On the to do list is doing the optimization with integral feedback (simulating a PID controller) and adding the remote control inputs to the software.

Please feel free to contact me for further information. I will eventually post video on Youtube.

I am doing a summer workshop on control theory of a pendulum robot for Robodox team of Granada Hills in LA if anybody wants to participate.

Enjoy,

Chris S.

[email protected]

Retired Lockheed Control System Engineer](MA3 | US Digital ($35 each) These are neat little magnetic encoders that can be read by a/d inputs rather that fooling with interrupts. )