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 m_agrc, char** m_argv)
{
rclcpp::init(m_argc, m_argv);
m_rosnode = std::make_shared<rclcpp::node>(“node_sub”);
sub = m_rosnode->create_subscription<std_msgs::msg::string>( “topic”,
std::bind(&MinimalSubscriber::topic_callback, this, _1));
while(rclcpp::ok()) { rclp::spin(m_rosnode); }
}
private:
void topic_callback(const std_msgs::msg::String::SharedPtr msg) { RCLCPP_INFO(m_rosnode->get_logger(), “I heard: ‘%s’”, msg->data.c_str()) }
rclcpp::Publisher<std_msgs::msg::string>::SharedPtr m_rosnode;
rclcpp::Subscription<std_msgs::msg::string>::SharedPtr sub;
};
int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
std::shared_ptr m_sub = std::make_shared;
rclcpp::shutdown();
return 0;
}
Hi I tried to build this above example, but I got an error: C:\dev\ros2_fastrtps\ros2-windows\include\rclcpp\subscription_factory: error C2672: ‘rclcpp::AnySubscriptionCallback<messaget,alloc>::set’: no matching overloaded function found.
this error was caused by this line : subscription = m_rosnode->create_subscription<std_msgs::msg::string>( “topic”, std::bind(&MinimalSubscriber::topic_callback, this, _1));
Can anyone help me? Thanks in advance!
This was cross-posted with a solution: https://discourse.ros.org/t/ros2-subs...