ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

ROS2 Topic Subscription Using Lambda Funtction

asked 2021-12-28 10:23:51 -0600

hakunamatata gravatar image

updated 2021-12-28 10:29:05 -0600

Can anybody please help me with this? why is the following wring?

auto temp_nh = rclcpp::Node::make_shared("foo_node");

auto fcnptr = [ ](geometry_msgs::msg::Point msg) { geometry_msgs::msg::Pose pick_pose; pick_pose.position = msg;};

        auto assisted_vision_sub = temp_nh->create_subscription<geometry_msgs::msg::Point>(topic_name, rclcpp::QoS(1), std::bind(fcnptr,std::placeholders::_1));
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-02-08 10:34:37 -0600

jdlangs gravatar image

updated 2022-02-08 10:35:26 -0600

You didn't include any error output in your question (please always do this) but I'm guessing you got some very cryptic compiler errors involving subscription callbacks. If so, it's because a callback that receives a message by value is not supported as you have in your lambda function. I could not find any documentation for this but this github PR details the allowed callback types which includes a few new ones from Galactic onwards (const geometry_msgs::msg::Point&). For Foxy, your best bet is to change the message type to geometry_msgs::msg::Point::SharedPtr (more common) or UniquePtr (more correct).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2021-12-28 10:23:51 -0600

Seen: 72 times

Last updated: Feb 08