bitbots_main icon indicating copy to clipboard operation
bitbots_main copied to clipboard

Migrate bitbots_vision to use generate_parameter_library with optimized parameter passing

Open Copilot opened this issue 5 months ago • 1 comments

This PR migrates the bitbots_vision package from its custom parameter system to use the standardized generate_parameter_library, bringing it in line with other packages like bitbots_path_planning.

Problem

The bitbots_vision package was using a custom ParameterGenerator class in params.py that manually handled parameter declaration and type conversion. This approach had several limitations:

  • No compile-time type checking or validation
  • Manual parameter descriptor creation prone to errors
  • Inconsistent with other packages using generate_parameter_library
  • Difficult to maintain and extend

Solution

Replaced the custom parameter system with generate_parameter_library:

1. Parameter Schema Definition with Hierarchy

Created config/vision_parameters.yaml defining 20 parameters with proper typing, validation, and hierarchical organization:

  • Component activation flags (6 boolean parameters)
  • ROS topic names (8 string parameters with read-only constraint)
  • YOEO model configuration with complete hierarchy (5 parameters under yoeo: structure):
    • yoeo.model_path, yoeo.nms_threshold, yoeo.conf_threshold, yoeo.framework, yoeo.caching
    • Framework validation using one_of<>: [["pytorch", "openvino", "onnx", "tvm"]]
  • Ball detection settings (2 parameters with range constraints)

2. Build System Integration

  • Added generate_parameter_library dependency to package.xml
  • Updated setup.py to call generate_parameter_module() at build time
  • Added .gitignore entry for generated parameter files (vision_parameters.py)

3. Code Architecture Updates with Type Safety

  • Added parameter listener fields directly to YOEOVision class (inherits from Node)
  • Implemented hierarchical dot notation parameter access throughout all subsystems (e.g., config.yoeo.framework)
  • Added comprehensive type hints using appropriate parameter types throughout all subsystems
  • Updated parameter initialization and dynamic reconfigure handling to work with generate_parameter_library
  • Maintained proper type checking with beartype

4. Complete Subsystem Migration with Optimized Parameter Passing

  • YOEO Object Manager: Receives only the yoeo substruct (config.yoeo) instead of full config for better encapsulation
  • YOEO Handlers: Updated to accept yoeo_config parameter with direct access (yoeo_config.framework, yoeo_config.caching)
  • Vision Components: Updated all ROS topic parameters to use dot notation
  • Optimized parameter comparison: Uses direct substruct comparison (cls._config != new_yoeo_config)
  • Enhanced ROS Utils: Created create_or_update_subscriber_with_config() that works directly with config objects

5. Code Quality Improvements

  • Removed unnecessary methods and compatibility layers
  • Added comprehensive type hints throughout the codebase
  • Simplified code structure by removing useless wrapper methods
  • Enhanced parameter validation at schema level
  • Optimized parameter passing: Components only receive their relevant parameter substructs

6. Legacy Code Removal

  • Removed custom ParameterGenerator class and params.py file
  • Cleaned up all imports and references to the old system
  • Eliminated unnecessary base classes and compatibility layers

Benefits

  • Type Safety: Complete compile-time type validation throughout all subsystems with proper type hints
  • Parameter Hierarchy: Clean organization with yoeo.* sub-parameters including caching for complete encapsulation
  • Optimized Architecture: Components only receive relevant parameters, improving encapsulation and performance
  • Bounds Checking: Numeric parameters enforce min/max constraints automatically
  • Framework Validation: Enforced choices for neural network framework at schema level
  • Better Documentation: All parameters include comprehensive descriptions
  • Consistency: Uses same parameter library and hierarchical patterns as other packages in the codebase
  • Maintainability: Eliminates custom parameter generation code with clean, type-safe architecture
  • Performance: No runtime dictionary conversions, direct attribute access with optimized parameter passing
  • Proper Integration: Follows established patterns with complete parameter hierarchy support and component isolation

Testing

  • Validated Python syntax for all modified files
  • Confirmed all type hints are properly implemented
  • Verified parameter defaults match existing configuration files
  • Ensured all subsystems properly use hierarchical parameter access with optimized substruct passing
  • Addressed all code review feedback for proper generate_parameter_library integration

The migration provides complete modernization of the parameter system with full parameter hierarchy, type safety, validation support, and optimized parameter passing throughout all subsystems, following the best practices established by the generate_parameter_library framework.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Sep 24 '25 16:09 Copilot

@copilot If you want to test it with ros etc. look at the devcontainer and make a ros docker as described there

Flova avatar Sep 24 '25 17:09 Flova