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

ROS 2 lights initialization #365

Merged
merged 9 commits into from
Jul 17, 2024
Merged

Conversation

KmakD
Copy link
Contributor

@KmakD KmakD commented Jul 15, 2024

Description

  • image messages are now passed using intra process communication
  • nodes were changed to components
  • initialization was moved to constructor, new structure representing LED control status was introduced
  • some files were renamed

Modifications

Summary by CodeRabbit

  • Bug Fixes

    • Improved LED control handling to enhance stability and reliability.
  • Refactor

    • Streamlined the internal workings of the DriverNode class to improve performance and maintainability.
  • New Features

    • Added functionality to better diagnose light status and control LEDs more effectively.

Copy link
Contributor

coderabbitai bot commented Jul 15, 2024

Walkthrough

The updates to lights_driver_node.hpp and lights_driver_node.cpp primarily involve updating the subscriber and callback mechanisms, renaming variables for clarity, and enhancing LED control functionality. These changes transition from using image_transport to rclcpp for subscriptions, improving performance and compatibility with the ROS 2 framework. Furthermore, the constructor and several function signatures were modified to reflect these updates and enhance the maintainability of the code.

Changes

File Path Change Summary
panther_lights/include/panther_lights/... Header guard updated, removed and added include files, variable and function signature changes, switched to rclcpp::Subscription.
panther_lights/src/lights_driver_node.cpp Renamed include directives, updated constructor, subscribers, service creation, LED control toggling, and diagnostics.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ROS2Node
    participant DriverNode
    participant LEDController

    User->>ROS2Node: Sends Image Message
    ROS2Node->>DriverNode: Publish Image Message
    DriverNode->>LEDController: Process Image and Control LEDs
    LEDController-->>DriverNode: LED Status
    DriverNode->>User: Update Status
Loading
sequenceDiagram
    participant DiagnosticSystem
    participant DriverNode
    participant LEDController

    loop Periodic Check
        DiagnosticSystem->>DriverNode: Trigger Diagnostic
        DriverNode->>LEDController: Get LED Status
        LEDController-->>DriverNode: Return Status
        DriverNode->>DiagnosticSystem: Report Status
    end
Loading

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3a575a7 and dac4f27.

Files selected for processing (10)
  • panther_lights/CMakeLists.txt (4 hunks)
  • panther_lights/README.md (2 hunks)
  • panther_lights/include/panther_lights/lights_controller_node.hpp (4 hunks)
  • panther_lights/include/panther_lights/lights_driver_node.hpp (4 hunks)
  • panther_lights/launch/lights.launch.py (3 hunks)
  • panther_lights/package.xml (1 hunks)
  • panther_lights/src/lights_controller_node.cpp (3 hunks)
  • panther_lights/src/lights_driver_node.cpp (8 hunks)
  • panther_lights/test/test_lights_controller_node.cpp (2 hunks)
  • panther_lights/test/test_lights_driver_node.cpp (1 hunks)
Files skipped from review due to trivial changes (1)
  • panther_lights/package.xml
Additional comments not posted (43)
panther_lights/include/panther_lights/lights_driver_node.hpp (6)

15-16: Header guard updated correctly.

The header guard has been updated to reflect the new file name.


24-24: Include directive updated correctly.

The include directive for sensor_msgs/msg/image.hpp has been added to replace the removed image_transport/image_transport.hpp.


38-44: Enum LEDControlStatus defined correctly.

The enum LEDControlStatus improves code readability and maintainability.


53-53: Constructor updated to use intra-process communication.

The constructor now uses intra-process communication by default, enhancing performance.


59-59: Member variable led_control_status_ introduced.

The member variable led_control_status_ is necessary to track the LED control status.


113-114: Subscriber declarations updated correctly.

The subscriber declarations now use rclcpp::Subscription instead of image_transport::Subscriber.

panther_lights/launch/lights.launch.py (6)

26-27: Imports for ComposableNodeContainer and ComposableNode added correctly.

These imports are necessary for the new node management approach.


62-66: ComposableNodeContainer initialized correctly.

The lights_container is now initialized using ComposableNodeContainer, enhancing modularity and performance.


68-75: DriverNode added as a ComposableNode.

The DriverNode is now managed as a component within the container.


76-85: ControllerNode added as a ComposableNode.

The ControllerNode is now managed as a component within the container.


96-96: lights_container added to actions.

The lights_container is now included in the launch description.


Line range hint 1-99:
Launch file structure updated correctly.

The overall structure of the launch file has been updated to use composable nodes, improving modularity and performance.

panther_lights/include/panther_lights/lights_controller_node.hpp (3)

15-16: Header guard updated correctly.

The header guard has been updated to reflect the new file name.


45-45: Constructor updated to use intra-process communication.

The constructor now uses intra-process communication by default, enhancing performance.


Line range hint 1-159:
Class structure updated correctly.

The overall class structure has been updated to remove the SetAnimation method, ensuring consistency with the new design.

panther_lights/test/test_lights_driver_node.cpp (5)

33-50: DriverNodeWrapper class added correctly.

The DriverNodeWrapper class facilitates testing of the DriverNode by providing access to protected members.


52-103: TestDriverNode class added correctly.

The TestDriverNode class sets up the test environment and provides utility functions in a structured manner.


105-115: ServiceTestSuccess test case added correctly.

The ServiceTestSuccess test case verifies successful service interaction with valid service requests.


117-127: ServiceTestFail test case added correctly.

The ServiceTestFail test case verifies service interaction failure with invalid service requests.


1-215: Test file structure updated correctly.

The overall structure of the test file has been updated to include new test cases and classes, improving test coverage and organization.

panther_lights/CMakeLists.txt (7)

15-15: Dependency Addition Approved

The addition of find_package(rclcpp_components REQUIRED) is necessary for the new node components.


30-38: Addition of lights_driver_node_component Approved

The addition of the lights_driver_node_component library and its dependencies is appropriate for the new node component.


42-54: Addition of lights_controller_node_component Approved

The addition of the lights_controller_node_component library and its dependencies is appropriate for the new node component.


56-58: Registration of lights_driver_node_component Approved

The registration of the lights_driver_node_component with rclcpp_components is necessary for component usage.


60-62: Registration of lights_controller_node_component Approved

The registration of the lights_controller_node_component with rclcpp_components is necessary for component usage.


175-189: Addition of Test Cases for lights_controller_node Approved

The addition of test cases for the lights_controller_node ensures that the new component's functionality is properly tested.


198-208: Addition of Test Cases for lights_driver_node Approved

The addition of test cases for the lights_driver_node ensures that the new component's functionality is properly tested.

panther_lights/src/lights_driver_node.cpp (9)

29-29: Header Inclusion Approved

The inclusion of #include "sensor_msgs/msg/image.hpp" is necessary for the ImageMsg type used in the subscriptions.


Line range hint 42-92: Constructor Updates Approved

The updates to the constructor, including the initialization of led_control_status_, setting up callback groups, and creating subscriptions, are necessary for the new component architecture.


64-68: Callback Group and Client Initialization Approved

The creation of the callback group and initialization of the enable_led_control_client_ with the new callback group is appropriate for ensuring mutually exclusive callbacks.


74-85: Subscription Updates Approved

The updates to the subscription creation to use ImageMsg::UniquePtr are appropriate for improving efficiency in intra-process communication.


87-88: Diagnostic Updater Initialization Approved

The initialization of the diagnostic updater with the hardware ID and the addition of a diagnostic task for the lights driver status are appropriate for monitoring the node's health.


144-153: Callback Updates Approved

The updates to the ToggleLEDControlCB method to handle the new led_control_status_ and provide appropriate logging are necessary for the new component architecture.


Line range hint 159-192: Frame Callback Updates Approved

