Ros_deep_learning how to manage the subscriber for the node Detectnet?

Hi
I tried to create a new node (move_controller) to subscribe the detections topic from DetectNet node.

auto det_sub = ROS_CREATE_SUBSCRIBER(vision_msgs::Detection2DArray, “detections”, 25, det_callback);

However, I’m wondering what kind of the arguments that I should design in the callback function (det_callback).

In the image reletaed topic, it uses the following design in the callback, the sensor_msgs::ImageConstPtr is included.

void img_callback( const sensor_msgs::ImageConstPtr input )

However, in namespace vision_msgs , I don’t see any pointers could be used for callback function.

When I design the callback as follows:
void det_callback( const vision_msgs::Detection2DArray input)

I got the following error from compiler:

/home/jetbot/ros_workspace/src/ros_deep_learning_project/src/node_move_controller.cpp:25:17: required from here
/opt/ros/eloquent/include/rclcpp/subscription_factory.hpp:87:3: error: no matching function for call to ‘rclcpp::AnySubscriptionCallback<vision_msgs::msg::Detection2DArray_<std::allocator<void> >, std::allocator<void> >::set(void (&)(vision_msgs::msg::Detection2DArray_<std::allocator<void> >))’
   any_subscription_callback.set(std::forward<CallbackT>(callback));


In file included from /opt/ros/eloquent/include/rclcpp/subscription_base.hpp:26:0,
                 from /opt/ros/eloquent/include/rclcpp/callback_group.hpp:26,
                 from /opt/ros/eloquent/include/rclcpp/any_executable.hpp:20,
                 from /opt/ros/eloquent/include/rclcpp/memory_strategy.hpp:24,
                 from /opt/ros/eloquent/include/rclcpp/memory_strategies.hpp:18,
                 from /opt/ros/eloquent/include/rclcpp/executor.hpp:33,
                 from /opt/ros/eloquent/include/rclcpp/executors/multi_threaded_executor.hpp:25,
                 from /opt/ros/eloquent/include/rclcpp/executors.hpp:21,
                 from /opt/ros/eloquent/include/rclcpp/rclcpp.hpp:145,
                 from /home/jetbot/ros_workspace/src/ros_deep_learning_project/src/ros_compat.h:71,
                 from /home/jetbot/ros_workspace/src/ros_deep_learning_project/src/node_move_controller.cpp:1:

Does anyone know how to implement the callback in the right way with C++?

Hi @lzlallen1980, does const vision_msgs::Detection2DArrayConstPtr& det work for you?

I found it referenced in this post: https://answers.ros.org/question/351056/problems-with-boostbind-in-a-class-with-message_filter/?answer=351074#post-id-351074

Otherwise you might want to try const vision_msgs::Detection2DArray* or similar.

Hi @dusty_nv
I tried both but none of them is working, I’m not sure if anything should be added into ros_combat.h

for

Detection2DArrayConstPtr&

I got this error

error: ‘Detection2DArrayConstPtr’ in namespace ‘vision_msgs’ does not name a type
void det_callback( const vision_msgs::Detection2DArrayConstPtr& input){

and for

const vision_msgs::Detection2DArray*

I got this error

error: no matching function for call to ‘rclcpp::AnySubscriptionCallback<const vision_msgs::msg::Detection2DArray_<std::allocator >, std::allocator >::set(void (&)(const vision_msgs::msg::Detection2DArray_<std::allocator >))’
any_subscription_callback.set(std::forward(callback));

however, I build it successfully withthe following arguments without adding anything else into ros_combat.h

const vision_msgs::Detection2DArray::SharedPtr

OK thanks, I will have to remember this is the correct way to use it as well.