iris-ua / iris_lama

LaMa - A Localization and Mapping library
BSD 3-Clause "New" or "Revised" License
336 stars 72 forks source link

carmen to rosbag #11

Closed aaravrav142 closed 4 years ago

aaravrav142 commented 4 years ago

Hi, Thank you for such a great piece of software. I wish to do some tests with the carmen log files and was wondering if you could provide a way to convert the carmen(.clf) data logs into rosbag (.bag) format. Can you help me with this and provide any instructions (command line) to do so.

Thanks Alex

eupedrosa commented 4 years ago

Hi, My converter is quite old. I forgot how old it was. Allow me some time to make sure it works. But the base is something like this:

    CarmenReader carmen;
    rosbag::Bag bag;
    bag.open(bagname, rosbag::bagmode::Write);

    geometry_msgs::TransformStamped odom;
    geometry_msgs::TransformStamped laser_pose;

    odom.header.frame_id = "/odom";
    odom.child_frame_id  = "/base_link";

    laser_pose.header.frame_id = "/base_link";
    laser_pose.child_frame_id  = "/laser";

    uint32_t seq = 0;
    while(true){

        LaserScan ls;
        Pose2D odometry;
        double timestamp;

        bool ok = carmen.readLaserScan(ls, odometry, timestamp);
        if (not ok) break;

        ros::Time stamp = ros::Time(timestamp);
        tf::tfMessage tfmsg;
        // build odometry transformation
        odom.header.seq = seq;
        odom.header.stamp = stamp;
        odom.transform.translation.x = odometry.x();
        odom.transform.translation.y = odometry.y();
        odom.transform.translation.z = 0.0;
        odom.transform.rotation = tf::createQuaternionMsgFromYaw(odometry.rotation());
        tfmsg.transforms.push_back(odom);
        // build laser transformation
        laser_pose.header.seq = seq;
        laser_pose.header.stamp = stamp;
        laser_pose.transform.translation.x = ls.sensor_origin_.x();
        laser_pose.transform.translation.y = ls.sensor_origin_.y();
        laser_pose.transform.translation.z = 0.0;
        laser_pose.transform.rotation = tf::createQuaternionMsgFromYaw(0);
        tfmsg.transforms.push_back(laser_pose);
        // build laser msg
        sensor_msgs::LaserScan laser_msg;
        laser_msg.header.seq = seq++;
        laser_msg.header.stamp = stamp;
        laser_msg.header.frame_id = "/laser";

        laser_msg.angle_min = - M_PI * 0.5;
        laser_msg.angle_max =   M_PI * 0.5;
        laser_msg.angle_increment = M_PI / ls.size();

        laser_msg.range_max = ls.max_range;
        laser_msg.range_min = ls.min_range;

        for (uint32_t i = 0; i < ls.size(); ++i )
            laser_msg.ranges.push_back(ls.at(i)[0]);

        // write data do bag
        bag.write("/tf", stamp, tfmsg);
        bag.write("/scan", stamp, laser_msg);
    }
aaravrav142 commented 4 years ago

Hi thanks for the reply. Can you provide the source or node to do so. I am new to ROS and any detail instructions would help. Thanks

eupedrosa commented 4 years ago

@aaravrav142, I found something better than my old code https://github.com/artivis/carmen_publisher

aaravrav142 commented 4 years ago

Thanks :)