Robotics StackExchange | Archived questions

How to use callback in a class containing ROS2 Node (Win10 X64, Visual Studio 14)

using std::placeholders::_1;

class MinimalSubscriber {

public:

MinimalSubscriber() {}

init(int magrc, char** margv)

{

rclcpp::init(margc, margv);

mrosnode = std::makesharedrclcpp::Node(“node_sub”);

sub = mrosnode->createsubscription( “topic”,

std::bind(&MinimalSubscriber::topic_callback, this, _1));

while(rclcpp::ok()) { rclp::spin(m_rosnode); }

}

private:

void topiccallback(const stdmsgs::msg::String::SharedPtr msg) { RCLCPPINFO(mrosnode->getlogger(), “I heard: ‘%s’”, msg->data.cstr()) }

rclcpp::Publisher::SharedPtr m_rosnode;

rclcpp::Subscription::SharedPtr sub;

};

int main(int argc, char * argv[])

{

rclcpp::init(argc, argv);

std::sharedptr msub = std::make_shared;

rclcpp::shutdown();

return 0;

}

Hi I tried to build this above example, but I got an error: C:\dev\ros2fastrtps\ros2-windows\include\rclcpp\subscriptionfactory: error C2672: ‘rclcpp::AnySubscriptionCallback::set’: no matching overloaded function found.

this error was caused by this line : subscription = mrosnode->createsubscription( “topic”, std::bind(&MinimalSubscriber::topic_callback, this, _1));

Can anyone help me? Thanks in advance!

Asked by ycs134470 on 2018-05-23 10:01:15 UTC

Comments

This was cross-posted with a solution: https://discourse.ros.org/t/ros2-subscriber-defined-in-class-win10-visual-studio-14/4863/5

Asked by William on 2018-05-23 18:31:45 UTC

Answers