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

Change behaviour of motor_power_enable to e_stop_torque_enable #479

Open
wants to merge 7 commits into
base: ros2-devel
Choose a base branch
from

Conversation

rafal-gorecki
Copy link
Contributor

@rafal-gorecki rafal-gorecki commented Jan 10, 2025

Description

  • Change service name instead of motor_power_enable to e_stop_torque_enable
  • e_stop_reset now automaticly enable torque.
    image

Requirements

  • Code style guidelines followed
  • Documentation updated

Tests 🧪

  • Robot
  • Container
  • Simulation

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a new service hardware/e_stop_torque_enable for managing motor torque during emergency stops
  • Changes

    • Removed service hardware/motor_power_enable
    • Updated error logging and reporting for improved diagnostics
    • Enhanced emergency stop handling mechanism
  • Documentation

    • Updated documentation to reflect beta release status
    • Added notes about hardware compatibility for Lynx and Panther robots
  • Beta Notice

    • Software is in beta release with potential stability considerations

Copy link
Contributor

coderabbitai bot commented Jan 10, 2025

Walkthrough

This pull request introduces a significant change in the emergency stop (E-Stop) mechanism for Husarion UGV hardware interfaces. The primary modification involves replacing the motor_power_enable service with a new e_stop_torque_enable service. This change enhances the safety and control of motor torque during emergency stop conditions. The modifications span across multiple files, including documentation, launch configurations, and implementation files, to ensure consistent behavior and clear communication of the new functionality.

Changes

File Change Summary
ROS_API.md - Added service hardware/e_stop_torque_enable
- Removed service hardware/motor_power_enable
- Added beta release and hardware compatibility notes
husarion_ugv_controller/launch/controller.launch.py - Replaced motor_power_enable remapping with e_stop_torque_enable
husarion_ugv_hardware_interfaces/README.md - Removed service server hardware/motor_power_enable
- Added service server hardware/e_stop_torque_enable
husarion_ugv_hardware_interfaces/include/husarion_ugv_hardware_interfaces/robot_system/ugv_system.hpp - Removed method MotorsPowerEnable
- Added method EStopTorqueEnable
husarion_ugv_hardware_interfaces/src/robot_system/ugv_system.cpp - Replaced MotorsPowerEnable method with EStopTorqueEnable
- Updated service binding from ~/motor_power_enable to ~/e_stop_torque_enable
husarion_ugv_hardware_interfaces/src/robot_system/robot_driver/roboteq_data_converters.cpp - Updated emergency stop flag description
- Improved error log formatting
husarion_ugv_hardware_interfaces/src/robot_system/system_e_stop.cpp - Added robot_driver_->TurnOffEStop() call in ResetEStop method

Sequence Diagram

sequenceDiagram
    participant User
    participant ROS Service
    participant UGVSystem
    participant RobotDriver

    User->>ROS Service: Call e_stop_torque_enable
    ROS Service->>UGVSystem: Invoke EStopTorqueEnable
    UGVSystem->>UGVSystem: Check E-Stop state
    alt E-Stop triggered
        UGVSystem->>RobotDriver: Enable/Disable Torque
    else E-Stop not triggered
        UGVSystem-->>User: Throw Runtime Error
    end
Loading

Possibly related PRs

Suggested reviewers

  • miloszlagan
  • delihus

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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. (Beta)
  • @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

🧹 Nitpick comments (3)
husarion_ugv_hardware_interfaces/src/robot_system/ugv_system.cpp (1)

Line range hint 529-552: Robust safety implementation for E-Stop torque control!

The implementation includes critical safety features:

  1. Validates E-Stop state before allowing torque changes
  2. Uses mutex for thread-safe operation
  3. Proper error handling and clear error messages

However, consider adding logging for successful torque state changes to aid in debugging.

Add success logging:

     if (!enable) {
         robot_driver_->TurnOnEStop();
+        RCLCPP_INFO(logger_, "Motor torque disabled successfully");
     } else {
         robot_driver_->TurnOffEStop();
+        RCLCPP_INFO(logger_, "Motor torque enabled successfully");
     }
