C. Swing-up Control (Demo)

Objective

The objectives of this part of the laboratory experiment of the rotary inverted pendulum are as follows:

  1. Use energy-based control scheme to develop a swing-up pendulum controller.

  2. Implement the swing-up controller on the Quanser Rotary Pendulum plant and evaluate its performance.

C. Swing up Control

In this section a nonlinear, energy-based control scheme is developed to swing the pendulum up from its hanging, downward position. The swing-up control described herein is based on the strategy outlined in [3]. Once upright, the control developed to balance the pendulum in the upright vertical position can be used.

Pendulum Dynamics

The dynamics of the pendulum can be redefined in terms of pivot acceleration AA (see Figure 9) as

Jpα¨12mpgLpsinα=12mpLpAcosα(31)J_p \ddot{\alpha} - \frac{1}{2}m_pgL_p\sin{\alpha} = \frac{1}{2}m_pL_pA\cos{\alpha} \quad \quad (31)
Figure 9. Force vector diagram

The pivot acceleration, AA, is the linear acceleration of the pendulum link base. The acceleration is proportional to the torque of the rotary arm and is expressed as

τ=mrLrA(32)\tau = m_rL_rA \quad \quad (32)

Control Law based on Lyapunov Function​

According to Lyapunov’s stability theory, a sufficient condition for asymptotic stability of a nonlinear system about an equilibrium point is that the first time derivative of a selected Lyapunov’s function (V(x)V(x)) is negative, i.e.,

Given

V(x)>0 x0(33)V(x) > 0 \qquad \forall~x \neq 0 \quad \quad (33)

sufficient condition for asymptotic stability is

V˙(x)<0 x0(34)\dot{V}(x) < 0 \qquad \forall~x \neq 0 \quad \quad (34)

Swing-up Control

Let us select a candidate Lyapunov function for arriving at the control law as a quadratic function of the difference in total energy (EE) and the reference energy (ErE_r) when the pendulum is in equilibrium in the upright position, i.e.,

V=12(EEr)2(35)V = \frac{1}{2}\left( E-E_r \right )^2 \quad \quad (35)

where the total energy (EE) is the sum of kinetic energy EKEE_{KE} and potential energy EPEE_{PE}.

EKE=12Jpα˙2(36)E_{KE} = \frac{1}{2}J_p{\dot{\alpha}}^2 \quad \quad (36)
EPE=12mpgLp(cosα+1)(37)E_{PE} = \frac{1}{2}m_pgL_p(\cos{\alpha} +1) \quad \quad (37)
E=EKE+EPE=12Jpα˙2+12mpgLp(cosα+1)(38)E = E_{KE} + E_{PE} = \frac{1}{2}J_p{\dot{\alpha}}^2 + \frac{1}{2}m_pgL_p(\cos{\alpha} +1) \quad \quad (38)

Also, the reference energy of the pendulum in equilibrium in its fully upright position as compared to its fully downward position becomes

Er=mpLpg(39)E_r = m_pL_pg \quad \quad (39)

Taking the time derivative of Equation 35, we get

V˙=(EEr)E˙(40)\dot{V} = \left( E-E_r \right ) \dot{E} \quad \quad (40)

Taking the time derivative of Equation 38, we get

E˙=α˙(Jpα¨12mpLpgsinα)(41)\dot{E} = \dot{\alpha}\left( J_p \ddot{\alpha} - \frac{1}{2}m_pL_pg\sin{\alpha} \right ) \quad \quad (41)

Now, we replace the bracketed term on the right-hand side of Equation 41 using the equation of motion of the pendulum obtained in Equation 31 to get

E˙=12mpLpAα˙cosα(42)\dot{E} = \frac{1}{2}m_pL_pA\dot{\alpha}\cos{\alpha} \quad \quad (42)

Substituting Equation 42 in Equation 38, the time rate of change of the selected Lyapunov equation becomes

V˙=(EEr)E˙=12mpLp(EEr)Aα˙cosα(43)\dot{V} = \left( E - E_r \right) \dot{E} = \frac{1}{2}m_pL_p \left( E - E_r \right)A \dot{\alpha}\cos{\alpha} \quad \quad (43)

Now, we need to select AA such that V˙<0\dot{V}<0 for asymptotic stability. This can easily be achieved by selecting AA as

A=(EEr)α˙cosα(44)A = -\left( E - E_r \right) \dot{\alpha}\cos{\alpha} \quad \quad (44)

With the above selection of control law for the pivot acceleration, Equation 43 becomes

V˙=12mpLp[(EEr)α˙cosα]2(45)\dot{V} = -\frac{1}{2}m_pL_p \left [ \left( E - E_r \right) \dot{\alpha}\cos{\alpha} \right ]^2 \quad \quad (45)

which guarantees V˙<0\dot{V}<0.

The selected control law (Equation 44) will continuously decrease the difference between current energy (EE) and the energy of the pendulum in the vertically up position (ErE_r). Note that the selected control law is nonlinear, it changes sign for 90<α<27090^{\circ}<\alpha<270^{\circ}and α˙<0\dot{\alpha}<0.

Now, for the quickest change in energy, we may want to use the maximum controller input (acceleration of the pivot), i.e.,

A=Amaxsign[(EEr)α˙cosα](46)A = -A_{\text{max}}\text{sign}\left [ \left( E - E_r \right) \dot{\alpha}\cos{\alpha} \right ] \quad \quad (46)

but this controller can lead to chattering. Instead, we use

A=satA,max(μ(EEr)sign(α˙cosα))(47)A = -\text{sat}_{A, \text{max}}(\mu \left( E-E_r \right ) \text{sign}(\dot{\alpha}\cos{\alpha})) \quad \quad (47)

where μ\mu is a tunable controller gain.

Recall that the acceleration of the pendulum pivot is related to the torque applied on the rotary arm

τ=mrLrA(48)\tau = m_rL_rA \quad \quad (48)

Additionally, from Equation 9 of the balance controller design section, we have

τ=ηgKgηmktRm(VmKgkmθ˙)(49)\tau = \frac{\eta_gK_g\eta_mk_t}{R_m}\left( V_m - K_gk_m\dot{\theta} \right ) \quad \quad (49)

Then, the voltage supplied to the rotary base motor is obtained by combining Equations 48 and 49 as

Vm=RmmrLrAηgKgηmkt+Kgkmθ˙(50)V_m = \frac{R_mm_rL_rA}{\eta_gK_g\eta_mk_t} + K_gk_m\dot{\theta} \quad \quad (50)

Where from Equation 47, A=satA,max(μ(EEr)sign(α˙cosα))A = -\text{sat}_{A, \text{max}}(\mu \left( E-E_r \right ) \text{sign}(\dot{\alpha}\cos{\alpha}))

The selected nonlinear control law will swing up the pendulum from the downward position towards the upright position. Once the pendulum is near the upright position, it is balanced around the fully upward position using the linear balance controller.

Combined Balance and Swing-up Control

The energy-based swing-up control can be combined with the balancing control in Equation 29 to obtain a control law that performs the dual tasks of swinging up the pendulum and balancing it. This can be accomplished by switching between the two control systems.

Basically, the same switching implemented for the balance control in Equation 30 is used. Only instead of feeding 0 V when the balance control is not enabled, the swing-up control is engaged. The controller therefore becomes

Vm={K(xdx),if α<ϵRmmrLrAηgKgηmkt+Kgkmθ˙,otherwise(51)V_m = \begin{cases} K(x_d - x), & \text{if}\ |\alpha| < \epsilon \\ \displaystyle \frac{R_mm_rL_rA}{\eta_gK_g\eta_mk_t} + K_gk_m\dot{\theta}, & \text{otherwise} \end{cases} \quad \quad (51)

where A=satA,max(μ(EEr)sign(α˙cosα))A = -\text{sat}_{A, \text{max}}(\mu \left( E-E_r \right ) \text{sign}(\dot{\alpha}\cos{\alpha}))

The parameter ϵ\epsilon in Equation 51 is a user-selected range of α\alpha over which the balance controller becomes active.

Experiment: Implementing the Swing up Control

  1. Run the part2setup.m script extracted from the Part 2.zip file in the 'Balance Control' section.

  2. Check if the correct gain K value is loaded onto the workspace.

  3. Open q_rotpen_swingup_student_2 Simulink diagram.

  4. To build the model, click the down arrow on Monitor & Tune under the Hardware tab and then click Build for monitoring . This generates the controller code.

  5. Press Connect button under Monitor & Tune and Press Start . The pendulum should be moving back and forth slowly. Gradually increase μ\mu until the pendulum goes up. You may do this by increasing the gain slider. When the pendulum swings up to the vertical upright position, the balance controller should engage and balance the link.

  6. After the link swings up and is balanced, wait for ~5 seconds and stop the SIMULINK.

  7. OPTIONAL: Save the data_alpha, data_theta, and data_Vm. Ensure that the data variables have 10 seconds of data saved.

Question for Report

Briefly summarize the swing-up controller experiment and your observations. Did the swing-up control behave as you expected?

Reference

[3] K. J. Åström and K. Furuta. Swinging up a pendulum by energy control. 13th IFAC World Congress, 1996.

Last updated

Was this helpful?