Skip to content

Instantly share code, notes, and snippets.

@hanjae-jea
Last active August 30, 2017 03:32
Show Gist options
  • Save hanjae-jea/c6e2ec98a1bf4ded4eb7341db1a78466 to your computer and use it in GitHub Desktop.
Save hanjae-jea/c6e2ec98a1bf4ded4eb7341db1a78466 to your computer and use it in GitHub Desktop.
0829.cpp
#include <CoDrone.h>
int mode = 0; // 0 none 1 start 2 running
int index = 0, fly = 0;
int throttleCount = 0;
int yy[800], tt[800], rr[800], pp[800];
void setup() {
CoDrone.begin(115200);
CoDrone.AutoConnect(NearbyDrone);
CoDrone.LedColor(EyeHold, 100, 100, 100, 200);
}
void loop() {
int yaw = -1 * CoDrone.AnalogScaleChange(analogRead(22));
int throttle = CoDrone.AnalogScaleChange(analogRead(23));
int roll = -1 * CoDrone.AnalogScaleChange(analogRead(24));
int pitch = CoDrone.AnalogScaleChange(analogRead(25));
if( mode == 0 ){
if( throttle > 90 ){
throttleCount++;
}else throttleCount = 0;
if( throttleCount >= 5 ){ mode = 1; throttleCount = 0; }
else {
CoDrone.LedColor(EyeDimming, 255, 0, 0,100);
}
}
if( mode == 1 ){
yy[index] = yaw;
tt[index] = throttle;
rr[index] = roll;
pp[index] = pitch;
index++;
if( throttle < -90 ){ throttleCount--; } else{ throttleCount = 0; }
if( throttleCount <= -5 ){
mode = 2;
throttleCount = 0;
// fly init
CoDrone.FlightEvent(TakeOff);
}else{
CoDrone.LedColor(EyeDimming, 0, 255,0, 100);
}
}
if( mode == 2 ){
YAW = yy[fly];
THROTTLE = tt[fly];
ROLL = rr[fly];
PITCH = pp[fly];
CoDrone.Control();
fly++;
if( fly >= index ){
CoDrone.FlightEvent(Landing);
YAW = 0; THROTTLE = 0; ROLL = 0; PITCH = 0;
mode = 3;
}else {
CoDrone.LedColor(EyeDimming, 0, 0, 255, 100);
}
}
if( mode == 3 ){
CoDrone.LedColor(EyeDimming, 255, 0, 255, 100);
}
delay(200);
}
#include <CoDrone.h>
void setup(){
CoDrone.begin(115200);
CoDrone.AutoConnect(NearbyDrone);
CoDrone.LedColor(EyeHold, 100, 100, 100, 500);
CoDrone.FlightEvent(TakeOff);
delay(2000);
CoDrone.FlightEvent(Landing);
}
void loop(){
}
#include <CoDrone.h>
int flight = 1;
int throttleCounter = 0;
void setup(){
CoDrone.begin(115200);
CoDrone.AutoConnect(NearbyDrone);
CoDrone.LedColor(EyeHold, 200, 0, 200, 500);
CoDrone.FlightEvent(TakeOff);
}
void loop(){
int yaw = -1 * CoDrone.AnalogScaleChange(analogRead(22));
YAW = yaw;
int throttle = CoDrone.AnalogScaleChange(analogRead(23));
THROTTLE = throttle;
if( throttle > 90 && flight == 0 ){
CoDrone.FlightEvent(TakeOff);
flight = 1;
}
if( throttle < -90 && flight == 1 ){
CoDrone.FlightEvent(Landing);
flight = 0;
}
int roll = -1 * CoDrone.AnalogScaleChange(analogRead(24));
ROLL = roll;
int pitch = CoDrone.AnalogScaleChange(analogRead(25));
PITCH = pitch;
CoDrone.Control();
delay(200);
}
#include <CoDrone.h>
int mode = 0;
void setup(){
CoDrone.begin(115200);
CoDrone.AutoConnect(NearbyDrone);
CoDrone.LedColor(EyeHold, 100, 100, 100, 500);
}
void loop() {
mode = (mode + 1) % 4;
if( mode == 0 ){ CoDrone.FlightEvent(Landing); }
if( mode == 1 ){ CoDrone.FlightEvent(TakeOff); }
if( mode == 2 ){ YAW = 100; CoDrone.Control(); }
if( mode == 3 ){ YAW = 0; CoDrone.Control(); }
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment