Skip to content

Commit fe48636

Browse files
committed
Further fixes
1 parent ae76213 commit fe48636

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

scripts/clang-formatter.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
find kitti*/ mola*/ -iname *.h -o -iname *.hpp -o -iname *.cpp -o -iname *.c | xargs -I FIL bash -c "echo FIL && clang-format-14 -i FIL"
3+
find include src -iname *.h -o -iname *.hpp -o -iname *.cpp -o -iname *.c | xargs -I FIL bash -c "echo FIL && clang-format-14 -i FIL"

src/LocalVelocityBuffer.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,21 @@ std::string LocalVelocityBuffer::SamplesByTime::asString() const
179179
std::ostringstream oss;
180180
oss << "SamplesByTime:\n";
181181

182-
auto dumpMap = [&](const std::string& name, const auto& map)
182+
auto dumpMap = [&](const std::string& name, const auto& map, bool isMatrix = false)
183183
{
184184
oss << " " << name << ":\n";
185185
for (const auto& [t, val] : map)
186186
{
187-
oss << " [" << t << "] = " << val << "\n";
187+
oss << " [" << t << "] = ";
188+
if (isMatrix)
189+
{
190+
oss << "\n";
191+
}
192+
oss << val << "\n";
188193
}
189194
};
190195

191-
dumpMap("q (orientation)", q);
196+
dumpMap("q (orientation)", q, true);
192197
dumpMap("v_b (linear velocity)", v_b);
193198
dumpMap("a_b (linear acceleration)", a_b);
194199
dumpMap("w_b (angular velocity)", w_b);
@@ -203,7 +208,7 @@ std::string LocalVelocityBuffer::Sample::asString() const
203208

204209
auto dumpOpt = [&](const std::string& name, const auto& opt)
205210
{
206-
oss << " " << name << ": ";
211+
oss << " " << name;
207212
if (opt.has_value())
208213
{
209214
oss << *opt << "\n";
@@ -214,10 +219,10 @@ std::string LocalVelocityBuffer::Sample::asString() const
214219
}
215220
};
216221

217-
dumpOpt("q (orientation)", q);
218-
dumpOpt("v_b (linear velocity)", v_b);
219-
dumpOpt("a_b (linear acceleration)", a_b);
220-
dumpOpt("w_b (angular velocity)", w_b);
222+
dumpOpt("q (orientation):\n", q);
223+
dumpOpt("v_b (linear velocity): ", v_b);
224+
dumpOpt("a_b (linear acceleration): ", a_b);
225+
dumpOpt("w_b (angular velocity): ", w_b);
221226

222227
return oss.str();
223228
}

src/trajectory_from_buffer.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,21 @@ Trajectory mola::imu::trajectory_from_buffer(
146146
t[0].w_b = mrpt::containers::find_closest(samples.by_type.w_b, 0.0)->second - bias_gyro;
147147
t[0].a_b = mrpt::containers::find_closest(samples.by_type.a_b, 0.0)->second - bias_acc;
148148

149-
// 3) Copy the closest gravity-aligned hints on global orientations:
150-
const auto closest_q = mrpt::containers::find_closest(samples.by_type.q, 0.0);
149+
// 3) Copy the latest gravity-aligned hints on global orientations:
150+
const double last_sample_rel_time = samples.by_time.rbegin()->first;
151+
const auto closest_q = mrpt::containers::find_closest(samples.by_type.q, last_sample_rel_time);
151152
ASSERTMSG_(
152153
closest_q,
153154
"At least one entry with gravity-aligned orientation is needed for IMU integration");
154155
const double stamp_first_R_ga = closest_q->first;
155-
t[stamp_first_R_ga].R_ga = closest_q->second;
156+
t[closest_q->first].R_ga = closest_q->second;
157+
158+
// 3b) and copy the closest velocity from the given samples:
159+
const auto closest_v_b =
160+
mrpt::containers::find_closest(samples.by_type.v_b, last_sample_rel_time);
161+
ASSERTMSG_(closest_v_b, "At least one entry with velocity is needed for IMU integration");
162+
const double stamp_first_v_b = closest_v_b->first;
163+
t[closest_v_b->first].v = closest_v_b->second;
156164

157165
// and assign the closest IMU reading to all frames:
158166
for (auto& [stamp, tp] : t)
@@ -251,12 +259,6 @@ Trajectory mola::imu::trajectory_from_buffer(
251259
});
252260
}
253261

254-
// 7) Copy the closest velocity from the given samples:
255-
const auto closest_v_b = mrpt::containers::find_closest(samples.by_type.v_b, 0.0);
256-
ASSERTMSG_(closest_v_b, "At least one entry with velocity is needed for IMU integration");
257-
const double stamp_first_v_b = closest_v_b->first;
258-
t[stamp_first_v_b].v = closest_v_b->second;
259-
260262
// 8) Integrate v:
261263
if (use_higher_order)
262264
{

tests/test-velocity-buffer.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <mrpt/containers/yaml.h>
2424
#include <mrpt/core/exceptions.h>
2525
#include <mrpt/core/round.h>
26+
#include <mrpt/poses/Lie/SO.h>
2627
#include <mrpt/system/os.h>
2728

2829
#include <iostream>
@@ -118,18 +119,18 @@ void unit_test_yaml_roundtrip()
118119
buf.parameters.tolerance_search_stamp = 1e-2;
119120
buf.set_reference_zero_time(123.456);
120121

121-
LinearVelocity v{1.0, 2.0, 3.0};
122-
AngularVelocity w{0.1, 0.2, 0.3};
123-
LinearAcceleration a{9.8, 0.0, -9.8};
124-
SO3 R = mrpt::math::CMatrixDouble33::Identity();
122+
const LinearVelocity v{1.0, 2.0, 3.0};
123+
const AngularVelocity w{0.1, 0.2, 0.3};
124+
const LinearAcceleration a{9.8, 0.0, -9.8};
125+
const SO3 R = mrpt::poses::CPose3D(0, 0, 0, 0.7, 0.0, 0.0).getRotationMatrix();
125126

126127
buf.add_linear_velocity(123.400, v);
127128
buf.add_angular_velocity(123.410, w);
128129
buf.add_linear_acceleration(123.420, a);
129130
buf.add_orientation(123.430, R);
130131

131132
// Serialize
132-
auto yml = buf.toYAML();
133+
const auto yml = buf.toYAML();
133134

134135
yml.printAsYAML();
135136

@@ -175,7 +176,12 @@ void unit_test_yaml_roundtrip()
175176
{
176177
const auto it = buf2.get_orientations().find(t);
177178
ASSERT_(it != buf2.get_orientations().end());
178-
ASSERT_(R1 == it->second);
179+
mrpt::math::CMatrixDouble33 error_R = R1.inverse() * it->second;
180+
if (mrpt::poses::Lie::SO<3>::log(error_R).norm() > 1e-4)
181+
{
182+
std::cerr << "R1:\n" << R1 << "\nit->second:\n" << it->second << "\n";
183+
THROW_EXCEPTION("Error in rotation matrix");
184+
}
179185
}
180186

181187
std::cout << "✅ LocalVelocityBuffer unit_test_yaml_roundtrip passed!" << std::endl;

0 commit comments

Comments
 (0)