Skip to content

Commit cd1eb51

Browse files
committed
Fix lint error
1 parent fee54e7 commit cd1eb51

3 files changed

Lines changed: 176 additions & 222 deletions

File tree

include/ndt_localizer/map_matcher.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class MapMatcher : public rclcpp::Node
3131
typedef pcl::PointCloud<PointType> CloudType;
3232
typedef pcl::PointCloud<PointType>::Ptr CloudTypePtr;
3333

34-
MapMatcher(const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
35-
virtual ~MapMatcher(void) = default;
34+
explicit MapMatcher(const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
3635

3736
void pose_callback(const nav_msgs::msg::Odometry::ConstSharedPtr & msg);
3837
void map_callback(const sensor_msgs::msg::PointCloud2::ConstSharedPtr & msg);

src/map_matcher.cpp

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77

88
namespace ndt_localizer
99
{
10-
MapMatcher::MapMatcher(const rclcpp::NodeOptions& options)
11-
: Node("map_matcher", options)
10+
MapMatcher::MapMatcher(const rclcpp::NodeOptions & options)
11+
: Node("map_matcher", options)
1212
{
1313
pose_pub_ = this->create_publisher<geometry_msgs::msg::PoseStamped>("ndt_pose", 1);
1414
cloud_pub_ = this->create_publisher<sensor_msgs::msg::PointCloud2>("cloud/aligned", 1);
1515
pose_sub_ = this->create_subscription<nav_msgs::msg::Odometry>(
16-
"estimated_pose", 1, std::bind(&MapMatcher::pose_callback, this, std::placeholders::_1));
16+
"estimated_pose", 1, std::bind(&MapMatcher::pose_callback, this, std::placeholders::_1));
1717
map_sub_ = this->create_subscription<sensor_msgs::msg::PointCloud2>(
18-
"map_cloud", 1, std::bind(&MapMatcher::map_callback, this, std::placeholders::_1));
18+
"map_cloud", 1, std::bind(&MapMatcher::map_callback, this, std::placeholders::_1));
1919
cloud_sub_ = this->create_subscription<sensor_msgs::msg::PointCloud2>(
20-
"scan_cloud", 1, std::bind(&MapMatcher::cloud_callback, this, std::placeholders::_1));
20+
"scan_cloud", 1, std::bind(&MapMatcher::cloud_callback, this, std::placeholders::_1));
2121

2222
epsilon_ = this->declare_parameter<double>("epsilon", 1e-2);
2323
leaf_size_ = this->declare_parameter<double>("leaf_size", 0.5);
@@ -43,23 +43,22 @@ MapMatcher::MapMatcher(const rclcpp::NodeOptions& options)
4343
tfl_ = std::make_shared<tf2_ros::TransformListener>(*tf_);
4444
}
4545

46-
void MapMatcher::pose_callback(const nav_msgs::msg::Odometry::ConstSharedPtr& msg)
46+
void MapMatcher::pose_callback(const nav_msgs::msg::Odometry::ConstSharedPtr & msg)
4747
{
4848
is_pose_updated_ = true;
4949
received_pose_ = *msg;
5050
}
5151

52-
void MapMatcher::map_callback(const sensor_msgs::msg::PointCloud2::ConstSharedPtr& msg)
52+
void MapMatcher::map_callback(const sensor_msgs::msg::PointCloud2::ConstSharedPtr & msg)
5353
{
5454
RCLCPP_INFO(this->get_logger(), "received map");
5555
pcl::fromROSMsg(*msg, *map_cloud_ptr_);
5656
is_map_received_ = true;
5757
}
5858

