Skip to content

Commit fc333ef

Browse files
committed
Add option 'use_imu_orientation' to disable using IMU orientation for initialization
1 parent 5183f8b commit fc333ef

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

include/mola_imu_preintegration/ImuInitialCalibrator.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ class ImuInitialCalibrator
4848
std::size_t required_samples = 50; //!< Minimum required samples
4949
double max_samples_age = .75; //!< Maximum samples age [seconds]
5050
double gravity = 9.81; //<! Gravity magnitude [m/s²]
51+
52+
/** If provided by the IMU, prefer gravity-aligned orientation from the sensor instead of
53+
* accelerometer data. Should be normally preferable, so default is true.
54+
*/
55+
bool use_imu_orientation = true;
5156
};
5257

5358
Parameters parameters;
@@ -88,4 +93,7 @@ class ImuInitialCalibrator
8893
std::map<double, const mrpt::obs::CObservationIMU> samples_;
8994
};
9095

96+
// Remove when all distros have the version with "use_imu_orientation"
97+
#define MOLA_IMU_PREINT_HAS_USE_IMU_ORIENT_PARAM
98+
9199
} // namespace mola::imu

src/ImuInitialCalibrator.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,23 @@ std::optional<ImuInitialCalibrator::Results> ImuInitialCalibrator::getCalibratio
132132
mrpt::math::TVector3D average_gyro(0, 0, 0);
133133
forEachGyro([&](const auto& omega) { average_gyro += omega; });
134134

135-
mrpt::poses::SO_average<3> so3_average;
136-
forEachOrientation([&](const auto& pose) { so3_average.append(pose.getRotationMatrix()); });
137135
std::optional<mrpt::poses::CPose3D> avr_so3;
138-
try
136+
if (parameters.use_imu_orientation)
139137
{
140-
auto rot = so3_average.get_average();
138+
mrpt::poses::SO_average<3> so3_average;
139+
forEachOrientation([&](const auto& pose) { so3_average.append(pose.getRotationMatrix()); });
140+
try
141+
{
142+
auto rot = so3_average.get_average();
141143

142-
avr_so3.emplace();
143-
avr_so3->setRotationMatrix(rot);
144-
}
145-
catch (const std::exception& e)
146-
{
147-
// Ignore, this means we had no data.
148-
(void)e;
144+
avr_so3.emplace();
145+
avr_so3->setRotationMatrix(rot);
146+
}
147+
catch (const std::exception& e)
148+
{
149+
// Ignore, this means we had no data.
150+
(void)e;
151+
}
149152
}
150153

151154
const std::size_t count = samples_.size();

0 commit comments

Comments
 (0)