[Documentation] [TitleIndex] [WordIndex

rosh overview: Roshlets | Basics | Messages | Parameters | Topics | Services | Nodes | Topic Tools | Packages | Bags | Bagys | roslaunch

Bags

rosh imports the rosbag Python API directly.

Example:

with Bag('test.bag') as bag:
  for topic, msg, t in bag.read_messages(topics=['chatter', 'numbers']):
      print msg

It also adds in its own rosh-isms, which are described below.

Retrieving messages by topic

The topics attribute gives you a tab-completable index of topics within a bag file. You can iterate over a topic to pull messages from the bag and you can also get the message class of a topic.

In [1]: b = Bag('chatter.bag')

In [2]: type(b.topics.chatter)
Out[2]: <class 'rosh.impl.bag.BagTopic'>

In [3]: rostype(b.topics.chatter)
Out[3]: <class 'std_msgs.msg._String.String'>

In [4]: for topic, message, t in b.topics.chatter:
   ...:     print message, t

data: hello world 1286482774.5 1286482774501392502
data: hello world 1286482774.5 1286482774501435969
data: hello world 1286482774.6 1286482774601234579
data: hello world 1286482774.6 1286482774601377595
data: hello world 1286482774.7 1286482774701203314
data: hello world 1286482774.7 1286482774701237932

Recording topics (Experimental)

EXPERIMENTAL: this does not have the same performance as rosbag record and should only be used for low-data topics.

You can setup a bag file to record a ROSH topic. You can start and stop the recording as you please.

bag = Bag('test.bag', 'w')
bag.record(topics.chatter)
bag.record(topics.rosout_agg)
bag.stop()
bag.start()
bag.close()

2019-11-16 13:16