The objectives of this part of the laboratory experiment on the rotary inverted pendulum are as follows:
Use energy-based control schemes to develop a swing-up pendulum controller.
Implement the swing-up controller on the Quanser Rotary Pendulum plant and evaluate its performance.
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.
The dynamics of the pendulum can be redefined in terms of pivot acceleration (see Figure 9) as
Given
sufficient condition for asymptotic stability is
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.
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
Run the part2setup.m script extracted from the Part 2.zip file in the 'Balance Control' section.
Check if the correct gain K value is loaded onto the workspace.
Open q_rotpen_swingup_student_2 Simulink diagram.
After the link swings up and is balanced, wait for ~5 seconds and stop the SIMULINK.
OPTIONAL: Save the data_alpha, data_theta, and data_Vm. Ensure that the data variables have 10 seconds of data saved.
Briefly summarize the swing-up controller experiment and your observations. Did the swing-up control behave as you expected?
[3] K. J. Åström and K. Furuta. Swinging up a pendulum by energy control. 13th IFAC World Congress, 1996.
The pivot acceleration, , is the linear acceleration of the pendulum link base. The acceleration is proportional to the torque of the rotary arm and is expressed as
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 () is negative, i.e.,
Let us select a candidate Lyapunov function for arriving at the control law as a quadratic function of the difference in total energy () and the reference energy () when the pendulum is in equilibrium in the upright position, i.e.,
where the total energy () is the sum of kinetic energy and potential energy .
Now, we need to select such that for asymptotic stability. This can easily be achieved by selecting as
which guarantees .
The selected control law (Equation 44) will continuously decrease the difference between current energy () and the energy of the pendulum in the vertically up position (). Note that the selected control law is nonlinear, it changes sign for and .
where is a tunable controller gain.
Where from Equation 47,
where
The parameter in Equation 51 is a user-selected range of 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 . The pendulum should be moving back and forth slowly. Gradually increase 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.
The objectives of this laboratory experiment are as follows:
Obtain the linear state-space representation of the rotary pendulum plant.
Design a state-feedback control system that balances the pendulum in its upright position using Pole Placement.
Simulate the closed-loop system to ensure the given specifications are met.
Implement the balance controller on the Quanser Rotary Pendulum plant and evaluate its performance.
This experiment involves modeling of the rotary inverted pendulum.
1
Rotary Servo
2
Thumbscrews
3
Rotary Arm
4
Shaft Housing
5
Shaft
6
Pendulum T-Fitting
7
Pendulum Link
8
Pendulum Encoder Connector
9
Pendulum Encoder
Mass of pendulum
0.127
Total length of pendulum
0.337
Distance from pivot to center of mass
0.156
Pendulum moment of intertia about center of mass
0.0012
Pendulum viscous damping coefficient as seen at the pivot axis
0.0024
Mass of rotary arm with two thumb screws
0.257
Rotary arm length from pivot to tip
0.216
Rotary arm length from pivot to center of mass
0.0619
Rotary arm moment of inertia about its center of mass
9.98 x 10^-4
Rotary arm viscous damping coefficient as seen at the pivot axis
0.0024
Rotary arm moment of inertia about pivot
0.0020
Pendulum encoder resolution
4096
The rotary inverted pendulum model is shown in Figure 2. The rotary arm pivot is attached to the Rotary Servo system and is actuated. The arm has a length of L_\rm{r}, a moment of inertia of J_\rm{r}, and its angle, , increases positively when it rotates counterclockwise (CCW). The servo (and thus the arm) should turn in the CCW direction when the control voltage is positive, i.e. V_\rm{m} > 0.
The pendulum link is connected to the end of the rotary arm. It has a total length of and it center of mass is {L_\rm{p}}/{2} . The moment of inertia about its center of mass is J_\rm{p}. The inverted pendulum angle, , is zero when it is perfectly upright in the vertical position and increases positively when rotated CCW.
Instead of using classical (Newtonian) mechanics, the Lagrange method is used to find the equations of motion of the system. This systematic method is often used for more complicated systems such as robot manipulators with multiple joints.
Specifically, the equations that describe the motions of the rotary arm and the pendulum with respect to the servo motor voltage, i.e., the dynamics, will be obtained using the Euler-Lagrange equation:
The variables are called generalized coordinates. For this system let
where, as shown in Figure 2, is the rotary arm angle and is the inverted pendulum angle. The corresponding velocities are
With the generalized coordinates defined, the Euler-Lagrange equations for the rotary pendulum system are
The Lagrangian of the system is described by
where is the total kinetic energy of the system and is the total potential energy of the system. Thus the Lagrangian is the difference between a system’s kinetic and potential energies.
The generalized forces are used to describe the nonconservative forces (e.g. friction) applied to a system with respect to the generalized coordinates. In this case, the generalized force acting on the rotary arm is
and acting on the pendulum is
See Table A in the Appendix for a description of the corresponding Rotary Servo parameters (e.g., such as the back-emf constant, k_\rm{m}). Our control variable is the input servo motor voltage, V_\rm{m}. Opposing the applied torque is the viscous friction torque, or viscous damping, corresponding to the term . Since the pendulum is not actuated, the only force acting on the link is the damping. The viscous damping coefficient of the pendulum is denoted by .
Once the kinetic and potential energy are obtained and the Lagrangian is found, then the task is to compute various derivatives to get the EOMs. After going through this process, the nonlinear equations of motion for the Rotary Pendulum are:
The torque applied at the base of the rotary arm (i.e. at the load gear) is generated by the servo motor as described by the equation 7. Refer to Table A in the Appendix for the Rotary Servo parameters.
Linearization of a nonlinear function about a selected point is obtained by retaining upto first order term in the Taylor Series expansion of the function about the selected point. For example, linearization of a two variable nonlinear function f(z) where
about the point
can be written as
The nonlinear equations of the inverted pendulum system obtained as Equations (7) and (8) are linearized about the equilibrium point with the pendulum in the upright position, i.e.,
, , , , ,
Linearization of Equation (7) about the above equilibrium state gives
where, from Equation(9) the servo motor torque coefficient is
and the back emf coefficient is
Likewise, linearization of Equation (8) about the equilibrium point with the pendulum in the upright position gives
where is the acceleration due to gravity. Note that the negative sign of the gravity torque ( term) in Equation 11 indicates negative stiffness with the pendulum in the vertically upright position.
Equation (10) and (11) can be arranged in the matrix form as
Where mass matrix , damping matrix , and the stiffness matrix become
Defining the state vector , output vector and the control input as
Equation (12) can be rewritten in state space form as
where the system state matrix , control matrix , output matrix and the feedthrough of input to the output matrix become
In the equations above, note that is a matrix of zeros, is a matrix of zeros, and is a identity matrix. Using the parameters of the system listed in Table 2 and the appendix Table A, the linear model matrices and can be computed.
Download the Part 1.zip file and extract the folder contents.
Open rotpen_part1_student.mlx live script and run the Modelling section. It will automatically load the parameters required for the state-space representation, and subsequently generate the A, B, C and D matrices required for the upcoming analysis. Please refer to Table 2 and Table A for additional information regarding the parameters. Note: The representative C and D matrices have already been included. The actuator dynamics have been added to convert your state-space matrices to be in terms of voltage. Recall that the input of the state-space model is the torque acting at the servo load gear (i.e. the pivot of the pendulum). However, we control the servo input voltage instead of control torque directly. The script uses the voltage torque relationship given in Equation 9 to transform torque to voltage.
Note down your state-space matrices for your report. Note: You may want to cross-check the state-space matrix with TAs before proceeding to balance control.
Find the open-loop poles of the system.
Hint: Use eig(A).
The control design and time-response requirements are: Specification 1: Damping ratio: 0.6 < < 0.8 Specification 2: Natural frequency: 3.5 rad/s < \omega_\rm{n} < 4.5 rad/s Specification 3: Maximum pendulum angle deflection: < 15 deg. Specification 4: Maximum control effort / voltage: |V_\rm{m}| < 10 V. The necessary closed-loop poles are found from specifications 1 and 2. The pendulum deflection and control effort requirements (i.e. specifications 3 and 4) are to be satisfied when the rotary arm is tracking a degree angle square wave.
The stability of a system can be determined from its poles ([2]):
Stable systems have poles only in the left-hand plane.
Unstable systems have at least one pole in the righthand plane and/or poles of multiplicity greater than 1 on the imaginary axis.
Marginally stable systems have one pole on the imaginary axis and the other poles in the left-hand plane.
The poles are the roots of the system’s characteristic equation. From the state-space, the characteristic equation of the system can be found using
where is the determinant function, is the Laplace operator, and the identity matrix. These are the eigenvalues of the state-space matrix .
If the control input of a system can take each state variable, where , from an initial state to a final state in finite time then the system is controllable, otherwise it is uncontrollable ([2]).
Rank Test The system is controllable if the rank of its controllability matrix
equals the number of states in the system, i.e.
If (A,B) are controllable and B is n×1, then A is similar to a companion matrix ([1]). Let the characteristic equation of A be
Then the companion matrices of A and B are
and
Define
where is the controllability matrix defined in Equation 16 and
Then
and
If are controllable, then pole placement can be used to design the controller. Given the control law , the state-space model of Equation (13) becomes
We can generalize the procedure to design a gain for a controllable system as follows:
Step 1 Find the companion matrices and . Compute . Step 2 Compute to assign the poles of to the desired locations.
Step 3 Find to get the feedback gain for the original system . Remark-1: It is important to do the conversion. Remember that represents the actual system while the companion matrices and do not.
Remark-2: The entire control design procedure using the pole placement method can be simply done in MATLAB using the function called 'place' or 'acker'. For a selected desired set of closed loop poles DP, the full state feedback gain matrix is obtained from
The rotary inverted pendulum system has four poles. As depicted in Figure 3, poles and are the complex conjugate dominant poles and are chosen to satisfy the natural frequency, , and damping ratio, , as given in Specification. Let the conjugate poles be
and
where and is the damped natural frequency. The remaining closed-loop poles, and , are placed along the real-axis to the left of the dominant poles, as shown in Figure 3.
The feedback control loop that balances the rotary pendulum is illustrated in Figure 4. The reference state is defined as
where is the desired rotary arm angle. The controller is
Note that if then , which is the control used in the pole-placement algorithm.
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
where is the angle about which the controller should engage. For example if degrees, then the control will begin when the pendulum is within ±10 degrees of its upright position, i.e. when degrees.
Select and such that they satisfy the given design specifications.
In the same rotpen_part1_student.mlx live script, go to the Balance Control section. Enter the chosen zeta
and omega_n
values.
Determine the locations of the two dominant poles and based on the specifications and enter their values in the MATLAB live script. Ensure that the other poles are placed at p3 = -30
and p4 = -40
.
Hint: Use Equation 27.
Find gain K
using a predefined Compensator Design MATLAB command
K = acker(A,B,DP)
, which is based on pole-placement design.
Note: DP
is a row vector of the desired poles found in Step 3.
For sanity check, if you use damping ratio of 0.7 and natural frequency of 4 rad/s, you should get around K = [-12 63 -5.5 7].
The s_rotpen_bal SIMULINK diagram shown in Figure 5 is used to simulate the closed-loop response of the Rotary Pendulum using the state-feedback control described in Balance Control with the control gain K found above. The Signal Generator block generates a 0.1 Hz square wave (with an amplitude of 1). The Amplitude (deg) gain block is used to change the desired rotary arm position. The state-feedback gain K is set in the Control Gain gain block and is read from the MATLAB workspace. The SIMULINK State-Space block reads the A, B, C, and D state-space matrices that are loaded in the MATLAB workspace. The Find State X block contains high-pass filters to find the velocity of the rotary arm and pendulum.
Run rotpen_part1_student.mlx live script. Ensure the gain K you found is loaded in the workspace (type K matrix in the command window).
Open and run the s_rotpen_bal.mdl for 10 seconds. The responses in the scopes shown in Figure 6 were generated using an arbitrary feedback control gain.
Note: When the simulation stops, the last 10 seconds of data is automatically saved in the MATLAB workspace to the variables data_theta
, data_alpha
, and data_Vm
.
Save the data corresponding to the simulated response of the rotary arm, pendulum, and motor input voltage obtained using your obtained gain K.
Note: The time is stored in the data_theta(:,1)
vector, the desired and measured rotary arm angles are saved in the data_theta(:,2)
and data_theta(:,3)
arrays. Similarly, the pendulum angle is stored in the data_alpha(:,2)
vector, and the control input is in the data_Vm(:,2)
structure.
Measure the pendulum deflection and voltage used. Are the specifications given satisfied?
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 7 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.
Download the Part 2.zip file, extract the folder contents and open the part2setup.m script.
Go to the 'Balance Control' section and put the gain K you found in Step 4 of Designing the Balance Control experiment. Run the script.
Open the q_rotpen_bal_student SIMULINK diagram.
As shown in Figure 7, the SIMULINK diagram is incomplete. Add the necessary 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.
Turn ON the power amplifier.
Ensure the pendulum is in the hanging down position, with the rotary arm aligned with the 0 marking, and is motionless.
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.
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 8).
CAUTION Be careful, as the pendulum will fall down when the controller is stopped.
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.
The linear state-space representation of the rotary inverted pendulum system, i.e., , , and matrices (numerical values).
Open-loop poles of the system.
Chosen and based on design specifications.
Corresponding locations of the two dominant poles and .
Gain vector .
Plots of the commanded position of the rotary arm (), simulated responses of the rotary arm (), pendulum (), and motor input voltage () generated using your obtained gain K.
Are Design Specifications 3 and 4 satisfied? Justify using the measured maximum pendulum deflection and motor input voltage values.
From Step B.3.10, plots of the commanded position of the rotary arm (), experimental responses of the rotary arm (), pendulum (), and motor input voltage () generated using the chosen gain K.
Are Design Specifications 3 and 4 satisfied? Justify using the measured maximum pendulum deflection and motor input voltage values.
Based on your open-loop poles found in Result A.2, is the system stable, marginally stable, or unstable?
Did you expect the stability of the inverted pendulum to be as what was determined? Justify.
For the questions below, calculations and intermediate steps must be shown.
Determine the controllability matrix of the system. Is the inverted pendulum system controllable? Hint: Use Equation 17.
Using the open-loop poles, find the characteristic equation of . Hint: The roots of the characteristic equation are the open-loop poles.
Instead of using , characteristic polynomials can also be found using MATLAB function poly()
.
Find the corresponding companion matrices and . Hint: For , use the characteristic equation of A found in Question B.1.2 and Equation 19. For , use Equation 20.
Determine the controllability matrix of the companion system.
Determine the transformation matrix .
Check if and with the obtained matrices.
Using the locations of the two dominant poles, and , based on the specifications (Result B.1.1), and the other poles at and , determine the desired closed-loop characteristic equation. Hint: The roots of the closed-loop characteristic equation are the closed-loop poles.
When applying the control to the companion form, it changes to . Find the gain that assigns the poles to their new desired location. Hint: Use Equation 26 and find the corresponding characteristic equation. Compare this equation with the desired closed-loop characteristic equation found in Question B.1.7 to determine the gain vector .
Once you have found , find using Step 3 in Pole Placement Theory.
Compare the gain vector calculated using Pole Placement Theory (Question B.1.9) with the gain vector obtained using MATLAB (Result B.1.3).
Motor nominal input voltage
6.0 V
Motor armature resistance
2.6 Ω ± 12%
Motor armature inductance
0.18 mH
Motor current-torque constant
7.68 × 10−3 N-m/A ± 12%
Motor back-emf constant
7.68 × 10−3 V/(rad/s) ± 12%
High-gear total gear ratio
70
Motor efficiency
0.69 ± 5%
Gearbox efficiency
0.90 ± 10%
rotor Rotor moment of inertia
3.90 × 10−7 kg-m2 ± 10%
High-gear equivalent moment of inertia without external load
1.823 × 10−3 kg-m2
High-gear Equivalent viscous damping coefficient
0.015 N-m/(rad/s)
Mass of bar load
0.038 kg
Length of bar load
0.1525 m
Mass of disc load
0.04 kg
Radius of disc load
0.05 m
Maximum load mass
5 kg
Maximum input voltage frequency
50 Hz
Maximum input current
1 A
Maximum motor speed
628.3 rad/s
[1] Bruce Francis. Ece1619 linear systems, 2001. [2] Norman S. Nise. Control Systems Engineering. John Wiley & Sons, Inc., 2008.
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 .