Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
testPixhawkRoverVelocityControl.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 * Simple example to demonstrate how to control in velocity using mavsdk
32 * a drone equipped with a Pixhawk connected to a Jetson TX2.
33 */
34
43
44#include <iostream>
45
46#include <visp3/core/vpConfig.h>
47
48// Check if std:c++17 or higher
49#if defined(VISP_HAVE_MAVSDK) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) \
50 && defined(VISP_HAVE_THREADS)
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#ifdef ENABLE_VISP_NAMESPACE
71 using namespace VISP_NAMESPACE_NAME;
72#endif
73 if (argc != 2) {
74 usage(argv[0]);
75 return EXIT_SUCCESS;
76 }
77
78 auto robot = vpRobotMavsdk(argv[1]);
79
80 if (!robot.setGPSGlobalOrigin(48.117266, -1.6777926, 40.0)) {
81 return EXIT_FAILURE;
82 }
83
84 std::cout << "Vehicle has flying capability: " << (robot.hasFlyingCapability() ? "yes" : "no") << std::endl;
85 robot.arm();
86
87 double delta_north = 1.;
88 double delta_east = 0.;
89 double delta_down = 0.;
90 double delta_yaw = 0.;
91
92 std::cout << "Move 1 meter north" << std::endl;
93 robot.setPositionRelative(delta_north, delta_east, delta_down, delta_yaw);
94
95 vpColVector frd_vel { 0.0, 0.0, 0.0, 0.0 };
96 frd_vel[0] = -0.3; // forward vel m/s
97 //frd_vel[3]= vpMath::rad(10.);
98
99 std::cout << "Go at 0.3m/s backward during 3 sec.\n";
100 robot.setVelocity(frd_vel);
101 vpTime::wait(3000);
102
103 std::cout << "Go at 0.3m/s forward and rotate 10 deg/s along yaw during 2 sec.\n";
104 frd_vel[0] = 0.3; // forward vel m/s
105 frd_vel[3] = vpMath::rad(10.); // yaw vel 10 deg/s converted in rad/s
106
107 double t = vpTime::measureTimeMs();
108 do {
109 vpTime::sleepMs(20);
110 robot.setVelocity(frd_vel);
111 } while (vpTime::measureTimeMs() - t < 2000.); //
112
113 robot.disarm();
114 return EXIT_SUCCESS;
115}
116
117#else
118
119int main()
120{
121#ifndef VISP_HAVE_MAVSDK
122 std::cout << "\nThis example requires mavsdk library. You should install it, configure and rebuild ViSP.\n"
123 << std::endl;
124#endif
125#if !((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
126 std::cout
127 << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and "
128 "rebuild ViSP.\n"
129 << std::endl;
130#endif
131 return EXIT_SUCCESS;
132}
133
134#endif // #if defined(VISP_HAVE_MAVSDK)
Implementation of column vector and the associated operations.
static double rad(double deg)
Definition vpMath.h:129
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT void sleepMs(double t)