vrpn  07.33
Virtual Reality Peripheral Network
vrpn_Tracker_PDI.h
Go to the documentation of this file.
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.
32 class VRPN_API vrpn_Tracker_G4_HubMap_El
33 {
34 public:
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  delete pBtnSrv;
44  }
45 
46  void ButtonName( char * NewName )
47  {
48  if (!NewName)
49  {}
50  else
51  {
52  strncpy(BtnName, NewName, VRPN_G4_HUB_NAME_SIZE);
53  }
54  }
55 
56  void ButtonCount( int n )
57  {
58  nBtnCount = n;
59  }
60 
61 
62  vrpn_Tracker_G4_HubMap_El * Next()
63  { return pNext; }
64 
65  void SetNext( vrpn_Tracker_G4_HubMap_El *pn)
66  { pNext = pn; }
67 
68  friend class vrpn_Tracker_G4_HubMap;
69  friend class vrpn_Tracker_G4;
70 
71 private:
72  int nHubID;
73  vrpn_Button_Server * pBtnSrv;
74  vrpn_Tracker_G4_HubMap_El * pNext;
75  char BtnName[VRPN_G4_HUB_NAME_SIZE];
76  int nBtnCount;
77 };
78 
79 typedef vrpn_Tracker_G4_HubMap_El HUBMAP_ENTRY;
80 
81 class VRPN_API vrpn_Tracker_G4_HubMap
82 {
83 public:
84  vrpn_Tracker_G4_HubMap():p_hub_map(NULL){};
85 
86  ~vrpn_Tracker_G4_HubMap()
87  {
88  while (p_hub_map != NULL)
89  {
90  HUBMAP_ENTRY *next = p_hub_map->Next();
91  delete p_hub_map;
92  p_hub_map = next;
93  }
94  }
95 
96  void Add( int nHub )
97  {
98  HUBMAP_ENTRY *next = p_hub_map;
99  p_hub_map = new HUBMAP_ENTRY( nHub );
100  p_hub_map->SetNext(next);
101  }
102 
103  HUBMAP_ENTRY * Find( int nHub )
104  {
105  HUBMAP_ENTRY * pH = p_hub_map;
106  while (pH && (pH->nHubID != nHub))
107  pH = pH->Next();
108  return pH;
109  }
110 
111  void ButtonInfo( int nHub, char * BtnName, int nBtnCount )
112  {
113  HUBMAP_ENTRY * pHub = Find( nHub );
114  if (pHub)
115  {
116  pHub->ButtonName( BtnName );
117  pHub->ButtonCount( nBtnCount );
118  }
119  }
120 
121  vrpn_Tracker_G4_HubMap_El * Begin()
122  {
123  return p_hub_map;
124  }
125 
126  HUBMAP_ENTRY * p_hub_map;
127 };
128 
129 class VRPN_API vrpn_Tracker_G4: public vrpn_Tracker {
130  public:
131  vrpn_Tracker_G4 (const char *name, vrpn_Connection *cn, const char *filepath,
132  vrpn_float64 Hz = 10.0, const char *rcmd = NULL, vrpn_Tracker_G4_HubMap * pHMap=NULL);
133 
134  ~vrpn_Tracker_G4(void);
135  virtual void mainloop();
136  int encode_to(char *buf);
137  BOOL Initialize ( VOID );
138  BOOL InitDigIOBtns( void );
139  BOOL Connect ( VOID );
140  VOID Disconnect ( VOID );
141  BOOL SetupDevice ( VOID );
142  VOID UpdateStationMap ( VOID );
143  BOOL DisplaySingle( timeval ct );
144  BOOL StartCont ( VOID );
145  BOOL StopCont ( VOID );
146  BOOL DisplayCont ( timeval ct );
147  void sendCommand(char * scmd);
148  void DoBoresightCmd(char *scmd);
149  void DoFilterCmd(char *scmd);
150  void SetFilterPreset( int nLev, CPDIfilter & f, char **pLevName );
151  void DoFORCmd( char *scmd );
152  void DoIncrementCmd( char *scmd );
153  void DoTipOffsetCmd( char *scmd );
154 
155  void ParseG4NativeFrame( PBYTE pBuf, DWORD dwSize, timeval current_time );
156 
157  protected:
158  vrpn_float64 update_rate;
159  vrpn_float64 pos[3], quat[4];
160  int status;
161  char *cmd; // additional commands for the tracker
162  bool isCont; // Keeps track of whether or not device is in continuous mode
163  CPDIg4 pdiG4; // PDI object for the device
164  CPDImdat pdiMDat; // Map of output format
165  LPCTSTR srcCalPath; // Filepath of the Source Calibration file
166  BOOL bCnxReady; // Keeps track of wheter the connection is active
167  DWORD dwStationMap; // map of the hubs and sensors
168  ePDIoriUnits OriUnits; // Orientaion Units e.g. Euler, Quaternion
169  ePDIposUnits PosUnits; // Positions Units e.g. Inches, Meters
170  vrpn_Tracker_G4_HubMap * m_pHMap;
171 
172  HANDLE hContEvent;
173  HWND hwnd;
174  DWORD dwOverflowCount;
175  BYTE pMotionBuf[VRPN_PDI_BUFFER_SIZE];
176 };
177 
178 class VRPN_API vrpn_Tracker_FastrakPDI: public vrpn_Tracker {
179  public:
180  vrpn_Tracker_FastrakPDI (const char * name, vrpn_Connection * cn,
181  vrpn_float64 Hz = 10, const char * rcmd = NULL, unsigned int nStylusMap = 0);
182 
183  ~vrpn_Tracker_FastrakPDI(void);
184  virtual void mainloop();
185  int encode_to(char *buf);
186  BOOL Initialize ( VOID );
187  BOOL InitStylusBtns();
188  BOOL Connect ( VOID );
189  VOID Disconnect ( VOID );
190  BOOL SetupDevice ( VOID );
191  VOID UpdateStationMap ( VOID );
192  VOID DisplaySingle ( timeval current_time );
193  BOOL StartCont ( VOID );
194  BOOL StopCont ( VOID );
195  BOOL DisplayCont ( timeval current_time );
196  VOID SendCommand( char *scmd );
197 
198  VOID ParseFastrakFrame ( PBYTE pBuf, DWORD dwSize, timeval current_time );
199 
200  protected:
201  vrpn_float64 update_rate;
202  vrpn_float64 pos[3], d_quat[4];
203  int status;
204  char *cmd; // pointer to individual command, member of rcmd, for tracker
205  BOOL isBinary; // keeps track of whether or not the device is in binary mode
206  BOOL isCont; // Keeps track of whether or not device is in continuous mode
207  BOOL isMetric; // tracks pos units
208  CPDIfastrak pdiDev; // PDI object for the device
209  CPDImdat pdiMDat; // Map of output format
210  CPDIser pdiSer; // Serial connection object for the device
211  BOOL bCnxReady; // Keeps track of whether the connection is active
212  DWORD dwStationMap; // Map of the hubs and sensors
213  DWORD m_nStylusMap; // Map of sensors with stylus
214  int m_nHeaderSize;// Num byte in P&O frame header
215  int m_nFrameSize; // Num bytes in entire P&O frame (inc header)
216  vrpn_Button_Server * FTstylusBtns[FT_MAX_SENSORS]; //< Pointer to button on each sensor (NULL if none)
217 
218  HANDLE hContEvent;
219  HWND hwnd;
220  DWORD dwOverflowCount;
221  BYTE pMotionBuf[VRPN_PDI_BUFFER_SIZE];
222 };
223 
224 class VRPN_API vrpn_Tracker_LibertyPDI: public vrpn_Tracker {
225  public:
226  vrpn_Tracker_LibertyPDI (const char * name, vrpn_Connection * cn,
227  vrpn_float64 Hz = 10, const char * rcmd = NULL, unsigned int nStylusMap = 0);
228 
229  ~vrpn_Tracker_LibertyPDI(void);
230  virtual void mainloop();
231  int encode_to(char *buf);
232  BOOL Initialize ( VOID );
233  BOOL InitStylusBtns();
234  BOOL Connect ( VOID );
235  VOID Disconnect ( VOID );
236  BOOL SetupDevice ( VOID );
237  VOID UpdateStationMap ( VOID );
238  VOID DisplaySingle ( timeval current_time );
239  BOOL StartCont ( VOID );
240  BOOL StopCont ( VOID );
241  BOOL DisplayCont ( timeval current_time );
242  VOID SendCommand( char *scmd );
243 
244  VOID ParseLibertyFrame ( PBYTE pBuf, DWORD dwSize, timeval current_time );
245 
246  protected:
247  vrpn_float64 update_rate;
248  vrpn_float64 pos[3], d_quat[4];
249  int status;
250  char *cmd; // pointer to individual command, member of rcmd, for tracker
251  BOOL isBinary; // keeps track of whether or not the device is in binary mode
252  BOOL isCont; // Keeps track of whether or not device is in continuous mode
253  BOOL isMetric; // tracks pos units
254  CPDIdev pdiDev; // PDI object for the device
255  CPDImdat pdiMDat; // Map of output format
256  CPDIser pdiSer; // Serial connection object for the device
257  BOOL bCnxReady; // Keeps track of whether the connection is active
258  DWORD dwStationMap; // Map of the hubs and sensors
259  DWORD m_nStylusMap; // Map of sensors with stylus
260  int m_nHeaderSize;// Num byte in P&O frame header
261  int m_nFrameSize; // Num bytes in entire P&O frame (inc header)
262 
263  vrpn_Button_Server * StylusBtns[LIBERTY_MAX_SENSORS]; //< Pointer to button on each sensor (NULL if none)
264 
265  HANDLE hContEvent;
266  HWND hwnd;
267  DWORD dwOverflowCount;
268  BYTE pMotionBuf[VRPN_PDI_BUFFER_SIZE];
269 };
270 
271 #endif
272 #endif
Generic connection class not specific to the transport mechanism.
#define VRPN_API
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
virtual int encode_to(char *buf)
Definition: vrpn_Tracker.C:533