Skip to content

Commit deef7c4

Browse files
vividfknzo25
andauthored
fix(pointcloud_preprocessor): fix the bug where the geometry message was not saved correctly. (autowarefoundation#7886)
* fix: fix bug that geometry message didn't save correctly Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: change some functions from public to protected Signed-off-by: vividf <yihsiang.fang@tier4.jp> --------- Signed-off-by: vividf <yihsiang.fang@tier4.jp> Co-authored-by: Kenzo Lobos Tsunekawa <kenzo.lobos@tier4.jp>
1 parent 0c20459 commit deef7c4

File tree

2 files changed

+25
-30
lines changed

2 files changed

+25
-30
lines changed

sensing/pointcloud_preprocessor/include/pointcloud_preprocessor/distortion_corrector/distortion_corrector.hpp

+17-19
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class DistortionCorrectorBase
6161
template <class T>
6262
class DistortionCorrector : public DistortionCorrectorBase
6363
{
64-
public:
64+
protected:
65+
geometry_msgs::msg::TransformStamped::SharedPtr geometry_imu_to_base_link_ptr_;
6566
bool pointcloud_transform_needed_{false};
6667
bool pointcloud_transform_exists_{false};
6768
bool imu_transform_exists_{false};
@@ -72,28 +73,12 @@ class DistortionCorrector : public DistortionCorrectorBase
7273
std::deque<geometry_msgs::msg::TwistStamped> twist_queue_;
7374
std::deque<geometry_msgs::msg::Vector3Stamped> angular_velocity_queue_;
7475

75-
explicit DistortionCorrector(rclcpp::Node * node)
76-
: node_(node), tf_buffer_(node_->get_clock()), tf_listener_(tf_buffer_)
77-
{
78-
}
79-
void processTwistMessage(
80-
const geometry_msgs::msg::TwistWithCovarianceStamped::ConstSharedPtr twist_msg) override;
81-
82-
void processIMUMessage(
83-
const std::string & base_frame, const sensor_msgs::msg::Imu::ConstSharedPtr imu_msg) override;
84-
void getIMUTransformation(
85-
const std::string & base_frame, const std::string & imu_frame,
86-
geometry_msgs::msg::TransformStamped::SharedPtr geometry_imu_to_base_link_ptr);
87-
void enqueueIMU(
88-
const sensor_msgs::msg::Imu::ConstSharedPtr imu_msg,
89-
geometry_msgs::msg::TransformStamped::SharedPtr geometry_imu_to_base_link_ptr);
90-
91-
bool isInputValid(sensor_msgs::msg::PointCloud2 & pointcloud);
76+
void getIMUTransformation(const std::string & base_frame, const std::string & imu_frame);
77+
void enqueueIMU(const sensor_msgs::msg::Imu::ConstSharedPtr imu_msg);
9278
void getTwistAndIMUIterator(
9379
bool use_imu, double first_point_time_stamp_sec,
9480
std::deque<geometry_msgs::msg::TwistStamped>::iterator & it_twist,
9581
std::deque<geometry_msgs::msg::Vector3Stamped>::iterator & it_imu);
96-
void undistortPointCloud(bool use_imu, sensor_msgs::msg::PointCloud2 & pointcloud) override;
9782
void warnIfTimestampIsTooLate(bool is_twist_time_stamp_too_late, bool is_imu_time_stamp_too_late);
9883
void undistortPoint(
9984
sensor_msgs::PointCloud2Iterator<float> & it_x, sensor_msgs::PointCloud2Iterator<float> & it_y,
@@ -105,6 +90,19 @@ class DistortionCorrector : public DistortionCorrectorBase
10590
static_cast<T *>(this)->undistortPointImplementation(
10691
it_x, it_y, it_z, it_twist, it_imu, time_offset, is_twist_valid, is_imu_valid);
10792
};
93+
94+
public:
95+
explicit DistortionCorrector(rclcpp::Node * node)
96+
: node_(node), tf_buffer_(node_->get_clock()), tf_listener_(tf_buffer_)
97+
{
98+
}
99+
void processTwistMessage(
100+
const geometry_msgs::msg::TwistWithCovarianceStamped::ConstSharedPtr twist_msg) override;
101+
102+
void processIMUMessage(
103+
const std::string & base_frame, const sensor_msgs::msg::Imu::ConstSharedPtr imu_msg) override;
104+
void undistortPointCloud(bool use_imu, sensor_msgs::msg::PointCloud2 & pointcloud) override;
105+
bool isInputValid(sensor_msgs::msg::PointCloud2 & pointcloud);
108106
};
109107

110108
class DistortionCorrector2D : public DistortionCorrector<DistortionCorrector2D>

sensing/pointcloud_preprocessor/src/distortion_corrector/distortion_corrector.cpp

+8-11
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,20 @@ template <class T>
4747
void DistortionCorrector<T>::processIMUMessage(
4848
const std::string & base_frame, const sensor_msgs::msg::Imu::ConstSharedPtr imu_msg)
4949
{
50-
geometry_msgs::msg::TransformStamped::SharedPtr geometry_imu_to_base_link_ptr =
51-
std::make_shared<geometry_msgs::msg::TransformStamped>();
52-
getIMUTransformation(base_frame, imu_msg->header.frame_id, geometry_imu_to_base_link_ptr);
53-
enqueueIMU(imu_msg, geometry_imu_to_base_link_ptr);
50+
getIMUTransformation(base_frame, imu_msg->header.frame_id);
51+
enqueueIMU(imu_msg);
5452
}
5553

5654
template <class T>
5755
void DistortionCorrector<T>::getIMUTransformation(
58-
const std::string & base_frame, const std::string & imu_frame,
59-
geometry_msgs::msg::TransformStamped::SharedPtr geometry_imu_to_base_link_ptr)
56+
const std::string & base_frame, const std::string & imu_frame)
6057
{
6158
if (imu_transform_exists_) {
6259
return;
6360
}
6461

62+
geometry_imu_to_base_link_ptr_ = std::make_shared<geometry_msgs::msg::TransformStamped>();
63+
6564
tf2::Transform tf2_imu_to_base_link;
6665
if (base_frame == imu_frame) {
6766
tf2_imu_to_base_link.setOrigin(tf2::Vector3(0.0, 0.0, 0.0));
@@ -83,20 +82,18 @@ void DistortionCorrector<T>::getIMUTransformation(
8382
}
8483
}
8584

86-
geometry_imu_to_base_link_ptr->transform.rotation =
85+
geometry_imu_to_base_link_ptr_->transform.rotation =
8786
tf2::toMsg(tf2_imu_to_base_link.getRotation());
8887
}
8988

9089
template <class T>
91-
void DistortionCorrector<T>::enqueueIMU(
92-
const sensor_msgs::msg::Imu::ConstSharedPtr imu_msg,
93-
geometry_msgs::msg::TransformStamped::SharedPtr geometry_imu_to_base_link_ptr)
90+
void DistortionCorrector<T>::enqueueIMU(const sensor_msgs::msg::Imu::ConstSharedPtr imu_msg)
9491
{
9592
geometry_msgs::msg::Vector3Stamped angular_velocity;
9693
angular_velocity.vector = imu_msg->angular_velocity;
9794

9895
geometry_msgs::msg::Vector3Stamped transformed_angular_velocity;
99-
tf2::doTransform(angular_velocity, transformed_angular_velocity, *geometry_imu_to_base_link_ptr);
96+
tf2::doTransform(angular_velocity, transformed_angular_velocity, *geometry_imu_to_base_link_ptr_);
10097
transformed_angular_velocity.header = imu_msg->header;
10198
angular_velocity_queue_.push_back(transformed_angular_velocity);
10299

0 commit comments

Comments
 (0)