pyrosbag package

Module contents

Note that, in order to access the data within the bag file, the rosbag_python package is extremely convenient. It is available on PyPI.

pyrosbag.pyrosbag module

Programmatically control a ROS bag file.

This module implements the base class, and the various functions.

Currently implemented are:

  • rosbag play
class pyrosbag.pyrosbag.Bag(filenames)[source]

Bases: object

Open and manipulate a bag file programmatically.

Parameters:filenames (StringTypes | List[StringTypes]) – The location of the bag files.
filenames

List[StringTypes] – The location of the bag files.

process

subprocess.Popen – The process containing the running bag file.

__enter__()[source]

Context manager entry point.

__exit__(exc_type, exc_value, traceback)[source]

Context manager exit point.

is_running

Check whether the bag file is running.

Returns:The bag file is running.
Return type:bool
send(string)[source]

Write something to process stdin.

Parameters:string (str) – The string to write.
Raises:BagNotRunningError – If interaction is attempted when the bag file is not running.
stop()[source]

Stop a running bag file.

Raises:BagNotRunningError – If the bag file is not running.
wait()[source]

Block until process is complete.

Raises:BagNotRunningError – If the bag file is not running.
exception pyrosbag.pyrosbag.BagError[source]

Bases: exceptions.Exception

Catch bag player exceptions.

exception pyrosbag.pyrosbag.BagNotRunningError(action='talk to')[source]

Bases: pyrosbag.pyrosbag.BagError

Raised when interaction is attempted with a bag file which is not running.

class pyrosbag.pyrosbag.BagPlayer(filenames)[source]

Bases: pyrosbag.pyrosbag.Bag

Play Bag files.

pause()[source]

Pause the bag file.

play(wait=False, stdin=-1, stdout=None, stderr=None, quiet=None, immediate=None, start_paused=None, queue_size=None, publish_clock=None, clock_publish_freq=None, delay=None, publish_rate_multiplier=None, start_time=None, duration=None, loop=None, keep_alive=None)[source]

Play the bag file.

Parameters:
  • wait (Optional[Bool]) – Wait until completion.
  • stdin (Optional[file]) – The stdin buffer. Default is subprocess.PIPE.
  • stdout (Optional[file]) – The stdout buffer.
  • stderr (Optional[file]) – The stderr buffer.
  • quiet (Optional[Bool]) – Suppress console output.
  • immediate (Optional[Bool]) – Play back all messages without waiting.
  • start_paused (Optional[Bool]) – Start in paused mode.
  • queue_size (Optional[int]) – Set outgoing queue size. Default is 100.
  • publish_clock (Optional[Bool]) – Publish the clock time.
  • clock_publish_freq (Optional[float]) – The frequency, in Hz, at which to publish the clock time. Default is 100.
  • delay (Optional[float]) – The number of seconds to sleep afer every advertise call (e.g., to allow subscribers to connect).
  • publish_rate_multiplier (Optional[float]) – The factor by which to multiply the publish rate.
  • start_time (Optional[float]) – The number of seconds into the bag file at which to start.
  • duration (Optional[float]) – The number of seconds from the start to play.
  • loop (Optional[Bool]) – Loop playback.
  • keep_alive (Optional[Bool]) – Keep alive past end of bag (e.g. for publishing latched topics).
resume()[source]

Resume the bag file.

step()[source]

Step through a paused bag file.

exception pyrosbag.pyrosbag.MissingBagError[source]

Bases: pyrosbag.pyrosbag.BagError

Bag file was not specified.

msg = 'No Bag files were specified.'