Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
You are viewing an older revision! See the latest version
2 Flight Controller Software
Introduction¶
Quadcopter (X-Mode) using RTOS.
Insert picture of build
Control loop: PI-PI.
D Gain will not be used as data is noisy and caused instability shortly after liftoff.
Progress:
- Code now utilises threads and ticker.
- Highest priority given to inner loop and plant output. Next priority given to outer loop. Lowest priority given to telemetry.
- Time critical routine given to command input.
- Code uses semaphores and mutexes.
- Threads are triggered periodically and optimised to run within a bound guarantee.
- Bus resource protected by mutex to ensure no corruption of data.
- Code is now ran at maximum speed for every task.
- 400Hz pulse, update and loop.
- 200Hz loop
- 50Hz time-guaranteed for command input
- 50Hz lowest priority telemetry.
- Code uses non-blocking I2C
- Will need to monitor state machine improvements.
- So far, RTOS has not entered deadlock for > 2hours of continuous operation. Code is stress testing by having it simulate the worst flying conditions it may be subjected to.
- MPU DMP quirks for setup are overcome by creating a separate class for non-blocking implementation, and adding a destructor to the original library for house-keeping purposes.
- Control loop now solid.
- PID gains now fully tuned.
- PID control theory, especially for early warning disturbance rejection almost compliant. There is no motivation to achieve compliance as even with flashed ESCs, the max input update rate is 400Hz. A naive Nyqist analysis would suggest that running the ESC at the same speed as a control loop would have ill consequences with aliasing.
Loop will soon incorporate altitude hold. Debating whether to use APM, Ardu- or Aeroquad approach. Algorithm will be posted here, no code until licencing and citation issues are pursuant.
Implementation¶
RTOS¶
4 main threads:
- Thread1: Output telemetry.
- Outputs: YPR, Gyro, Altitude, Voltage, RC Input, RC Command, PID output, ESC Power
- Thread frequency: 50Hz.
- Thread 2-Master: YPR sample, PI Master/Outer control loop. Attitude control.
- Subfunction: Sample MPU6050 and calculate Yaw Pitch Roll angles from DMP quaternion.
- Settings: 50Hz sampling rate (Attitude), 100Hz output FIFO buffer.
- Settings: Input limits: -500.0, 500.0; Output limits: -200.0, 200.0; Output bias: 0.0, Automatic mode
- Settings: KP: 0.5, TI: 1.0, TD = 0.0
- Thread frequency: 200Hz
- Subfunction: Sample MPU6050 and calculate Yaw Pitch Roll angles from DMP quaternion.
- Thread 2-Slave: Gyro sample, PI Slave/Inner control loop. Rate control.
- Settings: Input limits: -500.0, 500.0; Output limits: -200.0, 200.0; Output bias: 0.0, Automatic mode
- Settings: KP: 7.0, TI:2.0, TD = 0.0
- Thread frequency: 400Hz
- Thread 3: RC & Bluetooth Command
- Settings: Default quadcopter is unarmed
- Thread frequency: 50Hz
- Thread 4: Update ESC pulsewidth
- Note: My ESCs can apparently handle refresh rates of up to 400Hz. This means that the ESC should handle a 400Hz PWM pulse. This is distinguished from how fast I update the actual pulsewidth/duty cycle of my pulse!!!
- Settings: PWM frequency: 400Hz
- Thread frequency: 400Hz.
AHRS Sampling¶
Thread frequency: 200Hz
MPU6050 Sampling rate: 100Hz
FIFO Buffer Output rate: 100Hz
To be completed
Gyro Sampling & PID calculations¶
Master PID Loop¶
Thread frequency: 200Hz Control: PI
To be completed
Slave PID Loop¶
Thread frequency: 400Hz Control: PI
To be completed
RC & Bluetooth Command¶
Thread frequency: 50Hz
To be completed
Update ESC¶
Thread frequency: 400Hz
Pulse period: 400HZ
Pulse update rate = Thread frequency = 400Hz
To be completed