37 : bmx160(bmx160), rotation(rotation)
39 accelerometerCorrector.
fromFile(
"/sd/bmx160_accelerometer_correction.csv");
40 magnetometerCorrector.
fromFile(
"/sd/bmx160_magnetometer_correction.csv");
46 gyroscopeBias = Vector3f{0, 0, 0};
55 gyroscopeBias = Vector3f{0, 0, 0};
62 calibrationPoints = 0;
69 LOG_ERR(logger,
"Driver doesn't point to valid sensor");
73 Eigen::Vector3f avgAccel{0, 0, 0}, avgMag{0, 0, 0}, avgGyro{0, 0, 0}, vec;
76 uint16_t lastFifoSize;
81 for (
int i = 0; i < lastFifoSize; i++)
83 fifoElement = lastFifo[i];
98 if (lastFifoSize == 0)
107 avgAccel /= lastFifoSize;
108 avgMag /= lastFifoSize;
109 avgGyro /= lastFifoSize;
113 avgAccel = accelerometerCorrector.
correct(avgAccel);
114 avgMag = magnetometerCorrector.
correct(avgMag);
116 result.accelerationTimestamp = fifoElement.accelerationTimestamp;
120 result.angularSpeedTimestamp = fifoElement.accelerationTimestamp;
121 static_cast<GyroscopeData&
>(result) << (avgGyro - gyroscopeBias);
125 gyroscopeBias = (gyroscopeBias * calibrationPoints + avgGyro) /
126 (calibrationPoints + 1);
130 return rotateAxis(result);
138 Eigen::Vector3f accDataVector;
139 accData >> accDataVector;
140 accDataVector = rotation.
getMatrix() * accDataVector;
141 accData << accDataVector;
145 Eigen::Vector3f gyrDataVector;
146 gyrData >> gyrDataVector;
147 gyrDataVector = rotation.
getMatrix() * gyrDataVector;
148 gyrData << gyrDataVector;
152 Eigen::Vector3f magDataVector;
153 magData >> magDataVector;
154 magDataVector = rotation.
getMatrix() * magDataVector;
155 magData << magDataVector;
#define LOG_ERR(logger,...)
BMX160WithCorrectionData sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
bool selfTest() override
Check if the sensor is working.
BMX160WithCorrection(BMX160 *bmx160, AxisOrthoOrientation rotation={ Direction::POSITIVE_X, Direction::POSITIVE_Y})
bool init() override
Initialize the sensor.
const std::array< Data, FifoSize > getLastFifo(uint16_t &lastFifoSize)
virtual Data getLastSample()
bool fromFile(const std::string &fileName) override
Eigen::Vector3f correct(const Eigen::Vector3f &input) const override
This file includes all the types the logdecoder script will decode.
Structure to handle accelerometer data.
uint64_t accelerationTimestamp
This struct represents orthogonal rotations.
Eigen::Matrix3f getMatrix() const override
Returns a rotation matrix.
Structure to handle gyroscope data.
Structure to handle magnetometer data.