Adding a Crazyflie
Adding a Crazyflie to the Swarm is simple, but tedious. It's basically just replicating a copy of the other Crazyflies code, but there are multiple files you will need to make changes in. The following list should help you locate all the code you need to replicate:
Changes in vrpn.cpp
vrpn_Tracker_Remote *tracker#; extern float xPositionDesired#; extern float yPositionDesired#; extern float zPositionDesired#; extern float yawDesired#; extern float xPosition#; extern float yPosition#; extern float zPosition#; extern CCrazyflie *cflieCopter#; extern double initTime#; extern char takeOff#; extern double takeOffTime#; void vrpn_init(std::string connectionName, void (*callback)(void*, const vrpn_TRACKERCB), void (*callback2)(void*, const vrpn_TRACKERCB), void (*callback#)(void*, const vrpn_TRACKERCB), ......, char *key) { tracker# = new vrpn_Tracker_Remote("Crazyflie2#", connection); tracker#->register_change_handler(0, callback#); tracker#->mainloop();
Changes in nearGround()
void nearGround() //During Landing Mode checks how close to ground quad is for shutdown { ... ... ... if(cflieCopter#){ if((cflieCopter#->m_enumFlightMode == LANDING_MODE) && (zPosition# < 0.05)) { cflieCopter#->m_enumFlightMode = GROUNDED_MODE; } } }
Changes in updateHand()
void updateHand() { if(handMode == 1) { // cout << "Hand Roll: " << rollHand << endl; if(killCount > 5){ ... ... cflieCopter#->m_enumFlightMode = GROUNDED_MODE; } else if(trackCount > 5){ ... ... cflieCopter#->m_enumFlightMode = HAND_MODE; } else{ ... ... if(zPositionHand > 1.6) { ... ... cflieCopter#->m_enumFlightMode = TAKEOFF_MODE; cout << "Hand Mode: Launching Quads" << endl; } else if(zPositionHand < 0.4) { ... ... cflieCopter#->m_enumFlightMode = LANDING_MODE; ... } } } }
Changes in vrpn.h
void vrpn_init(std::string connectionName, void (*callback)(void*, const vrpn_TRACKERCB), void (*callback2)(void*, const vrpn_TRACKERCB), void (*callback#)(void*, const vrpn_TRACKERCB), ...., char *key);
Changes in eris_vrpn.cpp
Global Variables
void VRPN_CALLBACK handle_Crazyflie#(void*, const vrpn_TRACKERCB t); CCrazyRadio *crRadio# = 0; //***NOT NECESSARY IF LESS THAN 3 QUADS PER RADIO*** CCrazyflie *cflieCopter# = 0; ControllerObject pidCtrl# = { 0 }; // init all fields to zero float rollControlOutput#; float pitchControlOutput#; float yawControlOutput#; float thrustControlOutput#; double initTime# = 0; int vrpnPacketBackup# = 0; double vrpnBackupTime# = 0; double vrpnBackupTime#Prev = 0; double vrpnBackupTime#Delta = 0; float xPositionDesired# = 0.681; float yPositionDesired# = 0.129; float zPositionDesired# = 0.6; float yawDesired# = -90.0; float yawDifference# = 0; float quadYaw# = 0; float prevQuadYaw# = 0; float camYawDeg# = 0; float camYawDeg#Off = 0; float quadYaw#Off = 0; float correctedYaw# = 0; float xError# = 0.0; float yError# = 0.0; float xStepPositionError# = 0.0; float yStepPositionError# = 0.0; float xPosition# = -0.012; float yPosition# = -0.008; //Default Crazyflie location setpoints float zPosition# = 0.75; char takeOff# = 0; double loopTime#Start = 0; double loopTime#End = 0; double loopTime# = 0; double loopTime#Prev = 0; double loopTime#Delta = 0; double vrpnPacketTime# = 0; double vrpnPacketTime#Prev = 0; double vrpnPacketDelta# = 0; FILE * out# = NULL;
Changes in main()
controllerResetAllPID( &pidCtrl# ); controllerInit( &pidCtrl# ); vrpn_init("192.168.0.120:3883", handle_pos, handle_Crazyflie2, handle_Crazyflie#, handle_Crazyflie(#+1), ..., &keystroke_now); cflieCopter# = new CCrazyflie(crRadio(radio dongle number), (Radio Channel)); const char * logHeader# = "#Crazyflie# Log File\n\ #Time\t\t........ if(cflieCopter#) { out# = fopen("cflie#.txt", "w"); if(out# == NULL) { printf("Could not open cflie#.log:errno %d\n", errno); exit(-1); } fprintf(out#, "%s\n", logHeader#); } crRadio#->setARDTime(2000); //Sets Wait Time between Packet Retries (**MUST BE IN INCREMENTS OF 250**) crRadio#->setARC(0); //Sets Number of times Retries Packet Send crRadio#->setPower(P_0DBM); cflieCopter#->setSendSetpoints( true ); initTime# = cflieCopter#->currentTime(); cflieCopter#->m_enumFlightMode = GROUNDED_MODE; fclose(out#); delete cflieCopter#; delete crRadio#;