Chapter 3 Drone

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

CHAPTER 3

SYSTEM SIMULATION AND CONTROL DESIGN

In this chapter, the quadcopter model, which is formulated using physical system parameters and
dynamics equations, will be designed in Solid works 2018 and implemented in Matlab Simulink
environment by using SimMechanics Link utility which link Matlab Simulink with CAD
program. The Simulink model is used for open loop testing, verification and controller design.

3.1 SolidWorks

SolidWorks is computer aided engineering (CAE) and computer aided design (CAD) software
application with runs of Windows. The software has very advance designing capabilities in the
field do aerospace and robotics. It is one of the most widely used software by engineers from
various field which included, aerospace, robotics, mechanical engineering, civil engineering and
so on. To build the virtual simulation environment in MATLAB and the CAD model for
quadcopter for the controlling purposes, Solidworks 2018 was used for designing process. When
the model was finalized, it was then used with the control of quadcopter by integrating it with
MATLAB/Simulink. When the CAD model of the quadcopter is integrated into
MATLAB/Simulink it creates the complete control model for the quadcopter and all the
dynamics equations are derived automatically. Although, this a very useful technique to build
controls for a quadcopter, it sometimes gives error if the model is not correctly defined in Solid
works. There were a couple of instances when the CAD model was integrated with
MATLAB/Simulink it wrongly derived the motors and propeller controls. This was due the
definition was wrongly defined in the CAD model. Furthermore, the virtual environment was
also included with the CAD model rather than designing it separately again in MATLAB. To
start with, a CAD model was designed in SolidWorks for the quadcopter UAV having precise
physical parameters. This allowed us to extract information about the quadcopter dynamics and
control. It also helped us to understand how much power was required by the motor to rotate the
propeller, which gave us an idea of the battery needs to be used. The CAD modelling designing
of the quadcopter was done in SolidWorks. Figure 3-1 shows the complete model of the
quadcopter. Other components can be seen in Appendix B.
Figure 3-1: CAD model of quadcopter built in SolidWorks for virtual simulation environment

3.2 MATLAB& Simulink

This part of the project is based on simulation the quadcopter in virtual environment. To do this,
MATLAB Simulink were selected to design the control for the quadcopter having a virtual
simulation environment.

3.2.1 MATLAB

Matlab (Matrix Laboratory) is a multi-paradigm numerical computing environment and fourth-


generation programming language. A proprietary programming language developed by
MathWorks, MATLAB allows matrix manipulations, plotting of functions and data,
implementation of algorithms, creation of user interfaces, and interfacing with programs written
in other languages, including C, C++, Java, Fortran and Python. Although MATLAB is intended
primarily for numerical computing. An additional package, Simulink, adds graphical multi
domain simulation and model-based design for dynamic and embedded systems. The MATLAB
application is built around the MATLAB scripting language. Common usage of the MATLAB
application involves using the Command Window as an interactive mathematical shell or
executing text files containing MATLAB code.

3.2.2 SIMULINK

Simulink is developed by MathWorks, is a graphical programming environment for modelling,


simulating and analyzing multi-domain dynamic systems. Its primary interface is a graphical
block diagramming tool and a customizable set of block libraries.” It offers tight integration with
the rest of the MATLAB environment and can either drive MATLAB or be scripted from it.
Simulink is widely used in automatic control and digital signal processing for multi-domain
simulation and Model-Based Design. MathWorks and other third-party hardware and software
products can be used with Simulink. For example, state-flow extends Simulink with a design
environment for developing state machines and flow charts. MathWorks claims that, coupled
with another of their products, Simulink can automatically generate C source code for real-time
implementation of systems. As the efficiency and flexibility of the code improves, this is
becoming more widely adopted for production systems, in addition to being a tool for embedded
system design work because of its flexibility and capacity for quick iteration .
3.3 Construction of Simulation Model

The simulation model is built in stages, that is, at first solid, surface, or hybrid model is created
by CAD program(SolidWorks) . An assembly of elements can be used solely for simulation
studies because in such cases there exists an interaction between individual parts, which in turn
makes it possible to introduce the control system and perform motion analysis. Therefore, each
created simulation model is an assembly of many individual parts or sub-assemblies. For
instance, the sample CAD model presented in Figure 3-1 consists of: 3 assemblies and 62 parts,
but these assemblies include subsequent assemblies or parts, etc. Building of each part of
geometric model in SolidWorks, similar to the ones most currently used for this kind of
applications, begins with defining a 2D geometry that creates a solid or a surface after
completing one of numerous operations (e.g. extrusion or pocket). Then, based on expansion or
modification of the obtained element made by removing or adding material, the creation of parts
is continued. The majority of CAD systems offer normalized elements that can be used to build
assemblies. The product that is the result of the final assembly of components has a permanent
link to the individual part files, which means that changes made in one of the files are
automatically ascribed to the linked files, respectively. The product have its own geometry.
Geometrical models can be used not only for the construction of the simulation model, but in a
very simple way they can be utilized to carry out other types of analysis, such as dynamic
analysis. In this case, the calculation model which takes into account contact connections and
boundary conditions should be worked out.

The next stage of building the simulation model is the implementation of the CAD assembly
model in Matlab/Simulink environment (Fig.3- 2).

Fig.3-2. Implementation process of CAD model in Matlab/Simulink environment

For this purpose CAD software and Matlab/ Simulink, the SimMechanics Link utility has to be
installed and linked to the CAD program .

