Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optional config dir #460

Merged
merged 1 commit into from
Dec 11, 2024
Merged

optional config dir #460

merged 1 commit into from
Dec 11, 2024

Conversation

BOOTCFG
Copy link
Contributor

@BOOTCFG BOOTCFG commented Dec 9, 2024

Description

Requirements

  • Code style guidelines followed
  • Documentation updated

Tests 🧪

  • Robot
  • Container
  • Simulation

Summary by CodeRabbit

  • New Features

    • Introduced a new launch argument common_dir_path across multiple launch files, enhancing the configurability of the system by allowing users to specify a common configuration directory.
    • Updated paths for various components to utilize the new common_dir_path for improved flexibility.
  • Bug Fixes

    • Resolved hardcoded paths in the launch configurations, allowing for dynamic path construction based on user input.

Copy link
Contributor

coderabbitai bot commented Dec 9, 2024

Walkthrough

The changes introduce a new launch argument, common_dir_path, across multiple launch files in the Husarion UGV project. This argument allows users to specify a common configuration directory, enhancing the configurability of the launch files. The argument is initialized with a default empty string and is integrated into the launch descriptions of various components, including the controller, lights, localization, and manager. The existing paths in these files are updated to utilize this new argument, ensuring that the configuration can adapt based on user input.

Changes

File Path Change Summary
husarion_ugv_bringup/launch/bringup.launch.py Added common_dir_path argument; updated launch arguments for controller_launch, lights_launch, ekf_launch, and manager_launch.
husarion_ugv_controller/launch/controller.launch.py Added common_dir_path; updated husarion_ugv_controller_common_dir, robot_description_common_dir, and controller_config_path to use this argument.
husarion_ugv_lights/launch/lights.launch.py Added common_dir_path; updated husarion_ugv_lights_common_dir to use this argument.
husarion_ugv_localization/launch/localization.launch.py Added common_dir_path; updated localization_config_path to utilize this argument.
husarion_ugv_manager/launch/manager.launch.py Added common_dir_path; updated husarion_ugv_manager_common_dir to use a PythonExpression.

Suggested reviewers

  • rafal-gorecki

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
husarion_ugv_manager/launch/manager.launch.py (1)

38-48: Consider normalizing paths to prevent issues with trailing slashes

The current path construction could lead to issues if common_dir_path ends with a slash, potentially resulting in paths with double slashes.

Consider using os.path.join in the PythonExpression:

-    husarion_ugv_manager_common_dir = PythonExpression(
-            [
-                "'",
-                common_dir_path,
-                "/husarion_ugv_manager' if '",
-                common_dir_path,
-                "' else '",
-                FindPackageShare("husarion_ugv_manager"),
-                "'",
-            ]
-    )
+    husarion_ugv_manager_common_dir = PythonExpression(
+            [
+                "os.path.join('",
+                common_dir_path,
+                "', 'husarion_ugv_manager') if '",
+                common_dir_path,
+                "' else '",
+                FindPackageShare("husarion_ugv_manager"),
+                "'",
+            ]
+    )
husarion_ugv_lights/launch/lights.launch.py (1)

42-52: Consider normalizing paths to prevent issues with trailing slashes

Similar to manager.launch.py, the path construction could be improved to handle trailing slashes.

Consider using os.path.join in the PythonExpression:

-    husarion_ugv_lights_common_dir = PythonExpression(
-            [
-                "'",
-                common_dir_path,
-                "/husarion_ugv_lights' if '",
-                common_dir_path,
-                "' else '",
-                FindPackageShare("husarion_ugv_lights"),
-                "'",
-            ]
-    )
+    husarion_ugv_lights_common_dir = PythonExpression(
+            [
+                "os.path.join('",
+                common_dir_path,
+                "', 'husarion_ugv_lights') if '",
+                common_dir_path,
+                "' else '",
+                FindPackageShare("husarion_ugv_lights"),
+                "'",
+            ]
+    )
husarion_ugv_localization/launch/localization.launch.py (1)

95-105: Consider simplifying the path construction expression

While functional, the nested string concatenation in PythonExpression could be simplified for better readability.

Consider this alternative:

-    husarion_ugv_localization_common_dir = PythonExpression(
-            [
-                "'",
-                common_dir_path,
-                "/husarion_ugv_localization' if '",
-                common_dir_path,
-                "' else '",
-                FindPackageShare("husarion_ugv_localization"),
-                "'",
-            ]
-    )
+    husarion_ugv_localization_common_dir = PythonExpression([
+        f"'{common_dir_path}/husarion_ugv_localization' if '{common_dir_path}' else '{FindPackageShare('husarion_ugv_localization')}'"
+    ])
husarion_ugv_controller/launch/controller.launch.py (1)

37-70: Consider extracting common path construction logic

The path construction pattern is repeated across multiple launch files. Consider creating a helper function or shared module.

This would:

  1. Reduce code duplication
  2. Ensure consistent path handling
  3. Make future updates easier
  4. Centralize the logic for better maintainability

Would you like me to help create a shared module for this common functionality?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d3da0b5 and 919eb28.

📒 Files selected for processing (5)
  • husarion_ugv_bringup/launch/bringup.launch.py (6 hunks)
  • husarion_ugv_controller/launch/controller.launch.py (2 hunks)
  • husarion_ugv_lights/launch/lights.launch.py (2 hunks)
  • husarion_ugv_localization/launch/localization.launch.py (2 hunks)
  • husarion_ugv_manager/launch/manager.launch.py (2 hunks)
🔇 Additional comments (8)
husarion_ugv_manager/launch/manager.launch.py (1)

32-37: LGTM: Launch argument declaration is well-structured

The common_dir_path argument is properly declared with appropriate default value and description.

husarion_ugv_bringup/launch/bringup.launch.py (2)

32-37: LGTM: Launch argument declaration matches other files

The common_dir_path argument declaration is consistent with other launch files.


65-65: LGTM: Consistent propagation of common_dir_path to child launches

The common_dir_path argument is correctly propagated to all relevant child launch files (controller, lights, ekf, and manager).

Also applies to: 87-87, 105-105, 115-115

husarion_ugv_lights/launch/lights.launch.py (1)

36-41: LGTM: Launch argument declaration is consistent

The common_dir_path argument declaration maintains consistency with other launch files.

husarion_ugv_localization/launch/localization.launch.py (2)

89-94: LGTM: Launch argument declaration is well-structured

The new common_dir_path argument is properly declared with a clear description and appropriate default value.


111-111: Verify the impact on existing configurations

The path construction changes might affect existing setups. Please ensure:

  1. Backward compatibility with existing configurations
  2. Proper handling of empty/invalid common_dir_path values

Also applies to: 156-156

✅ Verification successful

Let me gather more information about the configuration files and their usage.


Based on the gathered information, I can now provide the final response:

Path construction changes are safely handled with proper fallbacks

The code implements proper handling of configuration paths with built-in safeguards:

  • All standard configuration files exist in the package (relative_localization.yaml, enu_localization.yaml, and their GPS variants)
  • The common_dir_path argument has a safe empty default value
  • When common_dir_path is empty, it automatically falls back to the package's share directory using FindPackageShare
  • The path construction is done through ROS 2's PathJoinSubstitution, ensuring proper path handling
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for existing config file references
rg -l "localization_config_path|husarion_ugv_localization.*config" --type python

# Check for potential path construction patterns
ast-grep --pattern 'PathJoinSubstitution([FindPackageShare("husarion_ugv_localization")$$$])'

Length of output: 1772


Script:

#!/bin/bash
# Find all configuration files in the package
fd -e yaml -e xml -e json . husarion_ugv_localization/config/

# Check for any references to configuration files in launch files
rg -t launch "config.*\.(yaml|xml|json)" -A 2 -B 2

# Check the content of the launch file to understand the variable usage
cat husarion_ugv_localization/launch/localization.launch.py

Length of output: 6597

husarion_ugv_controller/launch/controller.launch.py (2)

37-53: LGTM: Launch argument and path construction are consistent

The implementation follows the same pattern as other launch files, maintaining consistency across the codebase.


58-70: Verify dynamic package resolution

The dynamic construction of robot_description_pkg combined with common_dir_path needs careful verification:

  1. Package resolution when common_dir_path is empty
  2. Path construction for different robot models
✅ Verification successful

Based on the search results, I can now verify the dynamic package resolution pattern. The code shows consistent usage across multiple launch files where robot_description_pkg is constructed similarly. The pattern is safe because:

  1. When common_dir_path is empty, it correctly falls back to using FindPackageShare(robot_description_pkg).
  2. The path construction is consistent with other similar patterns in the codebase (e.g., in husarion_ugv_lights, husarion_ugv_manager, etc.).
  3. The PythonExpression construction follows the same pattern used throughout the codebase for conditional path resolution.

Dynamic package resolution verified

The implementation is correct and follows established patterns in the codebase for handling both direct paths and package-based resolution.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check robot model package references
rg "robot_description_pkg.*FindPackageShare" --type python

# Verify package resolution patterns
ast-grep --pattern 'PythonExpression([
  $$$
  FindPackageShare($pkg)
  $$$
])'

Length of output: 173


Script:

#!/bin/bash
# Check robot model package references with correct file type
rg "robot_description_pkg.*FindPackageShare" -t py

# Search for PythonExpression usage patterns
rg "PythonExpression.*FindPackageShare" -t py -A 3

# Look for robot_description_pkg variable usage
rg "robot_description_pkg\s*=" -t py -A 2

