vrpn  07.33
Virtual Reality Peripheral Network
vrpn_Tracker_WiimoteHead.h
Go to the documentation of this file.
1 
16 /*
17  Copyright Iowa State University 2009-2010
18  Distributed under the Boost Software License, Version 1.0.
19  (See accompanying comment below or copy at
20  http://www.boost.org/LICENSE_1_0.txt)
21 
22  Boost Software License - Version 1.0 - August 17th, 2003
23 
24  Permission is hereby granted, free of charge, to any person or organization
25  obtaining a copy of the software and accompanying documentation covered by
26  this license (the "Software") to use, reproduce, display, distribute,
27  execute, and transmit the Software, and to prepare derivative works of the
28  Software, and to permit third-parties to whom the Software is furnished to
29  do so, all subject to the following:
30 
31  The copyright notices in the Software and this entire statement, including
32  the above license grant, this restriction and the following disclaimer,
33  must be included in all copies of the Software, in whole or in part, and
34  all derivative works of the Software, unless such copies or derivative
35  works are solely in the form of machine-executable object code generated by
36  a source language processor.
37 
38  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40  FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
41  SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
42  FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
43  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
44  DEALINGS IN THE SOFTWARE.
45 */
46 
47 #ifndef __TRACKER_WIIMOTEHEAD_H
48 #define __TRACKER_WIIMOTEHEAD_H
49 
50 #include <quat.h> // for q_vec_type, q_xyz_quat_type
51 
52 #include "vrpn_Analog.h" // for vrpn_ANALOGCB, etc
53 #include "vrpn_Configure.h" // for VRPN_CALLBACK, VRPN_API
54 #include "vrpn_Shared.h" // for timeval
55 #include "vrpn_Tracker.h" // for vrpn_Tracker
56 
58 struct vrpn_HANDLERPARAM;
59 
70  public:
83  vrpn_Tracker_WiimoteHead(const char* name,
84  vrpn_Connection * trackercon,
85  const char* wiimote,
86  float update_rate,
87  float led_spacing = 0.145);
88 
90  virtual ~vrpn_Tracker_WiimoteHead();
91 
93  virtual void reset();
94 
96  void setup_wiimote();
97 
99  virtual void mainloop();
100 
106  void update_pose();
107 
109  void report();
110 
112  static int VRPN_CALLBACK VRPN_CALLBACK handle_connection(void*, vrpn_HANDLERPARAM);
113 
115  static void VRPN_CALLBACK VRPN_CALLBACK handle_analog_update(void* userdata, const vrpn_ANALOGCB info);
116 
117  protected:
118  // Pose update steps
119 
127  void _update_gravity_moving_avg();
128 
140  void _update_2_LED_pose(q_xyz_quat_type & newPose);
141 
150  void _update_flip_state();
151 
155  void _convert_pose_to_tracker();
156 
157  // Partial resets
160  void _reset_gravity();
161 
163  void _reset_points();
164 
166  void _reset_pose();
167 
168  // Internal query/accessor functions
169 
171  bool _should_report(double elapsedInterval) const;
172 
174  bool _have_gravity() const;
175 
176  // Configuration Parameters
177 
179  const char* d_name;
180 
182  const double d_update_interval;
183 
185  const double d_blobDistance;
186 
187  enum FlipState { FLIP_NORMAL, FLIP_180, FLIP_UNKNOWN };
190  FlipState d_flipState;
191 
193  struct timeval d_prevtime;
194 
195  //Cached data from Wiimote update
196  double d_vX[4];
197  double d_vY[4];
198  double d_vSize[4];
199  double d_points;
200 
210 
211 
213  q_xyz_quat_type d_gravityXform;
214 
216  q_xyz_quat_type d_currentPose;
217 
218  // flags
219 
221  bool d_contact;
222 
224  bool d_lock;
225 
227  bool d_updated;
228 
232 
233  // Gravity moving avg, window of 3
235  q_vec_type d_vGravPenultimate;
236  q_vec_type d_vGrav;
237 };
238 
239 #endif
vrpn_Tracker.h
vrpn_Tracker
Definition: vrpn_Tracker.h:49
vrpn_Tracker_WiimoteHead::d_blobDistance
const double d_blobDistance
distance between LEDs on glasses, in meters
Definition: vrpn_Tracker_WiimoteHead.h:185
vrpn_Tracker_WiimoteHead::d_name
const char * d_name
Tracker device name.
Definition: vrpn_Tracker_WiimoteHead.h:179
vrpn_Tracker_WiimoteHead::d_gravityXform
q_xyz_quat_type d_gravityXform
Gravity correction transformation.
Definition: vrpn_Tracker_WiimoteHead.h:213
vrpn_Analog_Remote
Definition: vrpn_Analog.h:181
vrpn_Tracker_WiimoteHead::d_vGravPenultimate
q_vec_type d_vGravPenultimate
Definition: vrpn_Tracker_WiimoteHead.h:235
vrpn_Tracker_WiimoteHead::d_ana
vrpn_Analog_Remote * d_ana
Source of analog data, traditionally vrpn_WiiMote Must present analog channels in this order:
Definition: vrpn_Tracker_WiimoteHead.h:209
vrpn_Tracker_WiimoteHead::d_update_interval
const double d_update_interval
maximum time between updates, in seconds
Definition: vrpn_Tracker_WiimoteHead.h:182
vrpn_Tracker_WiimoteHead::d_currentPose
q_xyz_quat_type d_currentPose
Current pose estimate.
Definition: vrpn_Tracker_WiimoteHead.h:216
vrpn_Tracker_WiimoteHead::d_contact
bool d_contact
Flag: Have we received the first message from the Wiimote?
Definition: vrpn_Tracker_WiimoteHead.h:221
vrpn_ANALOGCB
Definition: vrpn_Analog.h:168
vrpn_HANDLERPARAM
This structure is what is passed to a vrpn_Connection message callback.
Definition: vrpn_Connection.h:44
vrpn_Shared.h
vrpn_Tracker_WiimoteHead::d_vGravAntepenultimate
q_vec_type d_vGravAntepenultimate
Definition: vrpn_Tracker_WiimoteHead.h:234
vrpn_Tracker_WiimoteHead::d_updated
bool d_updated
Flag: Have we received updated Wiimote data since last report?
Definition: vrpn_Tracker_WiimoteHead.h:227
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_Tracker_WiimoteHead::FlipState
FlipState
Definition: vrpn_Tracker_WiimoteHead.h:187
vrpn_Tracker_WiimoteHead::d_points
double d_points
Definition: vrpn_Tracker_WiimoteHead.h:199
vrpn_Analog.h
VRPN_CALLBACK
#define VRPN_CALLBACK
Definition: vrpn_Configure.h:647
vrpn_Tracker_WiimoteHead::d_lock
bool d_lock
Flag: Does the tracking algorithm report a lock?
Definition: vrpn_Tracker_WiimoteHead.h:224
vrpn_Tracker_WiimoteHead::d_vGrav
q_vec_type d_vGrav
Definition: vrpn_Tracker_WiimoteHead.h:236
vrpn_Tracker_WiimoteHead::d_gravDirty
bool d_gravDirty
Flag: Have we received updated gravity data since last gravity update?
Definition: vrpn_Tracker_WiimoteHead.h:231
vrpn_Configure.h
VRPN_API
#define VRPN_API
Definition: vrpn_Configure.h:646
vrpn_Tracker_WiimoteHead
Provides a tracker device given data from a Wii Remote and LED glasses.
Definition: vrpn_Tracker_WiimoteHead.h:69