vrpn  07.33
Virtual Reality Peripheral Network
vrpn_Tracker_DTrack.h
Go to the documentation of this file.
1 // vrpn_Tracker_DTrack.h
2 //
3 // Advanced Realtime Tracking GmbH's (http://www.ar-tracking.de) DTrack/DTrack2 client
4 //
5 // developed by David Nahon for Virtools VR Pack (http://www.virtools.com)
6 // (07/20/2004) improved by Advanced Realtime Tracking GmbH (http://www.ar-tracking.de)
7 // (07/02/2007, 06/29/2009) upgraded by Advanced Realtime Tracking GmbH to support new devices
8 // (08/25/2010) a correction added by Advanced Realtime Tracking GmbH
9 // (12/01/2010) support of 3dof objects added by Advanced Realtime Tracking GmbH
10 
11 #ifndef VRPN_TRACKER_DTRACK_H
12 #define VRPN_TRACKER_DTRACK_H
13 
14 #include "vrpn_Configure.h" // for VRPN_API
15 #include "vrpn_Shared.h" // for timeval
16 
18 // There is a problem with linking on SGI related to the use of standard
19 // libraries.
20 #ifndef sgi
21 
22 #include <stdio.h> // for NULL
23 #include <vector> // for vector
24 
25 #include "vrpn_Analog.h" // for vrpn_Analog
26 #include "vrpn_Button.h" // for vrpn_Button_Filter
27 #include "vrpn_Tracker.h" // for vrpn_Tracker
28 
29 
30 // --------------------------------------------------------------------------
31 // Data types:
32 
33 // Standard marker data (3DOF):
34 
35 typedef struct{
36  int id; // id number (starting with 0)
37  float loc[3]; // location (in mm)
39 
40 // Standard body data (6DOF):
41 // - currently not tracked bodies are getting a quality of -1
42 
43 typedef struct{
44  int id; // id number (starting with 0)
45  float quality; // quality (0 <= qu <= 1, no tracking if -1)
46 
47  float loc[3]; // location (in mm)
48  float rot[9]; // rotation matrix (column-wise)
50 
51 // A.R.T. Flystick data (6DOF + buttons):
52 // - currently not tracked bodies are getting a quality of -1
53 // - note the maximum number of buttons and joystick values
54 
55 #define vrpn_DTRACK_FLYSTICK_MAX_BUTTON 16 // maximum number of buttons
56 #define vrpn_DTRACK_FLYSTICK_MAX_JOYSTICK 8 // maximum number of joystick values
57 
58 typedef struct{
59  int id; // id number (starting with 0)
60  float quality; // quality (0 <= qu <= 1, no tracking if -1)
61 
62  int num_button; // number of buttons
63  int button[vrpn_DTRACK_FLYSTICK_MAX_BUTTON]; // button state (1 pressed, 0 not pressed)
64  // (0 front, 1..n-1 right to left)
65  int num_joystick; // number of joystick values
66  float joystick[vrpn_DTRACK_FLYSTICK_MAX_JOYSTICK]; // joystick value (-1 <= joystick <= 1)
67  // (0 horizontal, 1 vertical)
68 
69  float loc[3]; // location (in mm)
70  float rot[9]; // rotation matrix (column-wise)
72 
73 
74 // --------------------------------------------------------------------------
75 // VRPN class:
76 
78 {
79 
80  public:
81 
82 #ifdef _WIN32
83  typedef SOCKET socket_type;
84 #else
85  typedef int socket_type;
86 #endif
87 
88 // Constructor:
89 // name (i): device name
90 // c (i): vrpn_Connection
91 // dtrackPort (i): DTrack UDP port
92 // timeToReachJoy (i): time needed to reach the maximum value of the joystick
93 // fixNbody, fixNflystick (i): fixed numbers of DTrack bodies and Flysticks (-1 if not wanted)
94 // fixId (i): renumbering of targets; must have exact (fixNbody + fixNflystick) elements (NULL if not wanted)
95 // act3DOFout (i): activate 3dof marker output if present
96 // actTracing (i): activate trace output
97 
98  vrpn_Tracker_DTrack(const char *name, vrpn_Connection *c,
99  int dtrackPort, float timeToReachJoy = 0.f,
100  int fixNbody = -1, int fixNflystick = -1, int* fixId = NULL,
101  bool act3DOFout = false, bool actTracing = false);
102 
104 
108 
109  virtual void mainloop();
110 
111 
112  private:
113 
114  // general:
115 
116  struct timeval tim_first; // timestamp of first frame
117  struct timeval tim_last; // timestamp of current frame
118 
119  bool tracing; // activate debug output
120  unsigned int tracing_frames; // frame counter for debug output
121 
122  // DTrack data:
123 
124  bool use_fix_numbering; // use fixed numbers of standard bodies and Flysticks
125 
126  int fix_nbody; // fixed number of standard bodies
127  int fix_nflystick; // fixed number of Flysticks
128 
129  std::vector<int> fix_idbody; // fixed vrpn standard body IDs
130  std::vector<int> fix_idflystick; // fixed vrpn Flystick IDs
131 
132  bool warning_nbodycal; // already warned cause of missing '6dcal' data
133 
134  // preparing data for VRPN:
135  // these functions convert DTrack data to vrpn data
136 
137  std::vector<bool> joy_simulate; // simulate time varying floating values
138  std::vector<float> joy_last; // current value of 'joystick' channel (hor, ver)
139  float joy_incPerSec; // increase of 'joystick' channel (in 1/sec)
140 
141  int dtrack2vrpn_marker(int id, const char* str_dtrack, int id_dtrack,
142  const float* loc, struct timeval timestamp);
143  int dtrack2vrpn_body(int id, const char* str_dtrack, int id_dtrack,
144  const float* loc, const float* rot, struct timeval timestamp);
145  int dtrack2vrpn_flystickbuttons(int id, int id_dtrack,
146  int num_but, const int* but, struct timeval timestamp);
147  int dtrack2vrpn_flystickanalogs(int id, int id_dtrack,
148  int num_ana, const float* ana, float dt, struct timeval timestamp);
149 
150  // communicating with DTrack:
151  // these functions receive and parse data packets from DTrack
152 
153  socket_type d_udpsock; // socket number for UDP
154  int d_udptimeout_us; // timeout for receiving UDP data
155 
156  int d_udpbufsize; // size of UDP buffer
157  char* d_udpbuf; // UDP buffer
158 
159  unsigned int act_framecounter; // frame counter
160  double act_timestamp; // time stamp
161 
162  bool output_3dof_marker; // 3dof marker output if available
163  int act_num_marker; // number of 3dof marker (due to '3d' line)
164  std::vector<vrpn_dtrack_marker_type> act_marker; // array containing 3dof marker data
165 
166  int act_num_body; // number of calibrated standard bodies (due to '6d' line)
167  std::vector<vrpn_dtrack_body_type> act_body; // array containing standard body data
168  bool act_has_bodycal_format; // DTrack sent '6dcal' format
169  int act_num_bodycal; // number of calibrated standard bodies (due to '6dcal' line)
170 
171  int act_num_flystick; // number of calibrated Flysticks
172  std::vector<vrpn_dtrack_flystick_type> act_flystick; // array containing Flystick data
173  bool act_has_old_flystick_format; // DTrack uses old Flystick format
174 
175  int d_lasterror; // last receive error
176 
177  bool dtrack_init(int udpport);
178  bool dtrack_exit(void);
179 
180  bool dtrack_receive(void);
181 };
182 
183 #endif
184 
185 #endif
186 
vrpn_Tracker.h
vrpn_Tracker
Definition: vrpn_Tracker.h:49
vrpn_dtrack_body_type
Definition: vrpn_Tracker_DTrack.h:43
vrpn_dtrack_flystick_type
Definition: vrpn_Tracker_DTrack.h:58
vrpn_Analog
Definition: vrpn_Analog.h:28
vrpn_DTRACK_FLYSTICK_MAX_BUTTON
#define vrpn_DTRACK_FLYSTICK_MAX_BUTTON
Definition: vrpn_Tracker_DTrack.h:55
vrpn_dtrack_flystick_type::id
int id
Definition: vrpn_Tracker_DTrack.h:59
vrpn_dtrack_marker_type
Definition: vrpn_Tracker_DTrack.h:35
vrpn_dtrack_body_type::quality
float quality
Definition: vrpn_Tracker_DTrack.h:45
vrpn_Shared.h
vrpn_Button.h
vrpn_dtrack_body_type::id
int id
Definition: vrpn_Tracker_DTrack.h:44
vrpn_BaseClass::mainloop
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_Connection
Generic connection class not specific to the transport mechanism.
Definition: vrpn_Connection.h:510
vrpn_DTRACK_FLYSTICK_MAX_JOYSTICK
#define vrpn_DTRACK_FLYSTICK_MAX_JOYSTICK
Definition: vrpn_Tracker_DTrack.h:56
vrpn_Analog.h
vrpn_Tracker_DTrack::socket_type
int socket_type
Definition: vrpn_Tracker_DTrack.h:85
vrpn_dtrack_flystick_type::quality
float quality
Definition: vrpn_Tracker_DTrack.h:60
vrpn_Tracker_DTrack
Definition: vrpn_Tracker_DTrack.h:77
vrpn_dtrack_marker_type::id
int id
Definition: vrpn_Tracker_DTrack.h:36
SOCKET
#define SOCKET
Definition: vrpn_Shared.h:46
vrpn_dtrack_flystick_type::num_joystick
int num_joystick
Definition: vrpn_Tracker_DTrack.h:65
vrpn_Configure.h
VRPN_API
#define VRPN_API
Definition: vrpn_Configure.h:646
vrpn_dtrack_flystick_type::num_button
int num_button
Definition: vrpn_Tracker_DTrack.h:62
vrpn_Button_Filter
All button servers should derive from this class, which provides the ability to turn any of the butto...
Definition: vrpn_Button.h:65