Function Documentation
version 2.2.1
Connection
disconnect()
Description
This function disconnects with the drone that you're connected to.
Syntax
disconnect()
Parameters
None
Returns
None
Example Code
//Arduino code
#include<CoDrone.h> //header
void setup(){
//below this have to code in setup
//open serial and connect
CoDrone.begin(115200);
CoDrone.pair(Nearest);
CoDrone.takeoff();
CoDrone.hover(3);
CoDrone.land();
CoDrone.disconnect(); // disconnects
}
void loop(){
}
pair()
Description
This function pairs the BLE board to the CoDrone. After establishing a connection, it always waits for 3 seconds before executing the next command. Pair works a bit differently between Arduino and Python. With the Arduino-based remote, pair()
with no parameters will pair with the last paired CoDrone. If it's your first time running pair()
, it will just find the nearest CoDrone it can find, then "lock in" with that CoDrone, save it to "PairInfo" and always pair with it until you run pair(drone.Nearest)
.
Syntax
pair()
pair(Nearest)
pair(bluetoothAddress)
Parameters
Nearest: If you specify Nearest
in Arduino, it will pair with the first drone it finds (which may not always be the nearest CoDrone, in some cases, just the first CoDrone it finds). This function can be used to "unlock" the drone from only pairing with the CoDrone it's been "locked in" with. Once you've paired with a nearest CoDrrone, you can run pair()
again with no parameters, and it will only pair with the "locked in" CoDrone.
address: This is the address of the CoDrone. In Arduino, this is a 6-index array of bytes representing the Bluetooth address.
Returns
None
Example Code
//Arduino code
#include<CoDrone.h> //header
void setup(){
//below this have to code in setup
CoDrone.begin(115200);
//IMPORATNT: You would only run ONE of the 3 options below
/* 1) This will pair with the last drone that the remote was paired to. If this is the first time pairing,
* this function will pair with whatever first drone it finds, and "lock in" to that drone and only pair with
* that drone
*/
CoDrone.pair();
/* 2) This will pair with the nearest drone that the BLE board finds. You can use this function to "unlock" a
* remote that's been "locked in" to a drone. So first run this code, then just upload and run with "CoDrone.pair()" * to "lock in" to that drone
*/
CoDrone.pair(Nearest);
}
void loop(){
}
Flight Commands (Start/Stop)
emergencyStop()
Description
This function immediately stops all commands and stops all motors, so the drone will stop flying immediately. The function will also zero-out all of the flight motion variables to 0.
Syntax
emergencyStop()
Parameters
None
Returns
None
Example Code
//Arduino code
#include<CoDrone.h> //header
void setup(){
//open serial and connect
CoDrone.begin(115200);
CoDrone.pair(Nearest);
CoDrone.takeoff(); // take off and hover for 3 second
CoDrone.emergencyStop(); // emergency stop
}
void loop(){
}
land()
Description
This function makes the drone stop all commands, hovers, and makes a soft landing where it is. The function will also zero-out all of the flight motion variables to 0.
Syntax
land()
Parameters
None
Returns
None
Example Code
//Arduino code
#include<CoDrone.h> //header
void setup(){
//below this have to code in setup
//open serial and connect
CoDrone.begin(115200);
CoDrone.pair(Nearest);
CoDrone.takeoff(); // take off and hover for 3 second
CoDrone.hover(3); // hover for 3 second
CoDrone.land(); //landing
}
void loop(){
}
takeoff()
Description
This function makes the drone take off and begin hovering. The drone will always hover for 3 seconds in order to stabilize before it executes the next command. If it receives no command for 8 seconds, it will automatically land.
Syntax
takeoff()
Parameters
None
Returns
None
Example Code
//Arduino code
#include<CoDrone.h> //header
void setup(){
//below this have to code in setup
//open serial and connect
CoDrone.begin(115200);
CoDrone.pair(Nearest);
CoDrone.takeoff(); // take off and hover for 3 second
CoDrone.hover(3); // hover for 3 second
CoDrone.land(); //landing
}
void loop(){
}
Flight Commands (Movement)
flySequence()
Description
This function make drone fly specific shape and hover after finish. The options are square, circle, spiral, triangle, hop, sway, zigzag
Syntax
flySequence(sequence)
Parameters
const Sequence: SQUARE, CIRCLE, SPIRAL, TRIANGLE, HOP, SWAY, ZIGZAG
Returns
None
Example Code
//Arduino code
#include<CoDrone.h> //header
void setup(){
//open serial and connect
CoDrone.begin(115200);
CoDrone.pair(Nearest);
CoDrone.takeoff();
CoDrone.flySequence(TRIANGLE); // Fly triangle shape
CoDrone.flySequence(SPIRAL); // Fly spiral shape
CoDrone.flySequence(SQUARE); // Fly square (right -> forward -> left -> backward)
CoDrone.land();
}
void loop(){
}
goToHeight()
Description
This is a setter function will make the drone fly to the given height above the object directly below its IR sensor (usually the ground). It’s effective between 20 and 2000 millimeters. It uses the IR sensor to continuously check for its height.
Syntax
goToHeight(height)
Parameters
height: An int from 20 to 2000 in millimeters
Returns
None
Example Code
//Arduino code
#include<CoDrone.h> //header
void setup(){
//open serial and connect
CoDrone.begin(115200);
CoDrone.pair(Nearest);
CoDrone.takeoff();
CoDrone.goToHeight(1000); // Fly 1000mm away from bottom and hover
}
void loop(){
}
go()
Description
A simpler Junior level function that represents positive flight with a direction, but with more natural language. It simply flies in the given direction for the given duration and power.
Syntax
go(direction)
go(direction, duration)
go(direction, duration, power)
Parameters
const Direction: a constant in Arduino. It’s the direction of the flight, which can be one of the following: FORWARD, BACKWARD, LEFT, RIGHT, UP, and DOWN.
duration: the duration of the flight motion in seconds. If undefined, defaults to 1 seconds. If duration is 0, it will turn right indefinitely.
power: the power at which the drone flies forward. Takes a value from 0 to 100. Defaults to 50 if not defined.
Returns
None
Example Code
//Arduino code
#include<CoDrone.h> //header
void setup(){
//open serial and connect
CoDrone.begin(115200);
CoDrone.pair(Nearest);
CoDrone.takeoff();
CoDrone.go(FORWARD); // Go forward at 50% power for 1 second
CoDrone.go(UP, 5); // Go up for 5 seconds at 50% power
CoDrone.go(BACKWARD, 3, 70) // Go backwards for 3 seconds at 70% power
}
void loop(){
}
hover()
Description
This function makes the drone hover for a given amount of time. If you enter a 0 or None, it will hover indefinitely until given a another command.
Syntax
hover(duration)
Parameters
duration: the duration of the hovering in seconds.
Returns
None
Example Code
//Arduino code
#include<CoDrone.h>
void setup(){
//open serial and connect
CoDrone.begin(115200);
CoDrone.pair(Nearest);
CoDrone.takeoff(); // take off and hover for 3 second
CoDrone.hover(3); // hover for 3 second
CoDrone.land(); //landing
}
void loop(){
}
rotate180()
Description
This function makes the drone rotate 180 degrees. Only rotates in a random direction, because this is a pre-set flight event in the firmware.
Syntax
rotate180()
Parameters
None
Returns
None
Example Code
turnDegree()
Description
A Senior level function that yaws by a given degree in a given direction. This function takes an input degree in an input direction, and turns until it reaches the given degree. In some instances, the drone may turn past the given degree and need to rotate all the way around again before reaching the correct degree.
Syntax
turnDegree(direction, degree)
Parameters
const Direction: LEFT or RIGHT
const Degree: a constant in Arduino. The degree the drone will turn to the right, with its starting position representing 0 degrees, ANGLE_30, ANGLE_45, ANGLE_60, ANGLE_90, ANGLE_120, ANGLE_135, ANGLE_150, ANGLE_180, ANGLE_210, ANGLE_225, ANGLE_240, ANGLE_270, ANGLE_300, ANGLE_315, ANGLE_330
Returns
None
Example Code
//Arduino code
#include<CoDrone.h> //header
void setup(){
//open serial and connect
CoDrone.begin(115200);
CoDrone.pair(Nearest);
CoDrone.takeoff();
CoDrone.turnDegree(LEFT, ANGLE_45); // Turn left 45 degrees
}
void loop(){
}
turn()
Description
A function that represents yaw, but with more natural language. It simply turns in the given direction, duration and power.
Syntax
turn(direction)
turn(direction, duration)
turn(direction, duration, power)
Parameters
const Direction: a constant in Arduino. It’s the direction of the turn, which can be one of the following: LEFT or RIGHT.
duration: the duration of the turn in seconds. If 0, it will turn right indefinitely. Defaults to 1 second if not defined.
power: the power at which the drone turns right. Takes a value from 0 to 100. Defaults to 50 if not defined.
Returns
None
Example Code
//Arduino code
#include<CoDrone.h> //header
void setup(){
//open serial and connect
CoDrone.begin(115200);
CoDrone.pair(Nearest);
CoDrone.takeoff();
CoDrone.turn(LEFT); // Turn left for 1 second at 50 power
CoDrone.turn(LEFT, 0); // Turn left at 50 power indefinitely
CoDrone.turn(RIGHT, 5, 100); // Turn right for 5 seconds at 100 power
}
void loop(){
}
Flight Variables
getPitch()
Description
This is a getter function that gets the value of the pitch variable.
Syntax
getPitch()
Parameters
None
Returns
power: The power of the pitch variable (int)
Example Code
//Arduino code
#include<CoDrone.h> //header
void setup(){
//open serial and connect
CoDrone.begin(115200);
CoDrone.pair(Nearest);
// save current pitch value in variable “current_pitch”
int current_pitch = CoDrone.getPitch();
}
void loop(){
}