Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(probabilistic_occupancy_gridmap): prevent node death by adding lookupTransform exception in util function #4713

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions perception/probabilistic_occupancy_grid_map/src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ bool transformPointcloud(
const std::string & target_frame, sensor_msgs::msg::PointCloud2 & output)
{
geometry_msgs::msg::TransformStamped tf_stamped;
tf_stamped = tf2.lookupTransform(
target_frame, input.header.frame_id, input.header.stamp, rclcpp::Duration::from_seconds(0.5));
// lookup transform
try {
tf_stamped = tf2.lookupTransform(
target_frame, input.header.frame_id, input.header.stamp, rclcpp::Duration::from_seconds(0.5));
} catch (tf2::TransformException & ex) {
RCLCPP_WARN(
rclcpp::get_logger("probabilistic_occupancy_grid_map"), "Failed to lookup transform: %s",
ex.what());
return false;
}
// transform pointcloud
Eigen::Matrix4f tf_matrix = tf2::transformToEigen(tf_stamped.transform).matrix().cast<float>();
pcl_ros::transformPointCloud(tf_matrix, input, output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,29 @@ def test_null_input(self, proc_info):
self.assertIn("occupancy_grid_map_node", nodes)
self.assertEqual(len(self.msg_buffer), 1)

def test_null_input2(self, proc_info):
"""Test null input.

input: null pointcloud without even frame_id
output: null ogm
"""
# wait for the node to be ready
time.sleep(3)
input_points = []
pub_raw, pub_obstacle, sub = self.create_pub_sub()
# publish input pointcloud
pt_msg = get_pointcloud_msg(input_points)
pt_msg.header.frame_id = ""
pub_raw.publish(pt_msg)
pub_obstacle.publish(pt_msg)
# try to subscribe output pointcloud once
rclpy.spin_once(self.node, timeout_sec=3.0)

# check if process is successfully terminated
nodes = self.node.get_node_names()
self.assertIn("occupancy_grid_map_node", nodes)
self.assertEqual(len(self.msg_buffer), 0)


@launch_testing.post_shutdown_test()
class TestProcessOutput(unittest.TestCase):
Expand Down