40 #include <visp3/sensor/vpMocapVicon.h>
44 #if defined(VISP_HAVE_VICON) && defined(VISP_HAVE_THREADS)
50 #include <visp3/sensor/vpMocapVicon.h>
52 #include <visp3/core/vpTime.h>
60 void quitHandler(
int sig)
62 std::cout << std::endl <<
"TERMINATING AT USER REQUEST" << std::endl << std::endl;
68 void usage(
const char *argv[],
int error)
70 std::cout <<
"SYNOPSIS" << std::endl
71 <<
" " << argv[0] <<
" [--server-address <address>]"
74 <<
" [--verbose] [-v]"
75 <<
" [--help] [-h]" << std::endl
77 std::cout <<
"DESCRIPTION" << std::endl
78 <<
" --server-address <address>" << std::endl
79 <<
" Server address." << std::endl
80 <<
" Default: 192.168.30.1." << std::endl
82 <<
" --only-body <name>" << std::endl
83 <<
" Name of the specific body you want to be displayed." << std::endl
84 <<
" Default: ''" << std::endl
86 <<
" --all-bodies" << std::endl
87 <<
" When used, get all bodies pose including non visible bodies." << std::endl
89 <<
" --verbose, -v" << std::endl
90 <<
" Enable verbose mode." << std::endl
92 <<
" --help, -h" << std::endl
93 <<
" Print this helper message." << std::endl
95 std::cout <<
"USAGE" << std::endl
96 <<
" Example to test Vicon connection:" << std::endl
97 <<
" " << argv[0] <<
" --server-address 127.0.0.1 --verbose" << std::endl
101 std::cout <<
"Error" << std::endl
103 <<
"Unsupported parameter " << argv[error] << std::endl;
107 void mocap_loop(std::mutex &lock,
bool opt_verbose,
bool opt_all_bodies, std::string &opt_serverAddress,
108 std::string &opt_onlyBody, std::map<std::string, vpHomogeneousMatrix> ¤t_bodies_pose)
115 std::map<std::string, vpHomogeneousMatrix> bodies_pose;
117 if (opt_onlyBody ==
"") {
123 bodies_pose[opt_onlyBody] = pose;
127 current_bodies_pose = bodies_pose;
134 void display_loop(std::mutex &lock,
const std::map<std::string, vpHomogeneousMatrix> ¤t_bodies_pose,
bool verbose)
136 std::map<std::string, vpHomogeneousMatrix> bodies_pose;
141 bodies_pose = current_bodies_pose;
143 for (std::map<std::string, vpHomogeneousMatrix>::iterator it = bodies_pose.begin(); it != bodies_pose.end(); ++it) {
145 std::cout <<
"Found body: " << it->first << std::endl;
147 std::cout <<
" Translation [m]: " << it->second.getTranslationVector().t() << std::endl
149 std::cout <<
" Roll/pitch/yaw [deg]: ";
150 for (
unsigned int i = 0; i < 3; i++) {
153 std::cout << std::endl;
161 int main(
int argc,
const char *argv[])
163 bool opt_verbose =
false;
164 std::string opt_serverAddress =
"192.168.30.1";
165 std::string opt_onlyBody =
"";
166 bool opt_all_bodies =
false;
169 std::map<std::string, vpHomogeneousMatrix> current_bodies_pose;
171 signal(SIGINT, quitHandler);
173 for (
int i = 1; i < argc; i++) {
174 if (std::string(argv[i]) ==
"--verbose" || std::string(argv[i]) ==
"-v") {
177 else if (std::string(argv[i]) ==
"--server-address") {
178 opt_serverAddress = std::string(argv[i + 1]);
181 else if (std::string(argv[i]) ==
"--only-body") {
182 opt_onlyBody = std::string(argv[i + 1]);
185 else if (std::string(argv[i]) ==
"--all-bodies") {
186 opt_all_bodies =
true;
188 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
199 std::thread mocap_thread(
200 [&lock, &opt_verbose, &opt_all_bodies, &opt_serverAddress, &opt_onlyBody, ¤t_bodies_pose]() {
201 mocap_loop(lock, opt_verbose, opt_all_bodies, opt_serverAddress, opt_onlyBody, current_bodies_pose);
203 std::thread display_thread(
204 [&lock, ¤t_bodies_pose, &opt_verbose]() { display_loop(lock, current_bodies_pose, opt_verbose); });
207 display_thread.join();
214 std::cout <<
"Install Vicon Datastream SDK to be able to test Vicon Mocap System using ViSP" << std::endl;
Implementation of an homogeneous matrix and operations on such kind of matrices.
static double deg(double rad)
bool getBodiesPose(std::map< std::string, vpHomogeneousMatrix > &bodies_pose, bool all_bodies=false)
void setVerbose(bool verbose)
void setServerAddress(const std::string &serverAddr)
bool getSpecificBodyPose(const std::string &body_name, vpHomogeneousMatrix &body_pose)
Implementation of a rotation vector as quaternion angle minimal representation.
Implementation of a rotation vector as Euler angle minimal representation.
VISP_EXPORT void sleepMs(double t)