13#ifndef BNO08X_RECORDS_HPP
14#define BNO08X_RECORDS_HPP
117[[nodiscard]]
constexpr uint32_t W(int32_t v)
noexcept {
118 return static_cast<uint32_t
>(v);
121[[nodiscard]]
constexpr int32_t I(uint32_t w)
noexcept {
122 return static_cast<int32_t
>(
static_cast<int64_t
>(w ^ 0x8000'0000U) - 0x8000'0000LL);
129 const Quat30& q)
noexcept {
130 return {detail::W(q.x), detail::W(q.y), detail::W(q.z), detail::W(q.w)};
134 const std::array<uint32_t, kOrientationWords>& w)
noexcept {
136 .
x = detail::I(w[0]), .y = detail::I(w[1]), .z = detail::I(w[2]), .w = detail::I(w[3])};
141 const uint32_t packed =
142 static_cast<uint32_t
>(p.stable_duration_s) | (
static_cast<uint32_t
>(p.delta_accel_mg) << 8U);
143 return {detail::W(p.delta_orientation_q28), detail::W(p.stable_threshold_q25), packed};
147 const std::array<uint32_t, kPowerMgmtWords>& w)
noexcept {
149 .stable_threshold_q25 = detail::I(w[1]),
150 .stable_duration_s =
static_cast<uint8_t
>(w[2] & 0xFFU),
151 .delta_accel_mg =
static_cast<uint8_t
>((w[2] >> 8U) & 0xFFU)};
154[[nodiscard]]
constexpr std::array<uint32_t, kArvrWords>
EncodeArvr(
156 return {detail::W(a.scaling_q30), detail::W(a.max_rotation_q29), detail::W(a.max_error_q29),
157 detail::W(a.stability_q29)};
161 const std::array<uint32_t, kArvrWords>& w)
noexcept {
163 .max_rotation_q29 = detail::I(w[1]),
164 .max_error_q29 = detail::I(w[2]),
165 .stability_q29 = detail::I(w[3])};
170 return {detail::W(s.accel_threshold_q24), s.step_threshold};
174 const std::array<uint32_t, kSigMotionWords>& w)
noexcept {
179[[nodiscard]]
constexpr std::array<uint32_t, kShakeWords>
EncodeShake(
181 const uint32_t flags = (s.enable_x ? 1U : 0U) | (s.enable_y ? 2U : 0U) | (s.enable_z ? 4U : 0U);
182 return {s.min_time_us, s.max_time_us, detail::W(s.threshold_q26), s.count, flags};
186 const std::array<uint32_t, kShakeWords>& w)
noexcept {
189 .threshold_q26 = detail::I(w[2]),
191 .enable_x = (w[4] & 1U) != 0U,
192 .enable_y = (w[4] & 2U) != 0U,
193 .enable_z = (w[4] & 4U) != 0U};
198 return {detail::W(e.offset), detail::W(e.scale_q15)};
202 const std::array<uint32_t, kEnvCalWords>& w)
noexcept {
208 return {g.reference_type, g.sync_interval_us,
209 detail::W(g.max_error_q29), detail::W(g.prediction_q10),
210 detail::W(g.alpha_q20), detail::W(g.beta_q20),
211 detail::W(g.gamma_q20)};
215 const std::array<uint32_t, kGyroRvConfigWords>& w)
noexcept {
217 .sync_interval_us = w[1],
218 .max_error_q29 = detail::I(w[2]),
219 .prediction_q10 = detail::I(w[3]),
220 .alpha_q20 = detail::I(w[4]),
221 .beta_q20 = detail::I(w[5]),
222 .gamma_q20 = detail::I(w[6])};
228constexpr int32_t MountQ30(int8_t code)
noexcept {
229 constexpr int32_t kOne = 1'073'741'824;
230 constexpr int32_t kHalf = 536'870'912;
231 constexpr int32_t kRoot = 759'250'125;
232 const int32_t mag = (code < 0) ? -code : code;
236 }
else if (mag == 2) {
238 }
else if (mag == 3) {
243 return (code < 0) ? -v : v;
247inline constexpr std::array<std::array<int8_t, 4>, 24> kMountCodes{{
248 {{1, 0, 0, 0}}, {{3, 0, 0, 3}}, {{0, 0, 0, 1}}, {{3, 0, 0, -3}}, {{0, 0, -1, 0}},
249 {{0, -3, -3, 0}}, {{0, -1, 0, 0}}, {{0, -3, 3, 0}}, {{0, 0, -3, 3}}, {{2, -2, -2, 2}},
250 {{3, -3, 0, 0}}, {{2, -2, 2, -2}}, {{-3, -3, 0, 0}}, {{-2, -2, -2, -2}}, {{0, 0, -3, -3}},
251 {{2, 2, -2, -2}}, {{-2, -2, -2, 2}}, {{0, -3, 0, 3}}, {{2, -2, 2, 2}}, {{-3, 0, -3, 0}},
252 {{2, 2, -2, 2}}, {{0, -3, 0, -3}}, {{2, -2, -2, -2}}, {{3, 0, -3, 0}},
270 const auto& c = detail::kMountCodes[row];
271 return Quat30{.
x = detail::MountQ30(c[1]),
272 .y = detail::MountQ30(c[2]),
273 .z = detail::MountQ30(c[3]),
274 .w = detail::MountQ30(c[0])};
302 const uint8_t s = detail::ToUnderlying(step_);
307 step_ =
static_cast<CalStep>(s + 1U);
328 [[nodiscard]]
static constexpr uint32_t
MinRateHz() noexcept {
334 bool accurate_{
false};
Compile-time helpers of the BNO08X driver: typed integer literals, exact hook matching,...
BNO08x protocol constants: SHTP channels, SH-2 report, command and record identifiers,...
Public types of the BNO08x driver: errors, Result<T>, configuration, events and the integer unit help...
A state object that turns the calibration procedure into steps. It sends nothing: it follows what you...
Definition bno08x_records.hpp:293
static constexpr uint32_t MinRateHz() noexcept
The slowest report rate the procedure allows, in Hz (DS p38).
Definition bno08x_records.hpp:328
bool ReadyToSave() const noexcept
Definition bno08x_records.hpp:319
void Observe(Accuracy a) noexcept
Tell the helper the latest magnetometer accuracy (the status of a magnetic field sample).
Definition bno08x_records.hpp:312
CalStep Step() const noexcept
Definition bno08x_records.hpp:296
void Advance() noexcept
The user finished the current step; go to the next one (WaitAccuracy needs Observe()).
Definition bno08x_records.hpp:301
void Reset() noexcept
Start again.
Definition bno08x_records.hpp:323
Accuracy
Accuracy of a sensor sample (status bits 1:0 of every input report, RM S6.5.1).
Definition bno08x_types.hpp:196
The BNO08x driver: everything it declares lives here; internals in detail.
Definition bno08x.hpp:36
constexpr std::size_t kEnvCalWords
Environmental calibration records.
Definition bno08x_records.hpp:112
constexpr std::size_t kSigMotionWords
Record 0xC274.
Definition bno08x_records.hpp:110
constexpr std::array< uint32_t, kEnvCalWords > EncodeEnvCalibration(const EnvCalibration &e) noexcept
Words of an environmental calibration record.
Definition bno08x_records.hpp:196
constexpr std::size_t kArvrWords
Records 0x3E2D and 0x3E2E.
Definition bno08x_records.hpp:109
constexpr std::array< uint32_t, kSigMotionWords > EncodeSignificantMotion(const SignificantMotionConfig &s) noexcept
Words of record 0xC274.
Definition bno08x_records.hpp:168
constexpr std::array< uint32_t, kOrientationWords > EncodeOrientation(const Quat30 &q) noexcept
Words of an orientation record (x, y, z, w; RM S4.1).
Definition bno08x_records.hpp:128
constexpr ShakeConfig DecodeShake(const std::array< uint32_t, kShakeWords > &w) noexcept
The record 0x7D7D of its words.
Definition bno08x_records.hpp:185
constexpr std::size_t kPowerMgmtWords
Record 0xD3E2.
Definition bno08x_records.hpp:108
constexpr std::array< uint32_t, kShakeWords > EncodeShake(const ShakeConfig &s) noexcept
Words of record 0x7D7D (the enable word has bit 0 X, bit 1 Y, bit 2 Z).
Definition bno08x_records.hpp:179
constexpr std::size_t kShakeWords
Record 0x7D7D.
Definition bno08x_records.hpp:111
constexpr GyroRvConfig DecodeGyroRvConfig(const std::array< uint32_t, kGyroRvConfigWords > &w) noexcept
The record 0xA1A2 of its words.
Definition bno08x_records.hpp:214
constexpr EnvCalibration DecodeEnvCalibration(const std::array< uint32_t, kEnvCalWords > &w) noexcept
The environmental calibration of its words.
Definition bno08x_records.hpp:201
constexpr std::array< uint32_t, kArvrWords > EncodeArvr(const ArvrStabilization &a) noexcept
Words of an AR/VR stabilisation record.
Definition bno08x_records.hpp:154
constexpr std::array< uint32_t, kGyroRvConfigWords > EncodeGyroRvConfig(const GyroRvConfig &g) noexcept
Words of record 0xA1A2.
Definition bno08x_records.hpp:206
constexpr Quat30 MountingQuaternion(std::size_t row) noexcept
The mapping quaternion of row row of DS Figure 4-3 (p41), the system orientation for a device mounted...
Definition bno08x_records.hpp:266
constexpr SignificantMotionConfig DecodeSignificantMotion(const std::array< uint32_t, kSigMotionWords > &w) noexcept
The record 0xC274 of its words.
Definition bno08x_records.hpp:173
constexpr std::size_t kOrientationWords
Words of each typed record.
Definition bno08x_records.hpp:107
constexpr ArvrStabilization DecodeArvr(const std::array< uint32_t, kArvrWords > &w) noexcept
The AR/VR record of its words.
Definition bno08x_records.hpp:160
constexpr Quat30 DecodeOrientation(const std::array< uint32_t, kOrientationWords > &w) noexcept
The quaternion of an orientation record.
Definition bno08x_records.hpp:133
constexpr std::array< uint32_t, kPowerMgmtWords > EncodePowerManagement(const PowerManagement &p) noexcept
Words of record 0xD3E2.
Definition bno08x_records.hpp:139
constexpr std::size_t kMountingCount
Number of mounting rows in DS Figure 4-3.
Definition bno08x_records.hpp:258
CalStep
Steps of the calibration procedure (CAL 1000-4044, DS S3.1).
Definition bno08x_records.hpp:278
@ MovePoses
Move the device through 4 to 6 orientations, about 1 s each.
@ RotateAxes
Rotate about 180 degrees around each axis, about 2 s each.
@ SetDown
Set the device down for 2 to 3 s so the gyroscope calibrates.
@ WaitAccuracy
Wait until the magnetometer accuracy reads medium or high.
@ Done
The calibration is stored.
constexpr PowerManagement DecodePowerManagement(const std::array< uint32_t, kPowerMgmtWords > &w) noexcept
The record 0xD3E2 of its words.
Definition bno08x_records.hpp:146
constexpr std::size_t kGyroRvConfigWords
Record 0xA1A2.
Definition bno08x_records.hpp:113
AR/VR stabilisation records 0x3E2D and 0x3E2E (RM S4.2).
Definition bno08x_records.hpp:48
int32_t stability_q29
Definition bno08x_records.hpp:52
int32_t max_error_q29
Maximum error, Q29.
Definition bno08x_records.hpp:51
int32_t max_rotation_q29
Maximum rotation, Q29.
Definition bno08x_records.hpp:50
friend constexpr bool operator==(const ArvrStabilization &lhs, const ArvrStabilization &rhs) noexcept=default
Equality of all fields, as a hidden friend.
int32_t scaling_q30
Scaling, Q30.
Definition bno08x_records.hpp:49
Environmental sensor calibration records 0x39AF, 0x4D20, 0x1AC9, 0x39B1, 0x4DA2.
Definition bno08x_records.hpp:82
int32_t scale_q15
Definition bno08x_records.hpp:85
int32_t offset
Definition bno08x_records.hpp:83
friend constexpr bool operator==(const EnvCalibration &lhs, const EnvCalibration &rhs) noexcept=default
Equality of all fields, as a hidden friend.
Gyro-integrated rotation vector configuration record 0xA1A2 (RM S4.3.12).
Definition bno08x_records.hpp:92
int32_t alpha_q20
Alpha, Q20.
Definition bno08x_records.hpp:98
int32_t prediction_q10
Prediction amount in seconds, Q10.
Definition bno08x_records.hpp:97
uint32_t sync_interval_us
Synchronisation interval.
Definition bno08x_records.hpp:95
int32_t gamma_q20
Definition bno08x_records.hpp:100
int32_t beta_q20
Beta, Q20.
Definition bno08x_records.hpp:99
friend constexpr bool operator==(const GyroRvConfig &lhs, const GyroRvConfig &rhs) noexcept=default
Equality of all fields, as a hidden friend.
uint32_t reference_type
Reference data type: 0x0207 game rotation vector, 0x0204 rotation vector.
Definition bno08x_records.hpp:93
int32_t max_error_q29
Maximum error, Q29 radians.
Definition bno08x_records.hpp:96
MotionEngine power management and stability classifier record 0xD3E2 (RM S4.3.1).
Definition bno08x_records.hpp:37
uint8_t delta_accel_mg
Definition bno08x_records.hpp:41
friend constexpr bool operator==(const PowerManagement &lhs, const PowerManagement &rhs) noexcept=default
Equality of all fields, as a hidden friend.
int32_t stable_threshold_q25
Stability: angular rate threshold in rad/s, Q25.
Definition bno08x_records.hpp:39
int32_t delta_orientation_q28
Stability: orientation change in radians, Q28.
Definition bno08x_records.hpp:38
uint8_t stable_duration_s
Stability: seconds the device must be still.
Definition bno08x_records.hpp:40
A unit quaternion in Q30 (the orientation records, RM S4.1).
Definition bno08x_records.hpp:27
friend constexpr bool operator==(const Quat30 &lhs, const Quat30 &rhs) noexcept=default
Equality of all fields, as a hidden friend.
int32_t y
Y component, Q30.
Definition bno08x_records.hpp:29
int32_t z
Z component, Q30.
Definition bno08x_records.hpp:30
int32_t x
X component, Q30.
Definition bno08x_records.hpp:28
int32_t w
Definition bno08x_records.hpp:31
Shake detector configuration record 0x7D7D.
Definition bno08x_records.hpp:68
int32_t threshold_q26
Acceleration threshold in m/s2, Q26.
Definition bno08x_records.hpp:71
bool enable_y
Detect on Y.
Definition bno08x_records.hpp:74
friend constexpr bool operator==(const ShakeConfig &lhs, const ShakeConfig &rhs) noexcept=default
Equality of all fields, as a hidden friend.
bool enable_x
Detect on X.
Definition bno08x_records.hpp:73
bool enable_z
Definition bno08x_records.hpp:75
uint32_t count
Shakes needed.
Definition bno08x_records.hpp:72
uint32_t max_time_us
Longest shake.
Definition bno08x_records.hpp:70
uint32_t min_time_us
Shortest shake.
Definition bno08x_records.hpp:69
Significant motion detector configuration record 0xC274.
Definition bno08x_records.hpp:59
uint32_t step_threshold
Definition bno08x_records.hpp:61
friend constexpr bool operator==(const SignificantMotionConfig &lhs, const SignificantMotionConfig &rhs) noexcept=default
Equality of all fields, as a hidden friend.
int32_t accel_threshold_q24
Acceleration threshold in m/s2, Q24.
Definition bno08x_records.hpp:60