vrpn 07.35
Virtual Reality Peripheral Network
|
Provides a tracker device given data from a Wii Remote and LED glasses. More...
#include <vrpn_Tracker_WiimoteHead.h>
Public Member Functions | |
vrpn_Tracker_WiimoteHead (const char *name, vrpn_Connection *trackercon, const char *wiimote, float update_rate, float led_spacing=0.145) | |
constructor | |
virtual | ~vrpn_Tracker_WiimoteHead () |
destructor | |
virtual void | reset () |
reset pose, gravity transform, and cached points and gravity | |
void | setup_wiimote () |
set up connection to wiimote-like analog device | |
virtual void | mainloop () |
VRPN mainloop function. | |
void | update_pose () |
function to drive the full pose update process | |
void | report () |
Pack and send tracker report. | |
![]() | |
vrpn_Tracker (const char *name, vrpn_Connection *c=NULL, const char *tracker_cfg_file_name=NULL) | |
virtual | ~vrpn_Tracker (void) |
int | read_config_file (FILE *config_file, const char *tracker_name) |
void | print_latest_report (void) |
int | register_server_handlers (void) |
void | get_local_t2r (vrpn_float64 *vec, vrpn_float64 *quat) |
void | get_local_u2s (vrpn_int32 sensor, vrpn_float64 *vec, vrpn_float64 *quat) |
![]() | |
vrpn_BaseClass (const char *name, vrpn_Connection *c=NULL) | |
Names the device and assigns or opens connection, calls registration methods. | |
virtual | ~vrpn_BaseClass () |
virtual void | mainloop ()=0 |
Called once through each main loop iteration to handle updates. Remote object mainloop() should call client_mainloop() and then call d_connection->mainloop(). Server object mainloop() should service the device and then call server_mainloop(), but should not normally call d_connection->mainloop(). | |
![]() | |
vrpn_BaseClassUnique () | |
virtual | ~vrpn_BaseClassUnique () |
Unregister all of the message handlers that were to be autodeleted. | |
vrpn_Connection * | connectionPtr () |
Returns a pointer to the connection this object is using. | |
Static Public Member Functions | |
static int VRPN_CALLBACK VRPN_CALLBACK | handle_connection (void *, vrpn_HANDLERPARAM) |
Callback triggered when a new client connects to the tracker. | |
static void VRPN_CALLBACK VRPN_CALLBACK | handle_analog_update (void *userdata, const vrpn_ANALOGCB info) |
Callback triggered when our data source issues an update. | |
![]() | |
static int VRPN_CALLBACK | handle_t2r_request (void *userdata, vrpn_HANDLERPARAM p) |
static int VRPN_CALLBACK | handle_u2s_request (void *userdata, vrpn_HANDLERPARAM p) |
static int VRPN_CALLBACK | handle_workspace_request (void *userdata, vrpn_HANDLERPARAM p) |
Protected Types | |
enum | FlipState { FLIP_NORMAL , FLIP_180 , FLIP_UNKNOWN } |
Protected Member Functions | |
void | _update_gravity_moving_avg () |
based on cached gravity data, use a moving average to update the tracker's stored gravity transform. | |
void | _update_2_LED_pose (q_xyz_quat_type &newPose) |
Create tracker-relative pose estimate based on sensor location of 2 tracked points. | |
void | _update_flip_state () |
If flip state is unknown, set flip state appropriately. | |
void | _convert_pose_to_tracker () |
Set the vrpn_Tracker position and rotation to that indicated by our d_currentPose;. | |
void | _reset_gravity () |
reset gravity transform and cached gravity vectors | |
void | _reset_points () |
reset cached points, point count, and flip state, | |
void | _reset_pose () |
reset current pose, last report time, and tracker pose | |
bool | _should_report (double elapsedInterval) const |
return true if we have new data or max time elapsed | |
bool | _have_gravity () const |
return true if our gravity values look like real data | |
![]() | |
bool | ensure_enough_unit2sensors (unsigned num) |
virtual int | register_types (void) |
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail. | |
virtual int | encode_to (char *buf) |
virtual int | encode_vel_to (char *buf) |
virtual int | encode_acc_to (char *buf) |
virtual int | encode_tracker2room_to (char *buf) |
Encodes the "Tracker to Room" transformation into the buffer specified. | |
virtual int | encode_unit2sensor_to (char *buf) |
Encodes the "Unit to Sensor" transformation into the buffer specified. | |
virtual int | encode_workspace_to (char *buf) |
![]() | |
virtual int | init (void) |
Initialize things that the constructor can't. Returns 0 on success, -1 on failure. | |
virtual int | register_senders (void) |
Register the sender for this device (by default, the name of the device). Return 0 on success, -1 on fail. | |
virtual int | register_types (void)=0 |
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail. | |
![]() | |
int | register_autodeleted_handler (vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER) |
Registers a handler with the connection, and remembers to delete at destruction. | |
int | send_text_message (const char *msg, struct timeval timestamp, vrpn_TEXT_SEVERITY type=vrpn_TEXT_NORMAL, vrpn_uint32 level=0) |
Sends a NULL-terminated text message from the device d_sender_id. | |
SendTextMessageBoundCall | send_text_message (vrpn_TEXT_SEVERITY type=vrpn_TEXT_NORMAL) |
Returns an object you can stream into to send a text message from the device like send_text_message(vrpn_TEXT_WARNING) << "Value of i is: " << i; This use requires including vrpn_SendTextMessageStreamProxy.h. | |
void | server_mainloop (void) |
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should be called by all servers in their mainloop() | |
void | client_mainloop (void) |
Handles functions that all clients should provide in their mainloop() (warning of no server, for example) Should be called by all clients in their mainloop() | |
Protected Attributes | |
const char * | d_name |
Tracker device name. | |
const double | d_update_interval |
maximum time between updates, in seconds | |
const double | d_blobDistance |
distance between LEDs on glasses, in meters | |
FlipState | d_flipState |
Whether we need to flip the order of the tracked points before calculating a pose. | |
struct timeval | d_prevtime |
Time of last tracker report issued. | |
double | d_vX [4] |
double | d_vY [4] |
double | d_vSize [4] |
double | d_points |
vrpn_Analog_Remote * | d_ana |
Source of analog data, traditionally vrpn_WiiMote Must present analog channels in this order: | |
q_xyz_quat_type | d_gravityXform |
Gravity correction transformation. | |
q_xyz_quat_type | d_currentPose |
Current pose estimate. | |
bool | d_contact |
Flag: Have we received the first message from the Wiimote? | |
bool | d_lock |
Flag: Does the tracking algorithm report a lock? | |
bool | d_updated |
Flag: Have we received updated Wiimote data since last report? | |
bool | d_gravDirty |
Flag: Have we received updated gravity data since last gravity update? | |
q_vec_type | d_vGravAntepenultimate |
q_vec_type | d_vGravPenultimate |
q_vec_type | d_vGrav |
![]() | |
vrpn_int32 | position_m_id |
vrpn_int32 | velocity_m_id |
vrpn_int32 | accel_m_id |
vrpn_int32 | tracker2room_m_id |
vrpn_int32 | unit2sensor_m_id |
vrpn_int32 | request_t2r_m_id |
vrpn_int32 | request_u2s_m_id |
vrpn_int32 | request_workspace_m_id |
vrpn_int32 | workspace_m_id |
vrpn_int32 | update_rate_id |
vrpn_int32 | connection_dropped_m_id |
vrpn_int32 | reset_origin_m_id |
vrpn_int32 | d_sensor |
vrpn_float64 | pos [3] |
vrpn_float64 | d_quat [4] |
vrpn_float64 | vel [3] |
vrpn_float64 | vel_quat [4] |
vrpn_float64 | vel_quat_dt |
vrpn_float64 | acc [3] |
vrpn_float64 | acc_quat [4] |
vrpn_float64 | acc_quat_dt |
struct timeval | timestamp |
vrpn_int32 | frame_count |
struct timeval | watchdog_timestamp |
vrpn_float64 | tracker2room [3] |
vrpn_float64 | tracker2room_quat [4] |
vrpn_int32 | num_sensors |
vrpn_Tracker_Pos * | unit2sensor |
vrpn_Tracker_Quat * | unit2sensor_quat |
unsigned | num_unit2sensors |
vrpn_float64 | workspace_min [3] |
vrpn_float64 | workspace_max [3] |
int | status |
![]() | |
vrpn_Connection * | d_connection |
Connection that this object talks to. | |
char * | d_servicename |
Name of this device, not including the connection part. | |
vrpn_int32 | d_sender_id |
Sender ID registered with the connection. | |
vrpn_int32 | d_text_message_id |
ID for text messages. | |
vrpn_int32 | d_ping_message_id |
Ask the server if they are there. | |
vrpn_int32 | d_pong_message_id |
Server telling that it is there. | |
Additional Inherited Members | |
![]() | |
bool | shutup |
![]() | |
static int | encode_text_message_to_buffer (char *buf, vrpn_TEXT_SEVERITY severity, vrpn_uint32 level, const char *msg) |
Encodes the body of the text message into a buffer, preparing for sending. | |
static int | decode_text_message_from_buffer (char *msg, vrpn_TEXT_SEVERITY *severity, vrpn_uint32 *level, const char *buf) |
Decodes the body of the text message from a buffer from the connection. | |
Provides a tracker device given data from a Wii Remote and LED glasses.
Assumes a reasonably-stationary Wii Remote (on a tripod, for example) and two LEDs on a pair of glasses, some fixed distance (default 0.145m) apart. You can use the "Johnny Lee" glasses with this.
Reports poses in a right-hand coordinate system, y-up, that is always level with respect to gravity no matter how your Wii Remote is tilted.
Definition at line 69 of file vrpn_Tracker_WiimoteHead.h.
|
protected |
Enumerator | |
---|---|
FLIP_NORMAL | |
FLIP_180 | |
FLIP_UNKNOWN |
Definition at line 187 of file vrpn_Tracker_WiimoteHead.h.
vrpn_Tracker_WiimoteHead::vrpn_Tracker_WiimoteHead | ( | const char * | name, |
vrpn_Connection * | trackercon, | ||
const char * | wiimote, | ||
float | update_rate, | ||
float | led_spacing = 0.145 |
||
) |
constructor
name | Name for the tracker device to expose |
trackercon | Connection to provide tracker device over |
wiimote | VRPN device name for existing vrpn_WiiMote device or device with a compatible interface - see vrpn_Tracker_WiimoteHead::d_ana for more info. If it starts with *, the server connection will be used instead of creating a new connection. |
update_rate | Minimum number of updates per second to issue |
led_spacing | Distance between LEDs in meters (0.145 is default) |
Definition at line 95 of file vrpn_Tracker_WiimoteHead.C.
References _convert_pose_to_tracker(), vrpn_BaseClassUnique::d_connection, d_currentPose, d_name, handle_connection(), vrpn_BaseClassUnique::register_autodeleted_handler(), vrpn_Connection::register_message_type(), reset(), setup_wiimote(), and vrpn_got_connection.
|
virtual |
destructor
Definition at line 141 of file vrpn_Tracker_WiimoteHead.C.
References d_ana, handle_analog_update(), and vrpn_Analog_Remote::unregister_change_handler().
|
protected |
Set the vrpn_Tracker position and rotation to that indicated by our d_currentPose;.
Definition at line 504 of file vrpn_Tracker_WiimoteHead.C.
References d_currentPose, vrpn_Tracker::d_quat, and vrpn_Tracker::pos.
Referenced by _reset_pose(), update_pose(), and vrpn_Tracker_WiimoteHead().
|
protected |
return true if our gravity values look like real data
Definition at line 567 of file vrpn_Tracker_WiimoteHead.C.
References d_vGrav.
Referenced by update_pose().
|
protected |
reset gravity transform and cached gravity vectors
Definition at line 510 of file vrpn_Tracker_WiimoteHead.C.
References d_gravDirty, d_gravityXform, d_vGrav, d_vGravAntepenultimate, d_vGravPenultimate, MAKE_IDENTITY_QUAT, and MAKE_NULL_VEC.
Referenced by reset().
|
protected |
reset cached points, point count, and flip state,
Definition at line 524 of file vrpn_Tracker_WiimoteHead.C.
References d_flipState, d_lock, d_points, d_vSize, d_vX, d_vY, and FLIP_UNKNOWN.
Referenced by reset().
|
protected |
reset current pose, last report time, and tracker pose
Definition at line 535 of file vrpn_Tracker_WiimoteHead.C.
References _convert_pose_to_tracker(), d_currentPose, d_flipState, d_lock, d_prevtime, d_updated, FLIP_UNKNOWN, MAKE_IDENTITY_QUAT, MAKE_NULL_VEC, and vrpn_gettimeofday.
Referenced by reset().
|
protected |
return true if we have new data or max time elapsed
Definition at line 552 of file vrpn_Tracker_WiimoteHead.C.
References d_update_interval, and d_updated.
Referenced by mainloop().
|
protected |
Create tracker-relative pose estimate based on sensor location of 2 tracked points.
If d_points == 2:
If the first report of a new tracking lock indicated that our "up" vector had no positive y component, we have the points in the wrong order - flip them around. This uses the assumption that the first time we see the glasses, they ought to be right-side up (a reasonable assumption for head tracking)
Definition at line 396 of file vrpn_Tracker_WiimoteHead.C.
References cvtDistToAngle, d_blobDistance, d_currentPose, d_flipState, d_lock, d_points, d_vX, d_vY, FLIP_180, FLIP_UNKNOWN, fovX, fovY, xResSensor, and yResSensor.
Referenced by update_pose().
|
protected |
If flip state is unknown, set flip state appropriately.
Definition at line 479 of file vrpn_Tracker_WiimoteHead.C.
References d_currentPose, d_flipState, FLIP_180, FLIP_NORMAL, FLIP_UNKNOWN, and update_pose().
Referenced by update_pose().
|
protected |
based on cached gravity data, use a moving average to update the tracker's stored gravity transform.
The moving average is computed over the last 3 unique gravity reports. The transform is the rotation required to rotate the averaged gravity vector to (0, 1, 0).
Definition at line 375 of file vrpn_Tracker_WiimoteHead.C.
References d_gravDirty, d_gravityXform, d_vGrav, d_vGravAntepenultimate, d_vGravPenultimate, MAKE_IDENTITY_QUAT, and MAKE_NULL_VEC.
Referenced by update_pose().
|
static |
Callback triggered when our data source issues an update.
Definition at line 302 of file vrpn_Tracker_WiimoteHead.C.
References vrpn_ANALOGCB::channel, d_contact, d_gravDirty, d_points, d_updated, d_vGrav, d_vGravAntepenultimate, d_vGravPenultimate, d_vSize, d_vX, d_vY, vrpn_ANALOGCB::msg_time, and vrpn_BaseClassUnique::userdata.
Referenced by setup_wiimote(), and ~vrpn_Tracker_WiimoteHead().
|
static |
Callback triggered when a new client connects to the tracker.
Definition at line 363 of file vrpn_Tracker_WiimoteHead.C.
References d_updated, and vrpn_BaseClassUnique::userdata.
Referenced by vrpn_Tracker_WiimoteHead().
|
virtual |
VRPN mainloop function.
Implements vrpn_BaseClass.
Definition at line 221 of file vrpn_Tracker_WiimoteHead.C.
References _should_report(), d_ana, d_prevtime, vrpn_Analog_Remote::mainloop(), report(), vrpn_BaseClassUnique::server_mainloop(), update_pose(), vrpn_gettimeofday, and vrpn_TimevalDurationSeconds().
void vrpn_Tracker_WiimoteHead::report | ( | ) |
Pack and send tracker report.
Definition at line 280 of file vrpn_Tracker_WiimoteHead.C.
References vrpn_BaseClassUnique::d_connection, d_prevtime, vrpn_BaseClassUnique::d_sender_id, d_updated, vrpn_Tracker::encode_to(), vrpn_Connection::pack_message(), vrpn_Tracker::position_m_id, vrpn_Tracker::timestamp, vrpn_CONNECTION_LOW_LATENCY, and vrpn_gettimeofday.
Referenced by mainloop().
|
virtual |
reset pose, gravity transform, and cached points and gravity
Reset the current pose to identity and store it into the tracker position/quaternion location, and set the updated flag.
Definition at line 165 of file vrpn_Tracker_WiimoteHead.C.
References _reset_gravity(), _reset_points(), and _reset_pose().
Referenced by vrpn_Tracker_WiimoteHead().
void vrpn_Tracker_WiimoteHead::setup_wiimote | ( | ) |
set up connection to wiimote-like analog device
Definition at line 171 of file vrpn_Tracker_WiimoteHead.C.
References d_ana, vrpn_BaseClassUnique::d_connection, d_contact, d_name, handle_analog_update(), vrpn_Analog_Remote::register_change_handler(), and vrpn_Analog_Remote::unregister_change_handler().
Referenced by vrpn_Tracker_WiimoteHead().
void vrpn_Tracker_WiimoteHead::update_pose | ( | ) |
function to drive the full pose update process
If we claim to have a tracker lock after updating, we will transform the current pose by the gravity transform before continuing.
Definition at line 246 of file vrpn_Tracker_WiimoteHead.C.
References _convert_pose_to_tracker(), _have_gravity(), _update_2_LED_pose(), _update_flip_state(), _update_gravity_moving_avg(), d_currentPose, d_flipState, d_gravDirty, d_gravityXform, d_lock, FLIP_180, FLIP_UNKNOWN, MAKE_IDENTITY_QUAT, and MAKE_NULL_VEC.
Referenced by _update_flip_state(), and mainloop().
|
protected |
Source of analog data, traditionally vrpn_WiiMote Must present analog channels in this order:
Definition at line 209 of file vrpn_Tracker_WiimoteHead.h.
Referenced by mainloop(), setup_wiimote(), and ~vrpn_Tracker_WiimoteHead().
|
protected |
distance between LEDs on glasses, in meters
Definition at line 185 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _update_2_LED_pose().
|
protected |
Flag: Have we received the first message from the Wiimote?
Definition at line 221 of file vrpn_Tracker_WiimoteHead.h.
Referenced by handle_analog_update(), and setup_wiimote().
|
protected |
Current pose estimate.
Definition at line 216 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _convert_pose_to_tracker(), _reset_pose(), _update_2_LED_pose(), _update_flip_state(), update_pose(), and vrpn_Tracker_WiimoteHead().
|
protected |
Whether we need to flip the order of the tracked points before calculating a pose.
Definition at line 190 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _reset_points(), _reset_pose(), _update_2_LED_pose(), _update_flip_state(), and update_pose().
|
protected |
Flag: Have we received updated gravity data since last gravity update?
Definition at line 231 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _reset_gravity(), _update_gravity_moving_avg(), handle_analog_update(), and update_pose().
|
protected |
Gravity correction transformation.
Definition at line 213 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _reset_gravity(), _update_gravity_moving_avg(), and update_pose().
|
protected |
Flag: Does the tracking algorithm report a lock?
Definition at line 224 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _reset_points(), _reset_pose(), _update_2_LED_pose(), and update_pose().
|
protected |
Tracker device name.
Definition at line 179 of file vrpn_Tracker_WiimoteHead.h.
Referenced by setup_wiimote(), and vrpn_Tracker_WiimoteHead().
|
protected |
Definition at line 199 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _reset_points(), _update_2_LED_pose(), and handle_analog_update().
|
protected |
Time of last tracker report issued.
Definition at line 193 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _reset_pose(), mainloop(), and report().
|
protected |
maximum time between updates, in seconds
Definition at line 182 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _should_report().
|
protected |
Flag: Have we received updated Wiimote data since last report?
Definition at line 227 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _reset_pose(), _should_report(), handle_analog_update(), handle_connection(), and report().
|
protected |
Definition at line 236 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _have_gravity(), _reset_gravity(), _update_gravity_moving_avg(), and handle_analog_update().
|
protected |
Definition at line 234 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _reset_gravity(), _update_gravity_moving_avg(), and handle_analog_update().
|
protected |
Definition at line 235 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _reset_gravity(), _update_gravity_moving_avg(), and handle_analog_update().
|
protected |
Definition at line 198 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _reset_points(), and handle_analog_update().
|
protected |
Definition at line 196 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _reset_points(), _update_2_LED_pose(), and handle_analog_update().
|
protected |
Definition at line 197 of file vrpn_Tracker_WiimoteHead.h.
Referenced by _reset_points(), _update_2_LED_pose(), and handle_analog_update().