47#include <visp3/core/vpConfig.h>
49#if defined(VISP_HAVE_MAVSDK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17)
51#include <visp3/core/vpTime.h>
52#include <visp3/gui/vpDisplayX.h>
53#include <visp3/io/vpKeyboard.h>
54#include <visp3/robot/vpRobotMavsdk.h>
56bool handleKeyboardInput(
vpRobotMavsdk &drone,
int key,
bool &flying,
double &lastCommandTime)
64 std::cout <<
"sending command" << std::endl;
74 std::cout <<
"sending command" << std::endl;
83 std::cout <<
"sending command" << std::endl;
92 std::cout <<
"sending command" << std::endl;
102 if (flying ==
true) {
110 if (flying ==
true) {
118 if (flying ==
true) {
126 if (flying ==
true) {
134 if (flying ==
true) {
142 if (flying ==
true) {
150 if (flying ==
true) {
158 if (flying ==
true) {
166 if ((flying ==
true) && (currentTime - lastCommandTime > 1500.)) {
167 std::cout <<
"1.5 s without order, sending command : stop moving." << std::endl;
180int main(
int argc,
char **argv)
183 std::string opt_connecting_info =
"udp://192.168.30.111:14552";
185 for (
int i = 1; i < argc; i++) {
186 if (std::string(argv[i]) ==
"--co" && i + 1 < argc) {
187 opt_connecting_info = std::string(argv[i + 1]);
189 }
else if (argc >= 2 && (std::string(argv[1]) ==
"--help" || std::string(argv[1]) ==
"-h")) {
190 std::cout <<
"\nUsage:\n"
191 <<
" " << argv[0] <<
"[--co <connection information>] [--help] [-h]\n"
194 <<
" --co <connection information>\n"
195 <<
" - UDP: udp://[host][:port]\n"
196 <<
" - TCP: tcp://[host][:port]\n"
197 <<
" - serial: serial://[path][:baudrate]\n"
198 <<
" - Default: udp://192.168.30.111:14552).\n\n"
199 <<
" For example, to connect to the simulator use URL: udp://:14552\n"
201 <<
" Print help message.\n"
205 std::cout <<
"Error : unknown parameter " << argv[i] << std::endl
206 <<
"See " << argv[0] <<
" --help" << std::endl;
211 std::cout << std::endl
212 <<
"WARNING: this program does no sensing or avoiding of obstacles, "
213 <<
"the drone WILL collide with any objects in the way! Make sure the "
214 <<
"drone has approximately 3 meters of free space on all sides." << std::endl
226 std::cout <<
"\nConfiguring drone settings ...\n" << std::endl;
231 std::cout <<
"\n| Control the drone with the keyboard :\n"
232 "| 't' to takeoff / 'l' to land / 'e' for emergency stop\n"
233 "| ('space','u','d','g') and ('i','k','j','l') to move\n"
240 if (keyboard.
kbhit()) {
243 running = handleKeyboardInput(drone, k, flying, lastCommandTime);
245 std::cout <<
"\nQuitting ...\n" << std::endl;
248 std::cout <<
"ERROR : failed to setup drone control." << std::endl;
252 std::cout <<
"\nCaught an exception: " << e << std::endl;
261#ifndef VISP_HAVE_MAVSDK
262 std::cout <<
"\nThis example requires mavsdk library. You should install it, configure and rebuid ViSP.\n"
265#if !(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17)
267 <<
"\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.
bool takeOff(bool interactive=true, int timeout_sec=10, bool use_gps=false)
bool setLateralSpeed(double body_frd_vy)
bool setVerticalSpeed(double body_frd_vz)
bool setForwardSpeed(double body_frd_vx)
void setTakeOffAlt(double altitude)
bool setYawSpeed(double body_frd_wz)
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()