B & C. Control Design and Controller Implementation (Week 2)
Objective
The objective is to design a controller that allows rapid reorientation of the link with very little vibrations from the link flexibility. This analysis is a preliminary approach to containing structural vibrations in real-world applications like aircraft and spacecraft structures as well as robotic links/manipulators
B. Control Design
The methodology used is to design two types of controllers, viz., Servo Controller and Link Controller. We will compare the closed loop performance between the two controllers.
In the Servo Controller design, partial state feedback is used, i.e., only the servo angle (θ) and its rate (θ˙) are used as feedback variables. We will make use of the controlSystemDesigner tool in MATLAB with simultaneous loop closure architecture for the controller.
In the Link Controller design, full state feedback is used, i.e, the servo angle (θ) and its rate (θ˙), as well as the link angle (α) and its rate (α˙), are used as feedback variables. The method we will use for full state feedback is based on the linear quadratic regulator (LQR) theory, which requires the given system to be state controllable.
State Space Model
The equations that describe the motions of the servo and the link with respect to the servo motor voltage are obtained using the lumped mass method and can be written as
Assuming the viscous damping of the link is negligible, i.e. Bl = 0 and substituting the torque τ using the expression,
the EOM can be rearranged as
The various system parameters can be found in Table 2 of Part A: System Identification.
Equations 3 and 4 can be represented in state-space form
withx=[θαθ˙α˙]T andu=Vm, where
In the output equation, only the position of the servo and link angles are being measured.
As such, the velocities of the servo and link angles can be computed in the digital controller if required, e.g., by taking the derivative and filtering the result though a high-pass filter. Hence, with all the states of the system as outputs, the C and D matrices are
Linear Quadratic Regulator (LQR) Design
Controllability
If the control input ′u′ of a system can take each state variable, xi where i=1...n, from an initial state to a final state in finite time, then the system is controllable, otherwise it is uncontrollable. The controllability of a system can be determined using the ‘Rank Test’. According to the Rank Test, the system is controllable if the rank of its controllability matrix
equals the number of states of the system,
LQR controller
If (A,B) are controllable, then the Linear Quadratic Regular optimization method can be used to find full state feedback controller gains. Given the plant model in state-space form where x represents the state vector, this technique finds a control input ‘u’ that minimizes the cost function
where Q and R are the user-defined weighting matrices Q=QT and R=RT. It is assumed that Q is positive semi-definite (all the eigenvalues ofQ are non-negative) and R is positive definite (all the eigenvalues of R are positive). The weighting matrices affect how LQR minimizes the function and are, essentially, tuning variables. Here, x is the state vector[θαθ˙α˙]T andu is the servo motor voltage input Vm.
Given the control law u=−Kx, the state-space model of the closed loop system becomes
where K is given by
is the controller gain vector. Note that the input voltage Vm is scalar, and therefore, R is also scalar. In practice, the weighting matrices Q and R are chosen to be diagonal. A simple way for choosing Q and R is using the Bryson's rule. This method works best when control design specifications regarding the system response and control input are given in terms of limits on excursions from equilibrium.
Assuming the time-domain design specifications are
Then one can use the Bryson’s rule to choose the weighting matrices as
Further tuning of Q and R may be required for improving the controller performance. Note that increasing R means increasing the penalty on the control input (using less control effort). Similarly, increasing Q means increasing the penalty on the states (states reaching equilibrium position quickly and with less overshoot). Matrix Q sets the weight on the states and determines how u will minimize J (and hence how it generates gain matrix K).
In our case,
Substituting Q and R in Eqn. 9 gives
where qθ=θmax21, qα=αmax21, qθ˙=θ˙max21, qα˙=α˙max21, R=Vm,max21
On observing Eq. 12, it can be seen that increasing qi causes control input Vm to work harder to minimize state xi, which will predominately increase ki. If qθ is increased, then kθ will increase to compensate for the larger weight placed on state θ. Depending on the model, changing a single qi can affect multiple ki gains because each state is not independent. If R is increased, then control input V has to work less to minimize J. In that case, LQR would generate a lower overall value of K. A block diagram of the system with fill state feedback controller is shown in Figure 1.

