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;
}
Originally posted by Erwan R. on ROS Answers with karma: 697 on 2012-06-11
Post score: 0
Original comments
Comment by karthik on 2012-06-11:
derekjchow is right... ros::spinOnce() is required.