47 #include <visp3/core/vpConfig.h>
50 #if defined(VISP_HAVE_MAVSDK) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
52 #include <visp3/core/vpTime.h>
53 #include <visp3/gui/vpDisplayX.h>
54 #include <visp3/io/vpKeyboard.h>
55 #include <visp3/robot/vpRobotMavsdk.h>
57 bool handleKeyboardInput(vpRobotMavsdk &drone,
int key,
bool &flying,
double &lastCommandTime)
61 if (drone.isRunning()) {
65 std::cout <<
"sending command" << std::endl;
75 std::cout <<
"sending command" << std::endl;
84 std::cout <<
"sending command" << std::endl;
93 std::cout <<
"sending command" << std::endl;
103 if (flying ==
true) {
104 drone.setVerticalSpeed(0.2);
111 if (flying ==
true) {
112 drone.setVerticalSpeed(-0.2);
119 if (flying ==
true) {
120 drone.setYawSpeed(0.4);
127 if (flying ==
true) {
128 drone.setYawSpeed(-0.4);
135 if (flying ==
true) {
136 drone.setForwardSpeed(0.2);
143 if (flying ==
true) {
144 drone.setForwardSpeed(-0.2);
151 if (flying ==
true) {
152 drone.setLateralSpeed(-0.2);
159 if (flying ==
true) {
160 drone.setLateralSpeed(0.2);
167 if ((flying ==
true) && (currentTime - lastCommandTime > 1500.)) {
168 std::cout <<
"1.5 s without order, sending command : stop moving." << std::endl;
182 int main(
int argc,
char **argv)
185 std::string opt_connecting_info =
"udp://192.168.30.111:14552";
187 for (
int i = 1; i < argc; i++) {
188 if (std::string(argv[i]) ==
"--co" && i + 1 < argc) {
189 opt_connecting_info = std::string(argv[i + 1]);
192 else if (argc >= 2 && (std::string(argv[1]) ==
"--help" || std::string(argv[1]) ==
"-h")) {
193 std::cout <<
"\nUsage:\n"
194 <<
" " << argv[0] <<
"[--co <connection information>] [--help] [-h]\n"
197 <<
" --co <connection information>\n"
198 <<
" - UDP: udp://[host][:port]\n"
199 <<
" - TCP: tcp://[host][:port]\n"
200 <<
" - serial: serial://[path][:baudrate]\n"
201 <<
" - Default: udp://192.168.30.111:14552).\n\n"
202 <<
" For example, to connect to the simulator use URL: udp://:14552\n"
204 <<
" Print help message.\n"
209 std::cout <<
"Error : unknown parameter " << argv[i] << std::endl
210 <<
"See " << argv[0] <<
" --help" << std::endl;
215 std::cout << std::endl
216 <<
"WARNING: this program does no sensing or avoiding of obstacles, "
217 <<
"the drone WILL collide with any objects in the way! Make sure the "
218 <<
"drone has approximately 3 meters of free space on all sides." << std::endl
222 vpRobotMavsdk drone(opt_connecting_info);
224 if (drone.isRunning()) {
230 std::cout <<
"\nConfiguring drone settings ...\n" << std::endl;
232 drone.setTakeOffAlt(1.0);
235 std::cout <<
"\n| Control the drone with the keyboard :\n"
236 "| 't' to takeoff / 'l' to land / 'e' for emergency stop\n"
237 "| ('space','u','d','g') and ('i','k','j','l') to move\n"
241 while (running && drone.isRunning()) {
244 if (keyboard.
kbhit()) {
247 running = handleKeyboardInput(drone, k, flying, lastCommandTime);
249 std::cout <<
"\nQuitting ...\n" << std::endl;
253 std::cout <<
"ERROR : failed to setup drone control." << std::endl;
258 std::cout <<
"\nCaught an exception: " << e << std::endl;
267 #ifndef VISP_HAVE_MAVSDK
268 std::cout <<
"\nThis example requires mavsdk library. You should install it, configure and rebuid ViSP.\n"
271 #if !((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
273 <<
"\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()