How to extract data structure values from rosbag using python3 [closed]

asked 2022-10-30 16:42:14 -0500

clarknator gravatar image

Greetings!

I have a rosbag with several topics and need help with one of them. My OS is Ubuntu 18 and Melodic install for ROS-1. I need to parse the values of x, y, and z from one topic that apears to be an object when I read the topic messages.

Normally this is straight forward. Rephrasing my question is "How do I read messages from the topic such that I can parse the values from a structure inside it?

Why do I know it is a structure? I can pull the topic from the bag and look at the cvs with pandas.

I can successfully do this in Matlab using their ros toolbox. I have clients who don't want to install ros or buy a MAtlab license but have a need to see the data from the ros bag. They could run a python script. That's where I could use your help.

The topic giving me issues is 'global_path'. I chose to use bagpy although I think importing rosbag would work as well.

The basic steps I followed were:

  • read bag

    b = bagreader('/home/bags/flight_1_2022-08-22-13-09-30.bag')

  • check available topics

    b.topic_table

      Topics         Types                   Message Count  Frequency
  • 0 /global_path >> planner_map_interfaces/Plan >> 2 >>0.001536
  • 1 /particle_filters_visualizer >> visualization_msgs/MarkerArray >> 820 >>0.999696
  • 2 /planner/planning_request >> planner_map_interfaces/PlanningRequest >> 2 >> 0.001537
  • 3 /search_belief >> visualization_msgs/Marker >> 1399 >> 2.000637
  • 4 /target_projection_node/filtered_targets >> planner_map_interfaces/FilteredTargets >> 343 >>0.496940
  • 5 /target_propagation/particle_filters_belief >> target_propagation/ParticleFiltersBelief >> 820 >> 0.999689
  • pull messages from topic /global_path >>>data = b.message_by_topic('/global_path')
  • print("File saved: {}".format(data)) :: creates a csv of global_path topic
  • result: /home//bags/flight_1_2022-08-22-13-09-30/global_path.csv

  • import pandas as pd

    df_plan = pd.read_csv(data)

    df_plan :: shows the table with 2 rows and 6 columns.'plan' is column 6

    df_plan.shape :: shows (2,6) This is 2 rows and 6 columns

  • an example of showing the first column of the csv, 'Time'.

  • Note the type of the first is float64. So are columns 2 thru 5

df_plan['Time']

0 1.661199e+09

1 1.661200e+09

Name: Time, dtype: float64

  • Next we see what type is the 6th column..

    df_plan['plan']

    0 [stamp: \n seq: 10\n stamp: \n secs: 0\n ...

    1 [stamp: \n seq: 8\n stamp: \n secs: 0\n ...

    Name: plan, dtype: object

  • The data type of column 6 is an object with label 'plan''.

  • the resultant cvs is a single column with many embedded fields

    • How can I format this 6th column? Is it when I first read the bag or when I extract the topic?

    • How do I read this column to extract the x, y, z positions inside the object?

    • in Matlab, I have a line to say the data type is a structure.
    • is there an equivalent using bagpy's bagreader or a method in rosbag?
  • Note the MAtlab use of 'readMessages' to specify a data format of 'struct'

bag = rosbag('/path/to ...

(more)
edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by ravijoshi
close date 2022-11-02 07:54:49.081834

Comments

duplicate of #q408736

ravijoshi gravatar image ravijoshi  ( 2022-11-02 07:54:56 -0500 )edit