18 #ifndef LHEADTRACKER_H
19 #define LHEADTRACKER_H
34 namespace vreckoDP_base {
36 #define HTI_CONNECTBYTE (char)0x87
37 #define HTI_CLOSEBYTE (char)0x88
42 #define HTD_COMMAND_LEN 2
43 #define HTD_CMD_RESET "*R"
44 #define HTD_CMD_DIAG "*\005"
45 #define HTD_CMD_REPORT "*d"
46 #define HTD_CMD_DEMAND "*D"
48 #define HTD_PACKET_LEN 16
50 #define HTI_MAX_NUM 1048575
51 #define HTI_2MAX_NUM 2097150
52 #define HTI_MIN_POS_DIFF 20
53 #define HTI_MIN_ROT_DIFF 80
54 #define HTI_POS_C 0.0005
55 #define HTI_ROT_C 40.0
62 #define CMD_TYPE_SLAVE_XMITTER_TYPE 1 // slave transmitter type
63 #define CMD_TYPE_FILTER_POINT 7 // filter point count
64 #define CMD_TYPE_RCVR_DIMENSIONS 8 // set receiver dimensions
66 #define htd_flush( port_fd ) ioctl( port_fd, TCFLSH, 2 )
67 #define if_err( param ) if( ( param ) < 0 )
87 LHeadTracker(
const char *port_name1,
const char *port_name2);
90 virtual int openDevice(
void);
91 int closeDevice(
void);
95 bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER
DOMNode *pParametersNode);
96 XERCES_CPP_NAMESPACE_QUALIFIER
DOMNode *saveXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *);
98 int getRotate(
float *p_rotate);
99 osg::Vec3 &getRotate(
void);
101 osg::Vec3 &getRotateA(
void);
102 osg::Matrix &getRotateM(
void);
103 osg::Quat &getRotateQ(
void);
104 int getTranslate(
float *p_trans);
105 osg::Vec3 &getTranslate(
void);
108 void setInitialPosition(osg::Vec4 &_pos);
109 void setInitialRotation(osg::Vec4 &_rot);
110 void setInitialPosition(osg::Vec4 &_pos1, osg::Vec4 &_pos2);
111 void setInitialRotation(osg::Vec4 &_rot1, osg::Vec4 &_rot2);
113 void demandReport(
void);
114 void setBaseT( osg::Vec4 b1, osg::Vec4 b2, osg::Vec4 b3, osg::Vec4 orig );
115 void setBaseR( osg::Vec4 b1, osg::Vec4 b2, osg::Vec4 b3, osg::Vec4 orig );
116 void resetBase( osg::Vec4 b1, osg::Vec4 b2, osg::Vec4 b3, osg::Vec4 orig );
117 void setSlaveTransmitterType(
unsigned char transmitter_type);
124 int scanDevice(
void);
126 HANDLE hCom, hCom_dual, _hCom;
129 bool openPort(
const char *pcCommPort, HANDLE *temp_hCom);
131 bool openPort(
const char *_pname,
int *temp_port_fd);
133 bool scanDeviceX(
void);
135 int diagnostic(
void);
136 int getRecData(
long int *x,
long int *y,
long int *z,
long int *pi,
long int *ya,
long int *ro,
char *packet);
137 void delay(
int msec);
138 int lhtRead(
char *buf,
int n);
140 int singleReport(
char *reply);
141 void printBuffer(
const char *buf,
int length);
143 osg::Vec4 getEuler(osg::Matrix& _mat);
147 osg::Vec4 pos[2], rot[2];
149 osg::Quat rotq[2], rotq_diff[2];
159 long int absX[2], absY[2], absZ[2];
160 long int absPI[2], absYA[2], absRO[2];
161 osg::Vec4 pos_diff[2];
162 osg::Vec4 rot_diff[2];
164 long int last_absPI[2], last_absYA[2], last_absRO[2];
165 osg::Vec4 last_rot[2];
169 bool first_report[2];
171 osg::Vec4 get_rel_pos(
long int x,
long int y,
long int z );
172 bool checkDiff(
const long int &x,
const long int &y,
const long int &z,
173 const long int &n_pi,
const long int &n_ya,
const long int &n_ro);