AE4610
  • Welcome
  • Experiments
  • Lab 0: MATLAB & SIMULINK
  • Lab 1: Rotary Servo Base
    • A. Integration (Week 1)
    • B. Modeling (Week 1)
    • C. Control Design (Week 2)
    • D. Controller Implementation & Evaluation (Week 3)
  • Lab 2: 3 DOF Gyroscope
    • A & B. Modeling and Control Design (Week 1)
    • C. Controller Implementation (Week 2)
  • Lab 3: Rotary Flexible Link
    • A. System Identification (Week 1)
    • B & C. Control Design and Controller Implementation (Week 2)
  • Lab 4: Rotary Inverted Pendulum
    • A & B. Modeling and Balance Control
    • C. Swing-up Control (Demo)
  • Final Project
  • Archive
    • Old Lab 1 Model Validation
    • Problem Set
    • DC Motor
    • Lab 1: Rotary Servo Base (Older Version)
      • A. Integration (Week 1)
      • B. Modelling (Week 1)
      • C. Position Control (Week 2)
    • Quadcopter
    • Gyroscope
    • Inverted Pendulum
    • 3DOF Helicopter
    • Torsional Pendulum
    • Aero LQR
      • A. System Identification
      • A. System Identification (Week 1) last check
      • B. Control Design & Implementation (Week 2)
    • Rotary Gyro
      • Rotary Gyro
    • 2 DOF AERO
      • A. System Identification
      • B. Control Design
      • C. Controller Implementation
    • Copy of Lab 4: Rotary Inverted Pendulum
      • Week 1
      • Week 2
Powered by GitBook
On this page
  • Objective
  • B. Balance Control (continued)
  • Feedback Control
  • B.3 Experiment: Implementing the Balance Controller
  • C. Swing up Control
  • Pendulum Dynamics
  • Control Law based on Lyapunov Function​
  • Swing-up Control
  • Combined Balance and Swing-up Control
  • Experiment: Implementing the Swing up Control
  • Results for Report
  • B.3) Balance Controller Implementation
  • C) Swing-up Controller Implementation
  • Questions for Report
  • C) Swing-up Controller Implementation
  • Reference

Was this helpful?

Export as PDF
  1. Archive
  2. Copy of Lab 4: Rotary Inverted Pendulum

Week 2

PreviousWeek 1

Last updated 6 months ago

Was this helpful?

Objective

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

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

  2. Implement the balance and swing-up controllers on the Quanser Rotary Pendulum plant and evaluate their performance.

B. Balance Control (continued)

Feedback Control

The feedback control loop that balances the rotary pendulum is illustrated in Figure 7. The reference state is defined as x_d = [\theta_d \ 0\ 0\ 0]^ \intercal \tag{28}where θd\theta_dθd​ is the desired rotary arm angle. The controller is u = K(x_d - x) \tag{29}Note that if xd=0x_d = 0xd​=0 then u=−Kxu = -Kxu=−Kx, which is the control gain used in the pole-placement algorithm.

B.3 Experiment: Implementing the Balance Controller

In this section, the state-feedback control that was designed and simulated in the previous sections is run on the actual Rotary Pendulum device.

Experiment Setup

The q_rotpen_bal_student SIMULINK diagram shown in Figure 8 is used to run the state-feedback control on the Quanser Rotary Pendulum system. The Rotary Pendulum Interface subsystem contains QUARC blocks that interface with the DC motor and sensors of the system. The feedback developed in the previous section is implemented using a Simulink Gain block.

  1. Download the Week 2.zip file, unzip it into a new folder and open the week2setup.m script.

  2. Open the q_rotpen_bal_student SIMULINK diagram.

  3. As shown in Figure 8, the SIMULINK diagram is incomplete. Add the blocks from the Simulink library to implement the balance control.

    • You need to add a switch logic to implement Equation 30. Use Multi-port switch with 2 data points and zero-based contiguous. The output from the compare to constant block will be 0 if false and 1 if true. Check your block with TA.

    • Ensure that you connect the final signal going into the u(V) terminal of the Rotary Pendulum Interface, which is also connected to the u scope terminal.

  4. Turn ON the power amplifier.

  5. Ensure the pendulum is in the hanging down position, with the rotary arm aligned with the 0 marking, and is motionless.

  6. Once it is running, manually bring up the pendulum to its upright vertical position. You should feel the voltage kick-in when it is within the range where the balance control engages. Once it is balanced, the controller will introduce the ±20 degree rotary arm rotation.

  7. The response should look similar to your simulation. Once you have obtained a response, click on the STOP button to stop the controller (data is saved for the last 10 seconds, so stop SIMULINK around 18-19 seconds once the response looks similar to Figure 9).

    CAUTION Be careful, as the pendulum will fall down when the controller is stopped.

  8. Similar to the simulation Simulink model, the response data will be saved to the workspace. Copy and paste into your group's folder. Ensure that the data variables have 10 seconds of data saved.

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

