Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple changes #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/examples/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

// System
#include <iostream>
using namespace std;
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glfw.h>
Expand Down
46 changes: 26 additions & 20 deletions src/examples/simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,29 @@


/* \author Jan Winkler */
/* Nishan Nepali */


// System
#include <iostream>

// libcflie
#include <cflie/CCrazyflie.h>


int main(int argc, char **argv) {
CCrazyRadio *crRadio = new CCrazyRadio("radio://0/10/250K");
#include <iostream>
#include <memory>
#include <cflie/CCrazyflie.h>
#include <cflie/CCrazyRadio.h>

if(crRadio->startRadio()) {
CCrazyflie *cflieCopter = new CCrazyflie(crRadio);
bool initializeRadio(std::unique_ptr<CCrazyRadio>& crRadio) {
crRadio = std::make_unique<CCrazyRadio>("radio://0/10/250K");
return crRadio->startRadio();
}

void controlCopter(CCrazyflie* cflieCopter) {
cflieCopter->setThrust(10001);

// Enable sending the setpoints. This can be used to temporarily
// stop updating the internal controller setpoints and instead
// sending dummy packets (to keep the connection alive).
cflieCopter->setSendSetpoints(true);
// Enable sending setpoints and add control logic here.

while(cflieCopter->cycle()) {
// Main loop. Currently empty.
while (cflieCopter->cycle()) {
// Main loop. Currently empty.

/* Examples to set thrust and RPY:

Expand All @@ -75,12 +75,18 @@ int main(int argc, char **argv) {
// Other than that, this example covers pretty much everything
// basic you will need for controlling the copter.
}
}

delete cflieCopter;
} else {
std::cerr << "Could not connect to dongle. Did you plug it in?" << std::endl;
}
int main(int argc, char** argv) {
std::unique_ptr<CCrazyRadio> crRadio;

if (initializeRadio(crRadio)) {
std::unique_ptr<CCrazyflie> cflieCopter(new CCrazyflie(crRadio.get()));
controlCopter(cflieCopter.get());
} else {
std::cerr << "Could not connect to dongle. Did you plug it in?" << std::endl;
}

delete crRadio;
return 0;
// No need to delete, smart pointers will handle it.
return 0;
}