example showing how to setup keyboard control of Parrot Bebop 2 drone.
WARNING: this program does no sensing or avoiding of obstacles, the drone WILL collide with any objects in the way! Make sure the drone has about 3-4 meters of free space around it before starting the program.
This program makes the drone controllable with a keyboard, with display of the video streaming.
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpTime.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/io/vpKeyboard.h>
#include <visp3/robot/vpRobotBebop2.h>
#include <iostream>
#ifdef VISP_HAVE_ARSDK
#ifdef ENABLE_VISP_NAMESPACE
#endif
{
bool running = true;
switch (key) {
case 'q':
running = false;
break;
case 'e':
running = false;
break;
case 't':
break;
case ' ':
break;
case 'i':
break;
case 'k':
break;
case 'l':
break;
case 'j':
break;
case 'r':
break;
case 'f':
break;
case 'd':
break;
case 'g':
break;
default:
break;
}
}
else {
running = false;
}
return running;
}
int main(int argc, char **argv)
{
try {
std::string ip_address = "192.168.42.1";
int stream_res = 0;
bool verbose = false;
for (int i = 1; i < argc; i++) {
if (std::string(argv[i]) == "--ip" && i + 1 < argc) {
ip_address = std::string(argv[i + 1]);
i++;
}
else if (std::string(argv[i]) == "--hd_stream") {
stream_res = 1;
}
else if (std::string(argv[i]) == "--verbose" || std::string(argv[i]) == "-v") {
verbose = true;
}
else if (argc >= 2 && (std::string(argv[1]) == "--help" || std::string(argv[1]) == "-h")) {
std::cout << "\nUsage:\n"
<< " " << argv[0] << "[--ip <drone ip>] [--hd_stream] [--verbose] [-v] [--help] [-h]\n"
<< std::endl
<< "Description:\n"
<< " --ip <drone ip>\n"
<< " Ip address of the drone to which you want to connect (default : 192.168.42.1).\n\n"
<< " --hd_stream\n"
<< " Enables HD 720p streaming instead of default 480p.\n"
<< " --verbose, -v\n"
<< " Enables verbose (drone information messages and velocity commands\n"
<< " are then displayed).\n\n"
<< " --help, -h\n"
<< " Print help message.\n"
<< std::endl;
return EXIT_SUCCESS;
}
else {
std::cout << "Error : unknown parameter " << argv[i] << std::endl
<< "See " << argv[0] << " --help" << std::endl;
return EXIT_FAILURE;
}
}
std::cout << "\nWARNING: this program does no sensing or avoiding of obstacles, "
"the drone WILL collide with any objects in the way! Make sure the "
"drone has approximately 3 meters of free space on all sides.\n"
<< std::endl;
ip_address);
if (drone.isRunning()) {
int k = 0;
bool running = true;
std::cout << "\nConfiguring drone settings ...\n" << std::endl;
drone.setMaxTilt(10);
drone.doFlatTrim();
#ifdef VISP_HAVE_FFMPEG
drone.setVideoResolution(stream_res);
drone.setStreamingMode(0);
std::cout << "\nWaiting for streaming to start ...\n" << std::endl;
drone.startStreaming();
drone.getRGBaImage(I);
vpDisplayX display(I, 100, 100, "DRONE VIEW");
#endif
std::cout << "\n| Control the drone with the keyboard :\n"
"| 't' to takeoff / spacebar to land / 'e' for emergency stop\n"
"| ('r','f','d','g') and ('i','k','j','l') to move\n"
"| 'q' to quit.\n"
<< std::endl;
while (running && drone.isRunning() && drone.isStreaming()) {
k = '0';
}
running = handleKeyboardInput(drone, k);
#ifdef VISP_HAVE_FFMPEG
drone.getRGBaImage(I);
#endif
}
std::cout << "\nQuitting ...\n" << std::endl;
}
else {
std::cout << "ERROR : failed to setup drone control." << std::endl;
return EXIT_FAILURE;
}
}
std::cout << "\nCaught an exception: " << e << std::endl;
return EXIT_FAILURE;
}
}
#else
int main()
{
std::cout << "\nThis example requires Parrot ARSDK3 library. You should install it.\n" << std::endl;
return EXIT_SUCCESS;
}
#endif
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
Keyboard management under unix (Linux or OSX). This class is not available under windows.
void setVerticalSpeed(int value)
void setYawSpeed(int value)
void takeOff(bool blocking=true)
VISP_EXPORT int wait(double t0, double t)