Skip to content

Commit 330ebff

Browse files
author
jyakaranda
committed
unsync msg 未处理
1 parent 6f79557 commit 330ebff

8 files changed

+504
-56
lines changed

include/imageProjection.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class ImageProjection : public nodelet::Nodelet
1212
ros::Publisher pub_segmented_cloud_;
1313
ros::Publisher pub_seg_info_;
1414
ros::Publisher pub_outlier_;
15-
sensor_msgs::PointCloud2 segmented_cloud_msg_;
16-
alego::cloud_info seg_info_msg_;
17-
sensor_msgs::PointCloud2 outlier_cloud_msg_;
15+
sensor_msgs::PointCloud2Ptr segmented_cloud_msg_;
16+
alego::cloud_infoPtr seg_info_msg_;
17+
sensor_msgs::PointCloud2Ptr outlier_cloud_msg_;
1818

1919
PointCloudT::Ptr full_cloud_;
2020
PointCloudT::Ptr segmented_cloud_;

include/laserOdometry.h

+56-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,65 @@
22

33
namespace loam
44
{
5+
using namespace std;
56
class LaserOdometry : public nodelet::Nodelet
67
{
78
public:
89
virtual void onInit();
10+
11+
private:
12+
ros::NodeHandle nh_;
13+
ros::NodeHandle pnh_;
14+
ros::Subscriber sub_segmented_cloud_;
15+
ros::Subscriber sub_segmented_info_;
16+
ros::Subscriber sub_outlier_;
17+
ros::Subscriber sub_imu_;
18+
ros::Subscriber sub_odom_;
19+
ros::Publisher pub_surf_;
20+
ros::Publisher pub_surf_less_;
21+
ros::Publisher pub_corner_;
22+
ros::Publisher pub_corner_less_;
23+
ros::Publisher pub_undistorted_pc_;
24+
25+
queue<sensor_msgs::PointCloud2ConstPtr> seg_cloud_buf_;
26+
queue<alego::cloud_infoConstPtr> seg_info_buf_;
27+
queue<sensor_msgs::PointCloud2ConstPtr> outlier_buf_;
28+
queue<nav_msgs::OdometryConstPtr> odom_buf_;
29+
queue<sensor_msgs::ImuConstPtr> imu_buf_;
30+
31+
int imu_ptr_front_, imu_ptr_last_, imu_ptr_last_iter_;
32+
std::array<double, imu_queue_length> imu_time_;
33+
std::array<float, imu_queue_length> imu_roll_;
34+
std::array<float, imu_queue_length> imu_pitch_;
35+
std::array<float, imu_queue_length> imu_yaw_;
36+
std::array<float, imu_queue_length> imu_shift_x_;
37+
std::array<float, imu_queue_length> imu_shift_y_;
38+
std::array<float, imu_queue_length> imu_shift_z_;
39+
std::array<float, imu_queue_length> imu_velo_x_;
40+
std::array<float, imu_queue_length> imu_velo_y_;
41+
std::array<float, imu_queue_length> imu_velo_z_;
42+
43+
// 里程计相关
44+
int odom_ptr_front_, odom_ptr_last_, odom_ptr_last_iter_;
45+
std::array<nav_msgs::OdometryConstPtr, odom_queue_length> odom_queue_;
46+
std::array<float, odom_queue_length> odom_roll_;
47+
std::array<float, odom_queue_length> odom_pitch_;
48+
std::array<float, odom_queue_length> odom_yaw_;
49+
50+
std::mutex m_buf_;
51+
52+
void mainLoop();
53+
54+
void adjustDistortion(PointCloudT::Ptr cloud, double scan_time);
55+
void calculateSmoothness();
56+
void markOcculudedPoints();
57+
void extractFeatures();
58+
59+
void segCloudHandler(const sensor_msgs::PointCloud2ConstPtr &msg);
60+
void segInfoHandler(const alego::cloud_infoConstPtr &msg);
61+
void outlierHandler(const sensor_msgs::PointCloud2ConstPtr &msg);
62+
63+
void imuHandler(const sensor_msgs::ImuConstPtr &msg);
64+
void odomHandler(const nav_msgs::OdometryConstPtr &msg);
965
};
1066
} // namespace loam
11-
12-
PLUGINLIB_EXPORT_CLASS(loam::LaserOdometry, nodelet::Nodelet)

include/utility.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,27 @@ using PointCloudT = pcl::PointCloud<PointT>;
4242
#define ANGLE2RAD(x) ((x) / 180.0 * M_PI)
4343

4444
const int N_SCAN = 16;
45-
const float ang_res_x = 0.18;
45+
const float ang_res_x = 0.18; // 10Hz
4646
const float ang_res_y = 2.0;
47+
const float scan_period = 0.1; // 10Hz
4748

48-
const int Horizon_SCAN = 360.0 / ang_res_x + 0.5; // 10Hz
49+
const int Horizon_SCAN = 360.0 / ang_res_x + 0.5;
4950
const float ang_bottom = 15.0;
5051
const int ground_scan_id = 7;
5152
const float sensor_mount_ang = 0.; // 向下为正,向上为负
5253

53-
// 可以调调参数
5454
const float seg_alpha_x = ANGLE2RAD(ang_res_x);
5555
const float seg_alpha_y = ANGLE2RAD(ang_res_y);
56+
// 可以调调参数
5657
const float seg_theta = 1.0472;
5758
const int seg_valid_point_num = 5;
5859
const int seg_valid_line_num = 3;
5960

61+
// (use_imu && use_odom) == false
6062
const bool use_imu = true;
61-
const bool use_odom = true;
63+
const bool use_odom = false;
64+
const int imu_queue_length = 1000;
65+
const int odom_queue_length = 1000;
6266

6367
class TicToc
6468
{

launch/test.launch

+2
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44

55
<node pkg="nodelet" type="nodelet" name="lego_manager" args="manager" output="log" />
66
<node pkg="nodelet" type="nodelet" name="ImageProjection" args="load loam/ImageProjection lego_manager" output="log" />
7+
<node pkg="nodelet" type="nodelet" name="LaserOdometry" args="load loam/LaserOdometry lego_manager" output="log" />
8+
79
</launch>

nodelet_plugins.xml

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<library path="lib/libimageProjection">
2-
<class name="loam/ImageProjection" type="loam::ImageProjection" base_class_type="nodelet::Nodelet">
3-
<description>
4-
ImageProjection
5-
</description>
6-
</class>
7-
<class name="loam/LaserOdometry" type="loam::LaserOdometry" base_class_type="nodelet::Nodelet"/>
2+
<class name="loam/ImageProjection" type="loam::ImageProjection" base_class_type="nodelet::Nodelet" />
3+
</library>
4+
5+
<library path="lib/liblaserOdometry">
6+
<class name="loam/LaserOdometry" type="loam::LaserOdometry" base_class_type="nodelet::Nodelet" />
7+
</library>
8+
9+
<library path="lib/liblaserMapping">
810
<class name="loam/LaserMapping" type="loam::LaserMapping" base_class_type="nodelet::Nodelet" />
911
</library>

rviz/test.rviz

+41-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Panels:
66
Expanded:
77
- /Global Options1
88
- /Status1
9+
- /outlier1/Status1
10+
- /PointCloud21
911
Splitter Ratio: 0.5
1012
Tree Height: 773
1113
- Class: rviz/Selection
@@ -100,7 +102,7 @@ Visualization Manager:
100102
Color: 255; 255; 255
101103
Color Transformer: FlatColor
102104
Decay Time: 0
103-
Enabled: true
105+
Enabled: false
104106
Invert Rainbow: false
105107
Max Color: 255; 255; 255
106108
Max Intensity: 255
@@ -117,7 +119,7 @@ Visualization Manager:
117119
Unreliable: false
118120
Use Fixed Frame: true
119121
Use rainbow: true
120-
Value: true
122+
Value: false
121123
- Alpha: 1
122124
Autocompute Intensity Bounds: true
123125
Autocompute Value Bounds:
@@ -130,12 +132,12 @@ Visualization Manager:
130132
Color: 255; 255; 255
131133
Color Transformer: Intensity
132134
Decay Time: 0
133-
Enabled: true
135+
Enabled: false
134136
Invert Rainbow: false
135137
Max Color: 255; 255; 255
136-
Max Intensity: 15.1721001
138+
Max Intensity: 15.1498003
137139
Min Color: 0; 0; 0
138-
Min Intensity: 9.99999975e-05
140+
Min Intensity: 0
139141
Name: segmented
140142
Position Transformer: XYZ
141143
Queue Size: 10
@@ -147,7 +149,7 @@ Visualization Manager:
147149
Unreliable: false
148150
Use Fixed Frame: true
149151
Use rainbow: true
150-
Value: true
152+
Value: false
151153
- Alpha: 1
152154
Autocompute Intensity Bounds: true
153155
Autocompute Value Bounds:
@@ -178,6 +180,36 @@ Visualization Manager:
178180
Use Fixed Frame: true
179181
Use rainbow: true
180182
Value: true
183+
- Alpha: 1
184+
Autocompute Intensity Bounds: true
185+
Autocompute Value Bounds:
186+
Max Value: 10
187+
Min Value: -10
188+
Value: true
189+
Axis: Z
190+
Channel Name: intensity
191+
Class: rviz/PointCloud2
192+
Color: 255; 255; 255
193+
Color Transformer: Intensity
194+
Decay Time: 0
195+
Enabled: true
196+
Invert Rainbow: false
197+
Max Color: 255; 255; 255
198+
Max Intensity: 15.1975002
199+
Min Color: 0; 0; 0
200+
Min Intensity: 9.99999975e-05
201+
Name: PointCloud2
202+
Position Transformer: XYZ
203+
Queue Size: 10
204+
Selectable: true
205+
Size (Pixels): 3
206+
Size (m): 0.100000001
207+
Style: Flat Squares
208+
Topic: /undistorted
209+
Unreliable: false
210+
Use Fixed Frame: true
211+
Use rainbow: true
212+
Value: true
181213
Enabled: true
182214
Global Options:
183215
Background Color: 48; 48; 48
@@ -203,7 +235,7 @@ Visualization Manager:
203235
Views:
204236
Current:
205237
Class: rviz/Orbit
206-
Distance: 77.0821152
238+
Distance: 61.62677
207239
Enable Stereo Rendering:
208240
Stereo Eye Separation: 0.0599999987
209241
Stereo Focal Distance: 1
@@ -218,10 +250,10 @@ Visualization Manager:
218250
Invert Z Axis: false
219251
Name: Current View
220252
Near Clip Distance: 0.00999999978
221-
Pitch: 0.864796996
253+
Pitch: 0.53979665
222254
Target Frame: <Fixed Frame>
223255
Value: Orbit (rviz)
224-
Yaw: 2.12711835
256+
Yaw: 2.67211771
225257
Saved: ~
226258
Window Geometry:
227259
Displays:

src/imageProjection.cpp

+32-31
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ namespace loam
77

88
void ImageProjection::onInit()
99
{
10+
NODELET_INFO("---------- ImageProjection init -----------");
1011
TicToc t_init;
11-
nh_ = getNodeHandle();
12+
nh_ = getMTNodeHandle();
1213

13-
seg_info_msg_.startRingIndex.resize(N_SCAN);
14-
seg_info_msg_.endRingIndex.resize(N_SCAN);
15-
seg_info_msg_.segmentedCloudColInd.assign(N_SCAN * Horizon_SCAN, false);
16-
seg_info_msg_.segmentedCloudGroundFlag.assign(N_SCAN * Horizon_SCAN, 0);
17-
seg_info_msg_.segmentedCloudRange.assign(N_SCAN * Horizon_SCAN, 0);
14+
segmented_cloud_msg_.reset(new sensor_msgs::PointCloud2());
15+
seg_info_msg_.reset(new alego::cloud_info());
16+
outlier_cloud_msg_.reset(new sensor_msgs::PointCloud2());
17+
18+
seg_info_msg_->startRingIndex.resize(N_SCAN);
19+
seg_info_msg_->endRingIndex.resize(N_SCAN);
20+
seg_info_msg_->segmentedCloudColInd.assign(N_SCAN * Horizon_SCAN, false);
21+
seg_info_msg_->segmentedCloudGroundFlag.assign(N_SCAN * Horizon_SCAN, 0);
22+
seg_info_msg_->segmentedCloudRange.assign(N_SCAN * Horizon_SCAN, 0);
1823
full_cloud_.reset(new PointCloudT());
1924
segmented_cloud_.reset(new PointCloudT());
2025
outlier_cloud_.reset(new PointCloudT());
@@ -33,34 +38,34 @@ void ImageProjection::onInit()
3338
neighbor_iter_.emplace_back(0, 1);
3439

3540
pub_segmented_cloud_ = nh_.advertise<sensor_msgs::PointCloud2>("/segmented_cloud", 10);
36-
pub_seg_info_ = nh_.advertise<sensor_msgs::PointCloud2>("/seg_info", 10);
41+
pub_seg_info_ = nh_.advertise<alego::cloud_info>("/seg_info", 10);
3742
pub_outlier_ = nh_.advertise<sensor_msgs::PointCloud2>("/outlier", 10);
3843
sub_pc_ = nh_.subscribe<sensor_msgs::PointCloud2>("/lslidar_point_cloud", 10, boost::bind(&ImageProjection::pcCB, this, _1));
39-
cout << "onInit end: " << t_init.toc() << endl;
44+
NODELET_INFO_STREAM("ImageProjection onInit end: " << t_init.toc());
4045
}
4146

4247
void ImageProjection::pcCB(const sensor_msgs::PointCloud2ConstPtr &msg)
4348
{
44-
cout << "pcCB" << endl;
49+
// cout << "pcCB" << endl;
4550
TicToc t_whole;
4651

47-
seg_info_msg_.header = msg->header;
52+
seg_info_msg_->header = msg->header;
4853
PointCloudT::Ptr cloud_in(new PointCloudT());
4954
pcl::fromROSMsg(*msg, *cloud_in);
5055
// ROS_INFO("cloud_in size: %d", cloud_in->points.size());
5156

5257
int cloud_size = cloud_in->points.size();
53-
seg_info_msg_.startOrientation = -atan2(cloud_in->points[0].y, cloud_in->points[0].x);
54-
seg_info_msg_.endOrientation = -atan2(cloud_in->points[cloud_size - 1].y, cloud_in->points[cloud_size - 1].x) + 2 * M_PI;
55-
if (seg_info_msg_.endOrientation - seg_info_msg_.startOrientation > 3 * M_PI)
58+
seg_info_msg_->startOrientation = -atan2(cloud_in->points[0].y, cloud_in->points[0].x);
59+
seg_info_msg_->endOrientation = -atan2(cloud_in->points[cloud_size - 1].y, cloud_in->points[cloud_size - 1].x) + 2 * M_PI;
60+
if (seg_info_msg_->endOrientation - seg_info_msg_->startOrientation > 3 * M_PI)
5661
{
57-
seg_info_msg_.endOrientation -= 2 * M_PI;
62+
seg_info_msg_->endOrientation -= 2 * M_PI;
5863
}
59-
else if (seg_info_msg_.endOrientation - seg_info_msg_.startOrientation < M_PI)
64+
else if (seg_info_msg_->endOrientation - seg_info_msg_->startOrientation < M_PI)
6065
{
61-
seg_info_msg_.endOrientation += 2 * M_PI;
66+
seg_info_msg_->endOrientation += 2 * M_PI;
6267
}
63-
seg_info_msg_.orientationDiff = seg_info_msg_.endOrientation - seg_info_msg_.startOrientation;
68+
seg_info_msg_->orientationDiff = seg_info_msg_->endOrientation - seg_info_msg_->startOrientation;
6469

6570
float vertical_ang, horizon_ang;
6671
int row_id, col_id, index;
@@ -145,7 +150,7 @@ void ImageProjection::pcCB(const sensor_msgs::PointCloud2ConstPtr &msg)
145150
int line_size = 0;
146151
for (int i = 0; i < N_SCAN; ++i)
147152
{
148-
seg_info_msg_.startRingIndex[i] = line_size + 5;
153+
seg_info_msg_->startRingIndex[i] = line_size + 5;
149154
for (int j = 0; j < Horizon_SCAN; ++j)
150155
{
151156
if (label_mat_(i, j) > 0 || ground_mat_(i, j) == 1)
@@ -167,18 +172,14 @@ void ImageProjection::pcCB(const sensor_msgs::PointCloud2ConstPtr &msg)
167172
}
168173
}
169174

170-
seg_info_msg_.segmentedCloudGroundFlag[line_size] = (ground_mat_(i, j) == 1);
171-
seg_info_msg_.segmentedCloudColInd[line_size] = j;
172-
seg_info_msg_.segmentedCloudRange[line_size] = range_mat_(i, j);
175+
seg_info_msg_->segmentedCloudGroundFlag[line_size] = (ground_mat_(i, j) == 1);
176+
seg_info_msg_->segmentedCloudColInd[line_size] = j;
177+
seg_info_msg_->segmentedCloudRange[line_size] = range_mat_(i, j);
173178
segmented_cloud_->points.push_back(full_cloud_->points[j + i * Horizon_SCAN]);
174179
++line_size;
175180
}
176-
else if (label_mat_(i, j) == 0 && range_mat_(i, j) != std::numeric_limits<float>::max())
177-
{
178-
ROS_WARN("error");
179-
}
180181
}
181-
seg_info_msg_.endRingIndex[i] = line_size - 1 - 5;
182+
seg_info_msg_->endRingIndex[i] = line_size - 1 - 5;
182183
}
183184
publish();
184185

@@ -195,7 +196,7 @@ void ImageProjection::pcCB(const sensor_msgs::PointCloud2ConstPtr &msg)
195196
nan_p.intensity = -1;
196197
std::fill(full_cloud_->points.begin(), full_cloud_->points.end(), nan_p);
197198

198-
std::cout << "image projection time: " << t_whole.toc() << " ms" << std::endl;
199+
// std::cout << "image projection time: " << t_whole.toc() << " ms" << std::endl;
199200
}
200201

201202
void ImageProjection::labelComponents(int row, int col)
@@ -314,14 +315,14 @@ void ImageProjection::publish()
314315
}
315316
if (pub_segmented_cloud_.getNumSubscribers() > 0)
316317
{
317-
pcl::toROSMsg(*segmented_cloud_, segmented_cloud_msg_);
318-
segmented_cloud_msg_.header = seg_info_msg_.header;
318+
pcl::toROSMsg(*segmented_cloud_, *segmented_cloud_msg_);
319+
segmented_cloud_msg_->header = seg_info_msg_->header;
319320
pub_segmented_cloud_.publish(segmented_cloud_msg_);
320321
}
321322
if (pub_outlier_.getNumSubscribers() > 0)
322323
{
323-
pcl::toROSMsg(*outlier_cloud_, outlier_cloud_msg_);
324-
outlier_cloud_msg_.header = seg_info_msg_.header;
324+
pcl::toROSMsg(*outlier_cloud_, *outlier_cloud_msg_);
325+
outlier_cloud_msg_->header = seg_info_msg_->header;
325326
pub_outlier_.publish(outlier_cloud_msg_);
326327
}
327328
}

0 commit comments

Comments
 (0)