Skip to content

Commit 653de8e

Browse files
committed
Added use_yaw_increments that uses yaw increments from IMU since last update as initial guess for the optimizer. This is a good choice when robot performs very fast yaw rotations
1 parent a9cb82c commit 653de8e

File tree

3 files changed

+62
-31
lines changed

3 files changed

+62
-31
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ find_package(catkin REQUIRED COMPONENTS
1414
pcl_ros
1515
octomap_ros
1616
nav_msgs
17-
)
17+
)
1818

1919
# Ceres solver
2020
find_package(Ceres REQUIRED)

src/dll_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main(int argc, char **argv)
1414
ros::spin();
1515

1616
return 0;
17-
}
17+
}
1818

1919

2020

src/dllnode.hpp

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class DLLNode
4343
m_globalFrameId = "map";
4444
if (!lnh.getParam("use_imu", m_use_imu))
4545
m_use_imu = false;
46-
m_roll = m_pitch = m_yaw = 0.0;
46+
if (!lnh.getParam("use_yaw_increments", m_useYawIncrements))
47+
m_useYawIncrements = false;
48+
m_roll_imu = m_pitch_imu = m_yaw_imu = 0.0;
4749

4850
// Read DLL parameters
4951
if(!lnh.getParam("update_rate", m_updateRate))
@@ -205,25 +207,28 @@ class DLLNode
205207
//! IMU callback
206208
void imuCallback(const sensor_msgs::Imu::ConstPtr& msg)
207209
{
208-
double r = m_roll;
209-
double p = m_pitch;
210-
double y = m_yaw;
210+
double r = m_roll_imu;
211+
double p = m_pitch_imu;
212+
double y = m_yaw_imu;
211213
auto o = msg->orientation;
212214
tf::Quaternion q;
213215
tf::quaternionMsgToTF(o, q);
214216
tf::Matrix3x3 M(q);
215-
M.getRPY(m_roll, m_pitch, m_yaw);
216-
if (isnan(m_roll) || isnan(m_pitch) || isnan(m_yaw))
217+
M.getRPY(m_roll_imu, m_pitch_imu, m_yaw_imu);
218+
if (isnan(m_roll_imu) || isnan(m_pitch_imu) || isnan(m_yaw_imu))
217219
{
218-
m_roll = r;
219-
m_pitch = p;
220-
m_yaw = y;
220+
m_roll_imu = r;
221+
m_pitch_imu = p;
222+
m_yaw_imu = y;
221223
}
222224
}
223225

224226
//! 3D point-cloud callback
225227
void pointcloudCallback(const sensor_msgs::PointCloud2ConstPtr& cloud)
226-
{
228+
{
229+
static double lastYaw_imu = -1000.0;
230+
double deltaYaw_imu = 0;
231+
227232
// If the filter is not initialized then exit
228233
if(!m_init)
229234
return;
@@ -265,7 +270,7 @@ class DLLNode
265270
sensor_msgs::PointCloud2 baseCloud;
266271
pcl_ros::transformPointCloud(m_baseFrameId, m_pclTf, *cloud, baseCloud);
267272

268-
// Uniform lidar downsampling based on front view projection
273+
// PointCloud2 to PointXYZ conevrsion, with range limits [0,1000]
269274
std::vector<pcl::PointXYZ> downCloud;
270275
PointCloud2_to_PointXYZ(baseCloud, downCloud);
271276

@@ -276,20 +281,35 @@ class DLLNode
276281
tz = mapTf.getOrigin().getZ();
277282

278283
// Get estimated orientation into the map
279-
double r, p;
284+
double roll, pitch, yaw;
280285
if(m_use_imu)
281-
mapTf.getBasis().getRPY(r, p, m_yaw); // Get roll and pitch from IMU
286+
{
287+
// Get roll and pitch from IMU, yaw from TF
288+
double r, p;
289+
mapTf.getBasis().getRPY(r, p, yaw);
290+
roll = m_roll_imu;
291+
pitch = m_pitch_imu;
292+
293+
// Get yaw increment from IMU, if so required
294+
if(m_useYawIncrements)
295+
{
296+
if(lastYaw_imu < -100.0)
297+
lastYaw_imu = m_yaw_imu;
298+
deltaYaw_imu = m_yaw_imu-lastYaw_imu;
299+
lastYaw_imu = m_yaw_imu;
300+
}
301+
}
282302
else
283-
mapTf.getBasis().getRPY(m_roll, m_pitch, m_yaw);
303+
mapTf.getBasis().getRPY(roll, pitch, yaw);
284304

285305
// Tilt-compensate point-cloud according to roll and pitch
286306
std::vector<pcl::PointXYZ> points;
287307
float cr, sr, cp, sp, cy, sy, rx, ry;
288308
float r00, r01, r02, r10, r11, r12, r20, r21, r22;
289-
sr = sin(m_roll);
290-
cr = cos(m_roll);
291-
sp = sin(m_pitch);
292-
cp = cos(m_pitch);
309+
sr = sin(roll);
310+
cr = cos(roll);
311+
sp = sin(pitch);
312+
cp = cos(pitch);
293313
r00 = cp; r01 = sp*sr; r02 = cr*sp;
294314
r10 = 0; r11 = cr; r12 = -sr;
295315
r20 = -sp; r21 = cp*sr; r22 = cp*cr;
@@ -303,16 +323,21 @@ class DLLNode
303323
}
304324

305325
// Launch DLL solver
326+
double a;
327+
if(m_use_imu && m_useYawIncrements)
328+
a = yaw+deltaYaw_imu;
306329
if(m_alignMethod == 1) // DLL solver
307-
m_solver.solve(points, tx, ty, tz, m_yaw);
330+
m_solver.solve(points, tx, ty, tz, a);
308331
else if(m_alignMethod == 2) // NDT solver
309-
m_grid3d.alignNDT(points, tx, ty, tz, m_yaw);
332+
m_grid3d.alignNDT(points, tx, ty, tz, a);
310333
else if(m_alignMethod == 3) // ICP solver
311-
m_grid3d.alignICP(points, tx, ty, tz, m_yaw);
334+
m_grid3d.alignICP(points, tx, ty, tz, a);
335+
if(m_use_imu && m_useYawIncrements)
336+
yaw = a;
312337

313338
// Update global TF
314339
tf::Quaternion q;
315-
q.setRPY(m_roll, m_pitch, m_yaw);
340+
q.setRPY(roll, pitch, yaw);
316341
m_lastGlobalTf = tf::Transform(q, tf::Vector3(tx, ty, tz))*odomTf.inverse();
317342

318343
// Update time and transform information
@@ -336,19 +361,25 @@ class DLLNode
336361
}
337362

338363
// Get estimated orientation from IMU if available
339-
double r, p;
364+
double roll, pitch, yaw;
340365
if(m_use_imu)
341-
m_lastOdomTf.getBasis().getRPY(r, p, m_yaw); // Get roll and pitch from IMU
366+
{
367+
// Get roll and pitch from IMU, yaw from TF
368+
double r, p;
369+
m_lastOdomTf.getBasis().getRPY(r, p, yaw);
370+
roll = m_roll_imu;
371+
pitch = m_pitch_imu;
372+
}
342373
else
343-
m_lastOdomTf.getBasis().getRPY(m_roll, m_pitch, m_yaw);
374+
m_lastOdomTf.getBasis().getRPY(roll, pitch, yaw);
344375

345376
// Get position information from pose
346377
tf::Vector3 t = initPose.getOrigin();
347-
m_yaw = getYawFromTf(initPose);
378+
yaw = getYawFromTf(initPose);
348379

349380
// Update global TF
350381
tf::Quaternion q;
351-
q.setRPY(m_roll, m_pitch, m_yaw);
382+
q.setRPY(roll, pitch, yaw);
352383
m_lastGlobalTf = tf::Transform(q, tf::Vector3(t.x(), t.y(), t.z()+m_initZOffset))*m_lastOdomTf.inverse();
353384

354385
// Prepare next iterations
@@ -387,14 +418,14 @@ class DLLNode
387418
bool m_init;
388419

389420
//! Use IMU flag
390-
bool m_use_imu;
421+
bool m_use_imu, m_useYawIncrements;
391422

392423
//! Indicates that the local transfrom for the pint-cloud is cached
393424
bool m_tfCache;
394425
tf::StampedTransform m_pclTf;
395426

396427
//! Particles roll and pich (given by IMU)
397-
double m_roll, m_pitch, m_yaw;
428+
double m_roll_imu, m_pitch_imu, m_yaw_imu;
398429

399430
//! Filter initialization
400431
double m_initX, m_initY, m_initZ, m_initA, m_initZOffset;

0 commit comments

Comments
 (0)