def bag_to_csv(filename):
  bagfile = Bag(filename)
  topics = init_topics(filename)
  
  start_time = bagfile.get_start_time()
  for topic, msg, timestamp in bagfile.read_messages(topics=topics.keys()):
    formatter = topics[topic]['formatter']
    data_line = formatter((topic,msg,timestamp,start_time))
    topics[topic]['file'].write(', '.join(map(str,data_line)) + '\n')

  for topic in topics.keys():
    topics[topic]['file'].close()

  bagfile.close()
Ejemplo n.º 2
0
    def rosbaginfo(self, req):
        response = RecordingGetBagInfoResponse()
        response.filesize = int(os.path.getsize(req.filename) / 1e+6)

        bag = Bag(req.filename, 'r')
        response.filename = req.filename
        response.starttime = bag.get_start_time()
        response.endtime = bag.get_end_time()
        response.topics = []

        topicmap = bag.get_type_and_topic_info()[1]
        for topic in topicmap.keys():
            topicinfo = BagTopicInfo()
            topicinfo.topicname = topic
            topicinfo.messagecount = topicmap[topic].message_count
            response.topics.append(topicinfo)
        return response
Ejemplo n.º 3
0
def bag_to_blobs(filename):
    bagfile = Bag(filename)

    blobs = []
    b_time = None
    curr_blobs = [None, None]
    poses = []
    start_time = bagfile.get_start_time()

    for topic, msg, timestamp in bagfile.read_messages():
        if topic[-9:] == 'blob_list':
            if len(msg.blobs) == 1:
                m_time = msg.header.stamp.to_sec()
                r_idx = int(topic[-20])
                blob = [msg.blobs[0].x, msg.blobs[0].y]
                #blobs.append([m_time,r_idx] + blob)

                if b_time is None:
                    b_time = m_time
                    curr_blobs[r_idx] = blob

                elif abs(b_time - m_time) < 0.001:
                    curr_blobs[r_idx] = blob
                    blobs.append([b_time] + curr_blobs[0] + curr_blobs[1])
                    b_time = None
                    curr_blobs = [None, None]

                else:
                    b_time = m_time
                    curr_blobs = [None, None]
                    curr_blobs[r_idx] = blob

        elif topic == '/tf':
            for tf_msg in msg.transforms:
                p_time = tf_msg.header.stamp.to_sec()
                base_frame = tf_msg.header.frame_id
                child_frame = tf_msg.child_frame_id
                pos = tf_msg.transform.translation
                pos = [pos.x, pos.y, pos.z]
                ori = tf_msg.transform.rotation
                ori = [ori.x, ori.y, ori.z, ori.w]
                poses.append([p_time, base_frame, child_frame, pos, ori])

    bagfile.close()

    return blobs, poses