35 std::transform(mode.begin(), mode.end(), mode.begin(), [](
unsigned char c) {
36 if (c ==
'-' || c ==
' ') return static_cast<char>(
'_');
37 return static_cast<char>(std::tolower(c));
52 std::string rest = mode;
53 if (!rest.empty() && rest[0] ==
'-') {
55 rest = rest.substr(1);
60 if (normalized.empty() || normalized ==
"world_z" || normalized ==
"yaw" || normalized ==
"heading")
62 if (normalized ==
"body_x" || normalized ==
"x")
64 if (normalized ==
"body_y" || normalized ==
"y")
66 if (normalized ==
"body_z" || normalized ==
"z")
69 throw std::invalid_argument(
70 "Invalid turn axis mode '" + mode +
71 "'. Expected one of: [-]world_z, [-]body_x, [-]body_y, [-]body_z");
84 throw std::invalid_argument(
85 "Invalid body axis '" + mode +
"'. Expected one of: body_x, body_y, body_z");
101 virtual void read(
float* accel,
float* gyro,
float* magneto) = 0;
117 float accel[3], g[3], magneto[3];
118 read(accel, g, magneto);
119 gyro[0] = g[0]; gyro[1] = g[1]; gyro[2] = g[2];
125 yaw_rate_axis_mode_ = mode;
126 yaw_rate_sign_ = 1.0f;
133 yaw_rate_axis_mode_ = cfg.mode;
134 yaw_rate_sign_ = cfg.sign;
139 return yaw_rate_axis_mode_;
144 return toString(yaw_rate_axis_mode_);
160 switch (yaw_rate_axis_mode_)
172 return yaw_rate_sign_ * rate;
210 float yaw_rate_sign_{1.0f};
const char * toString(const TurnAxisMode mode)
TurnAxisConfig parseTurnAxisConfig(const std::string &mode)
std::string normalizeTurnAxisMode(std::string mode)
TurnAxisMode parseTurnAxisMode(const std::string &mode)
TurnAxisMode parseBodyAxisMode(const std::string &mode)
Interface for IMU abstraction.
virtual void getAngularVelocity(float *gyro)
virtual void getIntegratedVelocity(float *vel)
void setYawRateAxisMode(const std::string &mode)
Configure which axis getYawRate() reports, using a string alias.
virtual void calibrate()=0
Run platform-specific IMU calibration if implemented.
void setYawRateAxisMode(const TurnAxisMode mode)
Configure which axis getYawRate() reports, using the enum form.
std::string getYawRateAxisModeName() const
virtual void resetIntegratedVelocity()
virtual void getLinearAcceleration(float *linear_accel)=0
virtual void getQuaternion(float *quat)=0
virtual float getHeading()=0
TurnAxisMode getYawRateAxisMode() const
virtual void read(float *accel, float *gyro, float *magneto)=0
Read accel, gyro, and magnetometer vectors into caller-owned buffers.
virtual bool waitForReady(int timeout_ms=1000)=0
Wait until the implementation has enough data to provide orientation.