robokudo.utils.file_loader

File path resolution utilities for RoboKudo.

This module provides utilities for resolving file paths in ROS packages.

module:

file_loader

synopsis:

File path resolution utilities for ROS packages

moduleauthor:

RoboKudo Team

Dependencies:
  • pathlib

  • rospkg

  • logging

Classes

FileLoader

File path resolution helper for ROS packages.

Module Contents

class robokudo.utils.file_loader.FileLoader

File path resolution helper for ROS packages.

This class provides methods for resolving file paths in ROS packages.

Variables:

logger – Logger instance for this class

Example:

loader = FileLoader()
pkg_path = loader.get_ros_pkg_path('my_package')
file_path = loader.get_path_to_file_in_ros_package('my_package', 'config/params.yaml')
logger = None
get_ros_pkg_path(ros_pkg_name: str) pathlib.Path

Get a Path object to a ROS2 package given the name

Throws OSError if ROS2 package can’t be found.

Parameters:

ros_pkg_name (str) – name of a ros2 package

Returns:

path object with the ros2 package path

Return type:

Path

Raises:

OSError – If ROS package cannot be found

Example:

pkg_path = loader.get_ros_pkg_path('my_package')
assert pkg_path.exists()
get_path_to_file_in_ros_package(ros_pkg_name: str, relative_path: str) pathlib.Path

Get a Path object to a given the filename inside a ROS package. Please note, that relative_path should NOT start with ‘/’, because then it would be considered as an absolute path from pathlib.Path.joinpath()

Throws OSError if ROS package can’t be found or relative_path in ROS package doesn’t exist.

Parameters:
  • ros_pkg_name (str) – name of a ros package

  • relative_path (str) – the filename of the desired file, relative to the path of ros_pkg_name

Returns:

path object to the desired file relative the ros package

Return type:

Path

Raises:

OSError – If package or file cannot be found

Example:

file_path = loader.get_path_to_file_in_ros_package('my_package', 'config/params.yaml')
assert file_path.exists()

Note

The relative_path should NOT start with ‘/’ to avoid being treated as an absolute path by pathlib.Path.joinpath()