ROSBagTransformer Class

class rosdata.core.rosbag_transformer.ROSBagTransformer[source]

A Class that processes the transform data from a ROS Bag file

__init__()[source]

Constructs and initialises a ROSBagTransform object.

build_transform_tree(bag, transform_topic: str = '/tf', static_transform_topic: str = '/tf_static', tree_root: Optional[str] = None)[source]

Processes the data in the supplied ROSBag, passed during object construction, and builds the transform tree. This function must be called prior to any other class methods. Depending on the bag size, this can take a while.

Parameters
  • bag (rosbag object) – an opened ROSbag object containing the transform data to be processed.

  • transform_topic (str, optional) – used to specify the transform topic. Defaults to “/tf”.

  • static_transform_topic (str, optional) – used to specify the transform topic. Defaults to “/tf_static”.

  • tree_root (str, optional) – used to specify the name of the frame that is the root of the tree. Defaults to none, which will automatically try and determine the tree root.

Raises
  • RuntimeError – if there are multiple tree roots and a tree root was not specified.

  • ValueError – if the specified tree root is not present in the transform tree.

frame_exists(frame: str) bool[source]

Checks to see if a frame exists within the transform tree.

Parameters

frame (str) – the name of the frame to check for

Returns

True if the frame exists

Return type

bool

get_chain(source: str, dest: str, return_type: type = <class 'tuple'>) Union[tuple, list][source]

gets the transform chain from a source to a destination frame. The source frame does not need to be directly connected to the dest.

Parameters
  • source (str) – the name of the source (i.e., start) frame

  • dest (str) – the name of the dest (i.e., end) frame (does not need to be directly connected to the source)

  • return_type (type, optional) – used to specify the return type. Defaults to tuple.

Raises

ValueError – if the source or destination frame does not exist within the tree.

Returns

returns either a tuple or list. If the return_type is set to tuple,

the returned value will contain a tuple of pairs holding the names of directly connected source to destination frames within the chain. If the return_type is set to a list, the returned value will be a list containing the names of the frames in the transform chain.

Return type

Union[tuple, list]

get_common_frame(frame_1: str, frame_2: str) str[source]

gets the lowest common ancester frame between two frames.

Parameters
  • frame_1 (str) – the first transform frame

  • frame_2 (str) – the second transform frame

Returns

the name of the lowest commom ancestor transform frame

Return type

str

get_transform_tree_frames() dict[source]

returns the transform tree as a dictionary

Returns

the transform tree

Return type

dict

load(filename: str)[source]

Loads a previously saved ROSBagTransformer object.

Parameters

filename (str) – the absolute path to the file

lookup_transform(source: str, dest: str, time: float, method: str = 'nearest', lookup_limit: Optional[float] = None, chain_limit: Optional[float] = None) tuple[source]

Looks up and returns the transform between a source and destination frame for a given time. If the entire transform chain is static then the method and limit arguments are ignored.

Parameters
  • source (str) – the name of the source frame

  • dest (str) – the name of the destination frame

  • time (float) – the time at which to look up the transform

  • method (str, optional) – the method to use when looking up the transform. Options include “exact”, “recent”, “nearest”, and “interpolate”. Defaults to “nearest”. Exact - will attempt to get an exact transform based on the desired time. Recent - will return a transform only if there is a past transform within the lookup_limit. Nearest - will return a future or past transform if there is one within the lookup_limit. Interpolate - will return an interpolated transform only if there is a transform either side of the desired time within the lookup_limit.

  • lookup_limit (float, optional) – the limit to use when looking up a transform. If a transform between the source and destination frame cannot be found within this limit a TransformStatus.LOOKUP_LIMIT_ERROR will be returned. Defaults to None.

  • chain_limit (float, optional) – if the selected transform has a chain differential greater than this value a TransformStatus.CHAIN_LIMIT_ERROR will be returned. Defaults to None.

Raises

ValueError – if the source or destination frame does not exist within the tree.

Returns

returns a tuple containing the [timestamp, chain_differential, transform, transform_status].

the timestamp will be that of the selected transform for the exact, recent and nearest methods, and be equal to the desired time for the interpolate method. The chain_differential will be that of the selected transform for the exact, recent and nearest methods, and be the maximum differential of the two transforms used in the interpolate method.

Return type

tuple

lookup_transforms(source: str, dest: str) tuple[source]

looks up and returns the transforms between a source and destination frame. If the transform is a chain (i.e., the source and destination are not directly connected) the transform will be updated whenever one of the transforms in the chain is updated.

Parameters
  • source (str) – the name of the source frame

  • dest (str) – the name of the destination frame

Raises

ValueError – if the source or destination frame does not exist within the tree.

Returns

returned tuple with types (list, bool). The list contains the

transforms between the source and destination. The list will have the form [timestamp (float), chain_differential (float), transform (SE3 object)] where timestamp is the most recent timestamp in the transform chain used to create the entire transform. The chain_differential is the difference between the most recent and oldest timestamp in the transform chain used to create the overall transform. The transform is an SE3 object containing the total transform between the source and destination frame. The boolean represents if the entire chain is static.

Return type

tuple

save(filename: str)[source]

Saves the ROSBagTransformer object to a file.

Parameters

filename (str) – the absolute path to the file

show_tree()[source]

Prints the tree to the terminal.

static_transform(source: str, dest: str) bool[source]

determines if the transform chain from a source to a destination frame is static.

Parameters
  • source (str) – the name of the source frame

  • dest (str) – the name of the destination frame (does not need to be directly connected to the source frame)

Raises

ValueError – if the source or destination frame does not exist within the tree.

Returns

returns true if the transform chain is static.

Return type

bool