Note: This content is accessible to all versions of every browser. However, this browser does not seem to support current Web standards, preventing the display of our site's design details.

Main / InvertedPendulum

(redirected from Main.LinearCart)

 Homework 30 min. Requirements Signale und Systeme II Rating Normal

IfA 2.2 Lab Manual

by Antonello Caruso, Andreas Kuhn and Quanser Inc.

1.  Introduction

The inverted pendulum is a classic problem in dynamics and control theory and widely used as a benchmark for testing control algorithms. It is a pendulum which has its mass above its pivot point. It is implemented with the pivot point mounted on a cart that can move horizontally. Whereas a normal pendulum is stable when hanging downwards, an inverted pendulum is inherently unstable and must be actively balanced in order to remain upright, either by applying a torque at the pivot point or by moving the pivot point horizontally as part of a feedback system. The latter approach is the aim of this experiment that is indeed based on feedback control concepts, particularly PD controllers.

In the first part of this experiment, you will design a controller that regulates the position of the High Fidelity Linear Cart (HFLC) servo plant to a desired set-point. Furthermore, we are going to design a state-feedback control system that dampens the transient motion of a Single Pendulum Gantry (SPG) and tracks the HFL cart to a commanded position without letting the pendulum swing up too much. Note that the Pendulum effectively is a disturbance to the controller. The first two parts, indeed, are for warming up only; The main purpose of the experiment is to design a controller that maintains the pendulum upright.

Attention: You will need about 3 feet of clearance from either end of the track to avoid collisions and ensure that the pendulum will not collide with any object while it swings!

2.  Position PV Control

2.1  Laboratory Objectives

The challenge in this laboratory is to design a controller that regulates the position of the High Fidelity Linear Cart (HFLC) servo plant (see figure) to a desired setpoint.

2.2  HFLC System Modeling

The Maple worksheet HFLC Equations.mws (or its HTML equivalent HFLC Equations.html) derives the open-loop mathematical model of the HFLC servo plant from first principles. The files can be downloaded from here. Both the open-loop transfer function, in the Laplace domain, and the state-space representation are given. Further analysis of a Proportional-plus-Velocity (PV) controller is also carried out. You can edit and re-calculate the equations by executing the worksheet using Maple 8.

The state-space representation of the open-loop HFLC system is

where for the cart position

and the model parameters , , , , and are defined in Section 1.3, below. The viscous damping Beq is not explicitly specified and in most cases is regarded as negligible (however, it could be calculated by doing system identification on the HFLC). The control input is the motor armature current, u = Im, and since the Power Supply UPM-50-25-3PHI is current-controlled the dynamics of the actuator are negligible. That is, the current running in the motor armature equals the current commanded by the controller. Finally, note that this model does not take into account Coulomb friction (i.e. Stiction).

2.3  Modeling Parameters

SymbolDescriptionValueUnit
Motor Torque Constant0.07Nm/A
Motor Efficiency100%
Motor Line-To-Line (Armature) Resistance1W
Motor Line-To-Line (Armature) Inductance0.65mH
Back--Force (EMF) Constant7.5E-003V/rpm
Motor Rated Voltage24V
Motor Continuous Stall Torque0.247N.m
Motor Peak Torque1.306Nm
Motor Continuous Stall Current3.0A
Motor Current at Peak Torque19A
Motor (Only) Mass0.7kg
HFL Cart System Mass1.79kg
Rotor Moment of Inertia1.64E-005kg m2
Cart Encoder Resolution9.741E-006m/count
4096counts/rev
Front and Rear Pendulum Encoder Resolution0.0015rad/count
4096counts/rev
Rear Pendulum Mechanical Range±30.9°

2.4  State-Feedback Controller Design

The position controller implemented in \xPC_Exp1_PV\HFLC_PV_sim.mdl and \xPC_Exp1PV\HFLC_PV_Real.mdl is a Proportional-plus-Velocity (PV) controller. Consider the following state-feedback law

and for a reference position

Since the reference state includes only a desired position and no speed reference, this controller is equivalent to the PV control law

for .

The Proportional-plus-Velocity (PV) control scheme is designed to meet two time-domain requirements:

