RflySimSDK v3.08
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_Tracker_WiimoteHead.h
浏览该文件的文档.
1/** @file vrpn_Tracker_WiimoteHead.h
2 @brief vrpn_Tracker interface provided by processing Wii Remote data
3 for head tracking.
4
5 @date 2009-2010
6
7 @author
8 Ryan Pavlik
9 <rpavlik@iastate.edu> and <abiryan@ryand.net>
10 http://academic.cleardefinition.com/
11 Iowa State University Virtual Reality Applications Center
12 Human-Computer Interaction Graduate Program
13
14 See ASME paper WINVR2010-3771 for more details on this system.
15*/
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
57class VRPN_API vrpn_Connection;
59
60/** @brief Provides a tracker device given data from a Wii Remote and LED glasses.
61
62 Assumes a reasonably-stationary Wii Remote (on a tripod, for example)
63 and two LEDs on a pair of glasses, some fixed distance (default 0.145m)
64 apart. You can use the "Johnny Lee" glasses with this.
65
66 Reports poses in a right-hand coordinate system, y-up, that is always
67 level with respect to gravity no matter how your Wii Remote is tilted.
68 */
69class VRPN_API vrpn_Tracker_WiimoteHead : public vrpn_Tracker {
70 public:
71 /** @brief constructor
72
73 @param name Name for the tracker device to expose
74 @param trackercon Connection to provide tracker device over
75 @param wiimote VRPN device name for existing vrpn_WiiMote device or
76 device with a compatible interface - see
77 vrpn_Tracker_WiimoteHead::d_ana for more info. If it starts
78 with *, the server connection will be used instead of creating a
79 new connection.
80 @param update_rate Minimum number of updates per second to issue
81 @param led_spacing Distance between LEDs in meters (0.145 is default)
82 */
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
89 /// @brief destructor
91
92 /// @brief reset pose, gravity transform, and cached points and gravity
93 virtual void reset();
94
95 /// @brief set up connection to wiimote-like analog device
97
98 /// @brief VRPN mainloop function
99 virtual void mainloop();
100
101 /** @brief function to drive the full pose update process
102
103 If we claim to have a tracker lock after updating, we will transform
104 the current pose by the gravity transform before continuing.
105 */
107
108 /// @brief Pack and send tracker report
109 void report();
110
111 /// @brief Callback triggered when a new client connects to the tracker
112 static int VRPN_CALLBACK VRPN_CALLBACK handle_connection(void*, vrpn_HANDLERPARAM);
113
114 /// @brief Callback triggered when our data source issues an update
115 static void VRPN_CALLBACK VRPN_CALLBACK handle_analog_update(void* userdata, const vrpn_ANALOGCB info);
116
117 protected:
118 // Pose update steps
119
120 /** @brief based on cached gravity data, use a moving average to update
121 the tracker's stored gravity transform.
122
123 The moving average is computed over the last 3 unique gravity reports.
124 The transform is the rotation required to rotate the averaged gravity
125 vector to (0, 1, 0).
126 */
128
129 /** @brief Create tracker-relative pose estimate based on sensor location
130 of 2 tracked points.
131
132 If d_points == 2:
133 - @post d_currentPose contains a tracker-relative pose estimate
134 - @post d_lock == true
135 Else:
136 - @post d_lock == false
137 - @post d_flipState = FLIP_UNKNOWN
138
139 */
141
142 /** @brief If flip state is unknown, set flip state appropriately.
143 @post d_flipState=FLIP_NORMAL if the up vector created by d_currentPose
144 has a positive y component (tracked object is right side up)
145 @post d_flipState=FLIP_180 if the up vector created by d_currentPose
146 does not have a positive y component (tracked object appears upside-down),
147 which means that you should re-try the pose computation with
148 the points in the opposite order.
149 */
151
152 /** @brief Set the vrpn_Tracker position and rotation to that indicated
153 by our d_currentPose;
154 */
156
157 // Partial resets
158 /** @brief reset gravity transform and cached gravity vectors
159 */
161
162 /// @brief reset cached points, point count, and flip state,
164
165 /// @brief reset current pose, last report time, and tracker pose
167
168 // Internal query/accessor functions
169
170 /// @brief return true if we have new data or max time elapsed
171 bool _should_report(double elapsedInterval) const;
172
173 /// @brief return true if our gravity values look like real data
174 bool _have_gravity() const;
175
176 // Configuration Parameters
177
178 /// @brief Tracker device name
179 const char* d_name;
180
181 /// @brief maximum time between updates, in seconds
182 const double d_update_interval;
183
184 /// @brief distance between LEDs on glasses, in meters
185 const double d_blobDistance;
186
187 enum FlipState { FLIP_NORMAL, FLIP_180, FLIP_UNKNOWN };
188 /// @brief Whether we need to flip the order of the tracked points
189 /// before calculating a pose.
190 FlipState d_flipState;
191
192 /// @brief Time of last tracker report issued
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
201 /** @brief Source of analog data, traditionally vrpn_WiiMote
202 Must present analog channels in this order:
203 - x, y, z components of vector opposed to gravity
204 - (0,0,1) is nominal Earth gravity
205 - four 3-tuples containing either:
206 - (x, y, size) for a tracked point (ranges [0, 1023], [0, 1023], [1,16])
207 - (-1, -1, -1) as a place holder - point not seen
208 */
210
211
212 /// @brief Gravity correction transformation
214
215 /// @brief Current pose estimate
217
218 // flags
219
220 /// @brief Flag: Have we received the first message from the Wiimote?
222
223 /// @brief Flag: Does the tracking algorithm report a lock?
224 bool d_lock;
225
226 /// @brief Flag: Have we received updated Wiimote data since last report?
228
229 /// @brief Flag: Have we received updated gravity data since
230 /// last gravity update?
232
233 // Gravity moving avg, window of 3
234 q_vec_type d_vGravAntepenultimate;
235 q_vec_type d_vGravPenultimate;
236 q_vec_type d_vGrav;
237};
238
239#endif
定义 vrpn_Analog.h:181
Generic connection class not specific to the transport mechanism.
定义 vrpn_Connection.h:562
Provides a tracker device given data from a Wii Remote and LED glasses.
定义 vrpn_Tracker_WiimoteHead.h:69
const double d_update_interval
maximum time between updates, in seconds
定义 vrpn_Tracker_WiimoteHead.h:182
vrpn_Tracker_WiimoteHead(const char *name, vrpn_Connection *trackercon, const char *wiimote, float update_rate, float led_spacing=0.145)
constructor
static int VRPN_CALLBACK VRPN_CALLBACK handle_connection(void *, vrpn_HANDLERPARAM)
Callback triggered when a new client connects to the tracker
bool d_updated
Flag: Have we received updated Wiimote data since last report?
定义 vrpn_Tracker_WiimoteHead.h:227
q_xyz_quat_type d_gravityXform
Gravity correction transformation
定义 vrpn_Tracker_WiimoteHead.h:213
bool _have_gravity() const
return true if our gravity values look like real data
void update_pose()
function to drive the full pose update process
virtual void mainloop()
VRPN mainloop function
void _reset_gravity()
reset gravity transform and cached gravity vectors
void _update_2_LED_pose(q_xyz_quat_type &newPose)
Create tracker-relative pose estimate based on sensor location of 2 tracked points.
virtual void reset()
reset pose, gravity transform, and cached points and gravity
void _convert_pose_to_tracker()
Set the vrpn_Tracker position and rotation to that indicated by our d_currentPose;
bool d_lock
Flag: Does the tracking algorithm report a lock?
定义 vrpn_Tracker_WiimoteHead.h:224
void _update_flip_state()
If flip state is unknown, set flip state appropriately.
FlipState d_flipState
Whether we need to flip the order of the tracked points before calculating a pose.
定义 vrpn_Tracker_WiimoteHead.h:190
bool d_gravDirty
Flag: Have we received updated gravity data since last gravity update?
定义 vrpn_Tracker_WiimoteHead.h:231
void _reset_points()
reset cached points, point count, and flip state,
q_xyz_quat_type d_currentPose
Current pose estimate
定义 vrpn_Tracker_WiimoteHead.h:216
vrpn_Analog_Remote * d_ana
Source of analog data, traditionally vrpn_WiiMote Must present analog channels in this order:
定义 vrpn_Tracker_WiimoteHead.h:209
void setup_wiimote()
set up connection to wiimote-like analog device
void report()
Pack and send tracker report
const char * d_name
Tracker device name
定义 vrpn_Tracker_WiimoteHead.h:179
virtual ~vrpn_Tracker_WiimoteHead()
destructor
void _update_gravity_moving_avg()
based on cached gravity data, use a moving average to update the tracker's stored gravity transform.
static void VRPN_CALLBACK VRPN_CALLBACK handle_analog_update(void *userdata, const vrpn_ANALOGCB info)
Callback triggered when our data source issues an update
bool _should_report(double elapsedInterval) const
return true if we have new data or max time elapsed
void _reset_pose()
reset current pose, last report time, and tracker pose
bool d_contact
Flag: Have we received the first message from the Wiimote?
定义 vrpn_Tracker_WiimoteHead.h:221
const double d_blobDistance
distance between LEDs on glasses, in meters
定义 vrpn_Tracker_WiimoteHead.h:185
定义 vrpn_Tracker.h:49
定义 vrpn_Analog.h:168
定义 rfly_quat.h:180
This structure is what is passed to a vrpn_Connection message callback.
定义 vrpn_Connection.h:41