Converting the model into SimMechanics is very useful because;


 It simplifies the building up of dynamic system.
 It can integrate with other physical modeling libraries automatically.
 We don’t have to derive the equations for electronics system, equations of motion, etc.
 It creates the complete model for us very quickly and easily and we can optimize it where
needed which can also be done very easily.
The first step of implementation process is to use the SimMechanics Link exporter to create
Physical Modeling XML file that includes information about the mass and inertia of each part of
the assembly, definitions of constraints between parts, as well as a set of STL (stereo
lithographic) files for representing surface geometries of the assembly bodies. The second step is
import of the received files into the Matlab/Simulink program and generation of a SimMechanics
model. The SimMechanics model, obtained immediately after the implementation, includes a
block scheme (Fig. 3-3) and allows only visualizing mechanism or machine (Fig. 3-4), without a
possibility of carrying out simulation research. Only rarely it is optimal, and does require
modifications like removing unnecessary constraints between elements of the model or changing
their types

Fig. 3-3. A sample SimMechanics block diagram

Fig. 3-4. Visualization of a sample SimMechanics model


3.3.1 Motor Control Modeling:

The quadcopter achieve desired motion through controlling the rotors. The rotor is mainly a
Brush less DC motor (BLDC) and a propeller. The quadcopter motor has its own control system
through the electronic speed controller (ESC). The motor receives an input and is expected to
produce a certain output regardless of its control mechanism.

Figure 3-5: BLCD Motor Model for

3.3.2 Motor Mixer:

The purpose of motor mixer block is to determine the motors input and thus the rotation speed for
each motor according to which the required thrust and moments are generated achieving the desired
attitude and altitude.
Figure 3-6 : Simulink Model of a Motor Mixer

3.3.3 Open Loop Simulation:

This simulation method is used to verify that the system built in Simulink is working and
responding as expected. Generally it is the first step in verification.

Performing open loop Simulation leads to the following observations:

 Changing the thrust of each motor equally only changes the altitude of the quadcopter.
 Thus, hovering condition results when the total thrust is equal to the quadcopter weight.
Hovering condition can be expressed by the following equation:

 When the total thrust is equal to the quadcopter weight and two rotors of the same
diagonal rotate faster the other two rotors; only the yaw angle changes.
 When changing the roll and pitch angles; the system oscillates and gets unstable due to
nonlinearity and absence of the controller.

These observations comply with the mathematical model derived and thus first step in
verification is achieved.

3.3.4 Controller Design:

The quadcopter is under actuated system which has four control inputs and six DOF. While
quadcopter can move in vertical axes without changing irrelevant states, it needs to change
attitude when moving in x or y axes. The control system consists of two main loops; inner loop,
which corresponds to orientation control, and outer loop which corresponds to the position
control. The main inner loop consists of two cascaded loops as well; one loop for tracking the
angular rate and another loop for tracking the angle. The inner loop must be at least ten times
faster than the outer loop .Specific roll and pitch angles, which are calculated according to
desired (x, y) coordinates, are compared to the actual angles measured by inertial measurement
unit (IMU) of the system. In the outer loop, the actual position is compared to the desired
position and thus is calculated .The control input vector components as shown in equation serve
as inputs to the control system as shown in the Figure
Figure 3-7: Simplified Comprehensive System Control

3.3.5 Altitude Control:

The actual quadcopter altitude is measured using barometer sensor. This measured altitude is
then compared to the desired altitude. The error obtained is fed to the altitude controller to
generate U1 signal.

Figure 3-8 : Altitude Controller

From equation:

3.3.6 Attitude and Heading Control:

Once U1 is calculated by the outer loop, the inner loop commands should now be calculated.
Since the movement along x and y axes is controlled through roll and pitch angles. In real
applications, this is done via the radio control.
Figure 3-9 :Attitude and Heading Controller

Figure 3-10 :Simulink Model for Translating Position (x, y) to Pitch and Roll Angles

3.3.7 Simplified PID Controller

Generally this simplified scheme of controller generates signals depending on the error between
the actual and desired state. In this thesis, PID controller is selected to stabilize the quadcopter
because it is intuitive to tune and easy to implement in code with little processing power. PID
controller has three tunable gains; proportional gain Kp, integral gain KI and derivative gain KD.
It can be represented with the following transfer function:

The proportional term Kp is directly proportional to the error, increasing it will increase the rise
time, i.e. making the system response faster. The Integral term KI is proportional to the sum of
the error values accumulated over time; this error often represents a disturbance (wind, modeling
errors, etc.). Increasing KI will decrease steady state error of the feedback system, however, this
term introduces a pole at the origin of the S-plane which might make the system oscillate and
even go unstable. The derivative KD term is a multiple of the rate of change of the error. It is
used to reduce the overshoot and make the system response slower. KD acts as a damper which
allows the use of larger KP value and results in improving steady state performance .Since KD is
acting on the derivative of the error, and not the error itself, it is always used in combination with
Kp and KI.

Figure 3-11 :Simplified PID Controller

There are various methods to tune PID controller and determine the best values of control gains.
In this thesis, the values are first determined for simulation purposes and then verified on the
actual system.

3.3.8 Overall System Control and result:

The full autopilot controller is obtained by combining all previous controllers together in a single
diagram (subsystem) .These controllers can contain any type of control algorithms.

Figure 3-11 :Quadcopter UAV Simulink Models Subsystems


Figure 3-12: Simulation result in Matlab Simulink

X-axis Y-axis

Altitude Rolling
Patching Yawing

You might also like