This code shows how to takeoff and land a drone equipped with a Pixhawk connected to a Jetson TX2 that runs this test using ViSP. The drone is localized thanks to Qualisys Mocap. Communication between the Jetson and the Pixhawk is based on Mavlink using MAVSDK 3rd party.
#include <iostream>
#include <visp3/core/vpConfig.h>
#if defined(VISP_HAVE_MAVSDK) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
#include <visp3/robot/vpRobotMavsdk.h>
void usage(const std::string &bin_name)
{
std::cerr << "Usage : " << bin_name << " <connection information>\n"
<< "Connection information format should be :\n"
<< " - For TCP: tcp://[server_host][:server_port]\n"
<< " - For UDP: udp://[bind_host][:bind_port]\n"
<< " - For Serial: serial:///path/to/serial/dev[:baudrate]\n"
<< "For example, to connect to the simulator use URL: udp://:14540\n";
}
int main(int argc, char **argv)
{
#ifdef ENABLE_VISP_NAMESPACE
#endif
if (argc != 2) {
usage(argv[0]);
return EXIT_SUCCESS;
}
auto drone = vpRobotMavsdk(argv[1]);
drone.setTakeOffAlt(1.);
drone.setVerbose(true);
drone.takeControl();
if (!drone.takeOff()) {
std::cout << "Takeoff failed" << std::endl;
return EXIT_FAILURE;
}
float ned_north, ned_east, ned_down, ned_yaw;
drone.getPosition(ned_north, ned_east, ned_down, ned_yaw);
std::cout <<
"Vehicle position in NED frame: " << ned_north <<
" " << ned_east <<
" " << ned_down <<
" [m] and " <<
vpMath::deg(ned_yaw) <<
" [deg]" << std::endl;
drone.getPosition(ned_M_frd);
std::cout << "Vehicle position in NED frame: "
std::cout << "Hold position for 4 sec" << std::endl;
drone.holdPosition();
drone.land();
return EXIT_SUCCESS;
}
#else
int main()
{
#ifndef VISP_HAVE_MAVSDK
std::cout << "\nThis example requires mavsdk library. You should install it, configure and rebuid ViSP.\n"
<< std::endl;
#endif
#if !((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
std::cout
<< "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and "
"rebuild ViSP.\n"
<< std::endl;
#endif
return EXIT_SUCCESS;
}
#endif
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpRotationMatrix getRotationMatrix() const
vpTranslationVector getTranslationVector() const
static double deg(double rad)
Implementation of a rotation vector as Euler angle minimal representation.
VISP_EXPORT int wait(double t0, double t)