15 #include "vrpnTracker.h"
16 #include "vrpnTrackerDevice.h"
17 #include "vrpnClient.h"
18 #include "config_vrpn.h"
30 VrpnTracker(
const string &tracker_name, vrpn_Connection *connection) :
31 _tracker_name(tracker_name)
33 _tracker =
new vrpn_Tracker_Remote(_tracker_name.c_str(), connection);
35 _tracker->register_change_handler((
void*)
this, &vrpn_position_callback);
36 _tracker->register_change_handler((
void*)
this, &vrpn_velocity_callback);
37 _tracker->register_change_handler((
void*)
this, &vrpn_acceleration_callback);
58 if (vrpn_cat.is_debug()) {
59 vrpn_cat.debug() << *
this <<
" marking " << *device <<
"\n";
61 _devices.push_back(device);
72 if (vrpn_cat.is_debug()) {
73 vrpn_cat.debug() << *
this <<
" unmarking " << *device <<
"\n";
76 Devices::iterator di =
77 find(_devices.begin(), _devices.end(), device);
79 if (di != _devices.end()) {
90 output(ostream &out)
const {
100 write(ostream &out,
int indent_level)
const {
101 indent(out, indent_level)
103 << _devices.size() <<
" devices)\n";
113 void VRPN_CALLBACK VrpnTracker::
114 vrpn_position_callback(
void *userdata,
const vrpn_TRACKERCB info) {
116 if (vrpn_cat.is_spam()) {
118 << *
self <<
" position_callback\n";
121 Devices::iterator di;
122 for (di = self->_devices.begin(); di !=
self->_devices.end(); ++di) {
128 device->_data.set_pos(
LPoint3(info.pos[0], info.pos[1], info.pos[2]));
129 device->_data.set_orient(
LOrientation(info.quat[3], info.quat[0], info.quat[1], info.quat[2]));
142 void VRPN_CALLBACK VrpnTracker::
143 vrpn_velocity_callback(
void *userdata,
const vrpn_TRACKERVELCB info) {
145 if (vrpn_cat.is_spam()) {
147 << *
self <<
" velocity_callback\n";
150 Devices::iterator di;
151 for (di = self->_devices.begin(); di !=
self->_devices.end(); ++di) {
157 device->_data.set_pos(
LPoint3(info.vel[0], info.vel[1], info.vel[2]));
158 device->_data.set_orient(
LOrientation(info.vel_quat[3], info.vel_quat[0],
159 info.vel_quat[1], info.vel_quat[2]));
160 device->_data.set_dt(info.vel_quat_dt);
173 void VRPN_CALLBACK VrpnTracker::
174 vrpn_acceleration_callback(
void *userdata,
const vrpn_TRACKERACCCB info) {
176 if (vrpn_cat.is_spam()) {
178 << *
self <<
" acceleration_callback\n";
181 Devices::iterator di;
182 for (di = self->_devices.begin(); di !=
self->_devices.end(); ++di) {
185 device->
get_data_type() == VrpnTrackerDevice::DT_acceleration) {
188 device->_data.set_pos(
LPoint3(info.acc[0], info.acc[1], info.acc[2]));
189 device->_data.set_orient(
LOrientation(info.acc_quat[3], info.acc_quat[0],
190 info.acc_quat[1], info.acc_quat[2]));
191 device->_data.set_dt(info.acc_quat_dt);
This is a unit quaternion representing an orientation.
int get_sensor() const
Returns the particular sensor index that this device wants to hear about from the VrpnTracker...
void unmark(VrpnTrackerDevice *device)
Removes the indicated VrpnTrackerDevice from the list of devices that are sharing this VrpnTracker...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
void unlock()
Releases the mutex associated with this particular device.
This is the actual interface to a particular VRPN tracker object, and all of its sensors.
The Panda interface to a VRPN tracker.
DataType get_data_type() const
Returns the type of data this device represents from the VrpnTracker.
void mark(VrpnTrackerDevice *device)
Adds the indicated VrpnTrackerDevice to the list of devices that are sharing this VrpnTracker...
const string & get_tracker_name() const
Returns the name of the tracker device that was used to create this VrpnTracker.
void acquire()
Grabs the mutex associated with this particular device.
static double convert_to_secs(struct timeval msg_time)
Little inline function to convert a struct timeval to only seconds.