Control Law based on Lyapunov Function​

Given

sufficient condition for asymptotic stability is

Swing-up Control

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

Taking the time derivative of Equation 35, we get

Taking the time derivative of Equation 38, we get

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

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

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

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

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

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

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

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

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

Experiment: Implementing the Swing up Control

  1. Run the week2setup.m script

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

  3. Open q_rotpen_swingup_student Simulink diagram.

  4. Open the Swing-Up subsystem.

  5. Go into Swing-Up| Energy-Based Swing-Up Control | Pendulum Energy block. Complete the diagram by referring to the total energy of the pendulum given in Equation 38.

  6. Turn on the power amplifier.

  7. Ensure the pendulum is in the hanging down position, with the rotary arm aligned with the 0 marking, and is motionless.

  8. Manually rotate the pendulum up to the upright position. The balance control implemented previously will be activated. While the inverted pendulum is balancing, record the total energy reading displayed in Pen Energy (J) numeric indicator.

  9. Close the SIMULINK. No need to save the data.

  10. Open q_rotpen_swingup_student_2 Simulink diagram.

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

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

Results for Report

B.3) Balance Controller Implementation

C) Swing-up Controller Implementation

  1. Did the swing-up behave as you expected with these parameters?

Questions for Report

C) Swing-up Controller Implementation

  1. Compute the maximum acceleration deliverable by the Rotary Servo. Assume the maximum equivalent voltage applied to the DC motor is 5 V such that V_m - K_gk_m\dot{\theta} = 5 \tag{52}

  1. Is the selected swing-up control law unique? Is it optimal? Comment.

Reference

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

When running this on the actual system, the pendulum begins in the hanging, downward position. We only want the balance control to be enabled when the pendulum is brought up around its upright vertical position. The controller is therefore u = \begin{cases} K(x_d - x) & |x_2| <\epsilon \\\ 0 & \text{otherwise} \end{cases} \tag{30} where ϵ\epsilonϵ is the angle about which the controller should engage. For example if ϵ=10\epsilon = 10ϵ=10 degrees, then the control will begin when the pendulum is within ±10 degrees of its upright position, i.e. when ∣x2∣<10|x_2| < 10∣x2​∣<10 degrees.

Go to the 'Balance Control' section and put the gain K you found in . Run the script.

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.

Press Connect button under Monitor & Tune and Press Start .

The dynamics of the pendulum can be redefined in terms of pivot acceleration AAA (see Figure 10) 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)Jp​α¨−21​mp​gLp​sinα=21​mp​Lp​Acosα(31)

The pivot acceleration, AAA, 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)τ=mr​Lr​A(32)

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)V(x)) is negative, i.e.,

V(x)>0∀ x≠0(33)V(x) > 0 \qquad \forall~x \neq 0 \quad \quad (33) V(x)>0∀ x=0(33)
V˙(x)<0∀ x≠0(34)\dot{V}(x) < 0 \qquad \forall~x \neq 0 \quad \quad (34) V˙(x)<0∀ x=0(34)

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

V=12(E−Er)2(35)V = \frac{1}{2}\left( E-E_r \right )^2 \quad \quad (35)V=21​(E−Er​)2(35)

where the total energy (EEE) is the sum of kinetic energy EKEE_{KE}EKE​ and potential energy EPEE_{PE}EPE​.

EKE=12Jpα˙2(36)E_{KE} = \frac{1}{2}J_p{\dot{\alpha}}^2 \quad \quad (36)EKE​=21​Jp​α˙2(36)
EPE=12mpgLp(cos⁡α+1)(37)E_{PE} = \frac{1}{2}m_pgL_p(\cos{\alpha} +1) \quad \quad (37)EPE​=21​mp​gLp​(cosα+1)(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)E=EKE​+EPE​=21​Jp​α˙2+21​mp​gLp​(cosα+1)(38)
Er=mpLpg(39)E_r = m_pL_pg \quad \quad (39)Er​=mp​Lp​g(39)
V˙=(E−Er)E˙(40)\dot{V} = \left( E-E_r \right ) \dot{E} \quad \quad (40)V˙=(E−Er​)E˙(40)
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)E˙=α˙(Jp​α¨−21​mp​Lp​gsinα)(41)
E˙=12mpLpAα˙cos⁡α(42)\dot{E} = \frac{1}{2}m_pL_pA\dot{\alpha}\cos{\alpha} \quad \quad (42)E˙=21​mp​Lp​Aα˙cosα(42)
V˙=(E−Er)E˙=12mpLp(E−Er)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)V˙=(E−Er​)E˙=21​mp​Lp​(E−Er​)Aα˙cosα(43)

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

A=−(E−Er)α˙cos⁡α(44)A = -\left( E - E_r \right) \dot{\alpha}\cos{\alpha} \quad \quad (44)A=−(E−Er​)α˙cosα(44)
V˙=−12mpLp[(E−Er)α˙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)V˙=−21​mp​Lp​[(E−Er​)α˙cosα]2(45)

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

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

A=−Amaxsign[(E−Er)α˙cos⁡α](46)A = -A_{\text{max}}\text{sign}\left [ \left( E - E_r \right) \dot{\alpha}\cos{\alpha} \right ] \quad \quad (46)A=−Amax​sign[(E−Er​)α˙cosα](46)
A=−satA,max(μ(E−Er)sign(α˙cos⁡α))(47)A = -\text{sat}_{A, \text{max}}(\mu \left( E-E_r \right ) \text{sign}(\dot{\alpha}\cos{\alpha})) \quad \quad (47)A=−satA,max​(μ(E−Er​)sign(α˙cosα))(47)

where μ\muμ is a tunable controller gain.

τ=mrLrA(48)\tau = m_rL_rA \quad \quad (48)τ=mr​Lr​A(48)
τ=ηgKgηmktRm(Vm−Kgkmθ˙)(49)\tau = \frac{\eta_gK_g\eta_mk_t}{R_m}\left( V_m - K_gk_m\dot{\theta} \right ) \quad \quad (49)τ=Rm​ηg​Kg​ηm​kt​​(Vm​−Kg​km​θ˙)(49)
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)Vm​=ηg​Kg​ηm​kt​Rm​mr​Lr​A​+Kg​km​θ˙(50)

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

Vm={K(xd−x),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)Vm​=⎩⎨⎧​K(xd​−x),ηg​Kg​ηm​kt​Rm​mr​Lr​A​+Kg​km​θ˙,​if ∣α∣<ϵotherwise​(51)

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

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

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.

Press Connect button under Monitor & Tune and Press Start .

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.

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.

Note down the values of the swing-up parameters, i.e., ErE_rEr​, A_\rm{max},and μ\muμ.

From , plots of the commanded position of the rotary arm (θc\theta_cθc​), experimental responses of the rotary arm (θ\thetaθ), pendulum (α\alphaα), and motor input voltage (u(Vm)u(V_m)u(Vm​)) obtained using your obtained gain K.

Are satisfied? Justify using the measured maximum pendulum deflection and motor input voltage values.

From , the total energy reading of the inverted pendulum.

From , plots of the experimental responses of the rotary arm (θ\thetaθ), pendulum (α\alphaα), and motor input voltage (u(Vm)u(V_m)u(Vm​)).

From , ErE_rEr​, A_\rm{max},and μ\muμ used to bring the pendulum up.

Evaluate the potential energy of the pendulum when it is in the downward (180°180 \degree180°) and upright positions (0°0 \degree0°).

For Question 2, Use Equation 50 to get the maximum acceleration (AAA) of the rotary arm.

Compare the calculated value of potential energy when upright position (Question C.1) with the value in .

Compare the calculated value of the maximum acceleration AmaxA_{max}Amax​ (Question C.2) with the value in .

Design Specifications 3 and 4
Step C.10
Result C.1
Step B.3.10
Step C.17
Step C.16
Result C.3
Step 4 of Designing the Balance Control experiment
109KB
Week 2.zip
archive
Figure 7. State-feedback control loop
Figure 8. q_rotpen_bal_student SIMULINK diagram can be used to run balance controller
Figure 9. Experiment balance control response example.
Figure 10. Force vector diagram