0
$\begingroup$

Rosanswers logo

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, rclcpp::message_memory_strategy::MessageMemoryStrategy<minicar_control::msg::Feedback, std::allocator>>> = std::shared_ptr<rclcpp::Subscription<const minicar_control::msg::Feedback &, std::allocator, rclcpp::message_memory_strategy::MessageMemoryStrategy<const minicar_control::msg::Feedback &, std::allocator>>>

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.


Originally posted by Edvard on ROS Answers with karma: 95 on 2022-10-21

Post score: 0


Original comments

Comment by ravijoshi on 2022-10-21:
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

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Edvard with karma: 95 on 2022-10-24

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by ravijoshi on 2022-10-24:
I am glad you made it work. This is why I encourage creating a minimal reproducible example

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.