Home

Quadcopter notes

Mechanical

Quadcopter lets you control all 3 axes of movement with very few moving parts.

Pitch roll and Yaw

Axes Control

Electrical

Electrical diagram

Code

Calibrate sensors

Get sensor data

There are two sensors, gyroscope and accelerometer. The gyroscope measures the rate of change of each axis and the accelerometer measures the acceleration in all 3 axes.

Getting gyroscope data

To estimate the drone’s angle from the rate of change on each axis, the data must be integrated over time.

The problem with this is that error accumulates, causing the gyro’s data to drift over time.

Getting accelerometer data

The acceleration from each axis must be converted into an angle.

The problem with this is that it is susceptible to vibrations, so it can’t be used for precise control.

Combining gyro and acc

In order to get an accurate drone angle, you can combine the gyro and acc data to prevent drift and reduce vibration effects on control.

The complementary filter fuses sensor data by weighting each input, usually giving the gyro 90–98% weight.

const double GYRO_WEIGHT = 0.9;
const double ACC_WEIGHT = 0.1;

double combined = GYRO_WEIGHT * gyroData + ACC_WEIGHT * accData;
// angles.x = GYRO_WEIGHT * (angles.x + (rates.x * deltaTime)) + ACC_WEIGHT * accelAngles.x;

Get controller data

Controller modes

Mode Description
Acro/rate mode Joystick changes the rate of chang eof the angle. Just needs gyro data.
Angle/stabilized mode Joystick changes tilt angle and drone auto levels to maintain that angle.
Horizon mode Small stick inputs behave like angle mode and large behave like acro mode.

The most common stick mode layout mode 2:

Controller Stick Direction Controls
Left up/down Altitude
Left left/right Yaw
Right up/down pitch
Right left/right roll

Calculate control axes

Since you don’t know the exact position of the yaw, you can use acro mode just for that axis.

PID

Stabilized PID

Set motor outputs

Each motor combines together the throttle, roll, pitch, and yaw deadening on its position.

Usually ESCs have a range from 1000-2000 PWM.

Safety checks

If something goes wrong, the drone should set the motors to 0 and exit the loop.