Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
testPixhawkDroneVelocityControl.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 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 https://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 * Simple example to demonstrate how to control in velocity using mavsdk
33 * a drone equipped with a Pixhawk connected to a Jetson TX2.
34 *
35*****************************************************************************/
36
46#include <iostream>
47
48#include <visp3/core/vpConfig.h>
49
50#if defined(VISP_HAVE_MAVSDK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17)
51
52#include <thread>
53#include <visp3/robot/vpRobotMavsdk.h>
54
55using std::chrono::seconds;
56using std::this_thread::sleep_for;
57
58void usage(const std::string &bin_name)
59{
60 std::cerr << "Usage : " << bin_name << " <connection information>\n"
61 << "Connection URL format should be :\n"
62 << " - For TCP : tcp://[server_host][:server_port]\n"
63 << " - For UDP : udp://[bind_host][:bind_port]\n"
64 << " - For Serial : serial:///path/to/serial/dev[:baudrate]\n"
65 << "For example, to connect to the simulator use URL: udp://:14540\n";
66}
67
68int main(int argc, char **argv)
69{
70 if (argc != 2) {
71 usage(argv[0]);
72 return EXIT_SUCCESS;
73 }
74
75 auto drone = vpRobotMavsdk(argv[1]);
76
77 drone.setTakeOffAlt(.5);
78 if (! drone.takeOff() )
79 {
80 std::cout << "Takeoff failed" << std::endl;
81 return EXIT_FAILURE;
82 }
83 vpColVector vel_command{0.0, 0.0, 0.0, 0.0};
84
85 drone.setForwardSpeed(0.3);
86 std::cout << "Set forward speed of 0.3 m/s for 4 sec" << std::endl;
87 sleep_for(seconds(4));
88
89 drone.setForwardSpeed(-0.3);
90 std::cout << "Set forward speed of -0.3 m/s for 4 sec" << std::endl;
91 sleep_for(seconds(4));
92
93 drone.stopMoving();
94 std::cout << "Stop moving for 4 sec" << std::endl;
95 sleep_for(seconds(4));
96
97 std::cout << "Land now..." << std::endl;
98 drone.land();
99
100 return EXIT_SUCCESS;
101}
102
103#else
104
105int main()
106{
107#ifndef VISP_HAVE_MAVSDK
108 std::cout << "\nThis example requires mavsdk library. You should install it, configure and rebuid ViSP.\n"
109 << std::endl;
110#endif
111#if !(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17)
112 std::cout
113 << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and "
114 "rebuild ViSP.\n"
115 << std::endl;
116#endif
117 return EXIT_SUCCESS;
118}
119
120#endif // #if defined(VISP_HAVE_MAVSDK)
Implementation of column vector and the associated operations.