Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
testRobotBebop2.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 http://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  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
46 #include <iostream>
47 
48 #include <visp3/core/vpTime.h>
49 #include <visp3/gui/vpDisplayX.h>
50 #include <visp3/robot/vpRobotBebop2.h>
51 
52 int main(int argc, char **argv)
53 {
54 #ifdef VISP_HAVE_ARSDK
55  try {
56  int stream_res = 0;
57  std::string ip_address = "192.168.42.1";
58  bool verbose = false;
59 
60  for (int i = 1; i < argc; i++) {
61  if (std::string(argv[i]) == "--ip" && i + 1 < argc) {
62  ip_address = std::string(argv[i + 1]);
63  i++;
64  } else if (std::string(argv[i]) == "--hd_resolution") {
65  stream_res = 1;
66  } else if (std::string(argv[i]) == "--verbose" || std::string(argv[i]) == "-v") {
67  verbose = true;
68  } else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
69  std::cout << "\nUsage:\n"
70  << " " << argv[0] << " [--ip <drone ip>] [--hd_resolution] [--verbose] [-v]"
71  << " [--help] [-h]\n"
72  << std::endl
73  << "Description:\n"
74  << " --ip <drone ip>\n"
75  << " IP address of the drone to which you want to connect (default : 192.168.42.1).\n\n"
76  << " --hd_resolution\n"
77  << " Enables HD 720p video instead of default 480p.\n\n"
78  << " --verbose, -v\n"
79  << " Enables verbose (drone information messages are then displayed).\n\n"
80  << "--help, -h\n"
81  << " Print help message.\n\n"
82  << std::endl;
83  return 0;
84  } else {
85  std::cout << "Error : unknown parameter " << argv[i] << std::endl
86  << "See " << argv[0] << " --help" << std::endl;
87  return 0;
88  }
89  }
90 
91  vpRobotBebop2 drone(
92  verbose, true, ip_address); // Create the drone with desired verbose level, settings reset, and corresponding IP
93 
94  if (drone.isRunning()) {
95 
96  drone.setVideoResolution(stream_res); // Set video resolution to 480p (default) or 720p
97 
98  drone.startStreaming(); // Start video decoding and streaming
99 
100  vpImage<vpRGBa> I(1, 1, 0);
101  drone.getRGBaImage(I); // Get color image from the drone video stream
102 
103 #ifdef VISP_HAVE_X11
104  vpDisplayX d(I);
105 #elif defined(VISP_HAVE_GDI)
106  vpDisplayGDI d(I);
107 #elif defined(VISP_HAVE_OPENCV)
108  vpDisplayOpenCV d(I);
109 #else
110  std::cout << "No image viewer is available..." << std::endl;
111 #endif
113  vpDisplay::flush(I);
114 
115  drone.doFlatTrim();
116  drone.takeOff(true);
117 
118  vpColVector vel(4, 0.0);
119  vel[3] = vpMath::rad(10);
120 
121  double delta_t = 0.040;
122  double t = vpTime::measureTimeMs();
123 
124  do { // We make the drone rotate around Z axis for 10 seconds at 10 deg/s
125  drone.setVelocity(vel, 1);
126 
127  drone.getRGBaImage(I);
129  vpDisplay::flush(I);
130 
131  vpTime::wait(delta_t * 1000);
132  } while (vpTime::measureTimeMs() - t < 10 * 1000);
133 
134  drone.land();
135 
136  } else {
137  std::cout << "Error : failed to setup drone control" << std::endl;
138  }
139 
140  std::cout << "-- End of test --" << std::endl;
141  } catch (const vpException &e) {
142  std::cout << "Caught an exception: " << e << std::endl;
143  }
144 #else
145  (void) argc;
146  (void) argv;
147  std::cout << "Install Parrot ARSDK, configure and build ViSP to use this example..." << std::endl;
148 #endif
149 }
VISP_EXPORT int wait(double t0, double t)
Definition: vpTime.cpp:173
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:134
error that can be emited by ViSP classes.
Definition: vpException.h:71
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
Definition: vpTime.cpp:126
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
static double rad(double deg)
Definition: vpMath.h:110
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130