husarion_ugv_hardware_interfaces/README.md (1)

29-29: Enhance service documentation for clarity.

While the service is documented, the description could be more specific about its relationship with E-Stop state.

Update the description:

-- `hardware/e_stop_torque_enable` [*std_srvs/SetBool*]: Enables or disables motor power.
+- `hardware/e_stop_torque_enable` [*std_srvs/SetBool*]: Enables or disables motor torque when E-Stop is triggered. This service will fail if E-Stop is not active.
ROS_API.md (1)

121-121: Consider documenting the default state.

It would be helpful to document the default state of motor torque when E-Stop is triggered (enabled/disabled by default).

Apply this diff to enhance the documentation:

-| ✅   | ❌   | `hardware/e_stop_torque_enable`                     | Allows enabling or disabling motor torque when the E-Stop is triggered. <br/> [std_srvs/srv/SetBool](https://docs.ros2.org/latest/api/std_srvs/srv/SetBool.html) |
+| ✅   | ❌   | `hardware/e_stop_torque_enable`                     | Allows enabling or disabling motor torque when the E-Stop is triggered. By default, motor torque is disabled when E-Stop is triggered. <br/> [std_srvs/srv/SetBool](https://docs.ros2.org/latest/api/std_srvs/srv/SetBool.html) |
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3d47255 and 1edbb8d.

📒 Files selected for processing (9)
  • ROS_API.md (1 hunks)
  • husarion_ugv_controller/launch/controller.launch.py (1 hunks)
  • husarion_ugv_hardware_interfaces/README.md (1 hunks)
  • husarion_ugv_hardware_interfaces/include/husarion_ugv_hardware_interfaces/robot_system/ugv_system.hpp (1 hunks)
  • husarion_ugv_hardware_interfaces/src/robot_system/lynx_system.cpp (1 hunks)
  • husarion_ugv_hardware_interfaces/src/robot_system/panther_system.cpp (1 hunks)
  • husarion_ugv_hardware_interfaces/src/robot_system/robot_driver/roboteq_data_converters.cpp (2 hunks)
  • husarion_ugv_hardware_interfaces/src/robot_system/system_e_stop.cpp (1 hunks)
  • husarion_ugv_hardware_interfaces/src/robot_system/ugv_system.cpp (3 hunks)
🔇 Additional comments (10)
husarion_ugv_hardware_interfaces/src/robot_system/system_e_stop.cpp (1)

58-58: LGTM! Verify E-Stop reset sequence.

The addition of TurnOffEStop() at the start of the reset sequence is logical and aligns with the new E-Stop torque management approach.

Run this script to verify the E-Stop reset sequence implementation across the codebase:

✅ Verification successful

Verified: E-Stop reset sequence is correctly implemented

The addition of TurnOffEStop() at the start of the reset sequence is correct and follows the documented E-Stop reset procedure, with proper safety checks in place:

  1. Turn off E-Stop command (new addition)
  2. Thread-safe GPIO manipulation
  3. Error flag clearing
  4. Reset confirmation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the E-Stop reset sequence implementation
# Expect: TurnOffEStop is called before other reset operations

# Search for ResetEStop implementations
ast-grep --pattern 'ResetEStop() {
  $$$
}'

# Search for TurnOffEStop implementations
ast-grep --pattern 'TurnOffEStop() {
  $$$
}'

Length of output: 93


Script:

#!/bin/bash
# Search for E-Stop related files and implementations
echo "=== Files containing E-Stop related code ==="
rg -l "(?i)estop|e_stop|e-stop"

echo -e "\n=== E-Stop method implementations ==="
rg -n "(?i)(?:reset|turn.*off).*(?:estop|e_stop)" -A 5

echo -e "\n=== Header files with E-Stop declarations ==="
fd -e hpp -e h | xargs rg -n "(?i)(?:reset|turn.*off).*(?:estop|e_stop)"

Length of output: 38519

husarion_ugv_hardware_interfaces/src/robot_system/lynx_system.cpp (1)

107-108: LGTM! Improved error message formatting.

