vrpn 07.35
Virtual Reality Peripheral Network
Loading...
Searching...
No Matches
vrpn_Tracker_WiimoteHead Class Reference

Provides a tracker device given data from a Wii Remote and LED glasses. More...

#include <vrpn_Tracker_WiimoteHead.h>

Inheritance diagram for vrpn_Tracker_WiimoteHead:
Collaboration diagram for vrpn_Tracker_WiimoteHead:

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.
 
- Public Member Functions inherited from vrpn_Tracker
 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)
 
- Public Member Functions inherited from vrpn_BaseClass
 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().
 
- Public Member Functions inherited from vrpn_BaseClassUnique
 vrpn_BaseClassUnique ()
 
virtual ~vrpn_BaseClassUnique ()
 Unregister all of the message handlers that were to be autodeleted.
 
vrpn_ConnectionconnectionPtr ()
 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 Public Member Functions inherited from vrpn_Tracker
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
 
- Protected Member Functions inherited from vrpn_Tracker
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)
 
- Protected Member Functions inherited from vrpn_BaseClass
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.
 
- Protected Member Functions inherited from vrpn_BaseClassUnique
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_Remoted_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
 
- Protected Attributes inherited from vrpn_Tracker
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_Posunit2sensor
 
vrpn_Tracker_Quatunit2sensor_quat
 
unsigned num_unit2sensors
 
vrpn_float64 workspace_min [3]
 
vrpn_float64 workspace_max [3]
 
int status
 
- Protected Attributes inherited from vrpn_BaseClassUnique
vrpn_Connectiond_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

- Public Attributes inherited from vrpn_BaseClassUnique
bool shutup
 
- Static Protected Member Functions inherited from vrpn_BaseClassUnique
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.
 

Detailed Description

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.

Member Enumeration Documentation

◆ FlipState

Enumerator
FLIP_NORMAL 
FLIP_180 
FLIP_UNKNOWN 

Definition at line 187 of file vrpn_Tracker_WiimoteHead.h.

Constructor & Destructor Documentation

◆ vrpn_Tracker_WiimoteHead()

vrpn_Tracker_WiimoteHead::vrpn_Tracker_WiimoteHead ( const char *  name,
vrpn_Connection trackercon,
const char *  wiimote,
float  update_rate,
float  led_spacing = 0.145 
)

constructor

Parameters
nameName for the tracker device to expose
trackerconConnection to provide tracker device over
wiimoteVRPN 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_rateMinimum number of updates per second to issue
led_spacingDistance 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.

Here is the call graph for this function:

◆ ~vrpn_Tracker_WiimoteHead()

vrpn_Tracker_WiimoteHead::~vrpn_Tracker_WiimoteHead ( void  )
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().

Here is the call graph for this function:

Member Function Documentation

◆ _convert_pose_to_tracker()

void vrpn_Tracker_WiimoteHead::_convert_pose_to_tracker ( )
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().

◆ _have_gravity()

bool vrpn_Tracker_WiimoteHead::_have_gravity ( ) const
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().

◆ _reset_gravity()

void vrpn_Tracker_WiimoteHead::_reset_gravity ( )
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().

◆ _reset_points()

void vrpn_Tracker_WiimoteHead::_reset_points ( )
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().

◆ _reset_pose()

void vrpn_Tracker_WiimoteHead::_reset_pose ( )
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().

Here is the call graph for this function:

◆ _should_report()

bool vrpn_Tracker_WiimoteHead::_should_report ( double  elapsedInterval) const
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().

◆ _update_2_LED_pose()

void vrpn_Tracker_WiimoteHead::_update_2_LED_pose ( q_xyz_quat_type &  newPose)
protected

Create tracker-relative pose estimate based on sensor location of 2 tracked points.

If d_points == 2:

  • Postcondition
    d_currentPose contains a tracker-relative pose estimate
  • Postcondition
    d_lock == true Else:
  • Postcondition
    d_lock == false
  • Postcondition
    d_flipState = FLIP_UNKNOWN

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)

Todo:
For some unnerving reason, in release builds, avgX tends to become NaN/undefined However, any kind of inspection (such as the following, or even a simple cout) appears to prevent the issue. This makes me uneasy, but I won't argue with what is working.

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().

◆ _update_flip_state()

void vrpn_Tracker_WiimoteHead::_update_flip_state ( )
protected

If flip state is unknown, set flip state appropriately.

Postcondition
d_flipState=FLIP_NORMAL if the up vector created by d_currentPose has a positive y component (tracked object is right side up)
d_flipState=FLIP_180 if the up vector created by d_currentPose does not have a positive y component (tracked object appears upside-down), which means that you should re-try the pose computation with the points in the opposite order.

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().

Here is the call graph for this function:

◆ _update_gravity_moving_avg()

void vrpn_Tracker_WiimoteHead::_update_gravity_moving_avg ( )
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).

Todo:
replace/supplement gravity moving average with Kalman filter

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().

◆ handle_analog_update()

void vrpn_Tracker_WiimoteHead::handle_analog_update ( void *  userdata,
const vrpn_ANALOGCB  info 
)
static

◆ handle_connection()

int vrpn_Tracker_WiimoteHead::handle_connection ( void *  userdata,
vrpn_HANDLERPARAM   
)
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().

◆ mainloop()

void vrpn_Tracker_WiimoteHead::mainloop ( void  )
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().

Here is the call graph for this function:

◆ report()

void vrpn_Tracker_WiimoteHead::report ( )

◆ reset()

void vrpn_Tracker_WiimoteHead::reset ( )
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().

Here is the call graph for this function:

◆ setup_wiimote()

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().

Here is the call graph for this function:

◆ update_pose()

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().

Here is the call graph for this function:

Member Data Documentation

◆ d_ana

vrpn_Analog_Remote* vrpn_Tracker_WiimoteHead::d_ana
protected

Source of analog data, traditionally vrpn_WiiMote Must present analog channels in this order:

  • x, y, z components of vector opposed to gravity
    • (0,0,1) is nominal Earth gravity
  • four 3-tuples containing either:
    • (x, y, size) for a tracked point (ranges [0, 1023], [0, 1023], [1,16])
    • (-1, -1, -1) as a place holder - point not seen

Definition at line 209 of file vrpn_Tracker_WiimoteHead.h.

Referenced by mainloop(), setup_wiimote(), and ~vrpn_Tracker_WiimoteHead().

◆ d_blobDistance

const double vrpn_Tracker_WiimoteHead::d_blobDistance
protected

distance between LEDs on glasses, in meters

Definition at line 185 of file vrpn_Tracker_WiimoteHead.h.

Referenced by _update_2_LED_pose().

◆ d_contact

bool vrpn_Tracker_WiimoteHead::d_contact
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().

◆ d_currentPose

q_xyz_quat_type vrpn_Tracker_WiimoteHead::d_currentPose
protected

◆ d_flipState

FlipState vrpn_Tracker_WiimoteHead::d_flipState
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().

◆ d_gravDirty

bool vrpn_Tracker_WiimoteHead::d_gravDirty
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().

◆ d_gravityXform

q_xyz_quat_type vrpn_Tracker_WiimoteHead::d_gravityXform
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().

◆ d_lock

bool vrpn_Tracker_WiimoteHead::d_lock
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().

◆ d_name

const char* vrpn_Tracker_WiimoteHead::d_name
protected

Tracker device name.

Definition at line 179 of file vrpn_Tracker_WiimoteHead.h.

Referenced by setup_wiimote(), and vrpn_Tracker_WiimoteHead().

◆ d_points

double vrpn_Tracker_WiimoteHead::d_points
protected

◆ d_prevtime

struct timeval vrpn_Tracker_WiimoteHead::d_prevtime
protected

Time of last tracker report issued.

Definition at line 193 of file vrpn_Tracker_WiimoteHead.h.

Referenced by _reset_pose(), mainloop(), and report().

◆ d_update_interval

const double vrpn_Tracker_WiimoteHead::d_update_interval
protected

maximum time between updates, in seconds

Definition at line 182 of file vrpn_Tracker_WiimoteHead.h.

Referenced by _should_report().

◆ d_updated

bool vrpn_Tracker_WiimoteHead::d_updated
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().

◆ d_vGrav

q_vec_type vrpn_Tracker_WiimoteHead::d_vGrav
protected

◆ d_vGravAntepenultimate

q_vec_type vrpn_Tracker_WiimoteHead::d_vGravAntepenultimate
protected

◆ d_vGravPenultimate

q_vec_type vrpn_Tracker_WiimoteHead::d_vGravPenultimate
protected

◆ d_vSize

double vrpn_Tracker_WiimoteHead::d_vSize[4]
protected

Definition at line 198 of file vrpn_Tracker_WiimoteHead.h.

Referenced by _reset_points(), and handle_analog_update().

◆ d_vX

double vrpn_Tracker_WiimoteHead::d_vX[4]
protected

◆ d_vY

double vrpn_Tracker_WiimoteHead::d_vY[4]
protected

The documentation for this class was generated from the following files: