image thumbnail

Rotary Flexible Link System Identification and LQR Design

version 1.1.0 (866 KB) by Quanser
System identification and LQR control design of the Quanser Rotary Flexible Link.


Updated 15 Dec 2021

View License

In this post, we show how to identify the state-space model of a flexible link system and design a state-feedback system to control the servo position while minimizing the link deflection.
The Quanser Rotary Flexible Link, pictured below, is a two-degree of freedom system with an actuated rotary servo and a flexible link. It emulates various real-world applications such as lightweight robot manipulators (e.g., in space applications) and cantilever beams.
The rotary servo base angle is measured using an incremental encoder, q, and the deflection of the flexible link, relative to the servo, is measured using a strain gage, denoted by α.
The objective is to design a controller that will:
  1. Control the position of the servo to a desired angle, and
  2. Minimize the deflection of the flexible link (as the servo changes positions).
The MathWorks System Identification Toolbox is used to identify the state-space model of the system. The identified model is then used to design a Linear Quadratic Regular (LQR) based state-feedback controller using the Control Systems Toolbox. The closed-loop response is tested on both the QLabs Virtual Rotary Flexible Link and the Rotary Flexible Link hardware.
Before You Run this Example
In addition to the required MathWorks products, in order to perform the system identification this example requires the QUARC Real-Time Control Software and the Quanser Rotary Flexible Link hardware. If you don’t have the QUARC software, you can sign up for free trial. If you don't have the hardware, then previously measured data can be loaded.
The control can be simulated in Simulink. It can also be ran the Rotary Flexible Link hardware or the Quanser QLabs Virtual Rotary Flexible Link software, which is the digital twin on the physical the system. If you don’t have QLabs, you can sign up for a free trial.
How Does it Work?

System Identification on the Quanser Rotary Flexible Link Hardware

The following Simulink model is used with the QUARC Real-Time Control Software to apply a square wave voltage to the servo motor and measure the response of the servo angle and the flexible link. The HIL Write Analog block applies a voltage to the DC motor and the HIL Read Timebase block measures the encoder and the strain gage through the Quanser Q2-USB data acquisition (DAQ) device.
The QUARC Bias Removal block removes any initial offset in the strain gage measurement. The voltage input, servo angle, and flexible link angle are logged and saved as MATLAB variables. The measured open-loop response is shown below.
The state-space model is identified using the System Identification Toolbox command ssest. The identified model is validated against the measured results using the compare command.
MeasuredData = iddata([theta,alpha],u,0.002);
[FlexlinkSS, IC] = ssest(MeasuredData,4);
As shown by the results in the plot generated by the compare command, the identified state-space model is quite accurate.

State-Feedback Control

The identified model is then used to design LQR state-feedback controller. The control can be ran simulated, ran on the Virtual
How to Run the Examples
Go through the Rotary_Flexible_Link_Sys_ID.mlx Live Script attached. It gives you different options to run Simulink models on the hardware, on the QLabs virtual twin, or using standard Simulink as well as load previously measured data from MAT files (if you don’t have the hardware or the virtual twin).

Simulating the LQR Control

The following Simulink model is used to simulate the closed-loop system. The Simulink State-Space Model block includes the identified model.

LQR Control on the Quanser Virtual Rotary Flexible Link

The LQR controller can be ran on the QLabs Virtual Rotary Flexible Link. The virtual twin of the flexible link system includes a more representative model of the hardware as opposed to the standard linear simulation used previously.
The first 3 cycles shown in the sample response below is when partial state-feedback control is used – where the Manual Switch in the Simulink model above is set to the downward position. In this mode, only the states of the servo are used, i.e., effectively only doing servo position control. The last 3 cycles of the response are with the full-state feedback control that takes into account the deflection of the beam and tries to minimize it. In full-state feedback mode, the oscillations in the flexible link when the servo changes position are dampened.

LQR Control on the Quanser Rotary Flexible Link Hardware

The LQR state-feedback controller is ran on the Quanser Rotary Servo hardware using the QUARC Real-Time Control Software with the following Simulink model.
A sample closed-loop response when running the controller on the hardware is shown below.
Similarly, to the virtual twin, the first 3 cycles are when partial-state feedback control is used, and the last 3 cycles is full-state feedback. Compared to the virtual twin response, there is more noise in the hardware but the effectiveness of the control is similar.

Cite As

Quanser (2022). Rotary Flexible Link System Identification and LQR Design (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2021a
Compatible with R2021a and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!