1. Overshoot less than or equal to 12.5% ⇒ .
2. Minimum time to first peak (i.e. fastest response) given that the maximum position reference is .

The closed-loop HFLC system has the form

where is the natural frequency and is the damping ratio. See Maple sheet HFLC Equations.mws for details on the derivation. These two parameters determine the overshoot and first peak time of the system. Solving for the damping ratio in the overshoot expression

results in

The minimum damping coefficient needed according to the specification can be calculated by inserting

The fastest time to attain the first peak is calculated using the maximum acceleration of the HFLC cart and the given maximum position command. The minimum peak time is:

where is the largest position reference and for a maximum UPM (Power Supply) input current the peak acceleration is

Note that limits the current to . The natural frequency is

where and are calculated as described above.

Therefore for a maximum UPM input current of , above equations yield

The resulting damping ratio and natural frequency characterize the desired closed-loop system that results in a response that meets specifications given above. That is, the closed-loop poles needed to yield the time-domain requirements are now defined. The PV control gain is calculated using Ackermann's pole placement formula (i.e. with the Matlab function place; have a look at the matlab help page of place; type help place in the command prompt of matlab) such that the poles of the closed-loop HFLC system match the desired poles of the characteristic equation in [6]. Thus the feedback gain that places the HFLC poles to the desired poles is

2.5  In-Lab Procedure

Objectives

• Ensure the closed-loop response of the HFLC model using the PV controller meets the overshoot before implementing the controller on the actual system.

Procedure

Follow these steps to simulate the PV controller using the state-space model of the HFLC:

1. To start the exercise, it is necessary to double click on the desktop icon IfA 2.2. This will invoke a startup script. The experiment files will be retrieved from a central server and will be stored in the following directory structure: c:\Scratch\HFLC. The script should also open the Simulink model (\xPC Exp1 PV\HFLC_PV_Sim.mdl). You should obtain a diagram similar to the one shown in the figure below.
2. Run the two Matlab scripts \xPC Exp1 PV\HFLC_setup.m and \xPC Exp1PV\PV_Controller.m. The first one sets all the parameters for the linear cart system and the second script sets the variables of the PV controller.
3. Click on start simulation to simulate the position response using the PV position controller. The position of the cart should track the commanded square position signal. Double click on the scope (x_ref + x_sim(m)) to see the signal output.
4. As you can see the response does not fulfill the requirements at the moment. This is because zeros are also introduced during the pole placement and they slow the system down. Try to fine-tune the gain by changing (e.g. ) until you meet the requirements.

Figure 1: Simulink model for the PV Controller

Controller Real-Time Implementation

We now implement the controller and run it in real-time.

Objectives

• Implement the previously designed PV position controller using xPC to command your HFLC servo plant.
• Run the simulation simultaneously, at every sampling period, to compare the actual and simulated responses.

Experimental Procedure

Follow the steps described below to implement the designed controller in real-time and observe its effect on the actual HFLC plant. When switching on the equipment, make sure the power emergency button is not engaged.

1. Open the Simulink model \xPC Exp1 PV\HFLC_PV_Real.mdl that implements a sample PV controller. The model has two parallel and independent control loops: one runs (lower loop in orange color) a pure simulation of the PV controller connected to the plant model and the other loop (upper loop in blue color) runs the actual HFLC servo plant by directly interfacing with the hardware.
2. Verify that the signal generator block is set to output a square wave signal of amplitude 1 and of frequency 1 Hz. The resulting position setpoint should be a square wave switching between ±10 mm.
3. Before compiling the diagram and running it in real-time with xPC, the statespace model of the HFLC servo and the feedback gain vector must be calculated and entered in the Matlab workspace (this has been done during the simulation using HFLC_setup.m and PV_Controller.m). Further, various parameters used in the subsystems such as filter cutoff frequencies, cart position safety limits, and the PWM amplifier gain are set in the same files.
4. Further the UPM power amplifier (the blue box) has to be initialized. You can do this by issuing the command UPMInit in the Matlab prompt. (Note: this command will need to be repeated whenever left & right lights flash on the UPM)
5. Ensure the real-time code is ran safely by manually moving the HFLC cart to the middle of the track (i.e. home position) so it is free to move on both sides. The UPM Home green light should be on.
6. The real-time code corresponding to the diagram can now be built by typing the Matlab command TargetBuild('HFLC_PV_Real').
7. In order to observe the system's real-time responses, the scopes are shown on the Target PC. Look at the simulink diagram to see which signals are shown on the scope. You should now be able to see on-the-fly the measured cart position as it tracks the reference position (i.e. the ± 0.01 m, 1 Hz square wave). You can also see the difference between the simulation and the real system which is due to model assumptions. The figure shown below depicts the actual and simulated cart position response next to the reference position.

