ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Why is my Callback function not called?

asked 2019-06-20 14:42:52 -0500

MarviB16 gravatar image

updated 2019-06-20 15:00:46 -0500

Hello,

so I have the following code:

These are my callback functions:

void callbackVel( const cu_msgs::CAN_VCUStateEstimation::ConstPtr& msg ) {
    ROS_INFO("HELLO");
    speed0 = msg->velocity[0] < 0.1;
}

void callbackPose( const geometry_msgs::PointStamped::ConstPtr& msg) {
    Vector3f tmp = vehiclePose;
    vehiclePose = Vector3f(
        msg->point.x,
        msg->point.y,
        msg->point.z
    );

    //increase driven distance
    odometer += (vehiclePose - tmp).norm();
}

And these are the subscriber definitions:

    ros::Subscriber subVel = nh.subscribe< cu_msgs::CAN_VCUStateEstimation >("/mailman/state_estimation", 1, callbackVel);
    ros::Subscriber subPose = nh.subscribe< geometry_msgs::PointStamped >("slam/best_guess/position", 1, callbackPose);
   ros::Rate r(10);
   while (ros::ok()) {
        //do stuff
        ros::spinOnce();
        r.sleep();
    }

The callback function "callbackPose" is called regularly as it should, but the callback function callbackVel is never called. Even though when I listen to "rostopic echo /mailman/state_estimation" I get the message at a frequency of about 100Hz. What could be the reason for that?

edit retag flag offensive close merge delete

Comments

Can you post the code from the publishing node?

LeoE gravatar image LeoE  ( 2019-06-21 04:46:00 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-06-21 08:54:50 -0500

bakerhillpins gravatar image

Taking a quick look at your method definitions and the subscriber template parameters I'd say you have different signatures. e.g. I see 2 issues with void callbackVel( const cu_msgs::CAN_VCUStateEstimation::ConstPtr& msg ) and nh.subscribe< cu_msgs::CAN_VCUStateEstimation >:

  1. The ::ConstPtr modifier creates a different type in C++ and hence a different method.
  2. the msg is a reference (& msg) in the method signature but it's setup as 'by value' in the subscriber template parameter.

C++ allows functions to be overloaded on the basis of const-ness of parameters only if the const parameter is a reference or a pointer.

Modify one (method sig) or the other (template param), for example here I removed the ConstPtr and Reference from the type in the method declaration:

void callbackVel( const cu_msgs::CAN_VCUStateEstimation msg ) {
ROS_INFO("HELLO");
speed0 = msg->velocity[0] < 0.1;
}
    ros::Subscriber subVel = nh.subscribe< cu_msgs::CAN_VCUStateEstimation >("/mailman/state_estimation", 1, callbackVel);
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-06-20 14:42:52 -0500

Seen: 1,611 times

Last updated: Jun 21 '19