ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Litle problem with assigning subscriber.

asked 2022-10-21 06:29:05 -0500

Edvard gravatar image

Hi. Sorry for all mistakes, English is not my native language. I have a subscriber that looks like this


rclcpp::Subscription<minicar_control::msg::Feedback>::SharedPtr hw_feedback_sub;
...
hw_feedback_sub = this->create_subscription<minicar_control::msg::Feedback>("hw_feedback", 1000, std::bind(&STMRobotHW::feedbackCallback, this, _1));

As far as I know this should work, but this is how problem looks in VS Code:

operand types are: std::shared_ptr<rclcpp::subscription<minicar_control::msg::feedback, std::allocator<void="">, rclcpp::message_memory_strategy::MessageMemoryStrategy<minicar_control::msg::feedback, std::allocator<void="">>>> = std::shared_ptr<rclcpp::subscription<const minicar_control::msg::feedback="" &amp;,="" std::allocator<void="">, rclcpp::message_memory_strategy::MessageMemoryStrategy<const minicar_control::msg::feedback="" &amp;,="" std::allocator<void="">>>>

I think, that this can be solved by removing hw_feedback_sub from header and use auto like this


auto hw_feedback_sub = this->create_subscription<minicar_control::msg::Feedback>("hw_feedback", 1000, std::bind(&STMRobotHW::feedbackCallback, this, _1));

But I want to know where I overlook mistake. Appreciate any help.

edit retag flag offensive close merge delete

Comments

The rclcpp::Subscription should be a class member. Removing it from header and using auto (the way you suggested), may avoid the error, but the callback will not be executed. On the other hand, I can not reproduce the error, as the code is incomplete. I suggest creating a minimal reproducible example

ravijoshi gravatar image ravijoshi  ( 2022-10-21 23:27:10 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-10-24 01:55:39 -0500

Edvard gravatar image

I manage to solve this problem. The issue was feedbackCallback method. Wrong version:


void feedbackCallback(const minicar_control::msg::Feedback &fb_msg);

Right version:


void feedbackCallback(const minicar_control::msg::Feedback::SharedPtr fb_msg);

@ravijoshi, thank you for your help. I didn't thought, that callback will not be executed.

edit flag offensive delete link more

Comments

I am glad you made it work. This is why I encourage creating a minimal reproducible example

ravijoshi gravatar image ravijoshi  ( 2022-10-24 02:11:47 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-10-21 06:29:05 -0500

Seen: 81 times

Last updated: Oct 24 '22