imu.cpp
Go to the documentation of this file.
1 #include "phidgets_api/imu.h"
2 
3 namespace phidgets {
4 
5 Imu::Imu() : Phidget(), imu_handle_(nullptr)
6 {
7  // create the handle
8  CPhidgetSpatial_create(&imu_handle_);
9 
10  // pass handle to base class
11  Phidget::init((CPhidgetHandle)imu_handle_);
12 
13  // register base class callbacks
15 
16  // register imu data callback
17  CPhidgetSpatial_set_OnSpatialData_Handler(imu_handle_, SpatialDataHandler,
18  this);
19 }
20 
22 {
23 }
24 
25 void Imu::setDataRate(int rate)
26 {
27  CPhidgetSpatial_setDataRate(imu_handle_, rate);
28 }
29 
30 void Imu::zero()
31 {
32  // zero (calibrate) gyro
33  CPhidgetSpatial_zeroGyro(imu_handle_);
34 }
35 
36 int Imu::SpatialDataHandler(CPhidgetSpatialHandle /* handle */, void *userptr,
37  CPhidgetSpatial_SpatialEventDataHandle *data,
38  int count)
39 {
40  for (int i = 0; i < count; ++i)
41  {
42  double ts = data[i]->timestamp.seconds +
43  (data[i]->timestamp.microseconds / 1000.0 / 1000.0);
44  ((Imu *)userptr)
45  ->dataHandler(data[i]->acceleration, data[i]->angularRate,
46  data[i]->magneticField, ts);
47  }
48  return 0;
49 }
50 
51 void Imu::dataHandler(const double acceleration[3], const double angularRate[3],
52  const double magneticField[3], double timestamp)
53 {
54  // This method can be overridden in a concrete subclass (e.g., ROS wrapper)
55  (void)acceleration;
56  (void)angularRate;
57  (void)magneticField;
58  (void)timestamp;
59 }
60 
61 int Imu::setCompassCorrectionParameters(double cc_mag_field, double cc_offset0,
62  double cc_offset1, double cc_offset2,
63  double cc_gain0, double cc_gain1,
64  double cc_gain2, double cc_T0,
65  double cc_T1, double cc_T2,
66  double cc_T3, double cc_T4,
67  double cc_T5)
68 {
69  return CPhidgetSpatial_setCompassCorrectionParameters(
70  imu_handle_, cc_mag_field, cc_offset0, cc_offset1, cc_offset2, cc_gain0,
71  cc_gain1, cc_gain2, cc_T0, cc_T1, cc_T2, cc_T3, cc_T4, cc_T5);
72 }
73 
74 } // namespace phidgets
virtual ~Imu()
Definition: imu.cpp:21
void setDataRate(int rate)
Definition: imu.cpp:25
void registerHandlers()
Definition: phidget.cpp:17
virtual void dataHandler(const double acceleration[3], const double angularRate[3], const double magneticField[3], double timestamp)
Definition: imu.cpp:51
void zero()
Definition: imu.cpp:30
int setCompassCorrectionParameters(double cc_mag_field, double cc_offset0, double cc_offset1, double cc_offset2, double cc_gain0, double cc_gain1, double cc_gain2, double cc_T0, double cc_T1, double cc_T2, double cc_T3, double cc_T4, double cc_T5)
Definition: imu.cpp:61
static int SpatialDataHandler(CPhidgetSpatialHandle spatial, void *userptr, CPhidgetSpatial_SpatialEventDataHandle *data, int count)
Definition: imu.cpp:36
CPhidgetSpatialHandle imu_handle_
Definition: imu.h:31
void init(CPhidgetHandle handle)
Definition: phidget.cpp:24


phidgets_api
Author(s): Tully Foote, Ivan Dryanovski
autogenerated on Fri Apr 9 2021 02:56:02