38 #include <visp3/sensor/vpMocapVicon.h>
42 #if defined(VISP_HAVE_VICON) && defined(VISP_HAVE_THREADS)
48 #include <visp3/sensor/vpMocapVicon.h>
50 #include <visp3/core/vpTime.h>
52 #ifdef ENABLE_VISP_NAMESPACE
62 void quitHandler(
int sig)
64 std::cout << std::endl <<
"TERMINATING AT USER REQUEST" << std::endl << std::endl;
70 void usage(
const char *argv[],
int error)
72 std::cout <<
"SYNOPSIS" << std::endl
73 <<
" " << argv[0] <<
" [--server-address <address>]"
76 <<
" [--verbose] [-v]"
77 <<
" [--help] [-h]" << std::endl
79 std::cout <<
"DESCRIPTION" << std::endl
80 <<
" --server-address <address>" << std::endl
81 <<
" Server address." << std::endl
82 <<
" Default: 192.168.30.1." << std::endl
84 <<
" --only-body <name>" << std::endl
85 <<
" Name of the specific body you want to be displayed." << std::endl
86 <<
" Default: ''" << std::endl
88 <<
" --all-bodies" << std::endl
89 <<
" When used, get all bodies pose including non visible bodies." << std::endl
91 <<
" --verbose, -v" << std::endl
92 <<
" Enable verbose mode." << std::endl
94 <<
" --help, -h" << std::endl
95 <<
" Print this helper message." << std::endl
97 std::cout <<
"USAGE" << std::endl
98 <<
" Example to test Vicon connection:" << std::endl
99 <<
" " << argv[0] <<
" --server-address 127.0.0.1 --verbose" << std::endl
103 std::cout <<
"Error" << std::endl
105 <<
"Unsupported parameter " << argv[error] << std::endl;
109 void mocap_loop(std::mutex &lock,
bool opt_verbose,
bool opt_all_bodies, std::string &opt_serverAddress,
110 std::string &opt_onlyBody, std::map<std::string, vpHomogeneousMatrix> ¤t_bodies_pose)
117 std::map<std::string, vpHomogeneousMatrix> bodies_pose;
119 if (opt_onlyBody ==
"") {
125 bodies_pose[opt_onlyBody] = pose;
129 current_bodies_pose = bodies_pose;
136 void display_loop(std::mutex &lock,
const std::map<std::string, vpHomogeneousMatrix> ¤t_bodies_pose,
bool verbose)
138 std::map<std::string, vpHomogeneousMatrix> bodies_pose;
143 bodies_pose = current_bodies_pose;
145 for (std::map<std::string, vpHomogeneousMatrix>::iterator it = bodies_pose.begin(); it != bodies_pose.end(); ++it) {
147 std::cout <<
"Found body: " << it->first << std::endl;
149 std::cout <<
" Translation [m]: " << it->second.getTranslationVector().t() << std::endl
151 std::cout <<
" Roll/pitch/yaw [deg]: ";
152 for (
unsigned int i = 0; i < 3; i++) {
155 std::cout << std::endl;
163 int main(
int argc,
const char *argv[])
165 bool opt_verbose =
false;
166 std::string opt_serverAddress =
"192.168.30.1";
167 std::string opt_onlyBody =
"";
168 bool opt_all_bodies =
false;
171 std::map<std::string, vpHomogeneousMatrix> current_bodies_pose;
173 signal(SIGINT, quitHandler);
175 for (
int i = 1; i < argc; i++) {
176 if (std::string(argv[i]) ==
"--verbose" || std::string(argv[i]) ==
"-v") {
179 else if (std::string(argv[i]) ==
"--server-address") {
180 opt_serverAddress = std::string(argv[i + 1]);
183 else if (std::string(argv[i]) ==
"--only-body") {
184 opt_onlyBody = std::string(argv[i + 1]);
187 else if (std::string(argv[i]) ==
"--all-bodies") {
188 opt_all_bodies =
true;
190 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
201 std::thread mocap_thread(
202 [&lock, &opt_verbose, &opt_all_bodies, &opt_serverAddress, &opt_onlyBody, ¤t_bodies_pose]() {
203 mocap_loop(lock, opt_verbose, opt_all_bodies, opt_serverAddress, opt_onlyBody, current_bodies_pose);
205 std::thread display_thread(
206 [&lock, ¤t_bodies_pose, &opt_verbose]() { display_loop(lock, current_bodies_pose, opt_verbose); });
209 display_thread.join();
216 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)