Difference between revisions of "F15: Quadcopter by Thomas"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Physical design)
 
(51 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
==Abstract==
 
==Abstract==
 
The goal of this project is try to implement the basic function of a drone, fly and controlling the direction by remote control.
 
The goal of this project is try to implement the basic function of a drone, fly and controlling the direction by remote control.
 +
 +
 +
 +
== Parts List & Cost ==
 +
 +
{| class="wikitable"
 +
|-
 +
! scope="col"| Item#
 +
! scope="col"| Part Desciption
 +
! scope="col"| Manufacturer
 +
! scope="col"| Qty
 +
! scope="col"| Cost
 +
|-
 +
! scope="row"| 1
 +
| SJ One Board
 +
|
 +
| 1
 +
| $80.00
 +
|-
 +
! scope="row"| 2
 +
| NEEWER® HJ450 4-Axis Frame
 +
|
 +
| 1
 +
| $15.99
 +
|-
 +
|-
 +
! scope="row"| 3
 +
| Afro ESC 20Amp Multi-rotor Motor Speed Controller
 +
|
 +
| 4
 +
| $83.96
 +
|-
 +
! scope="row"| 4
 +
|Spektrum 5520 DX5e DSMX 5 Channel TX/RX
 +
|
 +
| 1
 +
| $59.99
 +
|-
 +
! scope="row"| 5
 +
|AR400 4-Channel DSMX Aircraft Receiver
 +
|
 +
| 1
 +
| $29.99
 +
|-
 +
! scope="row"| 6
 +
|Sunnysky X2212-13 980KV Brushless Motor
 +
|
 +
| 4
 +
| $61.99
 +
|-
 +
! scope="row"| 7
 +
|Mpu-9250 Gyro Compass Acceleration Magnetic Field Sensor
 +
|
 +
| 1
 +
| $11.99
 +
|-
 +
! scope="row"| 8
 +
|Venom 30C 3S 3200mAh 11.1V
 +
|
 +
| 1
 +
| $41.72
 +
|-
 +
! scope="row"| 9
 +
|Andoer Anti-vibration Plate Shock Absorber Set
 +
|
 +
| 1
 +
| $6.98
 +
|-
 +
! scope="row"| 10
 +
|Kyosho Z8006 Zeal Vibration Absorption Sheet
 +
|
 +
| 1
 +
| $14.94
 +
|-
 +
! scope="row"| 11
 +
|NEEWER® High Elastic Anti-Vibration
 +
|
 +
| 4
 +
| $4.17
 +
|-
 +
! scope="row"| 12
 +
|Andoer Carbon Fiber 10x4.5" 1045 CW CCW Propeller
 +
|
 +
| 4
 +
| $13.99
 +
|-
 +
! scope="row"| 13
 +
|Quadcopter Power Distribution Board XT60 XT-60 20a Quad Mutlicopter 3.5mm
 +
|
 +
| 1
 +
| $10.29
 +
|-
 +
! scope="row"|
 +
| <b>TOTAL</b>
 +
|
 +
|
 +
| <b>$435.43</b>
 +
|-
 +
|}
  
 
==Design & Implementation==
 
==Design & Implementation==
 +
 +
===Physical design ===
 +
 +
The quad copter need MPU-9250 to caculate the positon, but there are a lot of vibration from the frame. Therefore, we have to use some physical design to decrease the vibration that will affect the sensor.
 +
I put the sensor in the Andoer Anti-vibration Plate Shock Absorber Set and wrap the sensor by Kyosho Z8006 Zeal Vibration Absorption Sheet.
 +
 +
 +
Here shows the result. We can see the sensor was warped by the Kyosho Z8006 Zeal Vibration Absorption Sheet.
 +
 +
[[File:Thomas quad sensor design.jpg|800px]]
  
 
===PWM===
 
===PWM===
The four motor on the done is controlled by the PWM (Pulse Width Modulation). The SJSUone board already gave us a good library to use, so we just have to set the frequency and pin at the beginning of the code.
+
The four motor on the drone is controlled by the PWM (Pulse Width Modulation). SJSUone board already gave us a good library to use, so we just have to set the frequency and pin number at the beginning of the code.
  
  
Line 12: Line 121:
 
<source lang="c">
 
<source lang="c">
  
#define PWM_FREQ 500
+
 
 
#include "lpc_pwm.hpp"
 
#include "lpc_pwm.hpp"
 
#include "uart0.hpp"
 
#include "uart0.hpp"
 
#include "stdio.h"
 
#include "stdio.h"
 +
 +
#define PWM_FREQ 500
  
 
void motor_test()
 
void motor_test()
Line 65: Line 176:
  
 
</source>
 
</source>
 +
 +
 +
Here is a diagram shows the output of the PWM. ''PWM_FREQ'' variable from the previous sample code can control the period and ''p'' variable can control the duration.
 +
 +
[[File:Thomas quad PWM diagram..PNG|800px]]
 +
 +
 +
For a drone, a shorter period of PWM can have better performance, more stable, but the range of the controlling will be smaller if we decrease the period. For example, my system is using 500 Hz PWM and my control range will be about 53% to 100% because the motor will start to rotate at 53%. However, if we change the frequency to 1000 Hz, the motor will start to rotate at 90%, so the the control range will be 90% to 100%. Therefore, we have to find the balance of the performance and the control range.
 +
 +
For controlling the motor, we have to set PWM frequency in every certain period very precisely, so delay function can not satisfy our need. Fortunately, FreeRTOS have the timer interrupt API that can execute the code in period. Here we are talking about the control rate that is different from the PWM rate. The control rate should lower than the PWM rate and the data rate from sensor. For my experiment, 50 Hz is enough to fly but hard to control it. If you want to control it, my recommendation is higher than the 150 Hz.
 +
 +
Here is part of my code.
 +
 +
<source lang="c">
 +
 +
void motor_control(void *p)
 +
{
 +
 +
        TickType_t xLastWakeTime;
 +
        int period_ms=2;// control rate (500 MHz)
 +
        const TickType_t xFrequency = MS_TO_TICK_RATE(period_ms);
 +
        PWM servo1(PWM::pwm1, 500);
 +
PWM servo2(PWM::pwm2, 500);
 +
PWM servo3(PWM::pwm3, 500);
 +
PWM servo4(PWM::pwm4, 500);
 +
 +
        xLastWakeTime = xTaskGetTickCount();
 +
 +
 +
        while(1)
 +
{
 +
             
 +
 +
                //PID control code is in here
 +
 +
vTaskDelayUntil( &xLastWakeTime, xFrequency ); //every 2ms the system will execute the code below
 +
 +
 +
                #ifdef Y_AXIS_ACTIVE
 +
servo1.set(pServ1);  //pServ1 will be the % of output for the next period
 +
servo3.set(pServ3);
 +
                #endif
 +
 +
 +
                #ifdef X_AXIS_ACTIVE
 +
servo2.set(pServ2);
 +
servo4.set(pServ4);
 +
                #endif
 +
        }
 +
 +
 +
 +
}
 +
 +
 +
 +
 +
 +
  
  
  
 +
</source>
  
 
The picture of the SJdrone
 
The picture of the SJdrone
 
[[File:Thomas quad SJdrone.jpg|200px]]
 
[[File:Thomas quad SJdrone.jpg|200px]]
 +
 +
== Conclusion ==
 +
 +
 +
=== Project Video ===
 +
Upload a video of your project and post the link here.
 +
 +
first lunch of the SJSU drone
 +
https://youtu.be/lzpCwFyz_Yk
 +
 +
first fly of the SJSU drone
 +
https://youtu.be/GKQJtUIinW8
 +
 +
second fly of the SJSU drone
 +
https://youtu.be/MFJ1-ZD47U0
 +
 +
third fly of the SJSU drone
 +
https://youtu.be/MBFmyweXbKY
 +
 +
final release of the SJSU drone
 +
https://youtu.be/Tv8Bm9wMOkI
 +
 +
final release of the SJSU drone 1
 +
https://youtu.be/xEOyXph9FBg
 +
 +
final release of the SJSU drone 2
 +
https://youtu.be/PvUbFLxbC-s

Latest revision as of 16:17, 4 October 2015

Abstract

The goal of this project is try to implement the basic function of a drone, fly and controlling the direction by remote control.


Parts List & Cost

Item# Part Desciption Manufacturer Qty Cost
1 SJ One Board 1 $80.00
2 NEEWER® HJ450 4-Axis Frame 1 $15.99
3 Afro ESC 20Amp Multi-rotor Motor Speed Controller 4 $83.96
4 Spektrum 5520 DX5e DSMX 5 Channel TX/RX 1 $59.99
5 AR400 4-Channel DSMX Aircraft Receiver 1 $29.99
6 Sunnysky X2212-13 980KV Brushless Motor 4 $61.99
7 Mpu-9250 Gyro Compass Acceleration Magnetic Field Sensor 1 $11.99
8 Venom 30C 3S 3200mAh 11.1V 1 $41.72
9 Andoer Anti-vibration Plate Shock Absorber Set 1 $6.98
10 Kyosho Z8006 Zeal Vibration Absorption Sheet 1 $14.94
11 NEEWER® High Elastic Anti-Vibration 4 $4.17
12 Andoer Carbon Fiber 10x4.5" 1045 CW CCW Propeller 4 $13.99
13 Quadcopter Power Distribution Board XT60 XT-60 20a Quad Mutlicopter 3.5mm 1 $10.29
TOTAL $435.43

Design & Implementation

Physical design

The quad copter need MPU-9250 to caculate the positon, but there are a lot of vibration from the frame. Therefore, we have to use some physical design to decrease the vibration that will affect the sensor. I put the sensor in the Andoer Anti-vibration Plate Shock Absorber Set and wrap the sensor by Kyosho Z8006 Zeal Vibration Absorption Sheet.


Here shows the result. We can see the sensor was warped by the Kyosho Z8006 Zeal Vibration Absorption Sheet.

Thomas quad sensor design.jpg

PWM

The four motor on the drone is controlled by the PWM (Pulse Width Modulation). SJSUone board already gave us a good library to use, so we just have to set the frequency and pin number at the beginning of the code.


The example of using the library.

#include "lpc_pwm.hpp"
#include "uart0.hpp"
#include "stdio.h"

#define PWM_FREQ 500

void motor_test()
{

    PWM servo1(PWM::pwm1, PWM_FREQ);
    PWM servo2(PWM::pwm2, PWM_FREQ);
    PWM servo3(PWM::pwm3, PWM_FREQ);
    PWM servo4(PWM::pwm4, PWM_FREQ);


    Uart0& terminal = Uart0::getInstance();
    terminal.init(38400);

    float p;
    int num;

    while(1){

        printf("NO=");
        scanf("%d",&num);
        printf("pwm percent=");
        scanf("%f", &p);
			
        switch(num){

            case 1:
                servo1.set(p);
                break;

            case 2:
                servo2.set(p);
                break;

            case 3:
                servo3.set(p);
                break;

            case 4:
                servo4.set(p);
                break;

            default:
                return;
        }
    }
}


Here is a diagram shows the output of the PWM. PWM_FREQ variable from the previous sample code can control the period and p variable can control the duration.

Thomas quad PWM diagram..PNG


For a drone, a shorter period of PWM can have better performance, more stable, but the range of the controlling will be smaller if we decrease the period. For example, my system is using 500 Hz PWM and my control range will be about 53% to 100% because the motor will start to rotate at 53%. However, if we change the frequency to 1000 Hz, the motor will start to rotate at 90%, so the the control range will be 90% to 100%. Therefore, we have to find the balance of the performance and the control range.

For controlling the motor, we have to set PWM frequency in every certain period very precisely, so delay function can not satisfy our need. Fortunately, FreeRTOS have the timer interrupt API that can execute the code in period. Here we are talking about the control rate that is different from the PWM rate. The control rate should lower than the PWM rate and the data rate from sensor. For my experiment, 50 Hz is enough to fly but hard to control it. If you want to control it, my recommendation is higher than the 150 Hz.

Here is part of my code.

void motor_control(void *p)
{

        TickType_t xLastWakeTime;
        int period_ms=2;// control rate (500 MHz)
        const TickType_t xFrequency = MS_TO_TICK_RATE(period_ms);
        PWM servo1(PWM::pwm1, 500);
	PWM servo2(PWM::pwm2, 500);
	PWM servo3(PWM::pwm3, 500);
	PWM servo4(PWM::pwm4, 500);

        xLastWakeTime = xTaskGetTickCount();


        while(1)
	{
              

                //PID control code is in here

		vTaskDelayUntil( &xLastWakeTime, xFrequency ); //every 2ms the system will execute the code below


                #ifdef Y_AXIS_ACTIVE
		servo1.set(pServ1);  //pServ1 will be the % of output for the next period
		servo3.set(pServ3);
                #endif


                #ifdef X_AXIS_ACTIVE
		servo2.set(pServ2);
		servo4.set(pServ4);
                #endif
        }



}

The picture of the SJdrone Thomas quad SJdrone.jpg

Conclusion

Project Video

Upload a video of your project and post the link here.

first lunch of the SJSU drone https://youtu.be/lzpCwFyz_Yk

first fly of the SJSU drone https://youtu.be/GKQJtUIinW8

second fly of the SJSU drone https://youtu.be/MFJ1-ZD47U0

third fly of the SJSU drone https://youtu.be/MBFmyweXbKY

final release of the SJSU drone https://youtu.be/Tv8Bm9wMOkI

final release of the SJSU drone 1 https://youtu.be/xEOyXph9FBg

final release of the SJSU drone 2 https://youtu.be/PvUbFLxbC-s