Figure 2: Sample position response using the PV controller

1. If the HFLC system does not behave as expected (e.g. due to inadequate tuning), press the emergency stop button to interrupt the power to the HFLC DC motor.
2. If the compilation was successful, you should now be able to start the control loop in real-time by issuing the Matlab command TargetRun.
3. Issue the Matlab command TargetStop to stop the real-time execution.
4. Now move the poles to change the overshoot by recalculating the damping and the natural frequency . Observe how the system changes for different values of . Try to explain how these values actually affect system dynamics.

3.  PP Control

3.1  Laboratory Objectives

The challenge in this laboratory is to design a state-feedback control system that dampens the transient motion of a Single Pendulum Gantry (SPG) and tracks the HFL cart to a commanded position. Note that the Pendulum effectively is a disturbance to the PV controller.

3.2  HFLC-plus-SPG System Modeling

The Maple worksheet named HFLC SPG Equations.mws (or its HTML equivalent HFLC SPG Equations.html) derives both nonlinear and linear models of the HFLC-plus-SPG system. As a result, the system's state-space representation is obtained. Using Maple 8, the worksheet equations can be edited and re-calculated by executing the worksheet. In summary, the state-space representation of the open-loop HLFC-plus-SPG system is

where

and

The model parameters , , , and are defined in Section 1.3 and the pendulum mass, , and centre of gravity, , are defined in Section 2.3. This model does not take into account Coulomb friction (i.e. Stiction), pendulum viscous damping , cart viscous damping , rotor moment of inertia , and pendulum inertia . The system input is the force of the cart,

and the control input is the motor armature current . That is, the controller enters in input given above.

3.3  Single Pendulum Specifications

The tables below list and characterize the main parameters associated with the Single Pendulum Gantry (SPG) module. The medium pendulum (i.e. 30 cm long) is used in the first part in this laboratory.

SymbolMatlab NotationDescriptionValueUnit
Medium Pendulum Full Length (from Pivot to Tip)0.3048m
Medium Pendulum Mass0.104kg
Medium Pendulum Length from Pivot to Center of Gravity0.1524m
SymbolDescriptionValueUnit
Short Pendulum Full Length (from Pivot to Tip)0.2096m
Short Pendulum Mass0.072kg
Short Pendulum Length from Pivot to Center of Gravity0.1143m
SymbolDescriptionValueUnit
Long Pendulum Full Length (from Pivot to Tip)0.6413m
Long Pendulum Mass0.230kg
Long Pendulum Length from Pivot to Center of Gravity0.3302m

3.4  State-Feedback Controller Design

The HFLC+SPG controller objective is for the cart to track a commanded position while minimizing the swing motions of the suspended pendulum. Thus the cart position, , is to track the reference position, , and the pendulum angle, , is to be regulated to 0º. The gantry controller implemented in \xPC Exp2 SPG\SPG_Sim.mdl and \xPC Exp2 SPG\SPG_Real.mdl is a pole-placement (PP) controller. Consider the following statefeedback law:

where

The controller is designed such that the cart position and the pendulum angle have the following characteristics:

1. Overshoot less than or equal to 5% ⇒ .
2. Response settles within 2% in 2.2 seconds or under ⇒ .

The HFLC+SPG system can be considered a second-order system by selecting its dominant second-order poles according to the specifications and placing the other poles along the real axis in the left-hand plane. The dominant second-order poles and can be described as

where for the natural frequency and the damping ratio

The natural frequency and the damping ratio determine the overshoot and settling time of the system. Solving for the damping ratio in the overshoot expression