The updated error message format enhances readability and maintains consistency with other error messages in the codebase.

husarion_ugv_hardware_interfaces/include/husarion_ugv_hardware_interfaces/robot_system/ugv_system.hpp (1)

113-113: LGTM! Verify all service bindings are updated.

The replacement of MotorsPowerEnable with EStopTorqueEnable improves safety by specifically managing torque during E-Stop conditions.

Run this script to verify all service bindings are updated:

✅ Verification successful

Service bindings successfully updated

All references to the old motor_power_enable service have been removed, and the new e_stop_torque_enable service is properly bound in the launch configuration and documented in the API.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify service bindings and usages
# Expect: No references to old motor_power_enable service

# Search for any remaining references to motor_power_enable
rg -i "motor_power_enable"

# Search for new e_stop_torque_enable service bindings
rg -i "e_stop_torque_enable"

Length of output: 667

husarion_ugv_hardware_interfaces/src/robot_system/panther_system.cpp (1)

128-140: LGTM! Enhanced error diagnostics.

The separation of front and rear driver error messages improves diagnostics by clearly identifying which driver is in an error state. The formatting is consistent with other error messages in the codebase.

husarion_ugv_hardware_interfaces/src/robot_system/robot_driver/roboteq_data_converters.cpp (2)

105-105: Improved clarity in E-Stop flag naming!

The updated flag name better distinguishes between Roboteq E-stop and ROS E-stop, making it clearer that this state indicates torque is disabled.


254-276: Enhanced error log formatting and readability!

The restructured error log generation:

  1. Only includes non-empty error logs, reducing noise
  2. Adds clear labels for each error type
  3. Properly handles trailing newlines
husarion_ugv_controller/launch/controller.launch.py (1)

221-221: Correct remapping for the new service name!

The remapping from hardware_controller/e_stop_torque_enable to hardware/e_stop_torque_enable is consistent with other hardware-related remappings.

husarion_ugv_hardware_interfaces/src/robot_system/ugv_system.cpp (1)

132-133: Correct service binding for the new E-Stop torque control!

The service binding is properly updated to use the new method name and maintains consistency with other service bindings.

ROS_API.md (2)

121-121: LGTM! Clear and concise documentation of the new service.

The documentation for the new hardware/e_stop_torque_enable service is well-written and accurately describes its functionality. The service type is correctly specified as std_srvs/srv/SetBool.


121-121: Verify the service implementation matches the documentation.

Let's verify that the service implementation aligns with the documented behavior.

✅ Verification successful

Service implementation matches documentation

The service implementation in UGVSystem::EStopTorqueEnable correctly implements the documented behavior:

  • Uses the documented service type (std_srvs/srv/SetBool)
  • Controls motor torque when E-Stop is triggered
  • Includes proper safety checks and thread synchronization
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the service implementation
ast-grep --pattern 'create_service<std_srvs::srv::SetBool>("hardware/e_stop_torque_enable"'

# Search for any tests related to this service
rg -l "e_stop_torque_enable.*test"

Length of output: 141


Script:

#!/bin/bash
# Search for e_stop related files
rg -l "e_stop"

# Search for SetBool service usage
ast-grep --pattern 'create_service<std_srvs::srv::SetBool>($_)'

# Search for torque enable related code
rg -l "torque.*enable|enable.*torque"

# Search for e_stop implementation
ast-grep --pattern 'void $_($$$) {
  $$$
  e_stop
  $$$
}'

Length of output: 2767


Script:

#!/bin/bash
# Check system_ros_interface.cpp content
cat husarion_ugv_hardware_interfaces/src/robot_system/system_ros_interface.cpp

# Check ugv_system.cpp for torque enable functionality
cat husarion_ugv_hardware_interfaces/src/robot_system/ugv_system.cpp

# Look for SetBool service handlers
ast-grep --pattern 'void $_($_: std_srvs::srv::SetBool::Request::SharedPtr, $_: std_srvs::srv::SetBool::Response::SharedPtr) {
  $$$
}'

Length of output: 29567

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.

1 participant