The Development of A Hardware in The Loop Simulation System For UAV Autopilot Design Using Labview
The Development of A Hardware in The Loop Simulation System For UAV Autopilot Design Using Labview
This chapter describes a continuing research on design and verification of the autopilot system
for an unmanned aerial vehicle (UAV) through hardware-in-the-loop (HIL) simulation. UAVs
have the characteristics of small volume, light weight, low cost in manufacture, high agility
and high maneuverability without the restriction of human body physical loading. Equipped
with the on-board autopilot system an UAV is capable of performing out-of-sight missions
that inspires scientists and engineers with a lot of innovative applications. Not only in the
military but also in the civil, the applications of UAVs are in full bloom. Apparently one of the
key challenge of UAV research and development is its autopilot system design.
For the purpose of designing an autopilot, the technology of hardware-in-the-loop simulation
plays an important role. The concept of HIL simulation is that a stand-alone personal
computer is used to simulate the behavior of the plant, several data-acquisition devices are
exploited to generate the real signals, and the prototype controller can be tested in real-time
and in the presence of real hardware. HIL simulation presents a new challenge of control
engineering developers as the correctness of a real-time model not only depends upon the
numerical computation, but the timelines with which the simulation model interacts with
external control equipment that is the major difference between HIL simulation and numerical
simulation. Due to the useful feature, HIL simulation is applicable to solve many problems in
engineering and sciences effectively (Shetty & Kolk, 1997; Ledin, 2001).
HIL simulation provides an effective technique for design and test of autopilot systems.
Using HIL simulation the hardware and software at subsystem level perform the actual
input/output signals and run at real time so that the test target (e.g. prototype controller) is
working as if in real process. This provides the ability to thoroughly test subsystems under
different working loads and conditions; therefore, engineers can correct and improve their
original designs early in the development process. The advantages of HIL simulation are
reducing the risk in test and shortening the development time. Especially HIL simulation is
suitable for critical or hazardous applications.
(Cosic et al., 1999) used TMS320C40 DSP to set up a HIL simulation platform for a semiautomatic guided missile system. (Carrijo et al., 2002) applied HIL simulation to test the onboard computer on a satellite launcher vehicle for motion and attitude control. (Sun et al.,
2006; Sun et al., 2008a; Sun et al., 2009; Sun et al., 2010) developed the HIL simulation system
to evaluate the performance of UAV autopilot that was employed different control laws.
110
Some valuable applications in traffic control (Bullock et al., 2004) and UAV design (Cole et
al., 2006; Salman et al., 2006) using HIL simulation can be found.
The hardware arrangement of HIL simulation includes a personal computer used to
simulate the behavior of an UAV plant, several plug-in data-acquisition (DAQ) devices used
to acquire/generate the specific real input/output signals, and the embedded control
system used to execute the control laws and send control signals to real hardware.
The software development environment for HIL simulation in this work is LabVIEW.
LabVIEW is a graphical programming language widely adopted throughout industry and
academia as a standard for data acquisition and instrument control software. LabVIEW
provides an intuitive graphical programming style to create programs in a pictorial form
called a block diagram that allows users to focus on flow of data within applications and
makes programming easy and efficiency. Additionally, LabVIEW can command plug-in
DAQ devices to acquire or generate analog/digital signals. In combination of LabVIEW and
DAQ devices, a PC-based or embedded control system can communicate with the outside
real world, e.g., take measurements, talk to an instrument, send data to another subsystem.
These features are very helpful in building a HIL simulation system for UAV autopilot
design. As a matter of fact, LabVIEW is not the only software development environment for
HIL simulation, but based on the enumerated advantages it is certainly a nice choice.
In this chapter we are going to apply different control methods to accomplish the design of
UAV autopilot, and compare their results in HIL simulations using LabVIEW. The chapter is
organized as follows. Section 2 describes the dynamic model of an UAV. Section 3 outlines
the HIL simulation system architecture and introduces hardware and software development
environment LabVIEW. Section 4 focuses on stability augmentation system design. Section 5
focuses on autopilot system design including pitch attitude hold mode, velocity hold mode,
roll attitude hold mode and heading angle hold mode. Section 6 concludes this chapter.
111
The dynamics of an aircraft obey the equations of motion derived by Newtons second law.
The forces and moments resulting from lift and drag, the control surface, the propulsion
system, and gravity govern the aircraft. A body-fixed coordinate system shown in Fig. 2 that
is fixed to center of mass and rotating with the aircraft is used to express these forces and
moments. The rigid body equations of motion in body-fixed coordinates can be derived as:
(Bryson, 1994; Cook, 2007)
m(U RV + QW ) = X mg sin + T cos
m(V + RU PW ) = Y + mg sin cos
(1)
I xx P ( I yy I zz )QR I xz ( R + QP ) = L
I yyQ ( I zz I xx )PR + I xz ( P 2 R 2 ) = M
(2)
I zz R ( I xx I yy )PQ + I xz (QR P ) = N
where
m
g
Iii
U, V, W
P, Q, R
X, Y, Z
L, M, N
T
,
Yp
Lp
Np
1
Yp
Lp
Np
( u0 Yr ) g v 0
0 p L a
Lr
+
0 r N a
Nr
0
0 0
Y r
L r a
N r r
0
(3)
- ( u0 - Yr ) g v 0
0 p La
Lr
+
0 r N a
Nr
0
0 j 0
Yr
Lr a
N r r
0
(4)
112
where
u, v, w
p, q, r
e
th
= throttle setting,
r :rudder
e :elevator
YB
a :aileron
M , q,
v O
L, p,
VT
: Angle of Attack
ZW
+
N , r,
X B , YB , Z B : body-axis coordinates
X W , YW , ZW : wind-axis coordinates
XW
+ XB
VT : true speed
ZB
113
Xu
Xw
X e
Xth
Zu
Zw
Ze
Zth
Mu
-6.114
0.789
-0.273
2.936
8.952
-9.220
3.919
143.24
1.275
Mw
Mq
Me
Mth
Yv
Yp
Yr
Yr
Lv
-1.291
Lp
-1.366
-64.192
Lr
-0.374
-5.113
0.764
-1.264
-2.136
Lr
-1.699
La
Nv
Np
Nr
N a
N r
-2.656
-5.414
0.967
5.974
0.584
1.250
1.307
-0.191
-4.969
0
1
0 0
0
2.9361
143.24 e
-64.192 th
(5)
1.2636
5.9744 a
4.9689 r
(6)
where the maximum deflection angles of elevator, aileron, and rudder are 15, 6,
and 10.
114
Real-Time Simulation
Plant
Servo
Prototype
Controller
Fig. 3. The concept of HIL simulation
115
116
-(s)
1.699(s + 4.7308)( s + 13.7827)
=
e (s) (s + 0.0106)( s + 8.854)(s + 3.917 j 2.4488)
(7)
The open-loop system has two real poles at 0.0106 , 8.854 , and a pair of stable complex
poles at 3.917 j2.4488 . The corresponding damping ratios and natural frequencies are
given in Table 2.
Poles
-0.0106
-3.917+j2.4488
-3.917-j2.4488
-8.854
Natural frequency
0.0106
4.6195
4.6195
8.8540
Damping ratio
1
0.8479
0.8479
1
Table 2. The natural frequency and damping ratio for open-loop poles
From the step response as shown in Fig. 5, it is obviously that the settling time is too long,
approximately 300 sec. As a result, the maneuverability is very poor. It is necessary to
design a SAS to enhance the handling quality. The block diagram for pitch-angle to elevator
feedback of SAS is shown in Fig. 6. The elevator deflection is produced in proportion to the
pitch angle and adding it to the pilots control input as:
e = e_pilot + K
117
(8)
where e_pilot is that part of the elevator deflection created by the pilot. The gain K is the
design parameter.
118
The root locus technique permits the designer to view the trajectories of the close-loop
system poles as the design parameter (feedback gain K) is varied. It is very convenient to
determine the value of K in SAS by applying the root locus technique. The root locus plot
constructed by using MATLAB for the pitch-attitude-to-elevator transfer function, Eq. (7), is
shown in Fig. 7.
Natural frequency
-2.5306
3.7915
3.7915
9.1904
Damping ratio
1
0.6564
0.6564
1
Table 3. The natural frequency and damping ratio for closed-loop poles
The dc gain (steady-state gain) of closed-loop system is -0.3313. It indicates that at steady
state the ratio of pitch angle to pilots control input is approximately one-third:
( )
1
e_pilot ( ) 3
(9)
In Fig. 8 the transient response shows a significant improvement that the settling time is
greatly reduced to 1.2 sec by employing SAS. At this stage, the performance of SAS is verified
by computer simulation that the desired handling quality for pilot command is achieved.
119
(10)
120
The signal flow diagram of HILS system is shown in Fig. 9. The LabVIEW virtual
instruments of the controller, plant, and host PC used to perform HILS experiment are
presented in Figs. 10-14. The sampling rate is 50 Hz.
121
122
123
From the HIL simulation results of PIL experiment in Fig. 16-17, pilot control using SAS
demonstrates an excellent handling performance than that without using SAS. The effect of
SAS on improving the handling qualities of UAV is confirmed.
124
5. Autopilot system
The function of stability augmentation system is to improve the flying qualities of an
airplane for pilot manual control. To lower pilot workload, particularly on long-range flights
or out-of-sight flights of UAV, most airplanes or UAVs are equipped with automatic flight
control systems or autopilots. The basic autopilot modes include pitch attitude hold mode,
airspeed hold mode, bank angle (roll attitude) hold mode and heading angle hold mode.
Normally pitch attitude is controlled by the elevator, airspeed is controlled by the engine
throttle, roll attitude is controlled by the aileron, and heading is controlled by the rudder.
Thus there are four feedback loops to achieve four different autopilot modes. Fig. 18 shows
the block diagram of pitch attitude hold mode in HILS experiment.
PXI System
PID
PC System
e
UAV
Fig. 18. The block diagram of pitch attitude control for autopilot in HILS experiment
5.1 PID controller design
The proportional-integral-derivative (PID) controllers are frequently used in practical
control systems owing to their simple structures and quite clear physical senses. Usually the
PID controller is described by the transfer function:
K PID (s) = K p +
Ki
+ Kds
s
(11)
where Kp, Ki, and Kd are gains to be determined to meet design requirements. Specifically,
the PID controller can be expressed by the form in time domain as:
1
u(t) = K p e(t) +
T
i
0 e()d + Td
de(t)
dt
(12)
where u is the controller output, e is the error between desired and actual output, Ti is
integral time, and Td is derivative time. Three important characteristics of PID controller are
described as follows: it provides feedback; it eliminates steady-state error through integral
action; it improves transient response by anticipating the future through derivative action.
In order to meet the design specifications on transient and steady-state response, PID
control is an ideal choice for autopilot design.
The PID controllers are designed by two phases. At first, the coarse PID gains are obtained
according to the well-known Ziegler Nichols tuning rules that provide an acceptable closed-
125
loop response. Next, let the coarse PID gains be the initial guess, the Nonlinear Control System
Toolset in MATLAB/Simulink is applied to optimally determine the fine PID gains to meet
time domain specifications such as rise time, overshoot, settling time, steady state error, and
actuator constrain. The resulting PID gains in four feedback loops of autopilot are listed in
Table 4.
Kp
Ti
Td
-11.99
0.001118
0.005657
Velocity Loop
0.07506
0.03649
0.004805
0.2571
0.003650
0.01531
Heading Loop
-1.9058
0.07574
-0.04379
Table 4. The PID Gains in Four Feedback Control Loops of UAV Autopilot.
5.2 HIL simulation results
In this section the prototype PID controller for each mode of autopilot is implemented by
the PXI real-time control system, and the performance is explored in HIL simulation. The
hardware arrangement of HIL simulation system is shown in Fig. 19. Figs. 20 and 21
represent the LabVIEW front panel and block diagram of UAV plant.
PCI-6602
PCI-6703
Personal Computer
Plant
SCB-68
SCB-68
Embedded Real-Time Controller
Controller
Fig. 19. The Hardware Setup of HIL simulation for UAV autopilot
126
127
The following LabVIEW front panel and block diagram windows shown in Fig. 22 represent
the prototype PID controller in pitch attitude hold mode of autopilot. It is noticed that the
values of PID gains in front panel are from Table 4 where the integral time Ti and the
derivative time Td are in minute available for LabVIEW PID function.
Fig. 22. LabVIEW front panel and block diagram window of PID controller
1.6
Computer Simulation in CT model
HIL Real-time Simulation in DT model (T=30ms)
1.4
1.2
(deg)
1
0.8
0.6
0.4
0.2
0
10
Time (sec)
Fig. 23. The unit-step response of PID controller in pitch attitude hold mode
Figs. 23-26 show the closed loop unit-step time response of PID controllers in pitch attitude
hold mode, velocity hold mode, bank angle hold mode and heading angle hold mode for
128
UAV autopilot. Apparently, the results of HIL simulation and computer simulation are very
close to each other. Fig. 23 exhibits an underdamped response in pitch control with 4 sec.
settling time, 30% overshoot, and no steady-state error; Fig. 24 also exhibits an
underdamped response (a little increase in damping ratio) in velocity control with 6 sec.
settling time, 35% overshoot, and no steady-state error; Fig. 25 also exhibits an
underdamped response (a bigger time constant) in roll control with over 25 sec. settling
time, 5% overshoot, and still no steady-state error; Fig. 26 exhibits an overdamped response
in heading control with 14 sec. settling time, no overshoot, and no steady-state error. From
the results in HIL simulation, PID controllers demonstrate very good performance.
2
Computer Simulation in CT model
HIL Real-time Simulation in DT model (T=30ms)
1.8
1.6
1.4
u (m/s)
1.2
1
0.8
0.6
0.4
0.2
0
10
Time (sec)
Fig. 24. The unit-step response of PID controller in airspeed hold mode
1.4
Computer Simulation in CT model
HIL Real-time Simulation in DT model (T=30ms)
1.2
(deg)
0.8
0.6
0.4
0.2
10
20
30
40
50
Time (sec)
Fig. 25. The unit-step response of PID controller in bank angle hold mode
129
1.4
Computer Simulation in CT model
HIL Real-time Simulation in DT model (T=30ms)
1.2
(deg)
0.8
0.6
0.4
0.2
10
20
30
Time (sec)
Fig. 26. The unit-step response of PID controller in heading angle hold mode
5.3 HIL simulation system including a servo unit
In this subsection the HIL simulation system with servo unit is taken into consideration. The
servo unit is described in section 3.3. The HIL simulation system with servo unit is
composed of three major parts: a Pentium 4 desktop personal computer (PC) system, a
National Instrument (NI) real-time PXI system, and a servo unit. The hardware arrangement
is shown in Fig. 27.
Plant
PCI-6040
SCB-68
Servo unit
PCI-6703
SCB-68
PXI-8184 RT Controller
PXI-6259, PXI-6602
Fig. 27. The hardware arrangement of HIL simulation system with a servo unit
130
After receiving feedback signals by DAQ PXI-6259 from plant (PC system) that represent
UAV actual states, the real-time PXI system carries out the proportional-integral-derivative
(PID) algorithm, computes the control effort (control surface deflection angle and throttle
setting) for UAV flight control, and then generates pulse-width-modulation (PWM) signals
by DAQ PXI-6602 to control a real servo. Each servo unit consists of two Futuba-S3001
servos and two accurate potentiometers. The servo receives PWM signals from PXI system
and rotates to a specific angle. The resulting angle is measured by a potentiometer and fed
back to the plant through DAQ PCI-6040. Finally the PC system computes the dynamical
states of UAV based on the state-space model and outputs these analog signals to the PXI
system by DAQ PCI-6703. As a whole the PC system, PXI system, and servo unit constitute a
real-time closed-loop control system for UAV autopilot HIL simulation.
The HIL simulation results of PID controller for system including servo is denoted by the
solid line in Fig. 28. Apparently the performance becomes a little worse because the real
servo and potentiometer involved in HILS system result in so called unmodelled dynamics
that is not taken into consideration in controller design. This deterioration of controller
performance is revealed by HIL simulation not by numerical simulation. The PID controller
has to be tuned to obtain an acceptable performance. It clearly demonstrates that HIL
simulation is indispensable to controller design and verification.
1.6
Numerical simulation
HIL simulation without servo
HIL simulation with servo
1.4
1.2
(deg)
1
0.8
0.6
0.4
0.2
0
10
Time (s)
Fig. 28. The performance of PID controller for HIL simulation system including servo
6. Conclusion
With the growing importance of autonomous vehicles for industry, science, aerospace and
defense applications, engineers are encouraged to use HIL simulation methodology to
shorten development cycle, lower total cost and improve functional performance of the
vehicles. LabVIEW features an easy-to-use graphical programming environment and an
intuitive data flow programming style that makes the work of HIL simulation to be easier
and more efficiency. This chapter not only provides LabVIEW solutions to HIL simulation
131
but also presents a complete analysis, design and HILS verification of UAV stability
augmentation system and autopilot.
7. References
Bullock, D., Johnson, B., Wells, R. B., Kyte, M. & Li, Z. (2004). Hardware-in-the-Loop
Simulation. Transportation Research Part C: Emerging Technologies, Vol. 12, No. 1,
(February 2004), pp. 73-89, ISSN 0968-090X
Bryson, A. E., Jr. (1994). Control of Spacecraft and Aircraft, Princeton University Press, ISBN 0691-08782-2, Princeton, New Jersey, USA
Carrijo, D. S., Oliva, A. P. & W. de Castro Leite Filho (2002). Hardware-in-the-Loop
Simulation development. International Journal of Modeling and Simulation, Vol. 22,
No. 3, pp. 167-175, (July 2002), ISSN 0228-6203
Cole, D. T., Sukkarieh, S. & Goktogan, A. H. (2006). System Development and
Demonstration of a UAV Control Architecture for Information Gathering Missions.
Journal of Field Robotics , Vol. 26, No. 6-7, (June-July 2006), pp. 417-440, ISSN 15564967
Cook, M. V. (2007). Flight Dynamics Principles (2nd Ed.), Elsevier, ISBN 978-0-7506-6927-6,
Oxford, UK
Cosic, K., Kopriva, I., Kostic, T., Samic, M. & Volareic, M. (1999), Design and
Implementation of a Hardware-in-the-Loop Simulator for a Semi-Automatic
Guided Missile System . Simulation Practice and Theory, Vol. 7, No. 2, (April 1999),
pp. 107-123, ISSN 1569-190X
Kayton, M. & Fried, W. R. (Editors). (1969). Avionics Navigation Systems, John Wiley & Sons,
ISBN 471-46180-6, New York, USA
Larson, R. W. (2011). LabVIEW for Engineers, Prentice-Hall, ISBN-13 978-0-13-609429-6, New
Jersey, USA
Ledin, J. (2001). Simulation Engineering, CMP Books, ISBN 157-820-0806, Lawrence, USA
Nelson, R. C. (1998). Flight Stability and Automatic Control (2nd Ed.), McGraw-Hill, ISBN 0-07115838-3, Boston, Massachusetts, USA
Nise, N. S. (2008). Control Systems Engineering (5th Ed.), John Wiley & Sons, ISBN 978-0-47016997-1, New Jersey, USA
Roskam, J. (2007). Airplane Flight Dynamics and Automatic Flight Controls, Part I,
DARcorporation, ISBN-13 978-1-884885-17-4, Kansas, USA
Roskam, J. (2003). Airplane Flight Dynamics and Automatic Flight Controls, Part II,
DARcorporation, ISBN 1-884885-18-7, Kansas, USA
Salman, S. A., Puttige, V. R. & Anavatti, S. G. (2006). Real-Time Validation and Comparison
of Fuzzy Identification and State-Space Identification for a UAV Platform.
Proceedings of the 2006 IEEE International Conference on Control Applications, pp. 21382143, ISBN 0-7803-9797-5, Munich, Germany, October 4-6, 2006
Shetty, D. & Kolk, R. A. (1997). Mechatronics System Design, PWS Publishing Company, ISBN
053-495-2852, Boston, USA
Sun, Y. P., Wu, L. T. & Liang, Y. C. (2006). System Identification of Unmanned Air Vehicle
and Autopilot Verification via Hardware-in-the-Loop Real-time Simulation.
Proceedings of International Forum on Systems and Mechatronics, ISBN 986-688-904-1,
Tainan, Taiwan, December 6-8, 2006
132
Sun, Y. P., Chu, C. Y., & Liang, Y. C. (2008a). Using Virtual Instruments to Develop an
Actuator-Based Hardware-in-the-Loop Test-Bed for Autopilot of Unmanned Aerial
Vehicle. Proceedings of SPIE-Fourth International Symposium on Precision Mechanical
Measurements, Vol. 7130, Part I, pp. 71301J-1-6, ISBN 9780819473646, Anhui, China,
August 25-29, 2008
Sun, Y. P., Wu, L. T. & Liang, Y. C. (2008b). Stability Derivatives Estimation of Unmanned
Aerial Vehicle. Key Engineering Materials, Vol. 381-382, pp. 137-140, ISSN 1013-9826
Sun, Y. P., Tsai, C. H. & Liang, Y. C. (2009). Fuzzy Logic Control Design and Verification of
Unmanned Aerial Vehicle Autopilot via Hardware-in-the-Loop Simulation.
Proceedings of the 2009 International Symposium on Mechatronic and Biomedical
Engineering and Applications, pp. 156-164, ISBN 978-986-7339-508 , Kaohsiung,
Taiwan, November 5, 2009
Sun, Y. P., Tsai, C. H. & Liang, Y. C. (2010). Design and Implementation of a Stability
Augmentation System for an Unmanned Aerial Vehicle Using Hardware-in-theLoop Simulation. Proceedings of the 2010 International Symposium on Mechatronic and
Biomedical Engineering and Applications, pp. 183-193, ISBN 978-986-7339-62-1,
Kaohsiung, Taiwan, November 9, 2010
Travis, J. & Kring, J. (2007). LabVIEW for Everyone: Graphical Programming Made Easy and Fun
(3rd Ed.), Prentice Hall, ISBN 0-13-185672-3, New Jersey, USA