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