Controlling an inverse pendulum in MATLAB Simulink without formulas. Setting up PID controllers

A simple and popular implementation of the inverse pendulum control law is the PID controller. Modern means of adjusting PID controller coefficients allow you to solve such problems by pressing a couple of buttons, even without knowledge of mathematics, physics, and without any technical knowledge at all. Let's look at an example of setting up PID controllers in Simulink for a classic inverse pendulum.

Control object (Plant)

We will assemble a model of an inverted pendulum in the Multibody library. For this we do not need knowledge of physics and mathematics. The Multibody library provides us with ready-made blocks of degrees of freedom, rigid bodies, and coordinate transformations that only need to be connected correctly. We assemble the subsystems separately for the pendulum and separately for the cart, and put everything together. The result is in the figure, the model is in the attached files.

Control object

Control object

Assembling individual elements into subsystems gives a more beautiful and structured look to the model.

Let us set the following model parameters: cart mass – 5 kg, pendulum mass – 1 kg, pendulum length – 2 m, friction coefficient for the cart – 0.1/10 N/(m/s), friction coefficient for the pendulum – 0.1/10 N*m /(deg/s).

Let's simulate and evaluate the results:

System states

System states

Animated result:

Control system

The control system will consist of two circuits, the first will be responsible for stabilizing the pendulum in the “up” position, and the second for the position of the trolley.

In the Simulink library we find the PID Controller block, we include it in the system in accordance with the classic control with negative feedback and immediately configure it. Open the block and click the Tune button as in the figure:

Our Control Object is automatically linearized and the PID controller is automatically configured.

We can use the sliders to adjust the robustness and speed of the regulator, after which we do not forget to update the coefficients with the Update Block button.

We assemble the contour of the trolley position and, in the same way, by pressing two buttons, we adjust it.

We’ll also add a separate circuit for the angular velocity of the pendulum; you can do without it, but it feels like it adds stability well. As a result, we have the following control system:

Let's add noise to the output signals to make the model more plausible:

Let's add a Kalman filter to the model to smooth out noise and have access to all op-amp states:

Complete model of an inverse pendulum

So, since in its normal state the pendulum has the “down” position, we will add a special block and call it Swing, in which we will program the signal by eye to swing the system and at the moment when the pendulum reaches the “up” position, we will turn on the controller. Let's also add an external disturbance – a 0.5 second pulse with an amplitude of 1 N, applied to the pendulum. And we will limit the force that the cart can develop to 25 N.

As a result, the entire model looks like this:

Let's model the system:

System states

System states

For about 10 seconds, the pendulum swings until it reaches the zero angle value, then the controller handles the error and brings the cart to coordinate 0, at the very end the pendulum is “pushed”.

Let's create the animation:

The model turned out to be quite stable. You can simplify it even further, leaving only two PID controllers for angle and coordinates.

To develop this model, not a single formula was used and not a single manual calculation was made. Simulink and Multibody did all this routine for us.

Project link

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *