robokudo.utils.module_loader

Dynamic module loading utilities for Robokudo.

This module provides functionality for dynamically loading Robokudo modules and components. It supports loading:

  • Analysis engines

  • Annotators

  • Camera configurations

  • Action servers

  • IO modules

  • Semantic maps

  • Object knowledge bases

  • Tree components

  • Types and utilities

The module handles:

  • ROS package path resolution

  • Module type management

  • Dynamic module importing

  • File path resolution

Classes

RobokudoModuleType

Enumeration of Robokudo module types.

ModuleLoader

Dynamic module loader for Robokudo components.

Module Contents

class robokudo.utils.module_loader.RobokudoModuleType

Bases: enum.Enum

Enumeration of Robokudo module types.

Defines the standard module types and their paths within a ROS package.

ActionServer = ['action_servers']

Action server modules

Annotator = ['annotators']

Annotator modules

AnalysisEngine = ['descriptors', 'analysis_engines']

Analysis engine descriptors

CameraConfig = ['descriptors', 'camera_configs']

Camera configuration descriptors

IO = ['io']

Input/output modules

SemanticMap = ['descriptors', 'semantic_maps']

Semantic map modules

ObjectKnowledgeBase = ['descriptors', 'object_knowledge']

Object knowledge base modules

TreeComponents = ['tree_components']

Behavior tree components

Types = ['types']

Type modules

Utils = ['utils']

Utility modules

Data = ['data']

Data modules

class robokudo.utils.module_loader.ModuleLoader

Dynamic module loader for Robokudo components.

Handles loading of various Robokudo module types from ROS packages. Provides path resolution and module importing functionality.

logger = None

The logger for the module loader instance.

_load_module(ros_pkg_name: str, module_type: RobokudoModuleType, module_name: str) types.ModuleType

Dynamically import a submodule of the ‘robokudo’ package (or another package). E.g., ‘robokudo.descriptors.analysis_engines.demo’

Parameters:
  • ros_pkg_name – Name of ROS package

  • module_type – Type of module to load

  • module_name – Name of module to load

Returns:

Loaded module object

load_ae(ros_pkg_name: str, module_name: str) robokudo.analysis_engine.AnalysisEngineInterface

Load an Analysis Engine (AE). Expects a class AnalysisEngine in the loaded module.

The ROS package must be in the same workspace with path structure: $package_path/src/robokudo_example_package/descriptors/analysis_engines/

Parameters:
  • ros_pkg_name – Name of ROS package containing AE

  • module_name – Name of analysis engine module

Returns:

Root of loaded analysis engine

load_annotator(ros_pkg_name: str, module_name: str) types.ModuleType

Load an annotator module. You can adjust the returned object as needed.

Parameters:
  • ros_pkg_name – Name of ROS package containing annotator

  • module_name – Name of annotator module

Returns:

None (TODO: implement annotator loading)

Return type:

None

load_camera_config(ros_pkg_name: str, module_name: str) typing_extensions.Any

Load a camera config module. Expects class CameraConfig.

Parameters:
  • ros_pkg_name – Name of ROS package containing config

  • module_name – Name of camera config module

Returns:

Loaded camera configuration

load_io(ros_pkg_name: str, module_name: str) types.ModuleType

Load an I/O module. Customize this if there’s a specific class to instantiate.

Parameters:
  • ros_pkg_name – Name of ROS package containing IO module

  • module_name – Name of IO module

Returns:

Loaded IO module

load_object_knowledge_base(ros_pkg_name: str, module_name: str) robokudo.object_knowledge_base.BaseObjectKnowledgeBase

Load an ObjectKnowledgeBase given the module name and the ros package name.

The path to the AE within the package is meant to be: $package_path/src/PACKAGE_NAME/descriptors/object_knowledge/.

Parameters:
  • ros_pkg_name – Name of ROS package containing knowledge base

  • module_name – Name of knowledge base module

Returns:

Loaded object knowledge base

load_semantic_map(ros_pkg_name: str, module_name: str, _skip_ros: bool = False) robokudo.semantic_map.BaseSemanticMap

Load a semantic map module. Expects class SemanticMap.

Parameters:
  • ros_pkg_name – Name of ROS package containing semantic map

  • module_name – Name of semantic map module

  • _skip_ros (bool) – Skip ROS-related initialization in SemanticMap constructor

Returns:

Loaded semantic map

load_tree_components(ros_pkg_name: str, module_name: str) types.ModuleType

Load tree components. If there’s a main class, instantiate it here.

Parameters:
  • ros_pkg_name – Name of ROS package containing components

  • module_name – Name of tree components module

Returns:

Loaded tree components module

load_types(ros_pkg_name: str, module_name: str) types.ModuleType

Load a ‘types’ module, or a class if needed.

Parameters:
  • ros_pkg_name – Name of ROS package containing types

  • module_name – Name of types module

Returns:

Loaded types module

load_utils(ros_pkg_name: str, module_name: str) types.ModuleType

Load a ‘utils’ module, or a class if needed.

Parameters:
  • ros_pkg_name – Name of ROS package containing utilities

  • module_name – Name of utility module

Returns:

Loaded utility module

get_file_paths(ros_pkg_name: str, module_type: RobokudoModuleType, dir_name: str, file_extension: str = None) typing_extensions.List[str]

Get paths to files in module directory.

If you previously used this to read data files from the ‘source’ folder, you can either remove it or refactor to read from:

  1. get_package_share_directory(‘robokudo’), or

  2. standard Python package resources.

If you truly need to load data from the installed package, see:
  • ament_index_python (to find share dir)

  • or importlib.resources

For now, you might remove this method or keep it if you adapt the logic.

Parameters:
  • ros_pkg_name – Name of ROS package

  • module_type – Type of module to search

  • dir_name – Name of directory to search

  • file_extension – Optional file extension filter

Returns:

List of paths to matching files