45 #include <boost/any.hpp>
46 #include <boost/lexical_cast.hpp>
47 #include <boost/variant/get.hpp>
48 #include <json/reader.h>
49 #include <json/value.h>
50 #include <vrpn_Tracker.h>
62 bool reportPose =
false;
63 bool reportPosition =
false;
64 bool reportOrientation =
false;
70 boost::optional<int> sensor,
71 common::InterfaceList &ifaces,
73 : m_remote(new vrpn_Tracker_Remote(src, conn.get())),
74 m_transform(t), m_ctx(ctx), m_internals(ifaces), m_opts(options),
75 m_info(info), m_sensor(sensor) {
76 if (m_info.reportsPosition || m_info.reportsOrientation) {
77 m_remote->register_change_handler(
this,
78 &VRPNTrackerHandler::handle,
79 m_sensor.get_value_or(-1));
81 if (m_info.reportsLinearVelocity || m_info.reportsAngularVelocity) {
82 m_remote->register_change_handler(
83 this, &VRPNTrackerHandler::handleVel,
84 m_sensor.get_value_or(-1));
86 if (m_info.reportsLinearAcceleration ||
87 m_info.reportsAngularAcceleration) {
88 m_remote->register_change_handler(
89 this, &VRPNTrackerHandler::handleAccel,
90 m_sensor.get_value_or(-1));
92 OSVR_DEV_VERBOSE(
"Constructed a TrackerHandler for "
93 << src <<
" sensor " << m_sensor.get_value_or(-1));
95 virtual ~VRPNTrackerHandler() {
96 if (m_info.reportsPosition || m_info.reportsOrientation) {
97 m_remote->unregister_change_handler(
this,
98 &VRPNTrackerHandler::handle,
99 m_sensor.get_value_or(-1));
101 if (m_info.reportsLinearVelocity || m_info.reportsAngularVelocity) {
102 m_remote->unregister_change_handler(
103 this, &VRPNTrackerHandler::handleVel,
104 m_sensor.get_value_or(-1));
106 if (m_info.reportsLinearAcceleration ||
107 m_info.reportsAngularAcceleration) {
108 m_remote->unregister_change_handler(
109 this, &VRPNTrackerHandler::handleAccel,
110 m_sensor.get_value_or(-1));
114 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
116 common::Transform getCurrentTransform()
const {
117 auto ret = m_transform;
122 static void VRPN_CALLBACK handle(
void *userdata, vrpn_TRACKERCB info) {
123 auto self =
static_cast<VRPNTrackerHandler *
>(userdata);
124 self->m_handle(info);
126 static void VRPN_CALLBACK handleVel(
void *userdata,
127 vrpn_TRACKERVELCB info) {
128 auto self =
static_cast<VRPNTrackerHandler *
>(userdata);
129 self->m_handle(info);
131 static void VRPN_CALLBACK handleAccel(
void *userdata,
132 vrpn_TRACKERACCCB info) {
133 auto self =
static_cast<VRPNTrackerHandler *
>(userdata);
134 self->m_handle(info);
136 virtual void update() { m_remote->mainloop(); }
140 void m_handle(vrpn_TRACKERCB
const &info) {
141 common::tracing::markNewTrackerData();
143 report.
sensor = info.sensor;
146 osvrQuatFromQuatlib(&(report.
pose.
rotation), info.quat);
148 auto xform = getCurrentTransform();
149 ei::map(report.
pose) =
152 if (m_opts.reportPose) {
156 if (m_opts.reportPosition) {
158 positionReport.
sensor = info.sensor;
165 if (m_opts.reportOrientation) {
167 oriReport.
sensor = info.sensor;
175 void m_handle(vrpn_TRACKERVELCB
const &info) {
183 overallReport.
sensor = info.sensor;
184 auto xform = getCurrentTransform();
187 m_info.reportsLinearVelocity;
188 if (m_info.reportsLinearVelocity) {
190 osvrVec3FromQuatlib(&(vel), info.vel);
192 ei::map(vel) = xform.transformDerivative(ei::map(vel));
194 overallReport.
state.linearVelocity = vel;
196 report.
sensor = info.sensor;
202 m_info.reportsAngularVelocity;
203 if (m_info.reportsAngularVelocity) {
205 osvrQuatFromQuatlib(&(state.incrementalRotation),
207 state.dt = info.vel_quat_dt;
209 ei::map(state.incrementalRotation) = xform.transformDerivative(
210 ei::map(state.incrementalRotation));
212 overallReport.
state.angularVelocity = state;
214 report.
sensor = info.sensor;
215 report.
state = state;
223 void m_handle(vrpn_TRACKERACCCB
const &info) {
230 overallReport.
sensor = info.sensor;
232 auto xform = getCurrentTransform();
235 m_info.reportsLinearAcceleration;
236 if (m_info.reportsLinearAcceleration) {
238 osvrVec3FromQuatlib(&(accel), info.acc);
240 ei::map(accel) = xform.transformDerivative(ei::map(accel));
242 overallReport.
state.linearAcceleration = accel;
244 report.
sensor = info.sensor;
245 report.
state = accel;
249 m_info.reportsAngularAcceleration;
250 if (m_info.reportsAngularAcceleration) {
253 osvrQuatFromQuatlib(&(state.incrementalRotation),
255 state.dt = info.acc_quat_dt;
257 ei::map(state.incrementalRotation) = xform.transformDerivative(
258 ei::map(state.incrementalRotation));
260 overallReport.
state.angularAcceleration = state;
262 report.
sensor = info.sensor;
263 report.
state = state;
269 unique_ptr<vrpn_Tracker_Remote> m_remote;
270 common::Transform m_transform;
271 common::ClientContext &m_ctx;
272 RemoteHandlerInternals m_internals;
274 common::TrackerSensorInfo m_info;
275 boost::optional<int> m_sensor;
278 TrackerRemoteFactory::TrackerRemoteFactory(
279 VRPNConnectionCollection
const &conns)
286 shared_ptr<RemoteHandler> ret;
295 opts.reportPose = info.reportsPosition || info.reportsOrientation;
296 opts.reportPosition = info.reportsPosition;
297 opts.reportOrientation = info.reportsOrientation;
299 auto const &devElt = source.getDeviceElement();
302 if (source.hasTransform()) {
304 xform = xformParse.getTransform();
309 m_conns.getConnection(devElt), devElt.getFullDeviceName().c_str(),
310 opts, info, xform, source.getSensorNumber(), ifaces, ctx));
int32_t sensor
Identifies the sensor that the report comes from.
The result of resolving a tree node to a device: either an original source to connect to...
OSVR_LinearAccelerationState state
The state itself.
OSVR_PoseState pose
The pose structure, containing a position vector and a rotation quaternion.
OSVR_CBool linearAccelerationValid
Whether the data source reports valid data for #OSVR_AccelerationState::linearAcceleration.
OSVR_LinearVelocityState state
The state itself.
Report type for a linear acceleration callback on a tracker interface.
OSVR_AngularVelocityState state
The state itself.
osvr::common::Transform const & getRoomToWorldTransform() const
Gets the transform from room space to world space.
A structure defining a 3D vector, often a position/translation.
Header including PathTree.h and all additional headers needed to define related types.
fully-resolved data about a tracker sensor. Defaults per the schema.
OSVR_Quaternion rotation
Orientation as a unit quaternion.
int32_t sensor
Identifies the sensor that the report comes from.
Header to bring unique_ptr into the osvr namespace.
The quaternion represents the incremental rotation taking place over a period of dt seconds...
int32_t sensor
Identifies the sensor that the report comes from.
Report type for an acceleration (linear and angular) callback on a tracker interface.
shared_ptr< RemoteHandler > operator()(common::OriginalSource const &source, common::InterfaceList &ifaces, common::ClientContext &ctx)
TrackerSensorInfo getTrackerSensorInfo(OriginalSource const &source)
int32_t sensor
Identifies the sensor that the report comes from.
TransformType transform() const
Read-only accessor for the pose as an Eigen transform.
int32_t sensor
Identifies the sensor that the report comes from.
Report type for an orientation callback on a tracker interface.
OSVR_CBool linearVelocityValid
Whether the data source reports valid data for #OSVR_VelocityState::linearVelocity.
void setStateAndTriggerCallbacks(const OSVR_TimeValue ×tamp, ReportType const &report)
Set state and call callbacks for a report type.
Report type for an angular acceleration callback on a tracker interface.
OSVR_CBool angularVelocityValid
Whether the data source reports valid data for #OSVR_VelocityState::angularVelocity.
OSVR_VelocityState state
The data state - note that not all fields are neccesarily valid, use the Valid members to check the s...
OSVR_AngularAccelerationState state
The state itself.
void osvrStructTimevalToTimeValue(OSVR_TimeValue *dest, const struct timeval *src)
Converts from a TimeValue struct to your system's struct timeval.
Internal, configured header file for verbosity macros.
int32_t sensor
Identifies the sensor that the report comes from.
Header for interoperation between the Eigen math library, the internal mini math library, and VRPN's quatlib.
OSVR_PositionState xyz
The position vector.
Report type for a position callback on a tracker interface.
Report type for a velocity (linear and angular) callback on a tracker interface.
int32_t sensor
Identifies the sensor that the report comes from.
Report type for an angular velocity callback on a tracker interface.
int32_t sensor
Identifies the sensor that the report comes from.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
int32_t sensor
Identifies the sensor that the report comes from.
OSVR_OrientationState rotation
The rotation unit quaternion.
OSVR_AccelerationState state
The data state - note that not all fields are neccesarily valid, use the Valid members to check the s...
Base class for remote device handler classes.
OSVR_Vec3 translation
Position vector.
Report type for a linear velocity callback on a tracker interface.
OSVR_CBool angularAccelerationValid
Whether the data source reports valid data for #OSVR_AccelerationState::angularAcceleration.
Report type for a pose (position and orientation) callback on a tracker interface.