Robotics StackExchange | Archived questions

How to extract data structure values from rosbag using python3

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:

      Topics         Types                   Message Count  Frequency
  • 0 /globalpath >> plannermap_interfaces/Plan >> 2 >>0.001536
  • 1 /particlefiltersvisualizer >> visualization_msgs/MarkerArray >> 820 >>0.999696
  • 2 /planner/planningrequest >> plannermap_interfaces/PlanningRequest >> 2 >> 0.001537
  • 3 /searchbelief >> visualizationmsgs/Marker >> 1399 >> 2.000637
  • 4 /targetprojectionnode/filteredtargets >> plannermap_interfaces/FilteredTargets >> 343 >>0.496940
  • 5 /targetpropagation/particlefiltersbelief >> targetpropagation/ParticleFiltersBelief >> 820 >> 0.999689

dfplan = pd.readcsv(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

df_plan['Time']

0 1.661199e+09

1 1.661200e+09

Name: Time, dtype: float64

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

Name: plan, dtype: object

bag = rosbag('/path/to/rosbag file');

bSel = select(bag,'Topic','/global_path');

msgStructs = readMessages(bSel,'DataFormat','struct');

msgStructs{1} ::this references plan 1 of 2

msgStructs{1}.Plan_

This has been challenging. I'm willing to share my bag or csv's. I tried rosbag, bagpy and pandas. I may have to parse the one-column result from the csv of the object represented by the 6th column. . I most humbly request any insight to extract the data of x, y, z from the dataframe object. Perhaps an inner loop and read each message as a row? I can provide files or do tests that help resolve this.. Kindest Regards

Asked by clarknator on 2022-10-30 16:42:14 UTC

Comments

duplicate of #q408736

Asked by ravijoshi on 2022-11-02 07:54:56 UTC

Answers