Skip to content

Commit 74d13e2

Browse files
committed
Initialize with IMU orientation
1 parent b5c8c55 commit 74d13e2

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

include/Headers/Accumulator.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@ class Accumulator {
9494
template <typename ContentType>
9595
ContentType get_prev(Buffer<ContentType>& source, double t) {
9696
int k_t = before_t(source, t) + 1;
97+
if (k_t >= source.content.size()) k_t = source.content.size() - 1;
9798

98-
// Get leftest State right to t (sorted new to old)
99-
for (int k = k_t; k < source.content.size(); ++k) {
99+
// Get leftest (newest) content right (previous) to t (sorted new to old)
100+
for (int k = k_t; k >= 0; --k) {
100101
ContentType cnt = source.content[k];
101102
if (t > cnt.time) return cnt;
102103
}
103104

104-
// If not a state found, push an empty one at t
105-
this->add(ContentType(), t);
106-
return source.front();
105+
// If not a content found, push an empty one at t
106+
return ContentType();
107107
}
108108

109109
// Process LiDAR pointcloud message

src/Modules/Accumulator.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ extern struct Params Config;
7272
/////////////////////////////////
7373

7474
State Accumulator::get_prev_state(double t) {
75+
if (this->BUFFER_X.empty()) {
76+
State X = Localizator::getInstance().latest_state();
77+
Accumulator::getInstance().add(X, t);
78+
X.time = t;
79+
return X;
80+
}
81+
7582
return this->get_prev(this->BUFFER_X, t);
7683
}
7784

src/Modules/Localizator.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ extern struct Params Config;
6464
// Initialize
6565
if (not this->initialized) {
6666
if (imus.empty()) return;
67-
IMU initial_IMU = IMU (); // imus.back();
68-
// IMU initial_IMU = imus.back();
67+
IMU initial_IMU = imus.back();
6968
this->initialize(initial_IMU);
7069
}
7170

@@ -85,7 +84,10 @@ extern struct Params Config;
8584
State Localizator::latest_state() {
8685
// If no integrated, return empty state
8786
if (this->last_time_integrated < 0)
88-
return State (Accumulator::getInstance().initial_time);
87+
return State (
88+
this->get_x(),
89+
Accumulator::getInstance().initial_time
90+
);
8991

9092
// If no updates, return integrated state
9193
if (this->last_time_updated < 0)

0 commit comments

Comments
 (0)