# Find launch files that might use similar package resolution
fd -e launch.py --exec cat {}

Length of output: 66677

@BOOTCFG BOOTCFG force-pushed the ros2-devel-better-config-dir branch from 919eb28 to 95b49be Compare December 9, 2024 22:57
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
husarion_ugv_controller/launch/controller.launch.py (1)

37-69: Consider adding validation for common_dir_path

While the path construction is correct, consider adding validation to ensure the provided directory exists when non-empty.

 common_dir_path = LaunchConfiguration("common_dir_path")
+def validate_common_dir(context):
+    path = context.launch_configurations.get('common_dir_path', '')
+    if path and not os.path.isdir(path):
+        raise RuntimeError(f"Specified common_dir_path '{path}' does not exist")
+
 declare_common_dir_path_arg = DeclareLaunchArgument(
     "common_dir_path",
     default_value="",
     description="Path to the common configuration directory.",
+    validator=validate_common_dir
 )
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 919eb28 and 95b49be.

📒 Files selected for processing (5)
  • husarion_ugv_bringup/launch/bringup.launch.py (6 hunks)
  • husarion_ugv_controller/launch/controller.launch.py (2 hunks)
  • husarion_ugv_lights/launch/lights.launch.py (2 hunks)
  • husarion_ugv_localization/launch/localization.launch.py (2 hunks)
  • husarion_ugv_manager/launch/manager.launch.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • husarion_ugv_bringup/launch/bringup.launch.py
  • husarion_ugv_localization/launch/localization.launch.py
  • husarion_ugv_manager/launch/manager.launch.py
🔇 Additional comments (3)
husarion_ugv_lights/launch/lights.launch.py (1)

36-52: LGTM: Well-structured path configuration implementation

The implementation correctly handles both cases:

  • When common_dir_path is provided: appends /husarion_ugv_lights
  • When empty: falls back to package share path

The default empty string is appropriate as it maintains backward compatibility.

Let's verify the path construction logic:

✅ Verification successful

Path configuration implementation is correctly structured and safe

The verification confirms that:

  1. The package has a proper config directory structure with all required YAML files
  2. The path construction logic is sound:
    • When common_dir_path is empty (default), it uses package files from husarion_ugv_lights/config/
    • When common_dir_path is provided, it will look for config files under <common_dir_path>/husarion_ugv_lights/config/
  3. All referenced config files exist in the package:
    • Robot-specific: panther_animations.yaml, lynx_animations.yaml, panther_driver.yaml, lynx_driver.yaml
    • Common: user_animations.yaml

The implementation maintains backward compatibility and provides flexibility for custom configurations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the package structure and potential config locations

# Check if the package exists and its structure
fd --type d "husarion_ugv_lights"

# Look for any existing config files that might be affected
fd --type f --extension yaml "husarion_ugv_lights/config"

Length of output: 571


Script:

#!/bin/bash
# Let's verify the config files and their locations with corrected commands

# Check for YAML files in the package
fd --extension yaml . husarion_ugv_lights

# Check the launch file to understand the config file usage
cat husarion_ugv_lights/launch/lights.launch.py

Length of output: 5696

husarion_ugv_controller/launch/controller.launch.py (2)

37-52: LGTM: Consistent implementation of common directory configuration

The implementation follows the same pattern as other launch files, maintaining consistency across the codebase.


57-69: Verify the dynamic path construction for robot description

The path construction looks correct but involves dynamic package names. We should verify:

  1. The package naming convention for different robot models
  2. The existence of config directories in these packages
✅ Verification successful

Let me verify the content of these configuration files to ensure they contain the expected robot descriptions.


Dynamic path construction for robot description is correctly implemented

The verification confirms that:

  1. Both lynx_description and panther_description packages exist with the expected naming convention
  2. Both packages contain proper config directories with valid YAML configurations:
    • Wheel configurations (WH*.yaml) with correct robot-specific parameters
    • Component configurations for optional sensors/accessories
  3. The mesh package references in the configs align with the dynamic path construction logic
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify robot description package naming and structure

# Check for robot description packages
fd --type d "(lynx|panther)_description$"

# Verify config directories in these packages
fd --type d "config$" -p "(lynx|panther)_description"

# Look for any existing controller configurations
fd --type f --extension yaml -p "(lynx|panther)_description/config"

Length of output: 550


Script:

#!/bin/bash
# Check content of config files to verify robot descriptions
for file in lynx_description/config/*.yaml panther_description/config/*.yaml; do
    echo "=== $file ==="
    cat "$file"
    echo
done

Length of output: 3523

@BOOTCFG BOOTCFG requested a review from KmakD December 11, 2024 10:04
@KmakD KmakD merged commit 533f520 into ros2-devel Dec 11, 2024
1 check passed
@KmakD KmakD deleted the ros2-devel-better-config-dir branch December 11, 2024 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants