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