The updates to the FrameCB method to use ImageMsg::UniquePtr and handle the new led_control_status_ are appropriate for the new component architecture.


Line range hint 238-242: Diagnostic Method Updates Approved

The updates to the DiagnoseLights method to handle the new led_control_status_ and provide appropriate diagnostics are necessary for the new component architecture.


248-249: Node Registration Approved

The registration of the DriverNode with rclcpp_components is necessary for component usage.

panther_lights/test/test_lights_controller_node.cpp (1)

35-35: Constructor Update Approved

The update to the constructor of ControllerNodeWrapper to match the new constructor of ControllerNode ensures consistency.

panther_lights/src/lights_controller_node.cpp (4)

43-44: Constructor Update Approved

The update to the constructor to initialize the node with the new options and parameters, including the use of intra-process communication, is appropriate for the new component architecture.


Line range hint 159-160: Frame Callback Update Approved

The update to the FrameCB method to use ImageMsg::UniquePtr is appropriate for improving efficiency in intra-process communication.


372-374: Node Registration Approved

The registration of the ControllerNode with rclcpp_components is necessary for component usage.


Line range hint 248-249: Diagnostic Updater Initialization Approved

The initialization of the diagnostic updater with the hardware ID and the addition of a diagnostic task for the lights controller status are appropriate for monitoring the node's health.

panther_lights/README.md (2)

20-20: LGTM! Consistent renaming of driver_node to lights_driver_node.

The section has been renamed correctly and the information is consistent.


78-78: LGTM! Consistent renaming of controller_node to lights_controller_node.

The section has been renamed correctly and the information is consistent.

@JanBrzyk JanBrzyk requested a review from pawelirh July 15, 2024 11:46
panther_lights/launch/lights.launch.py Show resolved Hide resolved
panther_lights/launch/lights.launch.py Outdated Show resolved Hide resolved
panther_lights/src/lights_driver_node.cpp Outdated Show resolved Hide resolved
panther_lights/src/lights_driver_node.cpp Outdated Show resolved Hide resolved
@KmakD KmakD requested a review from pawelirh July 16, 2024 07:37
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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dac4f27 and 90a9c02.

Files selected for processing (5)
  • panther_lights/include/panther_lights/lights_controller_node.hpp (4 hunks)
  • panther_lights/include/panther_lights/lights_driver_node.hpp (4 hunks)
  • panther_lights/launch/lights.launch.py (3 hunks)
  • panther_lights/src/led_animations_queue.cpp (1 hunks)
  • panther_lights/src/lights_driver_node.cpp (8 hunks)
Files skipped from review as they are similar to previous changes (3)
  • panther_lights/include/panther_lights/lights_controller_node.hpp
  • panther_lights/include/panther_lights/lights_driver_node.hpp
  • panther_lights/src/lights_driver_node.cpp
Additional comments not posted (2)
panther_lights/launch/lights.launch.py (1)

62-91: Review of ComposableNodeContainer and ComposableNode setup

The setup of the ComposableNodeContainer and ComposableNode is correctly implemented. The use of intra-process communication is consistent with the PR's objectives to enhance performance. However, ensure that the extra_arguments are correctly applied to all nodes within the container to fully utilize intra-process communication capabilities.

panther_lights/src/led_animations_queue.cpp (1)

121-121: Logger name updated in Validate function

The update to the logger name to "lights_controller" is consistent with the renaming of nodes and components. This change helps in maintaining clarity and traceability in log outputs.

@KmakD KmakD requested a review from pawelirh July 17, 2024 08:14
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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 90a9c02 and 24146ae.

Files selected for processing (2)
  • panther_lights/include/panther_lights/lights_driver_node.hpp (3 hunks)
  • panther_lights/src/lights_driver_node.cpp (8 hunks)
Files skipped from review as they are similar to previous changes (2)
  • panther_lights/include/panther_lights/lights_driver_node.hpp
  • panther_lights/src/lights_driver_node.cpp

panther_lights/src/lights_driver_node.cpp Outdated Show resolved Hide resolved
panther_lights/src/lights_driver_node.cpp Show resolved Hide resolved
panther_lights/src/lights_driver_node.cpp Outdated Show resolved Hide resolved
panther_lights/src/lights_driver_node.cpp Outdated Show resolved Hide resolved
panther_lights/src/lights_driver_node.cpp Outdated Show resolved Hide resolved
@KmakD KmakD requested a review from pawelirh July 17, 2024 10:21
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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 24146ae and be1871c.

Files selected for processing (1)
  • panther_lights/src/lights_driver_node.cpp (8 hunks)
Files skipped from review as they are similar to previous changes (1)
  • panther_lights/src/lights_driver_node.cpp

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: 1

Outside diff range, codebase verification and nitpick comments (1)
panther_lights/src/lights_driver_node.cpp (1)

Line range hint 96-101: Review of Shutdown Handling

The OnShutdown function correctly clears the LEDs and toggles LED control based on the led_control_granted_ flag. This ensures that resources are properly released when the node is shutting down. However, based on previous discussions, there seems to be an issue with the ToggleLEDControl freezing the system. This needs further investigation, as it could lead to problems during shutdown.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between be1871c and 3bb7fb1.

Files selected for processing (2)
  • panther_lights/include/panther_lights/lights_driver_node.hpp (3 hunks)
  • panther_lights/src/lights_driver_node.cpp (9 hunks)
Files skipped from review as they are similar to previous changes (1)
  • panther_lights/include/panther_lights/lights_driver_node.hpp
Additional comments not posted (3)
panther_lights/src/lights_driver_node.cpp (3)

Line range hint 42-96: Constructor Review: Initialization and Setup

The constructor has been refactored to remove the node_name parameter and directly use "lights_driver" as the node name. This simplifies the initialization but assumes that the node name does not need to be configurable, which should be verified if it aligns with the system's requirements.

  • Initialization of Parameters: Parameters like global_brightness, frame_timeout, and num_led are declared and retrieved correctly.
  • Error Handling: There is no error handling if the parameters are set to values that are not sensible (e.g., negative numbers for num_led). Consider adding checks or constraints on these parameters.
  • Resource Initialization: The use of chanel_1_ and chanel_2_ for setting global brightness directly after declaring parameters is efficient.

Overall, the constructor setup appears robust, but adding parameter validation could improve reliability.


108-132: Review of Initialization Timer Callback

The InitializationTimerCB function implements a retry mechanism for LED control initialization. It uses a combination of state flags (led_control_granted_, led_control_pending_) and timing checks to manage retries. Here are a few points to consider:

  • Error Handling: The function throws a runtime error if the maximum number of initialization attempts is exceeded. This is a good practice as it fails fast, preventing the system from being stuck in an indefinite initialization state.
  • Resource Management: The function correctly cancels the timer if LED control is granted, which is efficient in terms of resource usage.
  • Timing and Delays: The use of led_control_call_time_ to check for service response timeouts is a robust way to handle potential communication delays or failures.

This function appears well-implemented with proper error handling and resource management strategies.


257-274: Review of Diagnostic Functionality

The DiagnoseLights function effectively uses the diagnostic updater to report the status of the lights driver. It appropriately sets the error level and message based on the state of LED control. This function is a good example of how to implement diagnostics in a ROS node.

  • Error Levels and Messages: The use of different error levels (ERROR, WARN, OK) based on the state (led_control_granted_, led_control_pending_) is a best practice in ROS diagnostics.
  • Status Reporting: The function reports the status in a clear and concise manner, which is beneficial for system monitoring and troubleshooting.

This diagnostic implementation is robust and follows best practices.

panther_lights/src/lights_driver_node.cpp Show resolved Hide resolved
@pawelirh pawelirh merged commit be3f791 into ros2-devel Jul 17, 2024
@pawelirh pawelirh deleted the ros2-lights-initialization branch July 17, 2024 12:41
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