Cannot receive messages from bag file with different kinds of message inside it [closed]

asked 2014-01-27 04:16:10 -0600

ubisum gravatar image

updated 2014-01-27 05:02:05 -0600

Hello everyone.
I simulated my robot using Stage and recorded into a bag file messages sent to topics /odom, /base_scan, /tf.
This is what I got:

ubisum@biagioPC:~/fuerte_workspace/thesis_pack/bags$ rosbag info tf_bag.bag 
path:        tf_bag.bag
version:     2.0
duration:    34.2s
start:       Jan 01 1970 01:00:52.10 (52.10)
end:         Jan 01 1970 01:01:26.30 (86.30)
size:        3.3 MB
messages:    1712
compression: none [5/5 chunks]
types:       nav_msgs/Odometry     [cd5e73d190d741a2f92e81eda573aca7]
             sensor_msgs/LaserScan [90c7ef2dc6895d81024acba2ac42f369]
             tf/tfMessage          [94810edda583a504dfda3829e70d7eec]
topics:      /base_scan    342 msgs    : sensor_msgs/LaserScan
             /odom         343 msgs    : nav_msgs/Odometry    
             /tf          1027 msgs    : tf/tfMessage

After that, I subscribed my application to /base_scan topic and wrote a function that, every time a new LaserScan message is received, asks tf for the associated odometry data, in such a way I can converge all information from a robot's pose into a pos_node object.

void messageListener::laserCallback(const sensor_msgs::LaserScan msg){
  //std::string frame_id = msg->header.frame_id;
  ros::Time t = msg.header.stamp;
  tf::StampedTransform laserPose;
  std::string error;
  if (listener->waitForTransform ("/odom", "/base_scan", t, ros::Duration(0.5), ros::Duration(0.01), &error)){
    listener->lookupTransform("/odom", "/base_scan", t, laserPose);
    double yaw,pitch,roll;
    tf::Matrix3x3 mat =  laserPose.getBasis();
    mat.getRPY(roll, pitch, yaw);

    pos_node pn;
    pn.x = laserPose.getOrigin().x();
    pn.y = laserPose.getOrigin().y();
    pn.angle = yaw;

    const vector<float>& ranges =  msg.ranges;
    scan_node temp_sn;
    temp_sn.cartesian = polar2cart(ranges, msg.angle_min, msg.angle_increment, msg.range_min, msg.range_max);
    vector<scan_node> tempScanVec;
    extractCorners(&tempScanVec, 0.1, 0.1, 0.3);

    pn.corn_vec = tempScanVec[0].corners_list;

    printf("Error: %s\n", error.c_str());


    printf("Nothing to do\n");

Anyway, even if message is correctly played, it seems that no LaserScan message is received and my function is never executed.
This is how I subscribe:

ros::Subscriber sub_n = n.subscribe("/base_scan", 1000, &messageListener::laserCallback, this);
ros::Subscriber sub_end = n_end.subscribe("/end", 1000, &messageListener::end_loop, this);
printf("Subscription complete\n");

Do you know the reason? Thanks.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2016-08-14 01:51:42.945289