rosbag data에서 시간 가져오기

DONGJE LEE·2023년 4월 14일
0

ROS

목록 보기
7/8
post-thumbnail
#include <ros/ros.h>
#include <rosbag/bag.h>
#include <rosbag/view.h>
#include <std_msgs/Header.h>
#include <sensor_msgs/PointCloud2.h>
#include <sensor_msgs/PointField.h>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/Imu.h>
#include <sensor_msgs/NavSatFix.h>
#include <ros/time.h>
#include <geometry_msgs/Vector3.h>


int main(int argc, char** argv)
{
    rosbag::Bag m_bag_player;
    m_bag_player.open("***.bag", rosbag::bagmode::Read);

    rosbag::View view(m_bag_player);

    auto btime = (int)(view.getBeginTime().toSec());
    auto etime = (int)(view.getEndTime().toSec());
    std::cout << btime << " / " << etime << std::endl;

    sensor_msgs::NavSatFix gps_msg;

    BOOST_FOREACH (rosbag::MessageInstance const m, view)
    {
        std::string _str_topic_name = m.getTopic().c_str();
        if (_str_topic_name.find("gps_data_0") != std::string::npos)
        {
            sensor_msgs::NavSatFix::ConstPtr _msg_gps = m.instantiate<sensor_msgs::NavSatFix>();
            gps_msg = *(_msg_gps.get());
            auto msg_time = m.getTime().toSec();
        }
    }


    file.close();
    

    // Close the bag file
    m_bag_player.close();

    return 0;
}
profile
LiDAR & SLAM & Robotics & Autonomous System

0개의 댓글