forked from lukasvst/dm-vio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_IMUInterpolator.cpp
189 lines (146 loc) · 6.28 KB
/
test_IMUInterpolator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/**
* This file is part of DM-VIO.
*
* Copyright (c) 2022 Lukas von Stumberg <lukas dot stumberg at tum dot de>.
* for more information see <http://vision.in.tum.de/dm-vio>.
* If you use this code, please cite the respective publications as
* listed on the above website.
*
* DM-VIO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DM-VIO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DM-VIO. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include "live/IMUInterpolator.h"
#include "live/FrameContainer.h"
using namespace dmvio;
TEST(TestIMUInterpolator, SimpleTest)
{
FrameContainer frameContainer;
IMUInterpolator imuInt(frameContainer, nullptr);
Frame frame0;
frame0.imgTimestamp = 0.5;
frameContainer.addFrame(std::move(frame0));
auto pair = frameContainer.getImageAndIMUData().second;
imuInt.addGyrData({1.0, 1.0, 1.0}, 2);
imuInt.addAccData({1.0, 1.0, 1.0}, 1);
imuInt.addAccData({2.0, 2.0, 2.0}, 3);
// Should be interpolated to one acc measurement with 1.5
imuInt.addAccData({5.0, 5.0, 5.0}, 4);
imuInt.addGyrData({5.0, 5.0, 5.0}, 4);
imuInt.addImage(nullptr, 5);
imuInt.addGyrData({7.0, 7.0, 7.0}, 8);
imuInt.addAccData({7.0, 7.0, 7.0}, 6);
// 4, 5, 8 --> one quarter of the way from 5 to 7 --> 5.5
auto imuData = frameContainer.getImageAndIMUData().second;
EXPECT_EQ(imuData.size(), 3);
// ensure that all measurements have valid acc and gyr data.
for(auto&& data : imuData)
{
EXPECT_TRUE(data.getAccData().size() > 0);
EXPECT_TRUE(data.getAccData().size() > 0);
}
// EXPECT_EQ(allData[0].timestamp, 2.0);
EXPECT_EQ(imuData[0].getAccData()[0], 1.5);
EXPECT_EQ(imuData[0].getGyrData()[0], 1.0);
// EXPECT_EQ(allData[1].timestamp, 4.0);
EXPECT_EQ(imuData[1].getAccData()[0], 5.0);
EXPECT_EQ(imuData[1].getGyrData()[0], 5.0);
// EXPECT_EQ(allData[2].timestamp, 5);
EXPECT_EQ(imuData[2].getAccData()[0], 6.0);
EXPECT_EQ(imuData[2].getGyrData()[0], 5.5);
EXPECT_EQ(imuData[0].getIntegrationTime(), 1.5);
EXPECT_EQ(imuData[1].getIntegrationTime(), 2.0);
EXPECT_EQ(imuData[2].getIntegrationTime(), 1.0);
}
TEST(TestIMUInterpolator, ProblematicInputOrders)
{
FrameContainer frameContainer;
IMUInterpolator imuInt(frameContainer, nullptr);
Frame frame0;
frame0.imgTimestamp = 0.5;
frameContainer.addFrame(std::move(frame0));
auto pair = frameContainer.getImageAndIMUData().second;
// First gyr data should not be put into the output, as it's impossible to interpolate acc data for it.
imuInt.addGyrData({1.0, 1.0, 1.0}, 2);
imuInt.addAccData({2.0, 2.0, 2.0}, 3);
imuInt.addGyrData({2.0, 2.0, 2.0}, 4);
imuInt.addAccData({3.0, 3.0, 3.0}, 5);
imuInt.addImage(nullptr, 6);
imuInt.addAccData({5.0, 5.0, 5.0}, 6);
imuInt.addGyrData({5.0, 5.0, 5.0}, 6);
auto imuData = frameContainer.getImageAndIMUData().second;
EXPECT_EQ(imuData.size(), 2);
EXPECT_EQ(imuData[0].getGyrData()[0], 2.0);
EXPECT_EQ(imuData[0].getAccData()[0], 2.5);
EXPECT_EQ(imuData[0].getIntegrationTime(), 3.5);
EXPECT_EQ(imuData[1].getGyrData()[0], 5);
EXPECT_EQ(imuData[1].getAccData()[0], 5);
EXPECT_EQ(imuData[1].getIntegrationTime(), 2);
}
void addEmptyFrame(IMUInterpolator& imuInt, double time, float imuData)
{
imuInt.addAccData({imuData, imuData, imuData}, time);
imuInt.addGyrData({imuData, imuData, imuData}, time);
imuInt.addImage(std::make_unique<dso::ImageAndExposure>(0, 0, time), time);
}
TEST(TestIMUInterpolator, TestFrameSkipping)
{
FrameContainer frameContainer;
IMUInterpolator imuInt(frameContainer, nullptr);
imuInt.addAccData({0.0, 0.0, 0.0}, 0.0);
imuInt.addGyrData({0.0, 0.0, 0.0}, 0.0);
addEmptyFrame(imuInt, 1.0, 1.0);
addEmptyFrame(imuInt, 2.0, 2.0);
auto&& pair = frameContainer.getImageAndIMUData(10);
EXPECT_EQ(pair.first->timestamp, 2.0);
addEmptyFrame(imuInt, 3.0, 3.0);
addEmptyFrame(imuInt, 4.0, 4.0);
addEmptyFrame(imuInt, 5.0, 5.0);
pair = frameContainer.getImageAndIMUData(1);
EXPECT_EQ(pair.first->timestamp, 4.0);
EXPECT_EQ(pair.second.size(), 2);
EXPECT_EQ(pair.second[0].getAccData()[0], 3.0);
EXPECT_EQ(pair.second[1].getAccData()[0], 4.0);
pair = frameContainer.getImageAndIMUData(1);
EXPECT_EQ(pair.first->timestamp, 5.0);
EXPECT_EQ(pair.second.size(), 1);
EXPECT_EQ(pair.second[0].getAccData()[0], 5.0);
}
// Test, where the first frame doesn't have IMU data yet.
TEST(TestIMUInterpolator, TestNoPrevAccData)
{
FrameContainer frameContainer;
IMUInterpolator imuInt(frameContainer, nullptr);
// This image should also be skipped, because it comes before the IMU data.
imuInt.addImage(std::make_unique<dso::ImageAndExposure>(0, 0, 0.5), 0.5);
float imuData = 1.0f;
imuInt.addAccData({imuData, imuData, imuData}, 1.2);
imuInt.addGyrData({imuData, imuData, imuData}, 1.2);
double time = 1.0;
// This image should be skipped, because the IMU data starts only after it.
imuInt.addImage(std::make_unique<dso::ImageAndExposure>(0, 0, time), time);
imuInt.addAccData({3, 3, 3}, 1.5);
imuInt.addGyrData({3, 3, 3}, 1.5);
imuInt.addImage(std::make_unique<dso::ImageAndExposure>(0, 0, 2.0), 2.0);
imuInt.addAccData({4, 4, 4}, 3.5);
imuInt.addGyrData({4, 4, 4}, 3.5);
auto pair = frameContainer.getImageAndIMUData(0); // don't skip frames.
// Note that the IMU data of the first frame is not used (as there is no previous frame), but we test it anyway.
EXPECT_EQ(pair.first->timestamp, 2.0);
EXPECT_EQ(pair.second.size(), 3);
EXPECT_EQ(pair.second[0].getAccData()[0], imuData);
EXPECT_DOUBLE_EQ(pair.second[1].getIntegrationTime(), 0.3);
EXPECT_EQ(pair.second[1].getAccData()[0], 3.0);
EXPECT_EQ(pair.second[2].getIntegrationTime(), 0.5);
EXPECT_EQ(pair.second[2].getAccData()[0], 3.25);
}