results in

The minimum damping coefficient needed for using the equation above is

The natural frequency is calculated by solving the 2% settling time equation

for , resulting in the expression

The minimum natural frequency required to meet the settling time specification is

The damping ratio and the natural frequency characterize the dominant second-order closed-loop poles that result in a response that meets specifications 1. and 2. The desired closed-loop poles calculated using the statefeedback law are For the HFLC+SPG system to mimic a second-order system, the remaining poles are placed along the real-axis at

The control gain is designed using Ackermann's pole placement formula (i.e. with the Matlab function place; have a look at the Matlab help file of this function). The gain

successfully places the closed-loop poles of the HFLC+SPG to their desired position,

As the error converges towards zero using statefeedback , and °. Remark that control gain has opposing signs for the cart and the pendulum because they have opposite direction conventions (i.e. the cart follows the right-hand convention and the pendulum is positive when CCW).

3.5  In-Lab Procedure

Experimental Setup

Figure 3: HFLC-plus-SPG System

System Wiring and Hardware Setup

• Mount the medium (i.e. 12-inch long) pendulum rod to the cart front pendulum shaft, as illustrated in Figure 3.
• Wire the front pendulum encoder to encoder input #1 of the Q8 terminal board. This connection is presented in the following Table and depicted in Figure 4 and Figure 5.
Cable#FromToFunction
1HFLC Front Pendulum Encoder ConnectorEncoder #1 on the Q8 Extended Terminal BoardMeasures the front pendulum angle,

Figure 4: SPG Encoder Connection on HFLC

Figure 5: SPG Encoder Connection on DAC

Objectives

• Ensure the closed-loop response using the pole-placement (PP) controller and the nonlinear model of the HFLC-plus-SPG meets the overshoot and settling time specifications without saturating the actuator before implementing the controller on the actual system.

Procedure

Follow these steps to simulate the pole-placement controller using the state-space model of the HFLC-plus-SPG:

1. Open Simulink model \xPC Exp2 SPG\SPG_Sim.mdl shown in Figure 6.
2. Run the Matlab script \xPC Exp2 SPG\Setup.m to set the model parameters and the control gain
3. Click on start simulation to simulate the cart position and pendulum response. The position of the cart, should track the commanded square position signal and meet the overshoot and settling time specifications. The pendulum angle should be stabilized about the angle zero. The horizontal position of the tip of the pendulum is also plotted.
4. Try to fine-tune the gain by changing (e.g. ) in order to improve the response.

Figure 6: Simulink diagram of HFLC-plus-SPG using PP

Objectives

• Implement the previously designed pole-placement (PP) controller in order to control the Single Pendulum Gantry (SPG) on the linear track.
• Compare the actual and simulated responses by running the simulation in parallel.

Procedure

To implement your designed controller in real-time and observe its effect on your actual HFLC plant, follow the steps described below:

1. Open Simulink model \xPC Exp2 SPG\SPG_Real.mdl shown in Figure 7 that implements a sample PP controller. The model runs the actual HFLC-plus-SPG plant by directly interfacing with the hardware. The states may be fed back partially or fully depending on the position of the manual switch in the Simulink model, shown in Figure 7. When partial feedback is chosen only the position and speed of the cart are used in the control. Thus the controller regulates the position of the cart but does not compensate for the swinging motions of the pendulum. When full feedback is chosen, the HFLC+SPG controller developed in this manual is used and both the cart position and pendulum angle position are controlled. Thus the pendulum swinging motions are dampened as the cart tracks a position reference.
2. Execute the script file \xPC Exp2 SPG\Setup.m to setup the workspace before compiling the diagram and running it in real-time. This file sets the state-space model of the HFLC+SPG system. It also calculates the feedback gain vector and enters it in the Matlab workspace. Further, various parameters used in the HFLC+3enc subsystem such as filter cutoff frequencies, cart position safety limits, and the PWM amplifier gain are also loaded.
3. Further the UPM power amplifier (the blue box) has to be initialized. You can do this by issuing the command UPMInit in the Matlab prompt. (Note: This command will need to be repeated whenever left & right lights flash on the UPM).
4. Ensure the real-time code is ran safely by manually moving the HFL cart to the middle of the track (i.e. home position) so it is free to move on both sides. The UPM Home green light should go on.
5. Figure 8 depicts the interior of the HFLC+SPG subystem. For safety precautions, a watchdog is placed that stops the real-time controller if the pendulum angle goes beyond the ALPHA_MIN and ALPHA_MAX limits specified in the \xPC Exp2 SPG\SPG_Setup.m file (given that ALPHA_LIM_ENABLE = 1). This file is called by \xPC Exp2 SPG\Setup.m.
6. The real-time code can now be built with the Matlab command TargetBuild ('SPG_Real').
7. In order to observe the system's real-time responses, the scopes are shown on the Target PC. Look at the simulink diagram to see which signals are shown on the scope. You should now be able to see on-the-fly the measured cart position as it tracks the reference position (i.e. the ± 0.15 m, 0.1 Hz square wave). You can also see the difference between the simulation and the real system which is due to model assumptions. The partial-feedback response of the HFL cart position and pendulum angle is given in Figure 9 and the full-state feedback response is given in Figure 10.
8. Verify that the suspended pendulum is not moving before starting the controller.
9. If the HFLC system does not behave as expected (e.g. due to inadequate tuning), press the emergency stop button to interrupt the power to the HFLC DC motor.
10. If the compilation was successful, you should now be able to run your actual system in real-time using TargetRun. The cart should track the position reference and regulate the pendulum angle to 0° (if full-state feedback is chosen).
11. Issue the Matlab command TargetStop if you want to stop the real-time execution.
12. Now move the poles to change the system response. Observe how the system changes for different values of
13. Set back to the value you had had before you changed it in Step 12.
14. Mount the other pendulums to the cart, as illustrated in Figure 3 and see what happens when the wrong controller for a certain pendulum length is used.
15. As a last step compile the controller you have developed in Experiment 1 (without the pendulum) and see how this controller would control the position when the pendulum is attached to the cart.

Figure 7: Diagram used for the Real-Time Implementation of the PP

Figure 8: HFLC+SPG Subsystem

Figure 9: HFLC+SPG partial-state feedback response

Figure 10: HFLC+SPG full-state feedback response

4.  Single Inverted Pendulum Control

Figure 11: HFLC-plus-SIP System

4.1  Laboratory Objectives

The challenge in this laboratory is to design a state-feedback control system that balances a Single Inverted Pendulum (SIP) and regulates the position of the High Fidelity Linear Cart to a desired setpoint.

4.2  HFLC-plus-SIP System Modeling

The Maple worksheet HFLC SIP Equations.mws (or its HTML equivalent HFLC SIP Equations.html) derives both nonlinear and linear models of the HFLC-plus-SIP system. As a result, the system's state-space representation is obtained. The worksheet equations can be edited and re-calculated by executing the worksheet using Maple 8. In summary, the state-space representation of the open-loop HLFC-plus-SIP system is

where

and

As discussed in Section 2.2, the model does not take into account Coulomb friction, pendulum viscous damping , cart viscous damping , rotor moment of inertia , and pendulum inertia . The system input is the force of the cart, , and the control input is the motor armature current .

4.3  Single Pendulum Specifications

the table below lists and characterizes the main parameters associated with the Single Inverted Pendulum (SIP) module. The medium (i.e. 12 inch, 30 cm long) pendulum is used in this laboratory.

SymbolMatlab NotationDescriptionValueUnit
Medium Pendulum Full Length (from Pivot to Tip)0.3048m
Medium Pendulum Mass0.104kg
Medium Pendulum Length from Pivot to Center of Gravity0.1524m

4.4  State-Feedback Controller Design

The HFLC+SIP controller objective is to follow a reference HFL cart position while balancing the inverted pendulum. Thus the cart position, , is to track the reference position, , and the upright pendulum angle, , is to be regulated to 180°. The gantry controller implemented in \xPC Exp3 SIP\SIP_Sim.mdl and \xPC Exp3 SIP\SIP_Real.mdl is a pole-placement (PP) controller. Consider the following statefeedback law:

where

The controller is designed such that the cart position and the pendulum angle have the following characteristics:

