A fuzzy system to control an inverted pendulum

Input variables

input variable Phi

This is the angle of the inverted pendulum. It defined as 0 the pendulum is horizontal to the right, and increasing counter clockwise.

input variable dPhi-dT

The angle velocity.

input variable X

The absolute position. At the end the pendulum should be positioned at 0.

input variable dX-dT

Velocity of the pendulum.

Output variables

output variable a

The acceleration of base point of the pendulum. This is the output of the fuzzy controller.

Fuzzy rules

They might be more complex than necessary, but there intend is also some features of pyfuzzy.

If you like you can change them by yourself.

Stabilizing the pendulum upright

If the pendulum is almost upright we should stabilize it there and try to lead it to position 0.

stop

If the pendulum is upright and we don't move, or it is not upright but turns in the right direction to become upright, we should stop moving.

tilts left

If the pendulum is tilted left we should also move left, but for reaching position 0 we supress this when the position is somewhere at the right of position 0. So we hold an slight left tilting which is followed until we reaching position near 0.

tilts right

If the pendulum is tilted right we should also move right, but for reaching position 0 we supress this when the position is somewhere at the left of position 0. So we hold an slight right tilting which is followed until we reaching position near 0.

far left

If the pendulum is tilted more left we should move left in any case, without any considerations about position.

far right

If the pendulum is tilted more right we should move right in any case, without any considerations about position.

Handling a downwards hanging pendulum

accelerate counter clockwise if down

If the pendulum is hanging down, ....

accelerate clockwise if down

If the pendulum is hanging down, ....

Result

a as function of Phi and dPhi_dT

Without considering position control, you get the following function: