Skip to content

Commit 0dc1437

Browse files
committed
Updated initialization, now it is able to start from non-static state.
1 parent 2658398 commit 0dc1437

File tree

8 files changed

+88
-82
lines changed

8 files changed

+88
-82
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# R-VIO
22

3-
R-VIO is an efficient, lightweight, **robocentric visual-inertial odometry** algorithm for consistent 3D motion tracking using only a monocular camera and a 6-axis IMU. Different from standard world-centric VINS algorithms which directly estimate absolute motion of the sensing platform with respect to a fixed, gravity-aligned, global frame of reference, R-VIO estimates the relative motion of higher accuracy with respect to a moving local frame (for example, IMU frame) and updates the global pose (orientation and position) estimate through composition. This algorithm is developed with the robocentric sliding-window filtering-based VIO framework that we originally proposed in our *IROS2018* paper and further extended in our recent *IJRR* paper:
3+
R-VIO is an efficient, lightweight, **robocentric visual-inertial odometry** algorithm for consistent 3D motion tracking using only a monocular camera and a 6-axis IMU. Different from standard world-centric VINS algorithms which directly estimate absolute motion of the sensing platform with respect to a fixed, gravity-aligned, global frame of reference, R-VIO estimates the relative motion of higher accuracy with respect to a moving, local frame (for example, IMU frame) and updates global pose (orientation and position) estimate through composition. This code is developed with the robocentric sliding-window filtering-based VIO framework that was originally proposed in our *IROS2018* paper and further extended in our recent *IJRR* paper:
44

55
- Zheng Huai and Guoquan Huang, **Robocentric visual-inertial odometry**, *The International Journal of Robotics Research (IJRR)*, July 2019: [here](https://journals.sagepub.com/doi/10.1177/0278364919853361).
66

config/rvio_euroc.yaml

+5-8
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,20 @@ Tracker.EnableEqualizer: 1
9292
# Use Sampson error or not (RANSAC)
9393
Tracker.UseSampson: 1
9494

95-
# Threshold for inlier (RANSAC)
96-
Tracker.nSampsonThrd: 1e-4
95+
# Error threshold for inlier (RANSAC)
96+
Tracker.nInlierThrd: 1e-4
9797

9898
#--------------------------------------------------------------------------------------------
9999
# Initialization Parameters (tunable).
100100
#--------------------------------------------------------------------------------------------
101101

102-
# Use initial alignment or not
103-
INI.EnableAlignment: 1
104-
105-
# Time length of initialization [s]
106-
INI.nTimeLength: 1
107-
108102
# Thresholds for moving detection [rad,m]
109103
INI.nThresholdAngle: 0.005
110104
INI.nThresholdDispl: 0.01
111105

106+
# Use gravity alignment or not
107+
INI.EnableAlignment: 1
108+
112109
# Record the outputs or not
113110
INI.RecordOutputs: 0
114111

include/rvio/System.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class System
4545

4646
~System();
4747

48-
void MonoVIO(const cv::Mat& im, const double& timestamp, const int& seq);
48+
void MonoVIO(const cv::Mat& im, const double& timestamp);
4949

5050
void PushImuData(ImuData* data) { mpSensorDatabase->PushImuData(data); }
5151

@@ -55,15 +55,14 @@ class System
5555

5656
double mnImuRate;
5757
double mnCamTimeOffset;
58-
double mnInitTimeLength;
5958

6059
int mnSlidingWindowSize;
6160
int mnMinCloneStates;
6261

6362
bool mbEnableAlignment;
6463
bool mbRecordOutputs;
6564

66-
bool mbIsInitialized;
65+
bool mbIsReady;
6766
bool mbIsMoving;
6867

6968
double mnThresholdAngle;

package.xml

-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@
2323
<depend>eigen_conversions</depend>
2424

2525
</package>
26-

src/rvio/Ransac.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ double Ransac::SampsonError(const Eigen::Vector3d& pt1,
200200
Eigen::Vector3d Fx1 = E*pt1;
201201
Eigen::Vector3d Fx2 = E.transpose()*pt2;
202202

203-
return (pow(pt2.transpose()*E*pt1,2))/
204-
(pow(Fx1(0),2)+pow(Fx1(1),2)+pow(Fx2(0),2)+pow(Fx2(1),2));
203+
return (pow(pt2.transpose()*E*pt1,2))/(pow(Fx1(0),2)+pow(Fx1(1),2)+pow(Fx2(0),2)+pow(Fx2(1),2));
205204
}
206205

207206

src/rvio/System.cc

+73-61
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,11 @@ System::System(const std::string& strSettingsFile)
8282
const int bRecordOutputs = fsSettings["INI.RecordOutputs"];
8383
mbRecordOutputs = bRecordOutputs;
8484

85-
mnInitTimeLength = fsSettings["INI.nTimeLength"];
86-
8785
mnThresholdAngle = fsSettings["INI.nThresholdAngle"];
8886
mnThresholdDispl = fsSettings["INI.nThresholdDispl"];
8987

90-
mbIsInitialized = false;
9188
mbIsMoving = false;
89+
mbIsReady = false;
9290

9391
mpTracker = new Tracker(strSettingsFile);
9492
mpUpdater = new Updater(strSettingsFile);
@@ -108,49 +106,92 @@ System::~System()
108106
}
109107

110108

111-
void System::MonoVIO(const cv::Mat& im, const double& timestamp, const int& seq)
109+
void System::MonoVIO(const cv::Mat& im, const double& timestamp)
112110
{
113111
static int nCloneStates = 0;
114-
static int nImuDataCount = 0;
115-
static int nImageCountAfterMoving = 0;
112+
static int nImageCountAfterInit = 0;
116113

117114
std::list<ImuData*> lImuDataSeq;
118115
int nImuData = mpSensorDatabase->GetImuDataByTimeStamp(timestamp+mnCamTimeOffset, lImuDataSeq);
119116
if (nImuData==0)
120117
return;
121118

122-
nImuDataCount += nImuData;
119+
120+
/**
121+
* Moving detection
122+
*/
123+
if (!mbIsMoving)
124+
{
125+
Eigen::Vector3d angle;
126+
Eigen::Vector3d displ;
127+
angle.setZero();
128+
displ.setZero();
129+
130+
for (std::list<ImuData*>::const_iterator lit=lImuDataSeq.begin();
131+
lit!=lImuDataSeq.end(); ++lit)
132+
{
133+
Eigen::Vector3d w = (*lit)->AngularVel;
134+
Eigen::Vector3d a = (*lit)->LinearAccel;
135+
double dt = (*lit)->TimeInterval;
136+
137+
angle += dt*w;
138+
displ += .5*pow(dt,2)*(a-mnGravity*a/a.norm());
139+
}
140+
141+
// If the change is lager than the threshold
142+
if (angle.norm()>mnThresholdAngle || displ.norm()>mnThresholdDispl)
143+
mbIsMoving = true;
144+
}
123145

124146

125147
/*
126148
* Initialization
127149
*/
128-
if (!mbIsInitialized)
150+
if (!mbIsReady)
129151
{
130152
static Eigen::Vector3d wm = Eigen::Vector3d::Zero();
131153
static Eigen::Vector3d am = Eigen::Vector3d::Zero();
154+
static int nImuDataCount = 0;
132155

133156
while (!lImuDataSeq.empty())
134157
{
135-
wm += (lImuDataSeq.front())->AngularVel;
136-
am += (lImuDataSeq.front())->LinearAccel;
137-
lImuDataSeq.pop_front();
158+
if (!mbIsMoving)
159+
{
160+
wm += (lImuDataSeq.front())->AngularVel;
161+
am += (lImuDataSeq.front())->LinearAccel;
162+
163+
lImuDataSeq.pop_front();
164+
nImuDataCount++;
165+
}
166+
else
167+
{
168+
if (nImuDataCount==0)
169+
{
170+
wm = (lImuDataSeq.front())->AngularVel;
171+
am = (lImuDataSeq.front())->LinearAccel;
172+
173+
nImuDataCount = 1;
174+
}
175+
else
176+
{
177+
wm = wm/nImuDataCount;
178+
am = am/nImuDataCount;
179+
}
180+
181+
mbIsReady = true;
182+
break;
183+
}
138184
}
139185

140-
if (nImuDataCount>mnInitTimeLength*mnImuRate)
186+
if (mbIsReady)
141187
{
142-
wm = wm/nImuDataCount;
143-
am = am/nImuDataCount;
144-
145188
Eigen::Vector3d g = am;
146189
g.normalize();
147-
Eigen::Vector3d gI = mnGravity*g;
148-
149-
Eigen::Matrix3d Rot;
150190

191+
Eigen::Matrix3d R = Eigen::Matrix3d::Identity();
151192
if (mbEnableAlignment)
152193
{
153-
// i. Align z-axis with g
194+
// i. Align z-axis with gravity
154195
Eigen::Vector3d zv = g;
155196

156197
// ii. Make x-axis perpendicular to z-axis
@@ -163,16 +204,20 @@ void System::MonoVIO(const cv::Mat& im, const double& timestamp, const int& seq)
163204
yv.normalize();
164205

165206
// iv. The orientation of {G} in {R0}
166-
Rot << xv, yv, zv;
207+
Eigen::Matrix3d tempR;
208+
tempR << xv, yv, zv;
209+
R = tempR;
167210
}
168-
else
169-
Rot.setIdentity();
170211

171212
xkk.setZero(26,1);
172-
xkk.block(0,0,4,1) = RotToQuat(Rot);
213+
xkk.block(0,0,4,1) = RotToQuat(R);
173214
xkk.block(7,0,3,1) = g;
174-
xkk.block(20,0,3,1) = wm; // bg
175-
xkk.block(23,0,3,1) = am-gI; // ba
215+
216+
if (nImuDataCount>1)
217+
{
218+
xkk.block(20,0,3,1) = wm; // bg
219+
xkk.block(23,0,3,1) = am-mnGravity*g; // ba
220+
}
176221

177222
double dt = 1/mnImuRate;
178223

@@ -191,46 +236,13 @@ void System::MonoVIO(const cv::Mat& im, const double& timestamp, const int& seq)
191236
Pkk(20,20) = nImuDataCount*dt*pow(msigmaGyroBias,2);
192237
Pkk(21,21) = nImuDataCount*dt*pow(msigmaAccelBias,2); // ba
193238
Pkk(22,22) = nImuDataCount*dt*pow(msigmaAccelBias,2);
194-
Pkk(23,23) = nImuDataCount*dt*pow(msigmaAccelBias,2);
195-
196-
mbIsInitialized = true;
239+
Pkk(23,23) = nImuDataCount*dt*pow(msigmaAccelBias,2);
197240
}
198-
199-
if (!mbIsInitialized) return;
200-
}
201-
202-
203-
/**
204-
* Static/Moving detection
205-
*/
206-
if (!mbIsMoving)
207-
{
208-
Eigen::Vector3d angle;
209-
Eigen::Vector3d displ;
210-
angle.setZero();
211-
displ.setZero();
212-
213-
for (std::list<ImuData*>::const_iterator lit=lImuDataSeq.begin();
214-
lit!=lImuDataSeq.end(); ++lit)
215-
{
216-
Eigen::Vector3d w = (*lit)->AngularVel;
217-
Eigen::Vector3d a = (*lit)->LinearAccel;
218-
double dt = (*lit)->TimeInterval;
219-
220-
angle += dt*w;
221-
displ += .5*pow(dt,2)*(a-mnGravity*a/a.norm());
222-
}
223-
224-
// If the change is lager than the threshold
225-
if (angle.norm()>mnThresholdAngle || displ.norm()>mnThresholdDispl)
226-
// Is moving
227-
mbIsMoving = true;
228241
else
229-
// Is static
230242
return;
231243
}
232244

233-
nImageCountAfterMoving++;
245+
nImageCountAfterInit++;
234246

235247

236248
/**
@@ -263,7 +275,7 @@ void System::MonoVIO(const cv::Mat& im, const double& timestamp, const int& seq)
263275
/**
264276
* State augmentation
265277
*/
266-
if (nImageCountAfterMoving>1)
278+
if (nImageCountAfterInit>1)
267279
{
268280
if (nCloneStates<mnSlidingWindowSize)
269281
{

src/rvio/Tracker.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ Tracker::Tracker(const std::string& strSettingsFile)
109109
mpCornerCluster = new CornerCluster(nImageHeight, nImageWidth, nGridSize);
110110

111111
const int bUseSampson = fsSettings["Tracker.UseSampson"];
112-
const double nInlierThreshold = fsSettings["Tracker.nSampsonThrd"];
112+
const double nInlierThreshold = fsSettings["Tracker.nInlierThrd"];
113113
mpRansac = new Ransac(bUseSampson, nInlierThreshold);
114114

115115
mbIsTheFirstImage = true;
116116

117117
mLastImage = cv::Mat();
118118

119-
mTrackPub = mTrackerNode.advertise<sensor_msgs::Image>("/rvio/track", 2);
120-
mNewerPub = mTrackerNode.advertise<sensor_msgs::Image>("/rvio/newer", 2);
119+
mTrackPub = mTrackerNode.advertise<sensor_msgs::Image>("/rvio/track", 1);
120+
mNewerPub = mTrackerNode.advertise<sensor_msgs::Image>("/rvio/newer", 1);
121121
}
122122

123123

src/rvio_mono.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void ImageGrabber::GrabImage(const sensor_msgs::ImageConstPtr& msg)
5555
{
5656
static int lastseq = -1;
5757
if ((int)msg->header.seq!=lastseq+1 && lastseq!=-1)
58-
ROS_ERROR("Image message drop! curr seq: %d expected seq: %d.", msg->header.seq, lastseq+1);
58+
ROS_DEBUG("Image message drop! curr seq: %d expected seq: %d.", msg->header.seq, lastseq+1);
5959
lastseq = msg->header.seq;
6060

6161
cv_bridge::CvImageConstPtr cv_ptr;
@@ -69,15 +69,15 @@ void ImageGrabber::GrabImage(const sensor_msgs::ImageConstPtr& msg)
6969
return;
7070
}
7171

72-
mpSys->MonoVIO(cv_ptr->image, cv_ptr->header.stamp.toSec(), msg->header.seq);
72+
mpSys->MonoVIO(cv_ptr->image, cv_ptr->header.stamp.toSec());
7373
}
7474

7575

7676
void ImuGrabber::GrabImu(const sensor_msgs::ImuConstPtr& msg)
7777
{
7878
static int lastseq = -1;
7979
if ((int) msg->header.seq!=lastseq+1 && lastseq!=-1)
80-
ROS_ERROR("IMU message drop! curr seq: %d expected seq: %d.", msg->header.seq, lastseq+1);
80+
ROS_DEBUG("IMU message drop! curr seq: %d expected seq: %d.", msg->header.seq, lastseq+1);
8181
lastseq = msg->header.seq;
8282

8383
Eigen::Vector3d angular_velocity;

0 commit comments

Comments
 (0)