Ian Hua / Quadcopter-mbedRTOS

You are viewing an older revision! See the latest version

Documentation

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.

Partslist

Sensors

  • TiltyQuad
    • InvenSense MPU6050
    • HMC5883L
    • MPL3115A2
    • Onboard voltage divider for voltage sensing

Frame

  • Hobbyking SK450
  • Custom 3D printed motor mounts
  • 5.5mm thickness vibration-absorbing foam

Propulsion

  • 4x Hobbyking Blue 30A ESC, flashed with SimonK firmware
  • 4x Turnigy D2826/950kV motors
  • 2x LH 10x4.5 props
  • 2x RH 10x4.5 props

Electrical

  • 1x Turnigy 1000mAh 20C Lipo (Entire control logic uses 300mA peak)
  • 1x Zippy 5000mAh 30C Lipo
  • 1x Turnigy 5A max Low RF Noise BEC

Radio

  • 1x HC-05 Bluetooth (TiltyQuad IMU)
  • 1x Turnigy 9x v2 9 channel receiver
  • 1x Turnigy 9x v2 9 channel transmitter, flash with OpenTX and running lipo pack

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
  • 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

Results/Demonstrations

Link to youtube video

To do/discussions (respective order of priority)

  1. Set priority (most important first): PID rate & ESC, PID attitude, Command, Telemetry
  2. Switch to RTOS-friendly/non-blocking I2C
  3. Improve Control loop (remove slight oscillations during attitude mode)
  4. Implement Altitude hold!
  5. Add support for EEPROM to store tuned gains outside of default
  6. Remap keyboard input for intuitive Telemetry/control
  7. Remove Bluetooth arming dependency
  8. Add in LCD output for offline setting/debugging
  9. Add in voltage sensing alarm
  10. Build GUI using Processing for Multiwii-like control
  11. Finish this article!

All wikipages