qualisys
Driver.hpp
Go to the documentation of this file.
1 #ifndef QUALISYS_DRIVER_HPP__
2 #define QUALISYS_DRIVER_HPP__
3 
4 #include <iostream>
5 #include <iodrivers_base/Driver.hpp>
6 
7 #include <base/Eigen.hpp>
8 
9 namespace qualisys
10 {
11 
12 struct QTMHeader
13 {
15  {
18  PacketXML = 2,
25  };
26 
27  uint32_t size;
28  uint32_t type;
29 
34  void checkValid() const
35  {
36  if( size < 8 )
37  throw std::runtime_error("QTM Protocol: invalid packet size.");
38 
39  if( type > 8 )
40  throw std::runtime_error("QTM Protocol: Invalid packet type.");
41  }
42 
43  size_t getSize() const
44  {
45  return size;
46  }
47 
48  size_t getPayloadSize() const
49  {
50  return getSize() - sizeof( QTMHeader );
51  }
52 
54  {
55  return static_cast<EPacketType>( type );
56  }
57 
58  QTMHeader() {}
59 
61  : size( size ), type( type )
62  {
63  }
64 } __attribute__ ((__packed__));
65 
67 {
69  {
86  };
87 
89  {
90  if( type > 16 )
91  throw std::runtime_error("QTMComponent: Invalid component type");
92 
93  return static_cast<EComponentType>(type);
94  }
95 
96  uint32_t size;
97  uint32_t type;
98  uint32_t marker_count;
99  uint16_t drop_rate;
101 } __attribute__ ((__packed__));
102 
103 struct Marker6d
104 {
105  float x,y,z;
106  float rot[9];
107 } __attribute__ ((__packed__));
108 
109 
110 class Driver : public iodrivers_base::Driver
111 {
112 public:
113  Driver();
114  ~Driver();
115 
126  void connect( const std::string& host, const unsigned int base_port = 22222 );
127 
133  void loadParameters( std::vector<std::string>& labels );
134 
141  void startStreamData( const std::string& label );
142 
145  void stopStreamData();
146 
155  bool getTransform( base::Time& time, base::Affine3d& transform );
156 
157 protected:
158  bool setQTMVersion( int major, int minor );
159  bool readQTMString( std::string& qtmstring );
160  std::string getBufferString();
162  void writeQTMCommand( const std::string& cmd );
163  void writeQTMCommand( uint8_t const* buffer, size_t size );
164 
165  int extractPacket( uint8_t const* buffer, size_t size) const;
166 
168  static const size_t MAX_MARKERS;
169 
170  // internal buffer for storing packets
171  uint8_t *buffer;
172  size_t buffer_size;
173 
174  int body_idx;
175 };
176 
177 }
178 
179 #endif
int extractPacket(uint8_t const *buffer, size_t size) const
Definition: Driver.cpp:231
void loadParameters(std::vector< std::string > &labels)
load marker configuration data from the server
Definition: Driver.cpp:86
bool setQTMVersion(int major, int minor)
Definition: Driver.cpp:192
uint32_t size
Definition: Driver.hpp:96
uint32_t size
Definition: Driver.hpp:245
float z
Definition: Driver.hpp:105
Definition: Driver.hpp:23
Definition: Driver.hpp:24
Definition: Driver.hpp:18
Driver()
Definition: Driver.cpp:18
uint8_t * buffer
Definition: Driver.hpp:171
bool getTransform(base::Time &time, base::Affine3d &transform)
read a marker packet
Definition: Driver.cpp:111
size_t buffer_size
Definition: Driver.hpp:172
uint16_t drop_rate
Definition: Driver.hpp:99
float y
Definition: Driver.hpp:105
QTMHeader(EPacketType type, size_t size)
Definition: Driver.hpp:60
EPacketType getType() const
Definition: Driver.hpp:53
float rot[9]
Definition: Driver.hpp:106
uint32_t marker_count
Definition: Driver.hpp:98
Definition: Driver.hpp:20
uint16_t out_of_sync_rate
Definition: Driver.hpp:100
qualisys::Driver __attribute__
Definition: Driver.hpp:16
Definition: Driver.hpp:21
Definition: Driver.hpp:103
Definition: Driver.hpp:17
uint32_t type
Definition: Driver.hpp:246
EPacketType
Definition: Driver.hpp:14
EComponentType getType() const
Definition: Driver.hpp:88
std::string getBufferString()
Definition: Driver.cpp:183
void startStreamData(const std::string &label)
start streaming marker data from the QTM Server
Definition: Driver.cpp:55
void connect(const std::string &host, const unsigned int base_port=22222)
connect to qualisys server
Definition: Driver.cpp:37
Definition: Driver.hpp:110
Definition: Driver.hpp:12
uint32_t size
Definition: Driver.hpp:27
size_t getPayloadSize() const
Definition: Driver.hpp:48
float x
Definition: Driver.hpp:105
Definition: Driver.hpp:22
bool readQTMPacket(QTMHeader::EPacketType type)
Definition: Driver.cpp:143
QTMHeader()
Definition: Driver.hpp:58
Definition: Driver.hpp:19
bool readQTMString(std::string &qtmstring)
Definition: Driver.cpp:173
uint32_t type
Definition: Driver.hpp:97
void stopStreamData()
stop streaming of marker data
Definition: Driver.cpp:77
void checkValid() const
Definition: Driver.hpp:34
~Driver()
Definition: Driver.cpp:26
static const size_t MAX_MARKERS
maximum number of markers supported
Definition: Driver.hpp:168
uint32_t type
Definition: Driver.hpp:28
void writeQTMCommand(const std::string &cmd)
Definition: Driver.cpp:214
Definition: Driver.hpp:66
EComponentType
Definition: Driver.hpp:68
size_t getSize() const
Definition: Driver.hpp:43
int body_idx
Definition: Driver.hpp:174