I have a class where declaration and implementation are in the .cpp file.
It has a member function called imageCallback()
, used in the constructor as seen below
namespace viso2_ros {
class MonoOdometer : public rclcpp::Node, public OdometerBase
{
MonoOdometer(const std::string& transport, const rclcpp::NodeOptions& options)
{
camera_sub_ = image_transport::create_subscription(this, "image", &MonoOdometer::imageCallback, transport, 1);
}
protected:
void imageCallback(
const sensor_msgs::msg::Image::ConstSharedPtr& image_msg) {
// implementation of the image callback function
}
}
} // end namespace
To me this looks ok, however it doesn't work.
The create_camera_subscription
is expecting this signature for the callback:
const function<void (const shared_ptr<const sensor_msgs::msg::Image_<allocator<void> > > &)>
but it gets this signature
void (viso2_ros::MonoOdometer::*)(const sensor_msgs::msg::Image::ConstSharedPtr &)
What does this signature mean? namespace::classname::pointer
? Why is it not a function?
(the callback signature is the exact same one they use in the documentation https://github.com/ros-perception/image_common/wiki/ROS2-Migration, if interested)