43#include <visp3/core/vpConfig.h>
46#if defined(VISP_HAVE_MAVSDK) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) && \
47 (defined(VISP_HAVE_QUALISYS) || defined(VISP_HAVE_VICON)) && defined(VISP_HAVE_THREADS)
52#include <visp3/robot/vpRobotMavsdk.h>
53#include <visp3/sensor/vpMocapQualisys.h>
54#include <visp3/sensor/vpMocapVicon.h>
56using std::chrono::seconds;
57using std::this_thread::sleep_for;
59#ifdef ENABLE_VISP_NAMESPACE
73void quitHandler(
int sig)
76 std::cout << std::endl <<
"TERMINATING AT USER REQUEST" << std::endl << std::endl;
85bool mocap_sdk_loop(std::mutex &lock,
bool qualisys,
bool opt_verbose,
bool opt_all_bodies,
86 std::string &opt_serverAddress, std::string &opt_onlyBody,
87 std::map<std::string, vpHomogeneousMatrix> ¤t_body_poses_enu_M_flu,
bool &mocap_failure,
88 bool &mavlink_failure)
90 std::shared_ptr<vpMocap> mocap;
92#ifdef VISP_HAVE_QUALISYS
93 mocap = std::make_shared<vpMocapQualisys>();
95 std::cout <<
"ERROR : Qualisys not found.";
100#ifdef VISP_HAVE_VICON
101 mocap = std::make_shared<vpMocapVicon>();
104 std::cout <<
"ERROR : Vicon not found.";
108 mocap->setVerbose(opt_verbose);
109 mocap->setServerAddress(opt_serverAddress);
110 if (mocap->connect() ==
false) {
112 mocap_failure =
true;
114 std::cout <<
"Mocap connexion failure. Check mocap server IP address" << std::endl;
119 bool internal_mavlink_failure =
false;
120 while (!g_quit && !internal_mavlink_failure) {
121 std::map<std::string, vpHomogeneousMatrix> body_poses_enu_M_flu;
123 if (opt_onlyBody ==
"") {
124 if (!mocap->getBodiesPose(body_poses_enu_M_flu, opt_all_bodies)) {
130 if (!mocap->getSpecificBodyPose(opt_onlyBody, enu_M_flu)) {
134 body_poses_enu_M_flu[opt_onlyBody] = enu_M_flu;
139 internal_mavlink_failure = mavlink_failure;
140 current_body_poses_enu_M_flu =
141 body_poses_enu_M_flu;
150int top(
const std::string &connection_info, std::map<std::string, vpHomogeneousMatrix> ¤t_body_poses_enu_M_flu,
151 std::mutex &lock,
bool &mocap_failure)
153 std::map<std::string, vpHomogeneousMatrix> body_poses_enu_M_flu;
154 bool internal_mocap_failure =
false;
155 const double fps = 100;
159 while (!g_quit && !internal_mocap_failure) {
162 body_poses_enu_M_flu = current_body_poses_enu_M_flu;
163 internal_mocap_failure = mocap_failure;
166 for (std::map<std::string, vpHomogeneousMatrix>::iterator it = body_poses_enu_M_flu.begin();
167 it != body_poses_enu_M_flu.end(); ++it) {
182void usage(
char *argv[],
int error)
184 std::cout <<
"SYNOPSIS" << std::endl
185 <<
" " << argv[0] <<
" [--only-body <name>] [-ob]"
186 <<
" [--mocap-system <qualisys>/<vicon>] [-ms <q>/<v>]"
187 <<
" [--device <device port>] [-d]"
188 <<
" [--server-address <server address>] [-sa]"
189 <<
" [--verbose] [-v]"
190 <<
" [--help] [-h]" << std::endl
192 std::cout <<
"DESCRIPTION" << std::endl
193 <<
"MANDATORY PARAMETERS :" << std::endl
194 <<
" --only-body <name>" << std::endl
195 <<
" Name of the specific body you want to be displayed." << std::endl
197 <<
"OPTIONAL PARAMETERS (DEFAULT VALUES)" << std::endl
198 <<
" --mocap-system, -ms" << std::endl
199 <<
" Specify the name of the mocap system : 'qualisys' / 'q' or 'vicon'/ 'v'." << std::endl
200 <<
" Default: Qualisys mode." << std::endl
202 <<
" --device <device port>, -d" << std::endl
203 <<
" String giving us all the informations necessary for connection." << std::endl
204 <<
" Default: serial:///dev/ttyUSB0 ." << std::endl
205 <<
" UDP example: udp://192.168.30.111:14540 (udp://IP:Port) ." << std::endl
207 <<
" --server-address <address>, -sa" << std::endl
208 <<
" Mocap server address." << std::endl
209 <<
" Default for Qualisys: 192.168.34.42 ." << std::endl
210 <<
" Default for Vicon: 192.168.34.1 ." << std::endl
212 <<
" --verbose, -v" << std::endl
213 <<
" Enable verbose mode." << std::endl
215 <<
" --help, -h" << std::endl
216 <<
" Print this helper message." << std::endl
220 std::cout <<
"Error" << std::endl
222 <<
"Unsupported parameter " << argv[
error] << std::endl;
230void parse_commandline(
int argc,
char **argv,
bool &qualisys, std::string &connection_info, std::string &server_address,
231 std::string &only_body,
bool &all_bodies,
bool &verbose)
235 for (
int i = 1;
i < argc;
i++) {
236 if (std::string(argv[i]) ==
"--only-body" || std::string(argv[i]) ==
"-ob") {
237 only_body = std::string(argv[i + 1]);
240 else if (std::string(argv[i]) ==
"--mocap-system" || std::string(argv[i]) ==
"-ms") {
241 std::string mode = std::string(argv[i + 1]);
242 if (mode ==
"qualisys" || mode ==
"q") {
245 else if (mode ==
"vicon" || mode ==
"v") {
249 std::cout <<
"ERROR : System not recognized, exiting." << std::endl;
254 else if (std::string(argv[i]) ==
"--device" || std::string(argv[i]) ==
"-d") {
255 connection_info = std::string(argv[i + 1]);
258 else if (std::string(argv[i]) ==
"--server-address" || std::string(argv[i]) ==
"-sa") {
259 server_address = std::string(argv[i + 1]);
262 else if (std::string(argv[i]) ==
"--all-bodies") {
265 else if (std::string(argv[i]) ==
"--verbose" || std::string(argv[i]) ==
"-v") {
268 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
284int main(
int argc,
char **argv)
286 std::map<std::string, vpHomogeneousMatrix> current_body_poses_enu_M_flu;
290 std::string opt_connectionInfo =
"/dev/tty.usbmodem1";
292 std::string opt_connectionInfo =
"udp://127.0.0.1:14550";
295 bool opt_qualisys =
false;
296 std::string opt_serverAddress;
297 std::string opt_onlyBody =
"";
298 bool opt_all_bodies =
false;
299 bool opt_verbose =
false;
302 parse_commandline(argc, argv, opt_qualisys, opt_connectionInfo, opt_serverAddress, opt_onlyBody, opt_all_bodies,
305 if (opt_qualisys && opt_serverAddress ==
"") {
306 opt_serverAddress =
"192.168.30.42";
308 else if (!opt_qualisys && opt_serverAddress ==
"") {
309 opt_serverAddress =
"192.168.30.1";
312 if (opt_onlyBody ==
"") {
313 std::cout <<
"The parameter --only-body MUST be given in the command line." << std::endl;
319 bool mocap_failure =
false;
320 bool mavlink_failure =
false;
321 std::thread mocap_thread([&lock, &opt_qualisys, &opt_verbose, &opt_all_bodies, &opt_serverAddress, &opt_onlyBody,
322 ¤t_body_poses_enu_M_flu, &mocap_failure, &mavlink_failure]() {
323 mocap_sdk_loop(lock, opt_qualisys, opt_verbose, opt_all_bodies, opt_serverAddress, opt_onlyBody,
324 current_body_poses_enu_M_flu, mocap_failure, mavlink_failure);
327 std::cout <<
"Mocap connexion failure. Check mocap server IP address" << std::endl;
332 std::thread mavlink_thread(
333 [&lock, ¤t_body_poses_enu_M_flu, &opt_connectionInfo, &mocap_failure, &mavlink_failure]() {
335 int result = top(opt_connectionInfo, current_body_poses_enu_M_flu, lock, mocap_failure);
339 fprintf(stderr,
"mavlink_control threw exception %i \n", error);
341 mavlink_failure =
true;
348 mavlink_thread.join();
361#ifndef VISP_HAVE_MAVSDK
362 std::cout <<
"\nThis example requires mavsdk library. You should install it, configure and rebuild ViSP.\n"
365#if !(defined(VISP_HAVE_QUALISYS) || defined(VISP_HAVE_VICON))
366 std::cout <<
"\nThis example requires data from a Qualisys or Vicon mocap system. You should install it, configure "
367 "and rebuild ViSP.\n"
370#if !((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
372 <<
"\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and "
Implementation of an homogeneous matrix and operations on such kind of matrices.
bool sendMocapData(const vpHomogeneousMatrix &enu_M_flu, int display_fps=1)
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)