RflySimSDK v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_Tracker_PDI.h
1// $Header: /PDIvrpn.root/2.0.0/PDIVRPN/vrpn/vrpn_Tracker_G4.h 1 6/05/12 12:21p Ben $
2#ifndef VRPN_TRACKER_PDI_H
3#define VRPN_TRACKER_PDI_H
4
5// See if we have defined the use of this code in vrpn_Configure.h or in CMake
6#include "vrpn_Configure.h"
7#include "vrpn_Tracker.h"
8#include "vrpn_Button.h"
9
10#ifdef VRPN_USE_PDI
11
12#include "tchar.h"
13#include <stdlib.h>
14#include <stdio.h>
15#include <string.h>
16#include <iostream>
17
18#include "PDI.h"
19
20#define VRPN_PDI_BUFFER_SIZE 0x1FA400 // 30 seconds of xyzaer+fc 8 sensors at 240 hz
21
22#define VRPN_G4_HUB_NAME_SIZE 64
23#define VRPN_G4_POWERTRAK_BUTTON_COUNT 4
24
25//vrpn_Tracker_G4_HubMap_El and vrpn_Tracker_G4_HubMap
26//classes are used in place of STL vector or list for listing
27//ordered non-contiguous hub identifiers for management of
28//digital i/o inputs on those hubs.
29//These classes could easily be used for listing stylus
30//button stations for other PDI trackers instead of the bitmap
31//approach used now.
32class VRPN_API vrpn_Tracker_G4_HubMap_El
33{
34public:
35 vrpn_Tracker_G4_HubMap_El( int nHub )
36 : pBtnSrv(NULL), nHubID(nHub), pNext(NULL), nBtnCount(0)
37 {
38 memset(BtnName, 0, sizeof(BtnName));
39 };
40 ~vrpn_Tracker_G4_HubMap_El()
41 {
42 if (pBtnSrv) {
43 try {
44 delete pBtnSrv;
45 } catch (...) {
46 fprintf(stderr, "vrpn_Tracker_G4_HubMap_El::~vrpn_Tracker_G4_HubMap_El(): delete failed\n");
47 return;
48 }
49 }
50 }
51
52 void ButtonName( char * NewName )
53 {
54 if (!NewName) {
55 } else {
56 vrpn_strcpy(BtnName, NewName);
57 }
58 }
59
60 void ButtonCount( int n )
61 {
62 nBtnCount = n;
63 }
64
65
66 vrpn_Tracker_G4_HubMap_El * Next()
67 { return pNext; }
68
69 void SetNext( vrpn_Tracker_G4_HubMap_El *pn)
70 { pNext = pn; }
71
72 friend class vrpn_Tracker_G4_HubMap;
73 friend class vrpn_Tracker_G4;
74
75private:
76 int nHubID;
77 vrpn_Button_Server * pBtnSrv;
78 vrpn_Tracker_G4_HubMap_El * pNext;
79 char BtnName[VRPN_G4_HUB_NAME_SIZE];
80 int nBtnCount;
81};
82
83typedef vrpn_Tracker_G4_HubMap_El HUBMAP_ENTRY;
84
85class VRPN_API vrpn_Tracker_G4_HubMap
86{
87public:
88 vrpn_Tracker_G4_HubMap():p_hub_map(NULL){};
89
90 ~vrpn_Tracker_G4_HubMap()
91 {
92 while (p_hub_map != NULL)
93 {
94 HUBMAP_ENTRY *next = p_hub_map->Next();
95 try {
96 delete p_hub_map;
97 } catch (...) {
98 fprintf(stderr, "vrpn_Tracker_G4_HubMap::~vrpn_Tracker_G4_HubMap(): delete failed\n");
99 return;
100 }
101 p_hub_map = next;
102 }
103 }
104
105 void Add( int nHub )
106 {
107 HUBMAP_ENTRY *next = p_hub_map;
108 p_hub_map = new HUBMAP_ENTRY(nHub);
109 p_hub_map->SetNext(next);
110 }
111
112 HUBMAP_ENTRY * Find( int nHub )
113 {
114 HUBMAP_ENTRY * pH = p_hub_map;
115 while (pH && (pH->nHubID != nHub))
116 pH = pH->Next();
117 return pH;
118 }
119
120 void ButtonInfo( int nHub, char * BtnName, int nBtnCount )
121 {
122 HUBMAP_ENTRY * pHub = Find( nHub );
123 if (pHub)
124 {
125 pHub->ButtonName( BtnName );
126 pHub->ButtonCount( nBtnCount );
127 }
128 }
129
130 vrpn_Tracker_G4_HubMap_El * Begin()
131 {
132 return p_hub_map;
133 }
134
135 HUBMAP_ENTRY * p_hub_map;
136};
137
138class VRPN_API vrpn_Tracker_G4: public vrpn_Tracker {
139 public:
140 vrpn_Tracker_G4 (const char *name, vrpn_Connection *cn, const char *filepath,
141 vrpn_float64 Hz = 10.0, const char *rcmd = NULL, vrpn_Tracker_G4_HubMap * pHMap=NULL);
142
143 ~vrpn_Tracker_G4(void);
144 virtual void mainloop();
145 int encode_to(char *buf);
146 BOOL Initialize ( VOID );
147 BOOL InitDigIOBtns( void );
148 BOOL Connect ( VOID );
149 VOID Disconnect ( VOID );
150 BOOL SetupDevice ( VOID );
151 VOID UpdateStationMap ( VOID );
152 BOOL DisplaySingle( timeval ct );
153 BOOL StartCont ( VOID );
154 BOOL StopCont ( VOID );
155 BOOL DisplayCont ( timeval ct );
156 void sendCommand(char * scmd);
157 void DoBoresightCmd(char *scmd);
158 void DoFilterCmd(char *scmd);
159 void SetFilterPreset( int nLev, CPDIfilter & f, char **pLevName );
160 void DoFORCmd( char *scmd );
161 void DoIncrementCmd( char *scmd );
162 void DoTipOffsetCmd( char *scmd );
163
164 void ParseG4NativeFrame( PBYTE pBuf, DWORD dwSize, timeval current_time );
165
166 protected:
167 vrpn_float64 update_rate;
168 vrpn_float64 pos[3], quat[4];
169 int status;
170 char *cmd; // additional commands for the tracker
171 bool isCont; // Keeps track of whether or not device is in continuous mode
172 CPDIg4 pdiG4; // PDI object for the device
173 CPDImdat pdiMDat; // Map of output format
174 LPCTSTR srcCalPath; // Filepath of the Source Calibration file
175 BOOL bCnxReady; // Keeps track of wheter the connection is active
176 DWORD dwStationMap; // map of the hubs and sensors
177 ePDIoriUnits OriUnits; // Orientaion Units e.g. Euler, Quaternion
178 ePDIposUnits PosUnits; // Positions Units e.g. Inches, Meters
179 vrpn_Tracker_G4_HubMap * m_pHMap;
180
181 HANDLE hContEvent;
182 HWND hwnd;
183 DWORD dwOverflowCount;
184 BYTE pMotionBuf[VRPN_PDI_BUFFER_SIZE];
185 PBYTE pLastBuf;
186 DWORD dwLastSize;
187};
188
189class VRPN_API vrpn_Tracker_FastrakPDI: public vrpn_Tracker {
190 public:
191 vrpn_Tracker_FastrakPDI (const char * name, vrpn_Connection * cn,
192 vrpn_float64 Hz = 10, const char * rcmd = NULL, unsigned int nStylusMap = 0);
193
194 ~vrpn_Tracker_FastrakPDI(void);
195 virtual void mainloop();
196 int encode_to(char *buf);
197 BOOL Initialize ( VOID );
198 BOOL InitStylusBtns();
199 BOOL Connect ( VOID );
200 VOID Disconnect ( VOID );
201 BOOL SetupDevice ( VOID );
202 VOID UpdateStationMap ( VOID );
203 VOID DisplaySingle ( timeval current_time );
204 BOOL StartCont ( VOID );
205 BOOL StopCont ( VOID );
206 BOOL DisplayCont ( timeval current_time );
207 VOID SendCommand( char *scmd );
208
209 VOID ParseFastrakFrame ( PBYTE pBuf, DWORD dwSize, timeval current_time );
210
211 protected:
212 vrpn_float64 update_rate;
213 vrpn_float64 pos[3], d_quat[4];
214 int status;
215 char *cmd; // pointer to individual command, member of rcmd, for tracker
216 BOOL isBinary; // keeps track of whether or not the device is in binary mode
217 BOOL isCont; // Keeps track of whether or not device is in continuous mode
218 BOOL isMetric; // tracks pos units
219 CPDIfastrak pdiDev; // PDI object for the device
220 CPDImdat pdiMDat; // Map of output format
221 CPDIser pdiSer; // Serial connection object for the device
222 BOOL bCnxReady; // Keeps track of whether the connection is active
223 DWORD dwStationMap; // Map of the hubs and sensors
224 DWORD m_nStylusMap; // Map of sensors with stylus
225 int m_nHeaderSize;// Num byte in P&O frame header
226 int m_nFrameSize; // Num bytes in entire P&O frame (inc header)
227 vrpn_Button_Server * FTstylusBtns[FT_MAX_SENSORS]; //< Pointer to button on each sensor (NULL if none)
228
229 HANDLE hContEvent;
230 HWND hwnd;
231 DWORD dwOverflowCount;
232 BYTE pMotionBuf[VRPN_PDI_BUFFER_SIZE];
233 PBYTE pLastBuf;
234 DWORD dwLastSize;
235};
236
237class VRPN_API vrpn_Tracker_LibertyPDI: public vrpn_Tracker {
238 public:
239 vrpn_Tracker_LibertyPDI (const char * name, vrpn_Connection * cn,
240 vrpn_float64 Hz = 10, const char * rcmd = NULL, unsigned int nStylusMap = 0);
241
242 ~vrpn_Tracker_LibertyPDI(void);
243 virtual void mainloop();
244 int encode_to(char *buf);
245 BOOL Initialize ( VOID );
246 BOOL InitStylusBtns();
247 BOOL Connect ( VOID );
248 VOID Disconnect ( VOID );
249 BOOL SetupDevice ( VOID );
250 VOID UpdateStationMap ( VOID );
251 VOID DisplaySingle ( timeval current_time );
252 BOOL StartCont ( VOID );
253 BOOL StopCont ( VOID );
254 BOOL DisplayCont ( timeval current_time );
255 VOID SendCommand( char *scmd );
256
257 VOID ParseLibertyFrame ( PBYTE pBuf, DWORD dwSize, timeval current_time );
258
259 protected:
260 vrpn_float64 update_rate;
261 vrpn_float64 pos[3], d_quat[4];
262 int status;
263 char *cmd; // pointer to individual command, member of rcmd, for tracker
264 BOOL isBinary; // keeps track of whether or not the device is in binary mode
265 BOOL isCont; // Keeps track of whether or not device is in continuous mode
266 BOOL isMetric; // tracks pos units
267 CPDIdev pdiDev; // PDI object for the device
268 CPDImdat pdiMDat; // Map of output format
269 CPDIser pdiSer; // Serial connection object for the device
270 BOOL bCnxReady; // Keeps track of whether the connection is active
271 DWORD dwStationMap; // Map of the hubs and sensors
272 DWORD m_nStylusMap; // Map of sensors with stylus
273 int m_nHeaderSize;// Num byte in P&O frame header
274 int m_nFrameSize; // Num bytes in entire P&O frame (inc header)
275
276 vrpn_Button_Server * StylusBtns[LIBERTY_MAX_SENSORS]; //< Pointer to button on each sensor (NULL if none)
277
278 HANDLE hContEvent;
279 HWND hwnd;
280 DWORD dwOverflowCount;
281 BYTE pMotionBuf[VRPN_PDI_BUFFER_SIZE];
282 PBYTE pLastBuf;
283 DWORD dwLastSize;
284};
285
286#endif
287#endif
定义 vrpn_Button.h:99
Generic connection class not specific to the transport mechanism.
定义 vrpn_Connection.h:562
定义 vrpn_Tracker.h:49