Skip to content

Commit bd7c8c7

Browse files
authored
Merge pull request #1 from TannerGilbert/ros2
fix: Change Velodyne message time handling
2 parents a002ccb + ca71eb4 commit bd7c8c7

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

include/preprocess.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ struct EIGEN_ALIGN16 Point
7070
{
7171
PCL_ADD_POINT4D;
7272
float intensity;
73-
std::uint32_t t;
73+
float time;
7474
std::uint16_t ring;
7575
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
7676
};
7777
} // namespace velodyne_ros
7878
POINT_CLOUD_REGISTER_POINT_STRUCT(velodyne_ros::Point,
79-
(float, x, x)(float, y, y)(float, z, z)(float, intensity, intensity)(std::uint32_t, t, t)(std::uint16_t, ring, ring))
79+
(float, x, x)(float, y, y)(float, z, z)(float, intensity, intensity)(float, time, time)(std::uint16_t, ring, ring))
8080
/****************/
8181

8282
/*** Ouster ***/
@@ -146,7 +146,7 @@ class Preprocess
146146
PointCloudXYZI pl_full, pl_corn, pl_surf;
147147
PointCloudXYZI pl_buff[128]; // maximum 128 line lidar
148148
vector<orgtype> typess[128]; // maximum 128 line lidar
149-
int lidar_type, point_filter_num, N_SCANS;
149+
int lidar_type, point_filter_num, N_SCANS, SCAN_RATE;
150150

151151
double blind, blind_sqr;
152152
bool feature_enabled, given_offset_time;

src/LIVMapper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ void LIVMapper::readParameters(rclcpp::Node::SharedPtr &node)
105105
try_declare.template operator()<int>("preprocess.lidar_type", AVIA);
106106
try_declare.template operator()<int>("preprocess.scan_line",6);
107107
try_declare.template operator()<int>("preprocess.point_filter_num", 3);
108+
try_declare.template operator()<int>("preprocess.scan_rate", 10);
108109
try_declare.template operator()<bool>("preprocess.feature_extract_enabled", false);
109110

110111
try_declare.template operator()<int>("pcd_save.interval", -1);
@@ -161,6 +162,7 @@ void LIVMapper::readParameters(rclcpp::Node::SharedPtr &node)
161162
this->node->get_parameter("preprocess.filter_size_surf", filter_size_surf_min);
162163
this->node->get_parameter("preprocess.lidar_type", p_pre->lidar_type);
163164
this->node->get_parameter("preprocess.scan_line", p_pre->N_SCANS);
165+
this->node->get_parameter("preprocess.scan_rate", p_pre->SCAN_RATE);
164166
this->node->get_parameter("preprocess.point_filter_num", p_pre->point_filter_num);
165167
this->node->get_parameter("preprocess.feature_extract_enabled", p_pre->feature_enabled);
166168

src/preprocess.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Preprocess::Preprocess() : feature_enabled(0), lidar_type(AVIA), blind(0.01), po
1919
{
2020
inf_bound = 10;
2121
N_SCANS = 6;
22+
SCAN_RATE = 10;
2223
group_size = 8;
2324
disA = 0.01;
2425
disA = 0.1; // B?
@@ -347,15 +348,16 @@ void Preprocess::velodyne_handler(const sensor_msgs::msg::PointCloud2::ConstShar
347348
pcl::PointCloud<velodyne_ros::Point> pl_orig;
348349
pcl::fromROSMsg(*msg, pl_orig);
349350
int plsize = pl_orig.points.size();
351+
if (plsize == 0) return;
350352
pl_surf.reserve(plsize);
351353

352354
bool is_first[MAX_LINE_NUM];
353355
double yaw_fp[MAX_LINE_NUM] = {0}; // yaw of first scan point
354-
double omega_l = 3.61; // scan angular velocity
356+
double omega_l = 0.361 * SCAN_RATE; // scan angular velocity
355357
float yaw_last[MAX_LINE_NUM] = {0.0}; // yaw of last scan point
356358
float time_last[MAX_LINE_NUM] = {0.0}; // last offset time
357359

358-
if (pl_orig.points[plsize - 1].t > 0) { given_offset_time = true; }
360+
if (pl_orig.points[plsize - 1].time > 0) { given_offset_time = true; }
359361
else
360362
{
361363
given_offset_time = false;
@@ -393,7 +395,7 @@ void Preprocess::velodyne_handler(const sensor_msgs::msg::PointCloud2::ConstShar
393395
added_pt.y = pl_orig.points[i].y;
394396
added_pt.z = pl_orig.points[i].z;
395397
added_pt.intensity = pl_orig.points[i].intensity;
396-
added_pt.curvature = pl_orig.points[i].t / 1000.0; // units: ms
398+
added_pt.curvature = pl_orig.points[i].time / 1000.0; // units: ms
397399

398400
if (!given_offset_time)
399401
{
@@ -456,7 +458,7 @@ void Preprocess::velodyne_handler(const sensor_msgs::msg::PointCloud2::ConstShar
456458
added_pt.y = pl_orig.points[i].y;
457459
added_pt.z = pl_orig.points[i].z;
458460
added_pt.intensity = pl_orig.points[i].intensity;
459-
added_pt.curvature = pl_orig.points[i].t / 1000.0;
461+
added_pt.curvature = pl_orig.points[i].time / 1000.0;
460462

461463
if (!given_offset_time)
462464
{

0 commit comments

Comments
 (0)