RepositoryC++
lobodol

lobodol/drone-flight-controller

A quadcopter flight controller based on Arduino Uno

418sao
94fork
11issue
0lượt xem

Quadcopter PID implementation

Build Status License: MIT

flight

1. Introduction

This Arduino sketch provides a flight controller for an X quadcopter based on an Arduino Uno board and the MPU6050 sensor.

Basically, this automation routine is an implementation of a digital PID with a refresh rate of 250Hz. The method used to calculate PID coefficients is Ziegler Nichols method. The frame of the quadcopter is based on the F450.

You can use this to calibrate your ESCs.

A detailed article is available here (in french).

(i) Currently under active development.

2. Requirements

Arduino libraries:

3. Pin connection:

       +-------------------------+
       |        MPU-6050         |
       |                         |
       | 3V3  SDA  SCL  GND  INT |
       +--+----+----+----+----+--+
          |    |    |    |
          |    |    |    |
+---------+----+----+----+----------------+
|        3.3V  A4   A5  GND               |
|                                         |
|                                         |
|                 Arduino Uno             |
|                                         |
| #4   #5   #6   #7   #8   #9  #10   #11  |
+--+----+----+----+----+----+----+----+---+
   |    |    |    |    |    |    |    |
  (M1) (M2) (M3) (M4)  |    |    |    |
                       |    |    |    |  
                       |    |    |    |
                    +--+----+----+----+---+
                    | C1   C2   C3   C4   |
                    |                     |
                    |     RF Receiver     |
                    +---------------------+
  
Legend:
Mx: Motor X
Cx: Receiver channel x

4. Configuration

4.1 Remote configuration

By default, this sketch uses the mode 2 for RF remote, according to the following picture:

remote modes

The channel mapping is then:

ChannelCommand
1ROLL
2PITCH
3THROTTLE
4YAW

To change the channel mapping, update the function configureChannelMapping according to your needs:

void configureChannelMapping() {
    mode_mapping[YAW]      = CHANNEL4;
    mode_mapping[PITCH]    = CHANNEL2;
    mode_mapping[ROLL]     = CHANNEL1;
    mode_mapping[THROTTLE] = CHANNEL3;
}

4.2 PID tuning

The default PID coeffcient values might work for an F450-like quadcopter. However, you can tune them in the global variable declaration section:

// PID coefficients
float Kp[3] = {4.0, 1.3, 1.3};    // P coefficients in that order : Yaw, Pitch, Roll
float Ki[3] = {0.02, 0.04, 0.04}; // I coefficients in that order : Yaw, Pitch, Roll
float Kd[3] = {0, 18, 18};        // D coefficients in that order : Yaw, Pitch, Roll

5. Quadcopter orientation

 Front
(1) (2)     x
  \ /     z ↑
   X       \|
  / \       +----→ y
(3) (4)
  • Motor 1: front left - clockwise
  • Motor 2: front right - counter-clockwise
  • Motor 3: rear left - counter-clockwise
  • Motor 4: rear right - clockwise

Paper plane

  • Left wing up implies a positive roll
  • Nose up implies a positive pitch
  • Nose right implies a positive yaw

The MPU6050 must be oriented as following:

  • X axis: roll
  • Y axis: pitch
  • Z axis: yaw

6. Start/stop

This sketch comes with a safety process: to start the quadcopter, move the left stick of the remote in the bottom left corner. Then move it back in center position.

To stop the quadcopter, move the left stick in the bottom right corner.

State machine

7. Unit tests

Pure utility functions are extracted into src/utils.h and covered by unit tests that run on the host machine — no Arduino required.

Tests use PlatformIO's native environment and the Unity test framework.

Prerequisites

If pio is not on your PATH (e.g. installed via the VS Code extension), add it once:

export PATH="$HOME/.platformio/penv/bin:$PATH"

Or add that line to your ~/.zshrc / ~/.bashrc to make it permanent.

Run all test suites

pio test -e native

Run a single suite

pio test -e native -f test_min_max

Covered functions

FunctionTest suite
minMaxtest/test_min_max/
calculateSetPointtest/test_calculate_set_point/
calculateYawSetPointtest/test_calculate_yaw_set_point/

Verify the sketch still compiles for the Uno

pio run -e uno

8. Debug

If you need to print debug messages, make sure to init Serial at 57600 bauds:

void setup() {
  Serial.begin(57600);
  // ...
}

void loop() {
  Serial.println(measures[ROLL]);
  // ...
}

Dự án tương tự

Khám phá các dự án và mô hình AI khác có sự tương đồng.

RepositoryC++
dridri/bcflight

Raspberry Pi based drone flight controller and remote control

174
Sep 25, 2026
RepositoryC++
cifertech/ESP32-Drone

Wi‑Fi quadcopter flight stack with browser UI

56
May 3, 2026
RepositoryC
cleanflight/cleanflight

Clean-code version of the baseflight flight controller firmware

2.7k
Oct 20, 2023
RepositoryC
qqqlab/madflight

Flight Controller for ESP32 / Raspberry Pico / STM32

525
Nov 19, 2026
RepositoryC
emuflight/EmuFlight

EmuFlight is flight controller software (firmware) used to fly multi-rotor craft.

505
Nov 26, 2026
RepositoryC
BossHobby/QUICKSILVER

Flight Controller Firmware

228
Nov 27, 2026
RepositoryJavaScript
emuflight/EmuConfigurator

Emuflight Configurator is a cross-platform configuration tool for the Emuflight flight control system

152
Dec 1, 2026
RepositoryPython
TimHanewich/centauri

A complete, custom-built quadcopter system (flight controller, transmitter, telemetry tools) built entirely from scratch in Python on a Raspberry Pi Pico, no off-the-shelf flight controller required.

92
Nov 27, 2026
RepositoryC
I-M-Robotics-Lab/STM32-Quadcopter

Quadcopter design based on STM32F411CEU Blackpill flight controller. Compatible with INAV 6.0 firmware.

86
Nov 13, 2025