mbedRTOS quadcopter quadrotor RATE and ATTITUDE mode (default). Altitude Hold soon to come. pHysiX Coding 2014.
Feel free to look at the code and implement your own. Don't forget to add in the correct licences, and relevant citation for the relevant developers if you do end up following parts of my code. Sharing is caring :) PM me for queries/code.
This article will be updated slowly, whenever I get a break from rock climbing, university and work commitments. Feel free to comment or ask me questions as need be.
Refer to Wiki Page for complete documentation!
Trung Tin Ian HUA - pHysiX Coding May 2014.
SAFETY FIRST
Quadcopters are inherently dangerous! When a quadcopter is on, it is a live saw!
NEVER UNDER ANY CIRCUMSTANCES DO THE FOLLOWING:
- Fly in a closed or confined space.
- Always allow enough room so that the quadcopter does not get near to people or valuables, and always allow enough room to take evasive action should you lose control.
- Touch the quadcopter when it is armed, even if the propellors are not spinning!!!
- The last thing you need is a trip to the ER/ED at 12am because the props cut off half your pinky (personal experience).
Please be observant when flying. If it looks as if you are losing control, just bring the quadcopter back to Earth. A broken motor/prop/frame/circuit can be replaced. Damaged property or worse yet, personal injury, can be irreversible!
Obey your local laws too regarding RC models. Be sensible so that others too can enjoy this wonderful hobby.
DISCLAIMER
My code is tailored to have a general approach in terms of flight motion and control. The safety features however are specific to my build!
A quirk is that even when the mbed enters deadlock or is taken offline, the ESCs will continue to run for a period until it figures out it has lost a signal. Chances are that the ESC may even shoot to 100% power!
You are free to use and test my code, BUT I TAKE NO RESPONSIBILITY in any circumstance for any problems you encounter, including and not limited to damage of any sort and especially injury to any person or animal.
With that aside, happy flying everyone!!! :D
Results/Demonstrations
Click on image to go to 1-Build Wiki. Link to youtube video
To do/discussions (respective order of priority)
- Switch to body frame instead of current YPR.
- Implement Altitude hold!
- Add support for EEPROM to store tuned gains outside of default
- Remap keyboard input for intuitive Telemetry/control
- Remove Bluetooth arming dependency
- Add in LCD output for offline setting/debugging
- Add in voltage sensing alarm
- Build GUI using Processing for Multiwii-like control
- Finish this article!
History
Restructured code. Licence reproduction and citation of sources not present when code was made public. Code now withdrawn and kept private
2014-05-19, by pHysiX [Mon, 19 May 2014 16:18:33 +0000] rev 55
Restructured code. Licence reproduction and citation of sources not present when code was made public. Code now withdrawn and kept private
PwmInRC library, removed mutex
2014-05-19, by pHysiX [Mon, 19 May 2014 16:05:11 +0000] rev 54
PwmInRC library, removed mutex
PwmInRC library updated with mutex for protection during ISR
2014-05-19, by pHysiX [Mon, 19 May 2014 15:43:50 +0000] rev 53
PwmInRC library updated with mutex for protection during ISR
Rearranged threads with correct priorities, semaphore and mutex. Timer reserved only for time critical tasks. Control loop now running at desirable rate. Code is stable (no RTOS crash), still need to test fly and retune PID!!!
2014-05-19, by pHysiX [Mon, 19 May 2014 15:35:35 +0000] rev 52
Rearranged threads with correct priorities, semaphore and mutex. Timer reserved only for time critical tasks. Control loop now running at desirable rate. Code is stable (no RTOS crash), still need to test fly and retune PID!!!
Code rearranged into threads. Timer reserved for time critical routines only. Implemented working semaphore and mutex
2014-05-19, by pHysiX [Mon, 19 May 2014 15:30:05 +0000] rev 51
Code rearranged into threads. Timer reserved for time critical routines only. Implemented working semaphore and mutex
Semaphores implemented, currently no hanging. Need to test flight
2014-05-19, by pHysiX [Mon, 19 May 2014 14:16:47 +0000] rev 50
Semaphores implemented, currently no hanging. Need to test flight
Changing RtosTimer functions into Threads
2014-05-19, by pHysiX [Mon, 19 May 2014 13:33:34 +0000] rev 49
Changing RtosTimer functions into Threads
Altimeter and IMU changed to non-blocking I2C
2014-05-19, by pHysiX [Mon, 19 May 2014 13:21:17 +0000] rev 48
Altimeter and IMU changed to non-blocking I2C
Broken I2C
2014-05-18, by pHysiX [Sun, 18 May 2014 09:05:41 +0000] rev 47
Broken I2C
Beginning to implement I2C RTOS driver
2014-05-17, by pHysiX [Sat, 17 May 2014 11:57:09 +0000] rev 46
Beginning to implement I2C RTOS driver