Welcome to the MCI Quadrocopter (WS 2014 Automation Project) WikiEdit
This wiki deals with commissioning and starting up a quadcopter using the microcontroller XMC 4500. It describes the basic steps like assembling, programming and testing.
One new field in automation and aviation is the field of quadcopters. In this field the whole background of automation and flight dynamics are combined. There is done a lot of research right now, because companies like Amazon try to deliver their cargo with these flying vehicles.
In the first term of our Masters program we had to configure a quadcopter, which is controlled with a remote control, with just mechanical setup we got from the company INFINEON. The general idea was to implement the whole measurement, control and software part of a quadcopter. We were split up in teams of eight people.
The general idea of this project was to train our skills in the electrical, the software and the team ability parts of our study program. Through the different stages of our project, we got an insight in different types of IMU’s, working with brushless motors and the mechanics behind a quadcopter.
To attract the whole attention of us to this project, the instruction team invented a big event at the end of this course. In total there were four teams with four different quadcopters. In this event they are attending a flight course similar to the Red Bull Air Race, and the winner will receive a price. With this method, the instruction team really got all our passion.
In this chapter the task is described in several steps to cover all necessary steps which are desired from the problem to the fragmentation of the task into different parts.
Problem and System description Edit
The main Problem of this project was to build up a whole quadcopter system, which include the hardware implementation and the design of the controller. Therefore a lot of work was done in preparation concerning the kinematic model which we got in a reader from similar projects.
First of all we discussed in a meeting what are the aims and how we can achieve it. We also talked about the realization of the project. We got an idea how does it work and build on that, this is explained in chapter 2.4.
After this meeting the mechatronic department provided us with all the necessary stuff which is Software and Hardware.
For this intent we require a quadcopterbaseframe. This baseframe was ordered as a kit which include following parts:
- 1x Base frame
- 4x Brushless DC-drives
- 4x propellers
- 4x Motor controllers
Additionally to the flightframe kit we need a servo.
Furthermore we need a power supply which is ensure by a litium ion accumulator with a capacity of 3200 mA and a voltage of 11,1V. The accumulator is depiced in the following figure.
Now the parts of the quatrocopter quite finished. To control the whole system we use a microcontroller from the company INFINEON. This microcontroller XMC 4500 is used to process the input signals of the IMU. The XMC microcontroller is depicted in the following figure.
The inertial measurement sensor (IMU) from figure has a DOF (degrees of freedom) of 9. This device has therefore 3 accelerometers, 3 gyroscopes and 3 magnetometers (compasses). The reasons therefore are explained later on.
To remote now the quatrocopter we need a remote controller which is available from the company spectrum. The used remode controller is shown in the following figure.
To receive the signal from the remote controller via the protocol a receiver is necessary.
The tasks are separated in Steps which have been done by small group works of about 1 – 3 participants.
Step 1 Edit
Split the theory model from chapter 2.4 into different parts. Therefore we had to get an overview how we can handle this problem and translate it from the theoretical into the practical.
Step 2 Edit
Ordering the whole equipment which is necessary for the preparation and to get the values for further investigations.
Step 3 Edit
We build up the kinematic model which means the mathematically formulation and implementation into MATLAB with the tool Simulink.
Step 4 Edit
Hence we had the kinematic model we had to find out the dynamic behavior with by experiment and approximate it with curve interpolation. The next step was to create a controller which works appropriate for the DC-drives.
Step 5 Edit
Now we were able to test the IMU therefore we had to make the interfaces and the sensor fusion with a Kalman filter.
Step 6 Edit
The remote control is missing so far, therefore we had to concentrate on the connection between the controller and the receiver.
Step 7 Edit
Now we are ready for the first tests.
Tools / Software Edit
For the Programming and the controlling we used different Software programs. Firstly we used MATLAB Simulink to build up a digital kinematic model and tried it. Additionally we used Dave for programming the XMC microcontroller.
Fragmatation into different parts Edit
The main part of the block diagram is the µ-controller XMC on the board. On part of the input of the µ-controller is the data from the sensor fusion which includes data from the IMU and the GPS modulus. The GPS is add on of the project and not realized in the first step. The interface between the µ-controller and IMU is I²C. In addition the data which is send from the remote control is received from the receiver is also an input of the µ-controller. The µ-controller software includes the flight control which is based on the kinematic model of the quadcopter. The output is the PWM signal for the ESC of the BLDC, this part exists for all 4 BLDC`s.
Kinematic model Edit
Like you could already have seen one big part of the whole project was the kinematic model. At first it seemed really hard to produce a MATLAB model, but with a lot of reading through different literature, we were able to produce a model.
Theory behind the Flight model Edit
In this chapter the theory behind the flight model should be explained. The most information for our project we got out of a PDF (Oscar Mauricio Agudelo, 2014).
Inertial frame and configuration Edit
In Figure 9 you can see the basic model of a quadcopter, like it was used in our project. Like you can see in this figure, the opposite rotors always have to turn in the same direction.
The inertial frame was place in the middle of our quadcopter.
The Yaw is the rotation around the z-axis with the angle ψ. The Pitch is the rotation around the y-axis with the angle θ. The Roll is the rotation around the x-axis with the angle φ.
The first decision we had to make, was if we are flying in the X- or in the plus - configuration. The plus - configuration was chosen, because of simplification reasons. In the picture above, the plus - configuration is already taken.
There you can see, that if you want to make a rotation around the x – axis, just two rotors have an impact. If you would take the X- configuration, there would be a control of all four rotors necessary for a rotation around one axis.
Production of the equations for the model Edit
The first equations, which are made for the kinematic model, are the translational motion in the inertial frame. These equations can be set up as:
In the equation above x, y and z are the position of the quadcopter. The term m·g is the inertial force, which pushes the quadcopter down to the ground. is the thrust vector which acts in the body frame, and R is the rotation matrix. is the drag force, caused by the air friction.
The rotation matrix is defined as following:
The size of the drag force is depending on the velocity in each direction, with the friction coefficient kd☁:
The thrust fi from the i-th rotor is calculated by the propeller lift coefficient k and ω1 is the angular velocity☁:
The sum of all thrust of the four motors is the total thrust☁:
In the paper we had, they assumed, that the dynamics of the motor are much faster than those of our quadcopter, therefore we did not take them into our calculations in the kinematic model of the whole model☁.
The angular velocity of each motor is proportional to the input voltage in the following equation. In this equation cm is constant, and vi is the input voltage applied to the motors☁:
For the rotational equations of our quadcopter, we use the Euler’s equations of rigid body dynamics☁:
In the above equation, Ι represents the inertia matrix of the quadcopter. The ω stands for the angular velocity actor and the τ stands for the external Torque vector.☁
The inertia matrix is defined as followed:
After computing the cross product, the Euler's equations reduces to:
The roll torque (τΦ) and the pitch torque (τθ) are derived from standard mechanics and where L represents the distance between the rotor and the quadcopter center point:
All four rotor-torques act on the z-axis. The first task of them is to overcome the gravity force. The total torque around the z-axis is the yaw, which is called τψ with the propeller drag coefficient b☁:
The roll, yaw and pitch are related to the components of the angular velocity vector with the projection matrix:
With these few simple equations, we can write down the whole set of equations for our model:
Experimental measurement of thrust Edit
To get the quadrocopter to fly we need the thrust force of the rotors which is calculated by the following formula
The density of the air , the radius of the propeller and the resulting area are known constants. The unknown constant called thrust coefficient is defined as the thrust force of an engine unit of frontal area per unit of incompressible dynamic pressure. This constant has to be calculated by experiment. If we apply a certain rotational speed to the propeller the force could be measured. Hence it is possible to calculate the missing constant .To measure the thrust of the motor we first need a test rig. The measurement structure is described in the following pictures.
The quadcopter was fixed on a piece of timber that it can’t fly away and damage the environment. On the left side the rotor is applied to the motor. This is our testing motor. On the right hand side the quadcopter is placed on a scale for the thrust measurement. When the propeller is turning on the one side it pushes down the other side with the equal force, which can be calculated from the weight value of the scale.
We applied the appropriate voltage and a certain duty cycle to the motor. The duty cycle was created via Labview. This duty cycle is scaled from 5 to 10 percent, which is usual for this type of motor. 5 percent duty cycle means no speed and 10 percent duty cycle means maximal rotational speed. So we increased the duty cycle from 5% to 10% in 0.5% steps. The result of the measurement was the rotational speed with the corresponding thrust force, which we need to calculate the thrust coefficient.
Table 1 shows the starting conditions. We applied a certain Duty cycle with a certain time to the motor and measured the current and the voltage, which is needed. As you can see in the table, we got no results for a Duty cycle smaller than 6, which means that the motor only starts to turn over this this.
It is possible to receive the electrical frequency from the oscilloscope by counting the oscillating period. The motor has 12 poles, which corresponds to 6 poles pairs. If we divide the electrical frequency by the number of the pole pairs we get the mechanical frequency and further if we multiply it with 2*pi we have the rotational frequency .
We also calculated the rounds per minute to compare it to the data of the optical rpm measuring instrument which was provided by the MCI.
The result of the measurement is the mass provided by the scale. The Trust force can be calculated with the gravitational acceleration. Hence we get
Now the rotational speed and the Trust force are provided by the measurement setup and hence it is possible to calculate the missing constant Ct with the formula
The thrust force and the rotational speed we get from Table 2andTable4.
Visualization of the test results:
We can see that both diagrams have a nonlinear behavior, which corresponds to the real motor behavior. With this measured data it is possible to create a transfer function (behavior) of the motor and hence implement it in the further process like the control of the system.
Remote Control Edit
As first step the remote control has to be assigned with the receiver to make sure that the receiver does not uses information from some other remote control. The receiver and the µ-controller communicate via a UART. The remote control has different channels, not all of them are used for the quadcopter. The remote control sends the information in form of bytes, therefore a protocol is used. Sender and receiver have to know the protocol that a communication is possible. The protocol is using 16 bytes, each information like pitch, roll, yaw and trust are two bytes large.
In the software a buffer is used where the first byte is stored then the buffer is shifted one byte to the left. Then the next value from the protocol is added to the shifted value in the buffer. All channels have an offset, but the value couldn’t be found, therefore this had to be done by experiment.
Motor, ESC, PWM Edit
As a motor we used four DJI E300 Motors.
Two of them are rotating clockwise and the other counter clockwise. These motors are Brushless DC Motors and it is compatible with different types of multicopters. Brushless DC Motors are synchronous motors that are powered by DC electric source via an integrated power supply, which produces an AC electric signal to drive the motor. The main advantage of the brushless DC motor is, because they don’t use brushes to change the phase and therefor the magnetic field. With brushes there would be a lot of abrasion and damages on the rotor.
These motors are plugged to the power supply form the battery and to the speed controllers.
As an Electronic speed control we used the DJI E300 Parts F450 F550 Components.
We need this Speed controller to convert the PWM signal, which is created with the remote control and the micro controller to the speed and direction of the motor. They are used on electrically powered radio controlled models, with the variety most often used for brushless DC motors.
They are PWM Controllers for electric motors. The ESC generally accepts a nominal 50 Hz PWM servo input signal whose pulse width varies from 1ms to 2 ms. When supplied with a 1 ms width pule at 50Hz, the ESC responds by turning off the DC motor attached to its output. When presented with 2.0 ms input signal, the motor runs at full speed.
Regardless of the type of the controller, it interprets control information not as mechanical motion as would be the case of a servo, but rather in a way that varies the switching rate of a network of field effect transistors of FETs.
In order to control our DC-Motors, they had to be triggered with a pulse width modulated signal. The software Dave from Infineon produces this signal. The basic steps of how to implement the PWM are out of our DAVE program and the DAVE help. In the function PWM_init the duty cycle for every motor is set to 0. The 5 means 5% of 50 Hz which equals 1ms which is further 0 rpm. At this way the rotational speed of the motors can be influenced.
Sensor Fusion Edit
The sensor fusion is one of the most important and fundamental parts for a quadrocopter controller. The sensor fusion of the IMU gives you the orientation of the quadrocopter and so it is the feedback of your system. If this data is wrong your controller gets wrong information about the orientation cannot control your system in a correct way.
The IMU - GY-9150 Edit
We used as IMU the GY-9150, which contains the MPU9150 chip from Invensense. This IMU achieves 9-DOF (Degrees of freedom) by combining two existing chips. The first chip is the MPU6050, which is a 3-axis accelerometer and a 3-axis gyroscope. The second chip is the AK8975, which is a 3-axis magnetometer. The data connection is realized through a I2C interface, where you can call the data of the MPU6050 directly. To get the data from the AK8975 you have to access to the external sensor connection of the IMU because the AK8975 works as a slave of the MPU6050. This you can also see in the block diagram at the documentation of the MPU-9150.pdf.
The Kalman filter Edit
We decided to search in the internet for a working Kalman filter, to save time at the sensor fusion. At the beginning of the project do did not realized how important is this part, so we decided to use an already existing Kalman filter. At the end of our project, we realized that this was a big mistake.
We used found a working Kalman filter program at GitHub which fuses the data of a of the MPU6050 with the data of a 3-axis magnetometer. This program is written in c++, but we need a c-code to run the program on our XMC4500 board of Infineon. Now was our next step to re-write and adjust this code as c-code in Dave3 (programming environment of Infineon) and connect it with the apps, which Dave is using. After several hours of getting started with Dave and re-write the program the code was finally working.
Do to a visualization of the sensor fusion we had the impression to have a well working code. The calculated angels are precise and represent the true orientation in a fast way. But after mounting the IMU on the quadrocopter we got bad results. Due to the high vibrations on the quadrocopter we get a very high noisy signals of the angles. We tried to create a better support for the IMU but we do not get better results. A solution would be to adjust the Kalman filter and to minimize the influence of the accelerometers, but therefore we need more time.
So we tried to get a other solution and we created a FIR - filter, which smooth our signal in a good way but it makes our system too slow.
The solution of this problem now would be to delete the done Kalman filter. We know from the other group that there is a working IMU-Library, which is working also with high vibrations on the frame.
To get a better understanding of the angel, which we got from the sensor fusion, we decided to visualize them. We used therefore a published code from GitHub to visualize the angles. The code is an open source code and run on processing. Processing is an open source programming language and IDE.
To visualize your angles you have to send a string like this "yaw;pitch;roll;temperature;presure;altitude\n" to the program. If you do not have the last three variables set them zero.
Way Of Realization Edit
The first step to implement a suitable flight control was to find a way to implement the controller. The aim is to control the angles (roll, pitch and yaw) of the quadrocopter. The feedback values are generated by the IMU and the input values are generated by the remote control. Therefore a closed loop can be generated. The correcting values of the controller then have to connect to the motors of the propeller. That means that a certain correction value for the angle of the pitch decreases the rotation speed of the propellers at one side and increases the rotational speed at the other side of the quadrocopter. The exact motors which are increased or decreased depends on the configuration which the quadrocopter flights. After this manipulation of the rotor speeds the values can be transferred to the motors as a value for the duty cycle. For the controlling of the yaw the angle velocity is used. That means that as long the remote control gives a values the quadrocopter rotates and otherwise the quadrocopter holds the position.
For the controller as a first step a PID-Controller is used. In a future application a higher order controller can be used to get a better controlling.
The picture above shows the implementation of the controller into the Simulink model. As a next the controller parameter have to be calculated.
The generation of the controller parameter was done by the auto-tune function in MatLab Simulink. There are many other ways to generate the controller parameter but the auto-tune function is a very powerful instrument which gave a first look at the area in which the parameter lies. A first flight with this parameters was done afterword. It shows that there are many differences between the kinematic model and the real system. Therefore another approach to get the controller parameter have to be done.
After the Auto-Tuning values did not bring a stable flight, we had to rethink our strategy to get the control parameters for the flight control. The next try was to find the P-, I- and D- Values with the method of Ziegler Nichols. In the first tries large controller parameter with a large P- value and no I- or D- values were generated. Then it was tried to find a point where the controller brings the best result. The main problem was, that for each try to change the value in the program the board have to reboot and this takes a long time if you are trying to add different values.
Therefore a software in C# was written which could write the controller values directly and without rebooting onto the quadrocopter by USB connection. This brought an enormous time saving. With this new program, the controller parameter could slowly reach to a better and better controlling.
Test flights Edit
The first test flight was done at a laboratory setup. Therefore a rubber tube was mounted between two supports. The quadrocopter then was grounded at the tube in T-configuration. This setup was used because the quadrocopter have a free axis which can be tried to control. The first tests yields no well results. That means that no stable flight was generated. Following the flight configuration was changed to the X-configuration. This results a more stable flight because two propellers on each side reacts to an angle change of an axis.
The following tests on the new setup still not yield any stable flight. Future it was found out that the rubber tube generates disturbance vibrations on the quadrocopter. Therefore the laboratory setup was changed. The quadrocopter was mounted on a robust pipe in the same way as before. This setup results less vibrations and an easier way to control.
But the additionally implemented test still not yields any results. That means that each signal from the quadrocopter has to be checked again. The subsequent test yields that the IMU generates at high propeller speeds a very noisy signal which allows not the control the quadrocopter. The first solution which was found was to mount the IMU in another way. So different mounting kinds were tested. The IMU was damped by a foam which not damp the IMU in a good way. Then the IMU was mounted directly to the flight frame by hot glue. This yields the best results due to the vibrations but the IMU has a noisy signal. The next concept was to filter the signal by a low-pass filter. Therefore a FIR-filter was used which filters directly the angle signals from the IMU. The filtering of the IMU yields a nearly noise free signal but the time delay of the FIR-filter makes the quadrocopter to slow and a controlling impossible. With other filter coefficients the filter influences the signal in a bad way that the measured angles not corresponds to the real angles of the quadrocopter.
Results and Future Prospective Edit
After the calibration of the IMU (inertial measurement sensor) with laboratory test fight set up a free flight for the demonstration of the sensors was done. It resulted in a strange flight where we were not able to control the quadcopter anymore, because the IMU had some troubles with noisy angles at high rotating motors. After many test flights an attempt with a FIR filter was done but unfortunately without additionally success. The problems are still the wrong a values for the actual angles. For future projects it is necessary to get at first a stable controller which can maybe be done with an improve of the Kalman filter (kalman filter coefficients). Another possibility can be an improve of the existing kinematic model of the real system. Afterwards it would be possible to create the quadcopter for the autonomous fly.Up to now the mechanical set up of the quadcopter works really well, as well as the connection between flight device and remoter. The only problem still exists in the IMU implementation and calculation of the angles.
All our programs are attached here.