The feedback control loop in Figure 1 is designed to stabilize the servo to a desired position,θd, while minimizing the deflection of the flexible link, wherex is the state column vector andK is the gain row vector as shown earlier. Note thatC is 4×4 identity matrix and D is 4×1 column of zeros in Figure 1.
The reference state is defined as
and the controller is
Controller Specifications:
The following specifications in the time domain are to be met when the rotary arm is tracking a 30°step change in its angular position.
Specification 1: Servo angle rise time: tr≤0.2s
Specification 2: Servo angle percentage overshoot: PO≤5%
Specification 3: Maximum link angle deflection:∣α∣max≤10°
Specification 4: Maximum control effort (voltage): ∣Vm∣max≤10V
Controller Design Procedure:
Note: The results from the following steps have to be included in the Analysis section of the report.
State Space Model
Download A_and_B_matrices.m file and input your Ks value from System Identification.
Obtain the A and B matrices of the system using the parameters from Part A: System identification. Check your A and B matrices with the TA.
Servo Controller Design (PD Controller):
For a rapid rotation of the link, we select the proportional gain based on using the maximum voltage input at the beginning. For a 30 degrees (=6πrad) of step command, required proportional gain =θcommandVmax=6π10 = 19.1. Select Proportional gain (Kθ) = 19.
With the servo angle (θ) as output, construct the state space model in MATLAB. >>
sys_servo = ss(A,B,[1,0,0,0],0)Open the controlSystemDesigner tool in MATLAB. >>
controlSystemDesigner(sys_servo)Under Edit Architecture, select the controller structure shown in the figure. Note that C1 is the proportional gain block and C2 is the derivative gain block. Hence, you need to add a differentiator in C2, not a real zero.

Set the gain value in C1 to 19 (see step 1).
Use the step response plot with the rise time and peak response characteristics selected, and adjust the derivative gain C2 to meet the given specs for the rise time and the percentage overshoot. The value of C2 is the feedback gain for the servo angle rate, i.e., (Kθ˙). Check your gain values with the TA.
Link Controller Design:
Using Bryson’s rule (Eq. 12-15) calculate Q and R matrices, based on the following suggested maximum values of state and control excursions:
θmax,initial=0.05rad,αmax=0.1rad, θ˙max=1rad/s,α˙max=0.5rad/s Vmax=1V Check if Q≥0 and R>0 (by finding eigenvalues of the matrix).
Using the
lqrcommand in MATLAB, calculate the optimal feedback gain vector K. Thelqrcommand solves the Algebraic Riccati equation which is required to determine the gain vector K is
>> [K,S,E] = lqr(A,B,Q,R);
where K is the gain matrix, S is the solution to the Riccati equation and E are closed loop system poles. Check your gain matrix K with the TA.
Check if the gain associated with servo angle (θ) feedback matches with its selected value in the servo controller design, i.e., Kθ = K(1,1) = 19. If not, adjust the weight qθ (increase the weight to increase the gain and decrease the weight to decrease the gain) while keeping the rest of the weights same. Repeat the lqr command till Kθ = K(1,1) = 19. Check your gain matrix K with the TA.
Simulation Evaluation:
Using Figure 1 as a guide, develop a Simulink model of the system. Note: SIMULINK references the current MATLAB workspace when setting variables. Use the variable names for the system matrices A and B and the control gain matrix K from your MATLAB script file for the LQR design. Make sure to include servo position command input, saturation blocks, and appropriate outputs. Use scopes and To Workspace blocks so that reference, output, and response signals can be tracked. (Make sure to maintain consistency between deg and rad in SIMULINK)
Using the controller gains found in step 3 of Link Controller Design, simulate the closed loop system for a step servo position command of 30°over a 10s duration.
Record (and plot for lab report) the servo angle (θ), link angle (α) and voltage input Vm.
Using the controller gains found in step 6 of Servo Controller Design, simulate the closed loop system for a step servo position command of 30°over a 10s duration.
This is easily done by selecting the gain matrix K used in your Simulink model as Kθ and Kθ˙ values from step 6 of Servo Controller Design and Kα=0, and Kα˙=0. Check your plots with the TA.
Record (and plot for lab report) the servo angle (θ), link angle (α) and voltage input Vm
C. Controller Implementation and Evaluation
In this experiment, the servo position is controlled while minimizing the link deflection using the Link Controller found. Measurements will then be taken to ensure that the specifications are satisfied. Also, we will implement the Servo Controller found for comparison.
Warning: In closed loop experiments, the link may swing around rather quickly. Stay clear of it during closed loop experiments.
Experiment
Turn the amplifier power on.
Download the q_flex.zip and open the Simulink file q_flex for controller implementation. This is the block diagram for this part of the experiment. Make sure you have K gain variable in the MATLAB workspace. Note: The Smooth Signal Generator block generates a 0.33 Hz square wave (with amplitude of 1) that is passed through a Rate Limiter block to smooth the signal (Rising slew rate of 100 and falling slew rate of -100). The Amplitude (deg) gain block is used to change the desired servo position command. The state-feedback gain K is set in the Link Control gain block and is read from the MATLAB workspace.

To build the model, click down arrow on Monitor & Tune under Hardware tab and then Build for monitoring
. This generates the controller code. Align the flexible link along the 0 mark on the servo stand.
Double click on the scopes and open them.
Ensure that the manual switch is connected to the full state feedback.
Click Connect
button under Monitor & Tune and then click Start 
A periodic square wave is given as commanded link rotation to the servo motor, causing the link to move left and right alternately for 10 seconds.
Copy the response data to your group folder. The response data is saved in variables data_theta, data_alpha, and data_vm. DO NOT DELETE or SAVE THE SIMULINK MODEL.
Connect the manual switch to the partial state feedback and repeat steps 4-9 again using the gains obtained from your Servo Controller Design. Make sure your files name is different from full state feedback.
Turn the power off.
Results & Questions for Report
Control Design
Results
Include the A and B matrices.
Include the results from the Servo Controller Design procedure (steps 1 through 6).
Include the results from the Link Controller Design procedure (steps 1 through 3).
Questions
Estimate the bandwidth for your Link and Servo controllers. Hint: Use 'bandwidth(sysclosed)' command in MATLAB with link rotation (θ) as the output.
>> sysclosed = ss((A-B*K), B, [1 0 0 0], 0);
>> bw = bandwidth(sysclosed)
>> bode(sysclosed)
The bode() function produces closed loop system frequency response plot. Include Bode plots of the closed loop system and list the bandwidth of the system with Link and Servo controllers.
Estimate the stability margins (gain and phase margins) of your Link and Servo controllers. Hint: Use 'margin(sysopen)' command in MATLAB where 'sysopen' is the state space model of the open loop system with the controller.
>> sysopen = ss(A,B,K,0)
>> margin(sysopen)
We get bode plot of the open loop system with the controller with margins listed on the plots. Include the Bode plots for the Link and Servo controllers.
Controller Implementation
Results
Run the Simulink that you built in control design with the same command input used in the experiment. Note: Average the first few seconds of the experimental data to obtain initial conditions for your state-space block in Simulink.
Plots of servo angle, link deflection angle, and input voltage vs time for Link Controller and Servo Controller. On the same plot, show the experimental results and simulation results with the Link Controller and the Servo Controller. Clearly label your plots.
Compare the experimental results using the two controllers and explain the differences.
Compare the experimental results with the simulation results individually for each controller and explain the differences.
Questions
Explain why the link deflection angle goes opposite to servo rotation initially.
Explain the impact of reducing the control weight R on the gain matrix K.
Last updated
Was this helpful?