45 #include <visp3/core/vpConfig.h>
48 #if defined(VISP_HAVE_MAVSDK) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
50 #include <visp3/core/vpTime.h>
51 #include <visp3/gui/vpDisplayX.h>
52 #include <visp3/io/vpKeyboard.h>
53 #include <visp3/robot/vpRobotMavsdk.h>
55 #ifdef ENABLE_VISP_NAMESPACE
58 bool handleKeyboardInput(vpRobotMavsdk &drone,
int key,
bool &flying,
double &lastCommandTime)
62 if (drone.isRunning()) {
66 std::cout <<
"sending command" << std::endl;
76 std::cout <<
"sending command" << std::endl;
85 std::cout <<
"sending command" << std::endl;
94 std::cout <<
"sending command" << std::endl;
104 if (flying ==
true) {
105 drone.setVerticalSpeed(0.2);
112 if (flying ==
true) {
113 drone.setVerticalSpeed(-0.2);
120 if (flying ==
true) {
121 drone.setYawSpeed(0.4);
128 if (flying ==
true) {
129 drone.setYawSpeed(-0.4);
136 if (flying ==
true) {
137 drone.setForwardSpeed(0.2);
144 if (flying ==
true) {
145 drone.setForwardSpeed(-0.2);
152 if (flying ==
true) {
153 drone.setLateralSpeed(-0.2);
160 if (flying ==
true) {
161 drone.setLateralSpeed(0.2);
168 if ((flying ==
true) && (currentTime - lastCommandTime > 1500.)) {
169 std::cout <<
"1.5 s without order, sending command : stop moving." << std::endl;
183 int main(
int argc,
char **argv)
186 std::string opt_connecting_info =
"udp://192.168.30.111:14552";
188 for (
int i = 1; i < argc; i++) {
189 if (std::string(argv[i]) ==
"--co" && i + 1 < argc) {
190 opt_connecting_info = std::string(argv[i + 1]);
193 else if (argc >= 2 && (std::string(argv[1]) ==
"--help" || std::string(argv[1]) ==
"-h")) {
194 std::cout <<
"\nUsage:\n"
195 <<
" " << argv[0] <<
"[--co <connection information>] [--help] [-h]\n"
198 <<
" --co <connection information>\n"
199 <<
" - UDP: udp://[host][:port]\n"
200 <<
" - TCP: tcp://[host][:port]\n"
201 <<
" - serial: serial://[path][:baudrate]\n"
202 <<
" - Default: udp://192.168.30.111:14552).\n\n"
203 <<
" For example, to connect to the simulator use URL: udp://:14552\n"
205 <<
" Print help message.\n"
210 std::cout <<
"Error : unknown parameter " << argv[i] << std::endl
211 <<
"See " << argv[0] <<
" --help" << std::endl;
216 std::cout << std::endl
217 <<
"WARNING: this program does no sensing or avoiding of obstacles, "
218 <<
"the drone WILL collide with any objects in the way! Make sure the "
219 <<
"drone has approximately 3 meters of free space on all sides." << std::endl
223 vpRobotMavsdk drone(opt_connecting_info);
225 if (drone.isRunning()) {
231 std::cout <<
"\nConfiguring drone settings ...\n" << std::endl;
233 drone.setTakeOffAlt(1.0);
236 std::cout <<
"\n| Control the drone with the keyboard :\n"
237 "| 't' to takeoff / 'l' to land / 'e' for emergency stop\n"
238 "| ('space','u','d','g') and ('i','k','j','l') to move\n"
242 while (running && drone.isRunning()) {
245 if (keyboard.
kbhit()) {
248 running = handleKeyboardInput(drone, k, flying, lastCommandTime);
250 std::cout <<
"\nQuitting ...\n" << std::endl;
254 std::cout <<
"ERROR : failed to setup drone control." << std::endl;
259 std::cout <<
"\nCaught an exception: " << e << std::endl;
268 #ifndef VISP_HAVE_MAVSDK
269 std::cout <<
"\nThis example requires mavsdk library. You should install it, configure and rebuid ViSP.\n"
272 #if !((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
274 <<
"\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and "
error that can be emitted by ViSP classes.
Keyboard management under unix (Linux or OSX). This class is not available under windows.
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()