Here we provide short descriptions of some of the more useful CoDrone functions included in the CoDrone Arduino Library.  This page will be updated as the CoDrone library develops.

Screen Shot 2016-05-21 at 4.18.32 PM
Contents:
  1. Begin
  2. Connect
  3. LEDs
  4. Control
  5. Events
  6. Receive
  7. Link Bluetooth
  8. Battle
  9. Trim
  10. Miscellaneous


Begin

#include <CoDrone.h>

  • The #include function tells Arduino that we plan to use the CoDrone.h library.
  • This allows the use of all CoDrone class functions and variables.
  • Be sure to include this line at the top of your code, before void setup().

CoDrone.begin(115200);

  • The begin function initializes the serial connection between the Smart Inventor board and the Bluetooth Module.
  • 115200 is the Baud rate of the serial connection.  This must be set to 115200.
  • This function must appear at the beginning of your code within void setup() to allow data to be sent to and from the Bluetooth Module.

Connect

AutoConnect(NearbyDrone);

  • Automatically connect to a nearby CoDrone.  
  • The code will not move past this function until a connection has been found.

AutoConnect(ConnectedDrone);

  • Automatically connect to the previously connected CoDrone.  
  • The code will not move past this function until a connection has been found.

AutoConnect(AddressInputDrone, droneAddress);

  • Automatically connect to the specified CoDrone
  • Replace AddressInputDrone with your specific drone’s address (see PrintDroneAddress()).
  • The code will not move past this function until a connection has been found.

Send_Disconnect();

  • Disconnect from the currently connected drone.

PrintDroneAddress();

  • Print the unique address of the current drone to the serial monitor.
  • The controller must be plugged into the computer

Example


  LEDs

When changing the CoDrone’s LEDs, keep in mind that the color change will remain until a new color is sent or the drone is powered off.

LedColor(mode, color, interval);

  • Set the mode, color and interval of the drone’s LEDs using a preset color (color table below)

LedColor(mode, R, G, B, interval);

  • Set the mode, color and interval of the drone’s LEDs using R B G values.  
  • Each R B G value can range from 0 to 255.

The LED functions utilize three settings:

Mode : The mode determines which LEDs to control and the style of control

Color : The color setting allows the user to select the color of the LED.  The user can choose a preset color, or an RGB color combination. 

Interval : The interval determines the interval of the selected mode.  If flicker is selected, the rate of flickering will be determined by the interval.  This number can range from 0 to 255. 

EyeNone

EyeHold

EyeMix

EyeFlicker

EyeFlickerDouble

EyeDimming

ArmNone

ArmHold

ArmMix,

ArmFlicker

ArmFlickerDouble

ArmDimming

ArmFlow

ArmFlowReverse

AliceBlue, AntiqueWhite, Aqua,  Aquamarine, Azure, Beige,  Bisque, Black,

BlanchedAlmond,  Blue, BlueViolet, Brown,BurlyWood, CadetBlue, Chartreuse,

Chocolate, Coral, CornflowerBlue,  Cornsilk, Crimson, Cyan, DarkBlue, DarkCyan,

DarkGoldenRod,  DarkGray, DarkGreen, DarkKhaki,  DarkMagenta, DarkOliveGreen,

DarkOrange, DarkOrchid, DarkRed,DarkSalmon,  DarkSeaGreen, DarkSlateBlue,

Darkslategray, darkturquois to, darkviolet, deepp Link, deepskyblu to,dimgray,

DodgerBlue,FireBrick, FloralWhite, ForestGreen,  Fuchsia, Gainsboro, GhostWhite,

Gold, GoldenRod, Gray, Green,GreenYellow, HoneyDew,  HotPink, IndianRed, Indigo,

Ivory, Khaki, Lavender,  LavenderBlush, LawnGreen, LemonChiffon,LightBlue,

LightCoral, LightCyan, LightGoldenRodYellow, LightGray, LightGreen,  LightPink,

LightSalmon, LightSeaGreen,LightSkyBlue, LightSlateGray, LightSteelBlue, LightYellow,

Lime, LimeGreen, Linen, Magenta, Maroon, MediumAquaMarine,MediumBlue,

MediumOrchid, MediumPurple, MediumSeaGreen, MediumSlateBlue,MediumSpringGreen,

MediumTurquoise,MediumVioletRed,  MidnightBlue, MintCream,MistyRose, Moccasin,

NavajoWhite, Navy, OldLace, Olive, OliveDrab, Orange,OrangeRed,Orchid,PaleGoldenRod,

PaleGreen, PaleTurquoise, PaleVioletRed, PapayaWhip, PeachPuff,Peru, Pink, Plum,

PowderBlue, Purple, RebeccaPurple,Red, RosyBrown, RoyalBlue,SaddleBrown, Salmon,

SandyBrown, SeaGreen, SeaShell,Sienna, Silver, SkyBlue,SlateBlue, SlateGray,Snow,

SpringGreen, SteelBlue, Tan, Teal, Thistle, Tomato, Turquoise, Violet,Wheat, White,

WhiteSmoke, Yellow, YellowGreen

Example

 


Control

Control();

  • Send the steering maneuvers to the CoDrone.  Leaving the field empty defaults to 50 (ms).

Control(Interval);

  • Send the steering maneuvers to the CoDrone at the set interval.  The interval is a number in milliseconds.  The default is 50 (ms).  Using the variable SEND_INTERVAL sends 50 (ms). 

The CoDrone is controlled by four variables:

Throttle: The vertical up and down movement of the drone

Yaw: The left and right rotation of the where the drone is facing

Roll: The left and right movement of the drone

Pitch: The backward and forward movement of the drone

Learn more here

Each set of motor commands must be followed by a Control() command.  This sends the manuever to the drone for execution.

Interval: The interval determines the rate of the send command.  The default is 50 (ms).  Communication with the drone occurs at intervals of 50ms.

 

Example


Events

DroneModeChange(event);

  • Sets the mode of the drone.  
  • Flight mode sets the drone into fly mode for default drone flight, controlling all 4 motors
  • Drive mode sets the drone into drive mode for the car wheels configuration, controlling only the front two motors.
  • Using modes that do not fit the hardware of the drone will lead to performance issues
  • The CoDrone’s mode will be saved even after the drone is turned off

Example

 

FlightEvent(event);

  • Sends the event to the CoDrone
  • Events are often short maneuvers such as TakeOff, Landing and Flip

Takeoff

FlipFront

FlipRear

FlipLeft

FlipRight

Stop

Landing

Reverse

Shot

UnderAttack

CircleLeft

CircleRight

Rotate180

Example


Receive

Receive();

  • Receives and processes the information from the CoDrone and stores the information into the proper variables.
  • Note that you need to request information from the CoDrone so that the CoDrone will send the information.

LowBatteryCheck(Level);

  • Gets the battery level and checks to see if it has dropped below Level percentage. If it is below Level it will beep a warning sound 5 times.
  • Level can be a value from 0 to 100

Example


Link Bluetooth

Send_LinkModeBroadcast(Mode);

  • Changes the mode of the communication between the SmartInventor board and the Bluetooth board to the inputted mode.
  • LinkModeMute: Stops communicating with the the Bluetooth module so that it can communicate to the computer for downloading programs and using the Serial monitor.
  • LinkModeActive: Uses the Bluetooth module to communicate with the CoDrone
  • LinkModePassive: Uses the Bluetooth communications, but it does not send any messages out from the board.

LowBatteryCheck(Level);

  • Gets the battery level and checks to see if it has dropped below Level percentage. If it is below Level it will beep a warning sound 5 times.
  • Level can be a value from 0 to 100

Example

LinkReset();

  • Reset the connection between the SmartInventor board and the Bluetooth board
  • Any CoDrones that are paired with the controller will be unpaired

Example


Battle

BattleBegin(TeamSelect);

  • Battle Begin initiates the battle mode, and Team Select allows the player to select a team:
    • TEAM_RED/TEAM_BLUE/TEAM_GREEN/TEAM_YELLOW/FREE_PLAY
  • Players on the same team cannot take damage from each other.  Free Players can take damage from anyone.
  • Team color will be reflected by the drone’s LED lights
  • Each player begins with 8 hit points.  Each time the player is shot, they lose 1 hit point.  When the player has 0 hit points, the drone is out.

BattleShooting();

  • Commands the CoDrone to shoot
  • The drone will also ‘recoil’ from the shot and move backwards slightly
  • Each shot does 1 hit point of damage

BattleReceive();

  • Checks if the drone was attacked
  • If the drone was attacked, the LED and buzzer will activate for a short period

CrashCustom(boolean custom);

  • Set to true to enable “CrashedCheck()” function
  • Default is false

boolean CrashedCheck();

  • Returns True is the CoDrone is out of HP
  • Returns False otherwise
  • Only works when CrashedCustom is set to true (i.e. CrashedCustom(true);)

BattleHitPoints(int points);

  • Sets the starting hit points for battle
  • range from 1-8
  • default is 8 hit points

Example


Trim

These functions show how to set the trim of the CoDrone. The trim is a offset to remove the problems of motors moving at different speeds. This is what helps to make the CoDrone fly straight and be able to hover in place.  Learn more here.

Trim is retained on the CoDrone even when it is turned off.

Set_Trim(Direction);

  • Adjusts the current value of the trim depending on the event. It will move the trim by 1 in the direction specified by the event.

 

RollIncrease

RollDecrease

PitchIncrease

PitchDecrease

YawIncrease

YawDecrease

ThrottleIncrease

ThrottleDecrease

 

Set_TrimAll(Roll, Pitch, Yaw, Throttle, Wheel);

  • Sets the trim to the given values for each direction. It sets the trims not just for the flight, but also for the steering (wheel, used in drive mode). Each value must be from -500 to 500.

Set_TrimFlight(Roll, Pitch, Yaw, Throttle);

  • Sets the trim to the given values for each direction. It sets the trims just for the flight. Each value must be from -500 to 500.

Set_TrimDrive(Wheel);

  • Sets the trim for the drive mode.

Example


Miscellaneous

ButtonPreesHoldWait(button);

  • Sets a delay while the button is pressed.  This prevents the button from being pressed multiple times on accident

ButtonPreesHoldWait(button,button);

  • Sets a delay while the buttons are pressed.  This prevents the button from being pressed multiple times on accident.  

AnalogScaleChange(AnalogValue);

  • Remaps the input range of an analog joystick (from 0 to 1023).  The range is defined from -100 to 100.
  • The CoDrone Remote joystick value sends analog values of 0 to 1023.  To use these values in our PITCH ROLL YAW THROTTLE commands, we use AnalogScaleChange to remap the values to value ranging from -100 to 100.

Buzz(frequency, tempo);

  • Tells the CoDrone remote to make a buzzing noise from the buzzer.  The frequency and tempo of the the buzz can be set

BeepWarning(count);

  • Tells the CoDrone remote to make a beeping noise
  • Set the amount of beeps in count