33 #include <libphidget22/phidget22.h>
41 int32_t serial_number,
int hub_port,
bool is_hub_port_device,
42 std::function<
void(
const double[3],
const double[3],
const double[3],
45 std::function<
void(
const double[4],
double)> algorithm_data_handler,
46 std::function<
void()> attach_handler, std::function<
void()> detach_handler)
47 : data_handler_(std::move(data_handler)),
48 algorithm_data_handler_(std::move(algorithm_data_handler)),
49 attach_handler_(std::move(attach_handler)),
50 detach_handler_(std::move(detach_handler))
53 if (ret != EPHIDGET_OK)
60 hub_port, is_hub_port_device, 0);
64 if (ret != EPHIDGET_OK)
66 throw Phidget22Error(
"Failed to set change handler for Spatial", ret);
71 ret = PhidgetSpatial_setOnAlgorithmDataHandler(
73 if (ret != EPHIDGET_OK)
75 throw Phidget22Error(
"Failed to set algorithm handler for Spatial",
82 ret = Phidget_setOnAttachHandler(
85 if (ret != EPHIDGET_OK)
94 ret = Phidget_setOnDetachHandler(
97 if (ret != EPHIDGET_OK)
114 if (ret != EPHIDGET_OK)
121 double cc_mag_field,
double cc_offset0,
double cc_offset1,
122 double cc_offset2,
double cc_gain0,
double cc_gain1,
double cc_gain2,
123 double cc_T0,
double cc_T1,
double cc_T2,
double cc_T3,
double cc_T4,
126 PhidgetReturnCode ret = PhidgetSpatial_setMagnetometerCorrectionParameters(
128 cc_gain0, cc_gain1, cc_gain2, cc_T0, cc_T1, cc_T2, cc_T3, cc_T4, cc_T5);
129 if (ret != EPHIDGET_OK)
131 throw Phidget22Error(
"Failed to set magnetometer correction parameters",
138 Phidget_SpatialAlgorithm algorithm;
140 if (algorithm_name.compare(
"none") == 0)
142 algorithm = SPATIAL_ALGORITHM_NONE;
143 }
else if (algorithm_name.compare(
"ahrs") == 0)
145 algorithm = SPATIAL_ALGORITHM_AHRS;
146 }
else if (algorithm_name.compare(
"imu") == 0)
148 algorithm = SPATIAL_ALGORITHM_IMU;
151 throw std::invalid_argument(
"Unknown spatial algorithm name");
154 PhidgetReturnCode ret =
156 if (ret != EPHIDGET_OK)
163 double angularVelocityDeltaThreshold,
164 double accelerationThreshold,
double magTime,
165 double accelTime,
double biasTime)
167 PhidgetReturnCode ret = PhidgetSpatial_setAHRSParameters(
169 angularVelocityDeltaThreshold, accelerationThreshold, magTime,
170 accelTime, biasTime);
171 if (ret != EPHIDGET_OK)
179 PhidgetReturnCode ret = PhidgetSpatial_setAlgorithmMagnetometerGain(
181 if (ret != EPHIDGET_OK)
183 throw Phidget22Error(
"Failed to set algorithm magnetometer gain", ret);
189 PhidgetReturnCode ret =
191 if (ret != EPHIDGET_OK)
199 PhidgetReturnCode ret =
201 if (ret != EPHIDGET_OK)
208 const double angular_rate[3],
209 const double magnetic_field[3],
210 double timestamp)
const
212 data_handler_(acceleration, angular_rate, magnetic_field, timestamp);
216 double timestamp)
const
232 const double acceleration[3],
233 const double angular_rate[3],
234 const double magnetic_field[3],
double timestamp)
237 ->dataHandler(acceleration, angular_rate, magnetic_field, timestamp);
241 void *ctx,
const double quaternion[4],
244 ((
Spatial *)ctx)->algorithmDataHandler(quaternion, timestamp);
249 ((
Spatial *)ctx)->attachHandler();
254 ((
Spatial *)ctx)->detachHandler();