Skip to content

Commit ca952ee

Browse files
committed
fix: fix bug that geometry message didn't save correctly
Signed-off-by: vividf <yihsiang.fang@tier4.jp>
1 parent fa6d8c5 commit ca952ee

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

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

+5-7
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,6 +73,7 @@ class DistortionCorrector : public DistortionCorrectorBase
7273
std::deque<geometry_msgs::msg::TwistStamped> twist_queue_;
7374
std::deque<geometry_msgs::msg::Vector3Stamped> angular_velocity_queue_;
7475

76+
public:
7577
explicit DistortionCorrector(rclcpp::Node * node)
7678
: node_(node), tf_buffer_(node_->get_clock()), tf_listener_(tf_buffer_)
7779
{
@@ -81,12 +83,8 @@ class DistortionCorrector : public DistortionCorrectorBase
8183

8284
void processIMUMessage(
8385
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);
86+
void getIMUTransformation(const std::string & base_frame, const std::string & imu_frame);
87+
void enqueueIMU(const sensor_msgs::msg::Imu::ConstSharedPtr imu_msg);
9088

9189
bool isInputValid(sensor_msgs::msg::PointCloud2 & pointcloud);
9290
void getTwistAndIMUIterator(

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)