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

Callback function seems to be never called

asked 2012-06-11 05:27:11 -0500

Erwan R. gravatar image

updated 2012-06-11 05:32:48 -0500

Hi again,

This question follows this one.

Now my node is compiling and executing, but it seems that the callback function is never called on the subscription to lasers. /scan is remapped to /base_scan (that send data, according to rostopic echo /base_scan ). As far as I understand, every time the node gets a message, it should trigger the callback and I should get a console output, a rxconsole output and the robot should move a little. I don't get what can fail in this case.

What's wrong with the code or what should be done to be sure that the node really gets the data ?

Sources :

  BrController::BrController(ros::NodeHandle &nh) : target_frame_("/base_controller/command")
 {
/* Node handle that manage the node and provide publishing and subscribing function */
nh_ = nh;

/* Set up the publisher for the cmd_vel topic : we'll publish on this topic to drive the robot */
 cmd_vel_pub_ = nh_.advertise<geometry_msgs::Twist>("/base_controller/command", 1);

scan_filter_sub_ = nh_.subscribe("scan", 50, &BrController::msgCallback, this);
 }

void BrController::msgCallback(const sensor_msgs::LaserScan & msg)
{
    geometry_msgs::Twist base_cmd;

    std::cout << "Callback" << std::endl;
    ROS_INFO("Callback");

   base_cmd.angular.z = 50;
   cmd_vel_pub_.publish(base_cmd);

   std::cout << "published command : [" << base_cmd.linear.x << " " << base_cmd.linear.y << " " <<  base_cmd.linear.z << "][" << base_cmd.angular.x << " " << base_cmd.angular.y << " " << base_cmd.angular.z << "]"<< std::endl; 
}


bool BrController::driveBraitenberg()
{
  //we are sending commands of type "twist" to drive the robot
  geometry_msgs::Twist base_cmd;

  while(nh_.ok())
  {
     // Nothing is done as we want the robot to be driven from the laser input  
   }

  return true;
}
edit retag flag offensive close merge delete

Comments

1

derekjchow is right... ros::spinOnce() is required.

karthik gravatar image karthik  ( 2012-06-11 06:49:33 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
5

answered 2012-06-11 06:23:58 -0500

derekjchow gravatar image

updated 2012-06-11 06:24:17 -0500

I believe you need to call ros::spinOnce() in the while loop in driveBraitenberg

See this article for more information.

edit flag offensive delete link more

Comments

Okey, problem solved, I was thinking I did that in the main, but seems that not.

Erwan R. gravatar image Erwan R.  ( 2012-06-11 22:13:51 -0500 )edit

Question Tools

Stats

Asked: 2012-06-11 05:27:11 -0500

Seen: 821 times

Last updated: Jun 11 '12