59-
void MapMatcher::cloud_callback(const sensor_msgs::msg::PointCloud2::ConstSharedPtr& msg)
59+
void MapMatcher::cloud_callback(const sensor_msgs::msg::PointCloud2::ConstSharedPtr & msg)
6060
{
61-
if (is_map_received_ && is_pose_updated_)
62-
{
61+
if (is_map_received_ && is_pose_updated_) {
6362
CloudTypePtr cloud_ptr(new CloudType);
6463
pcl::fromROSMsg(*msg, *cloud_ptr);
6564
cloud_ptr->is_dense = false;
@@ -68,17 +67,17 @@ void MapMatcher::cloud_callback(const sensor_msgs::msg::PointCloud2::ConstShared
6867
apply_voxel_grid_filter(leaf_size_, cloud_ptr);
6968
// RCLCPP_INFO_STREAM(this->get_logger(), "aft: " << cloud_ptr->points.size());
7069
const geometry_msgs::msg::TransformStamped sensor_to_base_tf =
71-
tf_->lookupTransform(received_pose_.child_frame_id, msg->header.frame_id, msg->header.stamp);
70+
tf_->lookupTransform(received_pose_.child_frame_id, msg->header.frame_id, msg->header.stamp);
7271
const Eigen::Matrix4f sensor_to_base_mat =
73-
tf2::transformToEigen(sensor_to_base_tf.transform).matrix().cast<float>();
72+
tf2::transformToEigen(sensor_to_base_tf.transform).matrix().cast<float>();
7473
pcl::transformPointCloud(*cloud_ptr, *cloud_ptr, sensor_to_base_mat);
7574
const Eigen::Matrix4f transform = get_ndt_transform(cloud_ptr);
76-
if (transform.isZero(1e-6))
77-
{
75+
if (transform.isZero(1e-6)) {
7876
return;
7977
}
80-
RCLCPP_INFO_STREAM(this->get_logger(), "transform:\n"
81-
<< transform);
78+
RCLCPP_INFO_STREAM(
79+
this->get_logger(), "transform:\n"
80+
<< transform);
8281
geometry_msgs::msg::PoseStamped aligned_pose;
8382
aligned_pose.header.stamp = msg->header.stamp;
8483
aligned_pose.header.frame_id = map_cloud_ptr_->header.frame_id;
@@ -92,44 +91,41 @@ void MapMatcher::cloud_callback(const sensor_msgs::msg::PointCloud2::ConstShared
9291
aligned_pose.pose.orientation.y = q.y();
9392
aligned_pose.pose.orientation.z = q.z();
9493
RCLCPP_INFO_STREAM(
95-
this->get_logger(), "aligned pose:\n"
96-
<< geometry_msgs::msg::to_yaml(aligned_pose.pose));
94+
this->get_logger(), "aligned pose:\n"
95+
<< geometry_msgs::msg::to_yaml(aligned_pose.pose));
9796
pose_pub_->publish(aligned_pose);
9897
is_pose_updated_ = false;
99-
}
100-
else
101-
{
102-
if (!is_pose_updated_)
103-
{
98+
} else {
99+
if (!is_pose_updated_) {
104100
RCLCPP_WARN_THROTTLE(
105-
this->get_logger(), *this->get_clock(), 1000,
106-
"cloud is received but pose has not been updated");
101+
this->get_logger(), *this->get_clock(), 1000,
102+
"cloud is received but pose has not been updated");
107103
}
108-
if (!is_map_received_)
109-
{
104+
if (!is_map_received_) {
110105
RCLCPP_WARN_THROTTLE(
111-
this->get_logger(), *this->get_clock(), 1000,
112-
"cloud is received but map has not been received");
106+
this->get_logger(), *this->get_clock(), 1000,
107+
"cloud is received but map has not been received");
113108
}
114109
}
115110
}
116111

117-
Eigen::Matrix4f MapMatcher::get_ndt_transform(const CloudTypePtr& cloud_ptr)
112+
Eigen::Matrix4f MapMatcher::get_ndt_transform(const CloudTypePtr & cloud_ptr)
118113
{
119114
const Eigen::Vector3f translation_vector = {
120-
static_cast<float>(received_pose_.pose.pose.position.x),
121-
static_cast<float>(received_pose_.pose.pose.position.y),
122-
static_cast<float>(received_pose_.pose.pose.position.z),
115+
static_cast<float>(received_pose_.pose.pose.position.x),
116+
static_cast<float>(received_pose_.pose.pose.position.y),
117+
static_cast<float>(received_pose_.pose.pose.position.z),
123118
};
124119
const Eigen::Translation3f init_translation(translation_vector);
125120
const Eigen::AngleAxisf init_rotation(
126-
Eigen::Quaternionf(
127-
received_pose_.pose.pose.orientation.w, received_pose_.pose.pose.orientation.x,
128-
received_pose_.pose.pose.orientation.y, received_pose_.pose.pose.orientation.z)
129-
.normalized());
121+
Eigen::Quaternionf(
122+
received_pose_.pose.pose.orientation.w, received_pose_.pose.pose.orientation.x,
123+
received_pose_.pose.pose.orientation.y, received_pose_.pose.pose.orientation.z)
124+
.normalized());
130125
const Eigen::Matrix4f init_guess = (init_translation * init_rotation).matrix();
131-
RCLCPP_INFO_STREAM(this->get_logger(), "init_guess:\n"
132-
<< init_guess);
126+
RCLCPP_INFO_STREAM(
127+
this->get_logger(), "init_guess:\n"
128+
<< init_guess);
133129
CloudTypePtr filtered_map_cloud_ptr(new CloudType);
134130
apply_passthrough_filter(range_, map_cloud_ptr_, filtered_map_cloud_ptr, translation_vector);
135131
CloudTypePtr filtered_scan_cloud_ptr(new CloudType);
@@ -149,14 +145,12 @@ Eigen::Matrix4f MapMatcher::get_ndt_transform(const CloudTypePtr& cloud_ptr)
149145
ndt.setNeighborhoodSearchMethod(pclomp::DIRECT7);
150146
CloudTypePtr aligned_cloud_ptr(new CloudType);
151147
ndt.align(*aligned_cloud_ptr, init_guess);
152-
if (!ndt.hasConverged())
153-
{
148+
if (!ndt.hasConverged()) {
154149
RCLCPP_ERROR(this->get_logger(), "ndt not converged!");
155150
return Eigen::Matrix4f::Zero();
156151
}
157152
RCLCPP_INFO_STREAM(this->get_logger(), "score: " << ndt.getFitnessScore());
158-
if (cloud_pub_->get_subscription_count() > 0)
159-
{
153+
if (cloud_pub_->get_subscription_count() > 0) {
160154
sensor_msgs::msg::PointCloud2 aligned_cloud_msg;
161155
aligned_cloud_ptr->header.frame_id = map_cloud_ptr_->header.frame_id;
162156
pcl::toROSMsg(*aligned_cloud_ptr, aligned_cloud_msg);
@@ -165,7 +159,7 @@ Eigen::Matrix4f MapMatcher::get_ndt_transform(const CloudTypePtr& cloud_ptr)
165159
return ndt.getFinalTransformation();
166160
}
167161

168-
void MapMatcher::apply_voxel_grid_filter(double leaf_size, CloudTypePtr& cloud_ptr)
162+
void MapMatcher::apply_voxel_grid_filter(double leaf_size, CloudTypePtr & cloud_ptr)
169163
{
170164
pcl::VoxelGrid<PointType> vg;
171165
vg.setInputCloud(cloud_ptr);
@@ -177,8 +171,8 @@ void MapMatcher::apply_voxel_grid_filter(double leaf_size, CloudTypePtr& cloud_p
177171
}
178172

179173
void MapMatcher::apply_passthrough_filter(
180-
double range, const CloudTypePtr& cloud_ptr, CloudTypePtr& output_cloud_ptr,
181-
const Eigen::Vector3f& center)
174+
double range, const CloudTypePtr & cloud_ptr, CloudTypePtr & output_cloud_ptr,
175+
const Eigen::Vector3f & center)
182176
{
183177
pcl::PassThrough<PointType> pass;
184178
pass.setInputCloud(cloud_ptr);

0 commit comments

Comments
 (0)