36 #include <visp3/core/vpConfig.h>
38 #ifdef VISP_HAVE_QUALISYS
43 #include <visp3/core/vpTime.h>
44 #include <visp3/sensor/vpMocapQualisys.h>
46 #include <qualisys_cpp_sdk/RTPacket.h>
47 #include <qualisys_cpp_sdk/RTProtocol.h>
50 #ifndef DOXYGEN_SHOULD_SKIP_THIS
51 class vpMocapQualisys::vpMocapQualisysImpl
55 : m_rtProtocol(), m_basePort(22222), m_udpPort(6734), m_majorVersion(1), m_minorVersion(19), m_bigEndian(false),
59 virtual ~vpMocapQualisysImpl() {
close(); }
63 m_rtProtocol.StopCapture();
64 m_rtProtocol.Disconnect();
70 for (
auto i = 0; i < n_attempt; i++) {
71 if (!m_rtProtocol.Connected()) {
72 if (!m_rtProtocol.Connect(
m_serverAddr.c_str(), m_basePort, &m_udpPort, m_majorVersion, m_minorVersion,
74 std::cout <<
"Qualisys connection error: " << m_rtProtocol.GetErrorString() << std::endl;
81 std::cout <<
"Qualisys connected" << std::endl;
83 return verifyDataStreamed();
87 std::cout <<
"Qualisys connection timeout" << std::endl;
92 bool verifyDataStreamed()
94 bool readSettingsOK =
false;
96 for (
auto i = 0; i < 6; i++) {
97 if (!m_dataAvailable) {
98 if (!m_rtProtocol.Read6DOFSettings(m_dataAvailable)) {
100 std::cout <<
"Reading 6DOF settings error: " << m_rtProtocol.GetErrorString() << std::endl;
108 std::cout <<
"Reading 6DOF settings succeded." << std::endl;
110 readSettingsOK =
true;
114 if (!readSettingsOK) {
116 std::cout <<
"Reading 6DOF settings timeout: " << std::endl;
121 for (
auto i = 0; i < 6; i++) {
122 if (!m_streamFrames) {
123 if (!m_rtProtocol.StreamFrames(CRTProtocol::RateAllFrames, 0, m_udpPort,
nullptr, CRTProtocol::cComponent6d)) {
125 std::cout <<
"Streaming frames error: " << m_rtProtocol.GetErrorString() << std::endl;
130 m_streamFrames =
true;
134 std::cout <<
"Starting to stream 6DOF data" << std::endl;
140 std::cout <<
"Streaming frames timeout: " << std::endl;
146 bool getBodyPose(
int iBody, std::string &name,
vpHomogeneousMatrix &M, CRTPacket *rtPacket)
149 float rotationMatrix[9];
151 if (rtPacket->Get6DOFBody(iBody, fX, fY, fZ, rotationMatrix)) {
152 const char *pTmpStr = m_rtProtocol.Get6DOFBodyName(iBody);
154 name = std::string(pTmpStr);
158 std::cout <<
"Unknown body" << std::endl;
163 M[0][3] = fX / 1000.;
164 M[1][3] = fY / 1000.;
165 M[2][3] = fZ / 1000.;
168 for (
unsigned int j = 0; j < 3; j++) {
169 for (
unsigned int i = 0; i < 3; i++) {
170 M[i][j] = rotationMatrix[k++];
181 bool getBodiesPose(std::map<std::string, vpHomogeneousMatrix> &bodies_pose,
bool all_bodies)
183 CRTPacket::EPacketType packetType;
185 if (m_rtProtocol.Receive(packetType,
true) == CNetwork::ResponseType::success) {
186 if (packetType == CRTPacket::PacketData) {
187 CRTPacket *rtPacket = m_rtProtocol.GetRTPacket();
188 for (
unsigned int iBody = 0; iBody < rtPacket->Get6DOFBodyCount(); iBody++) {
189 std::string bodyName;
192 if (!getBodyPose(iBody, bodyName, bodyPose, rtPacket)) {
193 std::cout <<
"Error : Could not get pose from body n°" << iBody << std::endl;
198 bodies_pose[bodyName] = bodyPose;
201 bodies_pose[bodyName] = bodyPose;
212 std::map<std::string, vpHomogeneousMatrix> bodies_pose;
214 if (bodies_pose.find(body_name) != bodies_pose.end()) {
215 body_pose = bodies_pose[body_name];
217 std::cout <<
"I found bodyName" << body_name << std::endl;
222 std::cout <<
"The body " << body_name <<
" was not found in Qualisys. Please check the name you typed."
229 std::cout <<
"Error : could not process data from Qualisys" << std::endl;
240 CRTProtocol m_rtProtocol;
241 unsigned short m_basePort;
242 unsigned short m_udpPort;
246 bool m_dataAvailable;
288 return m_impl->getBodiesPose(bodies_pose, all_bodies);
299 return m_impl->getSpecificBodyPose(body_name, body_pose);
318 void dummy_vpMocapQualisys() { };
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setServerAddress(const std::string &serverAddr)
bool getSpecificBodyPose(const std::string &body_name, vpHomogeneousMatrix &body_pose)
void setVerbose(bool verbose)
virtual ~vpMocapQualisys()
bool getBodiesPose(std::map< std::string, vpHomogeneousMatrix > &bodies_pose, bool all_bodies=false)
VISP_EXPORT void sleepMs(double t)