# Tandem Pendulum (pendulum)¶

Two pendulums are fixed on a cart, which can move in the horizontal direction.

The cart has a mass . The friction between the cart and the surface causes a frictional force , in opposite direction as the velocity of the cart.

Each pendulum has a mass , a moment of intertia , a length and an angle of deflection . The friction in the joint where the pendulums are mounted on the cart causes a frictional torque , in opposite direction as the speed of rotation . The system is shown in Fig. 12 .

The task is to control the position of the cart and to stabilize the pendulums in either the upward or downward position. Actuating variable is the force F.

Fig. 12 The pendulum system

The example comes with three models. A point mass model, a rigid body model and a partially linearized model.

The state vector is chosen in all three models as:

The class TwoPendulumModel is the implementation of a point mass model. The mass of each pendulum is considered concentrated at the end of its rod. The model resulting model equations are relatively simple and moments of inertia do not appear:

The class TwoPendulumRigidBodyModel is the implementation of a rigid body model. The rods are considered to have a mass and can not be ignored, each pendulum has a moment of inertia :

The class TwoPendulumModelParLin is the implementation of a the partially linearized point mass model. The input is chosen as

with , and as before in TwoPendulumModel. This transforms the model equations into the input afine form

All three models define the cart’s position

as the output of the system.

The example comes with five controllers. Two of them, LinearStateFeedback and LinearStateFeedbackParLin, implement linear state feedback, both using the package symbolic_calculation to calculate their gain and prefilter. The LinearQuadraticRegulator calculates its gain and prefilter by solving the continuous algebraic Riccati equation. The LjapunovController is designed with the method of Ljapunov to stabilize the pendulums in the upward position. And finally the SwingUpController, especially designed to swing up the pendulums using linear state feedback and to stabilize the system by switching to a Ljapunov controller once the pendulums point upwards.

A 3D visualizer is implemented. In case of missing VTK, a 2D visualization can be used instead.

An external settings file contains all parameters. All implemented classes import their initial values from here.

At program start, the main loads eleven regimes from the file default.sreg. The provided regimes not only show the stabilization of the system in different steady-states (e.g. both pendulums pointing downwards or both pointing upwards) but also ways to transition them between those states (e.g. swinging them up).

The example also provides two modules for postprocessing. They plot different combinations of results in two formats, one of them being pdf. The second format of files can be passed to a metaprocessor.

The structure of __main__.py allows starting the example without navigating to the directory and using an __init__.py file to outsource the import commands for additional files.