Interface for DX6i RC Quadcopter controller
Revision 0:6374902c761b, committed 2015-03-30
- Comitter:
- randrews33
- Date:
- Mon Mar 30 19:26:24 2015 +0000
- Commit message:
- Initial commit - basic, but untested functionality
Changed in this revision
DX6iController.cpp | Show annotated file Show diff for this revision Revisions of this file |
DX6iController.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DX6iController.cpp Mon Mar 30 19:26:24 2015 +0000 @@ -0,0 +1,127 @@ +/** + * Institution: Georgia Institute of Technology - ECE Department - Senior Design II + * Team: AH3 + * Created: 3/24/2015 + * Last Edit: 3/26/2015 + * By: Taylor Andrews, Luke Panayioto +**/ + +#include "DX6iController.h" + +DX6iController::DX6iController(pwmPin) : _pwmPin(pwmPin) { + pulseInterval = 0; + nChannels = 9; + + Throttle_Uptime = 700; //1 700 / 1100 / 1500 // Throttle + Roll_Uptime = 1100; //2 700 / 1100 / 1500 (R/L) // Roll + Pitch_Uptime = 1100; //3 770 / 1170 / 1550 (B/F) // Pitch + Yaw_Uptime = 1100; //4 700 / 1090 / 1500 (R/L) // Yaw + Stabilize_Uptime = 1100; //5 LLLL / MMMM / 1500 (3,2,1) + Enable_Uptime = 1500; //6 700 / ---- / 1500 (Off/On) Note: Bind I Button + Extra_Uptime = 1100; //7 LLLL / 1100 / HHHH // IDK + Extra2_Uptime = 1100; //8 LLLL / 1100 / HHHH // IDK + Remainder_Uptime = 22000 - ((pulseInterval * nChannels) + Throttle_Uptime + Roll_Uptime + Pitch_Uptime + Yaw_Uptime + Enable_Uptime + Stabilize_Uptime + Extra_Uptime + Extra2_Uptime); + + mThrottleTrim = 0; + mRollTrim = 0; + mPitchTrim = 0; + mYawTrim = 0; +} + +void DX6iController::generateSignal(int externalDelay) { + //Big pulse + // long remainder uptime (0) + _pwmPin = 1; //Soft pwm + wait_us(Remainder_Uptime - externalDelay); + _pwmPin = 0; + wait_us(pulseInterval); + + // Throttle pulse (1) + _pwmPin = 1; + wait_us(Throttle_Uptime + mThrottleTrim); + _pwmPin = 0; + wait_us(pulseInterval); + + // Roll pulse (2) + _pwmPin = 1; + wait_us(Roll_Uptime + mRollTrim); + _pwmPin = 0; + wait_us(pulseIntervalDelay); + + // Pitch pulse (3) + _pwmPin = 1; + wait_us(Pitch_Uptime + mPitchTrim); + _pwmPin = 0; + wait_us(pulseIntervalDelay); + + // Yaw pulse (4) + _pwmPin = 1; + wait_us(Yaw_Uptime + mYawTrim); + _pwmPin = 0; + wait_us(pulseInterval); + + // Stability pulse (5) + _pwmPin = 1; + wait_us(Stabilize_Uptime); + _pwmPin = 0; + wait_us(pulseInterval); + + // Enable pulse (6) + _pwmPin = 1; + wait_us(Enable_Uptime); + _pwmPin = 0; + wait_us(pulseInterval); + + _pwmPin = 1; + wait_us(Extra_Uptime); + _pwmPin = 0; + wait_us(pulseInterval); + + _pwmPin = 1; + wait_us(Extra2_Uptime); + _pwmPin = 0; + wait_us(pulseInterval); +} + +// TODO: ensure that new values are in an acceptable range +void DX6iController::updateThrottle(int newThrottle) { + Throttle_Uptime = newThrottle; + updateRemainder(); +} + +void DX6iController::updateRoll(int newRoll) { + Roll_Uptime = newRoll; + updateRemainder(); +} + +void DX6iController::updatePitch(int newPitch) { + Pitch_Uptime = newPitch; + updateRemainder(); +} + +void DX6iController::updateYaw(int newYaw) { + Yaw_Uptime = newYaw; + updateRemainder(); +} + +void DX6iController::updateRemainder() { + Remainder_Uptime = 22000 - (pulseInterval*nChannels + Throttle_Uptime + Roll_Uptime + Pitch_Uptime + Yaw_Uptime + + Enable_Uptime + Stabilize_Uptime + Extra_Uptime + Extra2_Uptime + + mThrottleTrim + mRollTrim + mPitchTrim + mYawTrim); +} + +void DX6iController::updateThrottleTrim(int newThrottleTrim) { + mThrottleTrim = newThrottleTrim; +} + +void DX6iController::updateRollTrim(int newRollTrim) { + mRollTrim = newRollTrim; +} + +void DX6iController::updatePitchTrim(int newPitchTrim) { + mPitchTrim = newPitchTrim; +} + +void DX6iController::updateYawTrim(int newYawTrim) { + mYawTrim = newYawTrim; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DX6iController.h Mon Mar 30 19:26:24 2015 +0000 @@ -0,0 +1,75 @@ +/** + * Institution: Georgia Institute of Technology - ECE Department - Senior Design II + * Team: AH3 + * Created: 3/24/2015 + * Last Edit: 3/26/2015 + * By: Taylor Andrews, Luke Panayioto +**/ + +#ifndef _DX6I_CONTROLLER_H_ +#define _DX6I_CONTROLLER_H_ + +#include "mbed.h" + +class DX6iController { +private: + DigitalOut _pwmPin; + + /** + * The signal received by the quadcopter is an array of nine PWM signals (called a PPM signal), and is + * exactly 22 ms long. Each segment in the array has a specific purpose. The first four correspond to + * the throttle, roll, pitch, and yaw, respectively. + * + * The fifth and sixth correspond to the stability and enable modes. The stability mode configures the + * quadcopter's internal stabilization systems through a combination of onboard accelerometers and + * gyroscopes. The stability mode has two presets, what I just label as "full" and "partial", in + * addition to an "off" setting (below it is initialized with full stability enabled, and it is highly + * encouraged to keep it there). The Enable mode simply allows the quadcopter to throttle, and only + * has two settings "on" and "off". Obviously, this must be configured for "on", unless it is utilized + * in some fashion as to prevent some sort of catastrophic collision. + * + */ + + // Channels: [Remainder] [Throttle] [Roll] [Pitch] [Yaw] [Stability] [Enable] ([Extra_1] [Extra_2] + + // delay between signals in microseconds (µSec) + int pulseInterval; // 400 µSec + int nChannels; //channels must be at least 7 + + // uptime of each signal in microseconds low / mid / high // Corrections to PPM signal order + int Throttle_Uptime; //1 700 / 1100 / 1500 // Throttle + int Roll_Uptime; //2 700 / 1100 / 1500 (R/L) // Roll + int Pitch_Uptime; //3 770 / 1170 / 1550 (B/F) // Pitch + int Yaw_Uptime; //4 700 / 1090 / 1500 (R/L) // Yaw + int Stabilize_Uptime; //5 LLLL / MMMM / 1500 (3,2,1) + int Enable_Uptime; //6 700 / ---- / 1500 (Off/On) Note: Bind I Button + int Extra_Uptime; //7 LLLL / 1100 / HHHH // IDK + int Extra2_Uptime; //8 LLLL / 1100 / HHHH // IDK + int Remainder_Uptime; + + // Trim values + int mThrottleTrim; + int mRollTrim; + int mPitchTrim; + int mYawTrim; + + void updateRemainder(); + +public: + DX6iController(PinName pwmPin); + ~DX6iController(); + + void generateSignal(int externalDelay); + + void updateThrottle(int newThrottle); + void updatePitch(int newPitch); + void updateRoll(int newRoll); + void updateYaw(int newYaw); + + void updateThrottleTrim(int newThrottleTrim); + void updatePitchTrim(int newPitchTrim); + void updateRollTrim(int newRollTrim); + void updateYawTrim(int newYawTrim); +}; + +#endif // _DX6I_CONTROLLER_H_ \ No newline at end of file