Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Industries Academia Support User Community Company

 

Systematic Controller Design and Rapid Prototyping

By: Jacob Apkarian, PhD Quanser Consulting Inc.
Send mail to Jacob Apkarian c/o Rick Drohan

Abstract

This article describes a systematic approach to computer-aided design and rapid prototyping of digital feedback controllers. The method described uses a 3 DOF model helicopter as an example. The article outlines each stage of the design. The first stage involves the derivation of the nonlinear differential equations via Lagrangian dynamics using the Symbolic Math Toolbox. A linear model is then derived, and an open loop Simulink® block of the system is implemented. An LQR controller is developed using the Control System Toolbox, and the performance is evaluated via Simulink. The controller is then implemented in real-time using WinCon™, and the performance of the closed-loop system is compared with that of the actual system.

You can download the M-files and Simulink models containing the parameters and control designs for this article. These files were generated using MATLAB 5.2, Simulink 2.2, and version 4.1 of the Control System Toolbox.

Introduction

The development of the fast PC, new design software, and the affiliated Internet technology has streamlined the design cycles in control system design and implementation. This article describes the various tools that are now readily available to take you from concept to implementation within a few hours. The example discussed is the 3 DOF helicopter experiment, shown in figure 1.

Figure 1: 3 DOF Helicopter Experiment

The 3D helicopter consists of a base upon which a long arm is mounted. The arm carries the "helicopter body" on one end and a counterweight on the other. The arm can tilt about an "elevation" axis as well as swivel about a vertical (travel) axis. Quadrature optical encoders mounted on these axes allow for measuring the elevation and travel of the arm. The helicopter body is mounted at the end of the arm. The helicopter body is free to pitch about the "pitch" axis. The pitch angle is measured via a third encoder. Two motors with propellers mounted on the helicopter body can generate a force proportional to the voltage applied to the motors. The force generated by the propellers causes the helicopter body to lift off the ground. The purpose of the counterweight is to reduce the power requirements on the motors. The counterweight is adjusted so that the effective mass of the body is approximately 70 gm. All electrical signals to and from the arm are transmitted via a slip-ring with eight contacts, eliminating the possibility of tangled wires and reducing the amount of friction and loading about the moving axes.

The purpose of the experiment is to design a controller to maneuver the helicopter body to a desired elevation and a desired travel position. We will design and evaluate the control system using readily available CAD tools. These tools are briefly described in the table below.

Step Function Tool Input File Output File
1 Nonlinear mathematical model derivation and linearization Symbolic Math Toolbox heli3d.m heli3d_m.m
2 Control system design MATLAB & Control System Toolbox heli3d_m.m & heli3d_d.m workspace
3 Simulation, iterate with step 2 Simulink heli3d_s.mdl & workspace various MAT-files
4 Real-Time controller code generation for Windows and Internet Simulink/RTW/WinCon heli3dp.mdl heli3dp.wcl
5 Running the controller, testing, and real-time tuning, or iterate with step 2 WinCon heli3dp.wcl
or
heli3dp.wcp
various MAT-files
6 Build and run stand-alone controller and control panel WinCon heli3p_r.wcl collect data as needed

STEP 1: Deriving the mathematical model. Tool : Symbolic Math Toolbox

We will be using the Symbolic Math Toolbox because the differential equations of the system are highly nonlinear and coupled and are very difficult to solve by hand. The process described here is implemented in a Symbolic Math Toolbox script file heli3d.m.

Figure 2: Transformation Frames for 3 DOF Helicopter

Transformation matrices and dynamics

We start by defining coordinate transformation frames embedded in the moving bodies of the system. These coordinate frames are shown in figure 2. The transformation matrices between frames are as follows:

  • From base frame to travel frame. These coordinate frames have the same origin.

  • From travel frame to helicopter body.

  • From travel frame to counterweight.

  • From helicopter body to front motor.

  • From helicopter body to back motor

We then obtain the transformations from the base to the moving bodies via the following equations:

We use these equations to obtain the potential energies of these bodies as:

and the kinetic energy of each body as:

The total kinetic and potential energies are obtained and the Lagrangian is computed:

Once we have dervived the Lagrangians for the three axes, we write the Lagrange equations for each axis.


Generalized force about elevation axis

Each motor exerts a force normal to the body, given by F = KmV, where Km is the force constant for the motor/propeller pair. If the body is horizontal, the two forces result in a torque about the elevation axis equal to LaKm(Vf+Vb), resulting in the generalized Lagrange equation:



Generalized force about travel axis

The system will rotate abou the travel axis only if the body is pitched and the body is hovering. The force resulting from the motors results in a torque about the travel axis given as (Vf + Vb) Km La sin(pitch(t)),

Generalized force about pitch axis

The body pitches because of the difference in the voltage applied to the motors. This results in a difference in the two forces generated by the two motors. This difference results in a torque about the pitch axis given by:

The above equations result in a set of nonlinear differential equations of the form:

which are solved to obtain the accelerations about the three axes as:



where we are defining

Linearization

The nonlinear equations derived using the Lagrangians are now linearized about the quiescient operating point.

To derive the quiescent voltage, we assume that the body is hovering. The force generated by the motors and the body weight should exactly counterbalance the counterweight. This relationship can be written as:

If both motors are exerting equal forces (Vf = Vb), and both motors have the same mass (mf = mb), then the body does not pitch and we obtain:

Linearizing the acceleration equations about the quiescent point [Q], we obtain a set of equations of the form:



The elements of the A & B matrices are derived and written in a MATLAB script file, heli3d_m.m, automatically from Symbolic Math Toolbox.

STEP 2 : Designing the control system. Tools : MATLAB and the Control System Toolbox

Following the development of the linear model, we write a MATLAB script file, heli3d.m, which reads in the output file of the Symbolic Math Toolbox program, heli3d_m.m, and calculates the values of the A and B matrices for a given set of system parameters. These parameters are as follows:

In this design, we are using a Linear Quadratic Regulator (LQR) controller. After several iterations with the Simulink model, heli3d_s.mdl, we select a set of Q and R matrices that result in the following gain matrix:

Examining the feedback gains obtained from the LQR design, we note the following feature: The second row gains have the exact same magnitudes as the first row!

The state feedback equation is:





Further examination reveals that the sum of the two rows results in:

Which can be re-written as

which is the Proportional+Integral+Derivative (PID) controller about the elevation axis. That means that the gains we obtain from LQR design can be used in an elevation control loop as follows:

with

Examining the difference between the gains, we note that the results, the feedback loop can be decomposed into two loops: one for pitch and one for travel.

The above equation can be re-written as:

which is a PD loop to command the pitch to track the desired pitch pc. The desired pitch is defined as:

which is another PID loop that controls the travel position.

We now have the following control equations:

Solving for Vf and Vb we obtain:

STEP 3 : Simulating the linear system. Tool : Simulink


Figure 3: Simulink Model of 3 DOF Helicopter and Controller (heli3ds.mdl)

The linear system is simulated using a Simulink model, heli3d_s.mdl. It consists of the following components:

Open loop model

This model simulates system dynamics and measurement. It reduces the A and B matrices to a set of integrators and gains. The elevation integrator is limited to positive values in order to simulate the helicopter landing on the ground. Augmenting the motor voltages by the constant -Vq simulates gravitational bias. Multiplying by a calibration constant that converts radians to degrees simulates encoder measurements. A quantizer set to the resolution of the encoders simulates the quantization effect. Because high-pass filters function as differentiators at frequencies below the passband, they are used to differentiate the three displacement states.


Figure 4: Simulink Model of Open Loop Helicopter Model (heli3ds.mdl) Command generation block

The command generation block generates the commands to the elevation and travel axes to evaluate the response of the system. The elevation is commanded to rise to 50 degrees at various rates and then return to zero. The travel is commanded to travel to +30 degrees and then return to zero.


Figure 5: Command Generation Block (heli3ds.mdl)

Controller

The implementation of the controller is shown in figure 5. It consists of three loops, as described in the control system design section. The pitch command is limited to +/- 90 degrees.

Figure 6: Simulink Feedback Controller Block (heli3ds.mdl)

STEP 4 : Generating and implementing code. Tools: Real-Time Workshop and WinCon 3.0

The controller is implemented using WinCon. WinCon is a real-time Windows 95 application that runs code generated using Real-Time Workshop® and Simulink to achieve digital real-time control on a PC equipped with a data acquisition and control board (DACB). WinCon 3.0 consists of a client and a server, referred to as WinCon W95Client and WinCon W95Server. Each server can communicate with several clients. A PC can have a client as well as a server operating on it at the same time.

WinCon W95Server

This is the software component that does the following:

  • Converts Simulink diagram to PC executable real-time code
  • Compiles and links the code using Microsoft Visual C++
  • Downloads the executable code to run on the WinCon client
  • Starts and stops the WinCon client
  • Maintains TCP/IP communications with the WinCon client
  • Maintains communications with Simulink to perform real-time changes in the WinCon client parameters
  • Plots the data streamed from a desired WinCon client in real-time
  • Saves data to a disk

WinCon W95Client

This is the real-time software component that runs the code generated from the Simulink diagram at the specified sampling rate. It does the following:

  • Receives controller code from the server
  • Runs the controller code in real-time
  • Maintains communications with a WinCon server and updates parameters in real time
  • Streams real-time data to the WinCon server requesting it

Configuration options

  • One PC - no network

    Figure 7: WinCon Single PC Configuration

    The simplest configuration is a single PC equipped with the appropriate software and hardware. In this configuration, the PC runs both the server and the client and can be used to perform real-time controlling, tuning, and monitoring in the same location.

  • Two PCs - direct connection or intranet

    This configuration consists of two PCs, one running the server and another running the client. In this case, the two PCs must be connected via an Ethernet connection. The advantage of this configuration is that the client runs on a PC that is usually not running any software other than Windows 95 and WinCon W95Client. Since the PC is not burdened with other tasks, you can get the fastest possible sampling rates.

  • Two PCs - Internet connection

    Figure 8: WinCon Internet Configuration

    This configuration consists of two PCs communicating via the Internet. Each PC is connected to a server and can each be located anywhere in the world.

  • Multiple PCs - Internet or intranet connection

    In this configuration, one server and many clients run as nodes on the Internet. The server can download code to several clients. It can maintain communications with all clients simultaneously.

Implementation

In order to run the controller in real-time, we simply replace the simulation block in the simulation with the 3D Heli block in figure 9. The difference here is that the voltages coming back from the controller are connected to two analog output blocks. The analog output blocks will output the desired voltage to the MultiQ analog outputs channels 0 and 1. The three variable are not simulated but measured directly using the MultiQ Encoder input blocks.

Figure 9: Simulink Controller of 3 DOF Helicopter (heli3dp.mdl)

We now compile the diagram using Real-Time Workshop and the Visual C++ compiler and generate a WinCon library file which can be loaded into the WinCon Client.

Figure 10: Encoder Measurement and Output Voltage Blocks to Interface with Actual Systems (heli3dp.mdl)

STEP 5 : Results. Tools: WinCon

We implement the desging using the two PCs - Internet connection configuration. In our implementation, the server computer is located in the engineer's office, while the client computer and the helicopter are located in the laboratory one floor above. Note that the operator of the server cannot even see the helicopter when running the controller and relies solely on the server real-time plotting capabilities to monitor the performance of the system. We then write a WinCon script (script_r.m) which runs the controller and waits for termination. To stop the run after 30 seconds, we place a limited duration run block in the controller. At the end of the run, data is collected and saved into a MATLAB MAT-file. Another script files loads the data and plots the results superimposing them on the simulation results. The plots in figure 11 show the commanded values (red), the simulation results (blue), and the actual data from the helicopter (green).

Figure 11: Simulation vs Actual Results for Pitch Limited to 20 Degrees

The simulation results and the actual results match quite closely. This indicates that the linear model is a good representation of the system when it is operating close to the quiescient conditions. Note, however, that the pitch command is limited to 20 degrees and the travel rate is limited command to 20 deg/sec, thus operating close to the quiescent region. What happens if we let the helicopter pitch to 45 degrees and command the system to travel at a rate of 100 deg/sec? This question can easily be answered by changing the associated parameters in the relevant block and running the simulation and the real-time controller again. The results are shown in figure 12.

Note that the simulation results and the actual results are not that close anymore. Specifically, note that the actual elevation drops slightly whenever the helicopter pitches to 45 degrees. This effect does not occur in the simulation. This is because the simulation does not take into account the fact that the effective thrust that causes elevation is reduced when the helicopter pitches.

Figure 12: Simulation vs Actual Results for Pitch Limited to 45 Degrees

Conclusion

This article described a systematic approach to computer-aided design and rapid prototyping of digital feedback controllers using a 3 DOF model helicopter as an example. With the various software available, designers can quickly develop nonlinear and linear models using Symbolic Math Toolbox and design controllers using MATLAB. Nonlinear simulations are implemented using Simulink, and real-time controllers are implemented using Real-Time Workshop and WinCon. The scripting capabilities of WinCon allow for rapid automated design/simulation/prototyping cycles. The Internet capabilities of WinCon further facilitate the remote control and monitoring capabilities, enabling the user to perform designs remotely.

Contact sales
E-mail this page
Print this page
Subscribe to newsletters