Skip to content

Commit 828047a

Browse files
authored
Merge pull request ros-navigation#4 from jmtc7/scanToPC-feature
Scan to pc feature
2 parents cbab60d + e64b984 commit 828047a

File tree

13 files changed

+135
-75
lines changed

13 files changed

+135
-75
lines changed

nav2_localization/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ find_package(message_filters REQUIRED)
1616
find_package(sensor_msgs REQUIRED)
1717
find_package(tf2_ros REQUIRED)
1818
find_package(tf2 REQUIRED)
19+
find_package(laser_geometry REQUIRED)
1920

2021
set(dependencies
2122
rclcpp
@@ -31,6 +32,7 @@ set(dependencies
3132
tf2_ros
3233
tf2
3334
nav2_msgs
35+
laser_geometry
3436
)
3537

3638
include_directories(include)

nav2_localization/include/nav2_localization/interfaces/matcher2d_base.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define NAV2_LOCALIZATION__MATCHER2D_BASE_HPP_
33

44
#include "geometry_msgs/msg/transform_stamped.hpp"
5-
#include "sensor_msgs/msg/laser_scan.hpp"
5+
#include "sensor_msgs/msg/point_cloud2.hpp"
66
#include "nav_msgs/msg/occupancy_grid.hpp"
77
#include "rclcpp_lifecycle/lifecycle_node.hpp"
88
#include "nav2_util/lifecycle_node.hpp"
@@ -28,7 +28,7 @@ class Matcher2d
2828
* @param curr_pose A pose to match the scan from.
2929
* @return The probability of the robot being at curr_pose, given scan
3030
*/
31-
virtual double getScanProbability(const sensor_msgs::msg::LaserScan::ConstSharedPtr &scan,
31+
virtual double getScanProbability(const sensor_msgs::msg::PointCloud2::ConstSharedPtr &scan,
3232
const geometry_msgs::msg::TransformStamped &curr_pose) = 0;
3333

3434
/**

nav2_localization/include/nav2_localization/interfaces/solver_base.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "geometry_msgs/msg/transform_stamped.hpp"
1010
#include "nav_msgs/msg/odometry.hpp"
1111
#include "geometry_msgs/msg/pose_with_covariance_stamped.hpp"
12-
#include "sensor_msgs/msg/laser_scan.hpp"
12+
#include "sensor_msgs/msg/point_cloud2.hpp"
1313
#include "nav_msgs/msg/occupancy_grid.hpp"
1414

1515
// Others
@@ -37,7 +37,7 @@ class Solver
3737
*/
3838
virtual geometry_msgs::msg::TransformStamped solve(
3939
const geometry_msgs::msg::TransformStamped& curr_odom,
40-
const sensor_msgs::msg::LaserScan::ConstSharedPtr& laser_scan) = 0;
40+
const sensor_msgs::msg::PointCloud2::ConstSharedPtr& scan) = 0;
4141

4242
/**
4343
* @brief Initializes the filter being used with a given pose

nav2_localization/include/nav2_localization/nav2_localization.hpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
#include "nav_msgs/msg/occupancy_grid.hpp"
1313
#include "message_filters/subscriber.h"
1414
#include "sensor_msgs/msg/laser_scan.hpp"
15+
#include "sensor_msgs/msg/point_cloud2.hpp"
1516
#include "tf2_ros/message_filter.h"
1617
#include "tf2_ros/transform_broadcaster.h"
1718
#include "tf2_ros/transform_listener.h"
1819
#include "geometry_msgs/msg/pose_with_covariance_stamped.hpp"
1920
#include "geometry_msgs/msg/pose_stamped.hpp"
21+
#include "laser_geometry/laser_geometry.hpp"
22+
2023

2124
namespace nav2_localization
2225
{
@@ -85,7 +88,7 @@ class LocalizationServer : public nav2_util::LifecycleNode
8588
void initTransforms();
8689

8790
/**
88-
* @brief Initializes the laser scan message filter
91+
* @brief Initializes the scan message filter
8992
*/
9093
void initMessageFilters();
9194

@@ -101,11 +104,17 @@ class LocalizationServer : public nav2_util::LifecycleNode
101104
void mapReceived(const nav_msgs::msg::OccupancyGrid::SharedPtr msg);
102105

103106
/**
104-
* @brief Callback when the laser is received
105-
* @param laser_scan pointer to the received laser message
107+
* @brief Callback when a LaserScan is received. It will convert it to a PC and use the callback for generic scans
108+
* @param scan pointer to the received LaserScan message
106109
*/
107110
void laserReceived(sensor_msgs::msg::LaserScan::ConstSharedPtr laser_scan);
108111

112+
/**
113+
* @brief Callback when the scan is received
114+
* @param scan pointer to the received PointCloud2 message
115+
*/
116+
void scanReceived(sensor_msgs::msg::PointCloud2::ConstSharedPtr scan);
117+
109118
/**
110119
* @brief Callback when the initial pose of the robot is received
111120
* @param msg pointer to the received pose
@@ -116,7 +125,7 @@ class LocalizationServer : public nav2_util::LifecycleNode
116125
rclcpp::Subscription<nav_msgs::msg::OccupancyGrid>::ConstSharedPtr map_sub_;
117126
bool first_map_received_{false};
118127

119-
// Laser scan
128+
// Scan
120129
std::string scan_topic_;
121130

122131
// Transforms
@@ -130,8 +139,12 @@ class LocalizationServer : public nav2_util::LifecycleNode
130139

131140
// Message filters
132141
std::shared_ptr<message_filters::Subscriber<sensor_msgs::msg::LaserScan>> laser_scan_sub_;
142+
std::shared_ptr<message_filters::Subscriber<sensor_msgs::msg::PointCloud2>> scan_sub_;
133143
std::shared_ptr<tf2_ros::MessageFilter<sensor_msgs::msg::LaserScan>> laser_scan_filter_;
144+
std::shared_ptr<tf2_ros::MessageFilter<sensor_msgs::msg::PointCloud2>> scan_filter_;
134145
message_filters::Connection laser_scan_connection_;
146+
message_filters::Connection scan_connection_;
147+
laser_geometry::LaserProjection laser_to_pc_projector_;
135148

136149
// Sample Motion Model Plugin
137150
pluginlib::ClassLoader<nav2_localization::SampleMotionModel> sample_motion_model_loader_;

nav2_localization/include/nav2_localization/particle_filter.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
#ifndef NAV2_LOCALIZATION__PARTICLE_FILTER_HPP_
23
#define NAV2_LOCALIZATION__PARTICLE_FILTER_HPP_
34

@@ -26,4 +27,4 @@ class ParticleFilter
2627
};
2728
} // nav2_localization
2829

29-
#endif // NAV2_LOCALIZATION__PARTICLE_FILTER_HPP_
30+
#endif // NAV2_LOCALIZATION__PARTICLE_FILTER_HPP_

nav2_localization/include/nav2_localization/plugins/matchers/likelihood_field_matcher2d.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class LikelihoodFieldMatcher2d : public Matcher2d
1212
public:
1313
LikelihoodFieldMatcher2d() : Matcher2d(){}
1414

15-
double getScanProbability(const sensor_msgs::msg::LaserScan::ConstSharedPtr& scan,
15+
double getScanProbability(const sensor_msgs::msg::PointCloud2::ConstSharedPtr& scan,
1616
const geometry_msgs::msg::TransformStamped &curr_pose) override;
1717
void setMap(const nav_msgs::msg::OccupancyGrid::SharedPtr &map) override;
1818
void setSensorPose(const geometry_msgs::msg::TransformStamped &sensor_pose) override;
@@ -46,4 +46,4 @@ class LikelihoodFieldMatcher2d : public Matcher2d
4646
};
4747
} // nav2_localization
4848

49-
#endif // NAV2_LOCALIZATION__LIKELIHOOD_FIELD_MATCHER2D_HPP_
49+
#endif // NAV2_LOCALIZATION__LIKELIHOOD_FIELD_MATCHER2D_HPP_

nav2_localization/include/nav2_localization/plugins/sample_motion_models/diff_drive_odom_motion_model.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ class DiffDriveOdomMotionModel : public SampleMotionModel
3030
};
3131
} // nav2_localization
3232

33-
#endif // NAV2_LOCALIZATION__DIFF_DRIVE_ODOM_MOTION_MODEL_HPP_
33+
#endif // NAV2_LOCALIZATION__DIFF_DRIVE_ODOM_MOTION_MODEL_HPP_

nav2_localization/include/nav2_localization/plugins/solvers/mcl_solver2d.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// Types
1010
#include "geometry_msgs/msg/transform_stamped.hpp"
1111
#include "nav_msgs/msg/odometry.hpp"
12-
#include "sensor_msgs/msg/laser_scan.hpp"
1312
#include "nav_msgs/msg/occupancy_grid.hpp"
1413

1514
// Others
@@ -25,7 +24,7 @@ class MCLSolver2d : public nav2_localization::Solver
2524

2625
geometry_msgs::msg::TransformStamped solve(
2726
const geometry_msgs::msg::TransformStamped& curr_odom,
28-
const sensor_msgs::msg::LaserScan::ConstSharedPtr& laser_scan) override;
27+
const sensor_msgs::msg::PointCloud2::ConstSharedPtr& scan) override;
2928

3029
void initFilter(const geometry_msgs::msg::PoseWithCovarianceStamped::SharedPtr &pose) override;
3130

@@ -45,4 +44,4 @@ class MCLSolver2d : public nav2_localization::Solver
4544
};
4645
} // nav2_localization
4746

48-
#endif // NAV2_LOCALIZATION__MCL_SOLVER2D_HPP_
47+
#endif // NAV2_LOCALIZATION__MCL_SOLVER2D_HPP_

nav2_localization/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<depend>sensor_msgs</depend>
2222
<depend>tf2_ros</depend>
2323
<depend>rclcpp_lifecycle</depend>
24+
<depend>laser_geometry</depend>
2425

2526
<test_depend>ament_lint_auto</test_depend>
2627
<test_depend>ament_lint_common</test_depend>
Binary file not shown.

0 commit comments

Comments
 (0)