1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
/*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact Inria about acquiring a ViSP Professional
* Edition License.
*
* See https://visp.inria.fr for more information.
*
* This software was developed at:
* Inria Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
*
* If you have questions regarding the use of this file, please contact
* Inria at visp@inria.fr
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
* Interface for the Irisa's Afma6 robot.
*/
/*!
\example testRobotBebop2.cpp
Example to control Parrot Bebop2.
*/
#include <iostream>
#include <visp3/core/vpTime.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/robot/vpRobotBebop2.h>
int main(int argc, char **argv)
{
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
#ifdef VISP_HAVE_ARSDK
try {
int stream_res = 0;
std::string ip_address = "192.168.42.1";
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-resolution") {
stream_res = 1;
}
else if (std::string(argv[i]) == "--verbose" || std::string(argv[i]) == "-v") {
verbose = true;
}
else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
std::cout << "\nUsage:\n"
<< " " << argv[0] << " [--ip <drone ip>] [--hd-resolution] [--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-resolution\n"
<< " Enables HD 720p video instead of default 480p.\n\n"
<< " --verbose, -v\n"
<< " Enables verbose (drone information messages are then displayed).\n\n"
<< " --help, -h\n"
<< " Print help message.\n\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;
}
}
vpRobotBebop2 drone(
verbose, true, ip_address); // Create the drone with desired verbose level, settings reset, and corresponding IP
if (drone.isRunning()) {
drone.setVideoResolution(stream_res); // Set video resolution to 480p (default) or 720p
drone.startStreaming(); // Start video decoding and streaming
vpImage<vpRGBa> I(1u, 1u, vpRGBa(0));
drone.getRGBaImage(I); // Get color image from the drone video stream
#ifdef VISP_HAVE_X11
vpDisplayX d(I);
#elif defined(VISP_HAVE_GDI)
vpDisplayGDI d(I);
#elif defined(HAVE_OPENCV_HIGHGUI)
vpDisplayOpenCV d(I);
#else
std::cout << "No image viewer is available..." << std::endl;
#endif
vpDisplay::display(I);
vpDisplay::flush(I);
drone.doFlatTrim();
drone.takeOff(true);
vpColVector vel(4, 0.0);
vel[3] = vpMath::rad(10);
double delta_t = 0.040;
double t = vpTime::measureTimeMs();
do { // We make the drone rotate around Z axis for 10 seconds at 10 deg/s
drone.setVelocity(vel, 1);
drone.getRGBaImage(I);
vpDisplay::display(I);
vpDisplay::flush(I);
vpTime::wait(delta_t * 1000);
} while (vpTime::measureTimeMs() - t < 10 * 1000);
drone.land();
}
else {
std::cout << "Error : failed to setup drone control" << std::endl;
}
std::cout << "-- End of test --" << std::endl;
}
catch (const vpException &e) {
std::cout << "Caught an exception: " << e << std::endl;
}
#else
(void)argc;
(void)argv;
std::cout << "Install Parrot ARSDK, configure and build ViSP to use this example..." << std::endl;
#endif
}
|