1. Overshoot less than or equal to 5% ⇒ .
2. Response settles within 2% in 2.2 seconds or under ⇒ .

The HFLC+SIP system can be considered a second-order system by selecting its dominant second-order poles according to the specifications and placing the other poles along the real axis in the left-hand plane. The desired closed-loop poles calculated using the statefeedback law are (see Section 2.4 for details on the procedure). For the HFLC+SPG system to mimic a second-order system, the remaining poles are placed along the real-axis at

The control gain is designed using Ackermann's pole placement formula. The gain

successfully places the closed-loop poles of the HFLC+SIP to their desired position,

4.5  In-Lab Procedure

The experimental setup, system wiring and hardware setup are described in Section 2.5.

Objectives

• Ensure the closed-loop response using the pole-placement (PP) controller and the nonlinear model of the HFLC-plus-SIP meets the overshoot and settling time specifications without saturating the actuator before implementing the controller on the actual system.

Procedure

Follow these steps to simulate the pole-placement controller using the state-space model of the HFLC-plus-SIP:

1. Open Simulink model \xPC Exp3 SIP\SIP_Sim.mdl shown in Figure 12.
2. Run the Matlab script \xPC Exp3 SIP\Setup.m to set the model parameters and the control gain
3. Click on start simulation to simulate the cart position and pendulum response. The position of the cart should track the commanded square position signal and meet the overshoot and settling time specifications. The pendulum angle should be regulated to 180°. The horizontal position of the tip of the pendulum is also plotted.
4. Try to fine-tune the gain by changing in order to improve the response.

Figure 12: Simulink diagram of HFLC-plus-SIP using PP

Objectives

• Implement the previously designed pole-placement (PP) controller in order to control the Single Inverted Pendulum (SIP) on the linear track.

Procedure

To implement your designed controller in real-time and observe its effect on your actual HFLC plant, follow the steps described below:

1. Open Simulink model \xPC Exp3 SIP\SIP_Real.mdl shown in Figure 13 that implements a sample PP controller. The model runs the actual HFLC-plus-SIP plant by directly interfacing with the hardware.
2. Execute the script file \xPC Exp3 SIP\Setup.m to setup the workspace before compiling the diagram and running it in real-time. This file sets the state-space model of the HFLC+SIP system. It also calculates the feedback gain vector and enters it in the Matlab workspace.
3. Ensure the real-time code is ran safely by manually moving the HFL cart to the middle of the track (i.e. home position) so it is free to move on both sides. The UPM Home green light should go on.
4. The real-time code can now be built with the Matlab command TargetBuild ('SIP_Real').
5. In order to observe the system's real-time responses, the scopes are shown on the Target PC. Look at the Simulink diagram to see which signals are shown on the scope. You should now be able to see on-the-fly the measured cart position as it tracks the reference position.
6. Verify that the suspended pendulum is not moving before starting the system.
7. The position setpoint can be either 0 mm (initial position of the HFL cart) or a square wave signal. Verify that the signal generator block is set to output a square wave signal of amplitude 1 and of frequency 0.1 Hz; the resulting position setpoint is a square wave switching between ±100 mm. Verify that the position setpoint is set to 0 mm for the moment.
8. If the HFLC system does not behave as expected (e.g. due to inadequate tuning), press the emergency stop button to interrupt the power to the HFLC DC motor.
9. If the compilation was successful, you should now be able to run your actual system in real-time using TargetRun.
10. Manually rotate the pendulum in the upright position until the controller is activated (i.e. when the cart begins moving), as illustrated in Figure 14. The rotation does not have a mandatory direction; that is, it can be clockwise or counter-clockwise. Release the pendulum as soon as the controller is activated.
11. The cart should track the position reference and regulate the pendulum angle to 180°.
12. While the system is running, change the manual switch which commands the position setpoint.
13. While the system is running, try introducing a disturbance by poking GENTLY the tip of the rod.
14. Issue the Matlab command TargetStop if you want to stop the real-time excecution.

Figure 13: Simulink diagram of the HFLC-plus-SIP real-time implementation

Figure 14: Rotate the pendulum clockwise or counter-clockwise in the upright position