## Welcome to the World of Modelling and Simulation

### What is Modelling?

This blog is all about system dynamics modelling and simulation applied in the engineering field, especially mechanical, electrical, and ...

### Design and Control of a Drone: Beginners' Guide to Build an UAV

This century, we have seen some of the fascinating developments in the field of control and robotics. UAV - Unmanned Aerial Vehicle - or, simply Drone, is a part of this achievements. Now-a-days, every big industry, such as, Amazon, Google, etc. is investing a lot in the research and development of commercially applicable drones. In this article, I would like to present a simple way to design a drone and control it virtually. To do that, one need to have experience on any computer-aided-design (CAD) software, such as AutoCAD, SolidWorks, and so forth, and numerical computational tools, for example, MATLAB. There are various shapes and sizes of the drone available and depending on that, their nomenclatures are different. In this tutorial, I will be using SolidWorks to design the physical structure of a quadcopter - a drone having four rotors/motors to propel. A typical quadcopter may have the following fundamental parts:

2. Electric Motor
3. Arm to support Motors
4. Base Plate
5. Control System

The design of a quadcopter depends on the applications where it may be implemented. For this tutorial, I have chosen a very basic design as a demonstration purpose. In SolidWorks, if you have a large drawing, it is better to use 'part drawing' template (.SLDPRT) for individual elements and then, assemble all the parts in an assembly file (.SLDASM). At first, I designed the four parts (blade, base plate, arm, and motor) in SolidWorks part files. In the following, those parts are shown below:

The features that I used to design the four parts above are very straightforward. For example, for the baseplate, I drew a two dimensional (2D) rectangle, and then, extruded it along the vertical axis. Also, the holes were drawn as circles in the main sketch and then, cut holes through them. Once the parts are designed, then you are ready to assemble them in the SolidWorks assembly file. Create a new assembly file and insert those parts. You can duplicate the same part by simply using copy/paste feature with your mouse. Since it is a quadcopter, we need four arms, four motors and four propeller blades, which can be duplicated easily. Now, the task is to assemble them.

The dimensions used for the quadcopter are highlighted below by the orthographic drawing. In SolidWorks, the orthographic drawings are easily obtained from the option 'Make 2D Drawings from 3D'. From this, we can select particular views of the 3D object, such as, front or top or side views etc.

In SolidWorks, there is an add-in named 'Motion Analysis' where we can visualize the motion of the assembly parts asif the body moves in real world. Below, the quadcopter motion is visualized by provided rotations at the four motors.

The physical model that has been developed is now ready to be exported into MATLAB Simulink environment. In SolidWorks, we used the option ‘Export to Simmechanics/Simscape’ to convert the CAD model into MATLAB readable file. The following screenshots show the steps. But, to add the MATLAB link to the SolidWorks, you first need to enable a plug-in in Matlab, here is the link to download and install.

After that, simply run the Simulink model that will produce a similar CAD model in Matlab window shown below.

Now to build a controller, at first, we need to provide motion to the quadcopter. Here, the signal generated from the source block from Simulink library is transferred to the four motors at the coupling of the motor and blades. We use a signal generator from Simulink library. Then, we create an arbitrary signal to drive the quadcopter. The signal goes through the PID controller and eventually goes into the plant or quadcopter assembly. Here, the controller is a proportional, integral, and derivative unit that filters the input signal and sends output to the four motors of the quadcopter. After receiving the signal, the propeller blades start rotating.

The quadcopter has six degrees of freedom in the 3D simulation space. The motions are translations along the x, y, z axes, and rotations about those axes. We have provided torque at the junctions between rotor blade and motor shaft that actuates the quadcopter drone in the 3D space where it translates as well as rotates. Our task here is to control the quadcopter in 3D space where we would like to drive it in a manner that we are able to control the altitude of it.

Following image shows the complete Simulink model of the quadcopter system. As we see that the input is generated from the signal generator (here it is a step signal) and then passed into the controller. From the controller, it reaches the quadcopter. Finally, the signal from the quadcopter goes back to the controller through the feedback line. Thus, we have a feedback control system for the quadcopter.

The next image shows the PID controller for the quadcopter. We use a unit value for both proportional and integral controller, and 0.1 for the derivative controller. There is no definite reason for choosing these values, any values may be taken into account. However, we need to be careful while choosing the values since high derivative values make the system unstable.

The following plot shows the response of the quadcopter after running a simulation.
Finally, we are done! You can now navigate your first drone virtually in 3D space just like the following animation from my quadcopter model.