项目作者: giusenso

项目描述 :
Flight controller for an autonomous quadcopter drone.
高级语言: C++
项目地址: git://github.com/giusenso/quadcopter-drone-flight-control.git
创建时间: 2020-09-23T17:21:58Z
项目社区:https://github.com/giusenso/quadcopter-drone-flight-control

开源协议:MIT License

下载


Autonomous Drone Flight Control

Table of contents

Project Overview

Drone Configuration

  1. Front
  2. cw (1) (2) ccw x
  3. \ / z
  4. X \|
  5. / \ +----→ y
  6. ccw (4) (3) cw
Channel Command
1 yaw
2 pitch
3 throttle
4 roll
5 vra

Roadmap

1. Non-autonomous Drone

  • Define basic data structures and workflow
  • pcb design
  • Implement Tx —> Rx communication using interrups
  • Map commands <Throttle, Roll, Pitch, Yaw> into motor signals <m1, m2, m3, m4>
  • Signal smoothening
  • Implement a safe arm/disarm routine
  • Testing

2. Hovering

  • Implement an IMU class for MPU9250
  • Implement a PID class and algorithm
  • Implement a gyro-based hovering maneuver
  • Testing
  • Implement a real time Kalman Filter Algorithm
  • Implement a full hovering maneuver
  • Testing

3. Other Autonomous Maneuver

  • Autonomous take-off and landing

Hardware

  • Frame: S500 glass fiber 480mm
  • Motors: Emax 2216 810kv
  • Propellers: Emax 1045
  • ESC: HAKRC 35A
  • MCU: ATmega 328 (Arduino Nano)
  • IMU: mpu9250 + barometer (10dof sensor)
  • Lipo battery: 3S 5000mAh
  • Radio Tx: Flysky FS-i6X
  • Radio Rx: Flysky X6B

Electronic schematics

Pin Mapping

Board Pin Port Pin Signal Hardware
A4 PC4 SDA IMU
A5 PC5 SCL IMU
D3 PD3 M4 Motor 4
D4 PD4 Ch4 Radio Rx
D5 PD5 Ch3 Radio Rx
D6 PD6 Ch2 Radio Rx
D7 PD7 Ch1 Radio Rx
D9 PB1 M3 Motor 3
D10 PB2 M2 Motor 2
D11 PB3 M1 Motor 1
D12 PB4 Ch5 Radio Rx
  1. ATmega328
  2. +--------------+
  3. | D13 D12 |<-------------|Ch5| (Radio Rx)
  4. | 3.3v D11 |----> (M1)
  5. | Ref D10 |----> (M2)
  6. | A0 D9 |----> (M3)
  7. | A1 D8 |
  8. | A2 D7 |<-------------|Ch1| (Radio Rx)
  9. | A3 D6 |<-------------|Ch2| (Radio Rx)
  10. (MPU9250) |SDA|---->| A4 D5 |<-------------|Ch3| (Radio Rx)
  11. (MPU9250) |SCL|---->| A5 D4 |<-------------|Ch4| (Radio Rx)
  12. | A6 D3 |----> (M4)
  13. | A7 D2 |
  14. | 5v GND |
  15. | RST RST |
  16. GND -----| GND Rx |
  17. 3.3v -----| VIN Tx |
  18. +--------------+

Power Busses

  1. +---------+ +-----------+
  2. | MPU9250 | | Brushless |
  3. +---+--+--+ | Motors |
  4. | | +---+--+----+
  5. +======+ | | | |
  6. | |-------------- GND ----------+--|----+----------+ |
  7. | LIPO |----(buck)---- 3.3v ------------+ | |
  8. | 3S |----(buck)---- 7.3v -----------------|--+ |
  9. | |------------ 11.1/12.6v -------------|--|----------+
  10. +======+ | |
  11. | |
  12. +---+--+---+
  13. | Radio Rx |
  14. +----------+

Software

  • Language: C/C++, Matlab
  • IDE: Visual Studio Code w\ PlatformIO
  • Additional libs: Arduino.h, Servo.h

Repository structure

  1. .
  2. ├── include
  3. ├── atmega328_pin_mapping.h
  4. └── README
  5. ├── lib
  6. ├── drone
  7. ├── drone.cpp
  8. └── drone.h
  9. ├── MPU9250
  10. ├── MPU9250.cpp
  11. └── MPU9250.h
  12. ├── PID
  13. ├── PID.cpp
  14. └── PID.h
  15. └── README
  16. ├── platformio.ini
  17. ├── README.md
  18. ├── src
  19. └── main.cpp
  20. └── test
  21. └── README

Data Structures

Drone:

  1. typedef struct drone{
  2. uint8_t state;
  3. int16_t av_throttle;
  4. int16_t av_roll;
  5. int16_t av_pitch;
  6. int16_t av_yaw;
  7. int16_t throttle[N];
  8. int16_t roll[N];
  9. int16_t pitch[N];
  10. int16_t yaw[N];
  11. int16_t ch5;
  12. float roll_coeff;
  13. float pitch_coeff;
  14. float yaw_coeff;
  15. uint16_t m1;
  16. uint16_t m2;
  17. uint16_t m3;
  18. uint16_t m4;
  19. IMU* imu; // imu data for control
  20. PID* pid_x; // pid control on gyro_x
  21. PID* pid_y; // pid control on gyro_y
  22. } drone;

PID controller:

  1. typedef struct PID{
  2. float setpoint;
  3. float Kp, Ki, Kd;
  4. float dt;
  5. float err[2];
  6. float output[2];
  7. float P, I, D;
  8. float integral;
  9. float min, max;
  10. }PID;

Control System

Sketch of control system for full hovering maneuver: