Skip to content

Update Torque Disable #28

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

Merged
merged 14 commits into from
Apr 5, 2025
Merged

Update Torque Disable #28

merged 14 commits into from
Apr 5, 2025

Conversation

yun-goon
Copy link
Contributor

@yun-goon yun-goon commented Apr 4, 2025

Description

Update Torque Disable

Woojin-Crive and others added 10 commits April 4, 2025 08:20
- Add omy_hat.model and omy_end.model to supported dynamixel models
- Update dynamixel.model to include new OMY models (220 and 230)
- Update gitignore to ensure model files are tracked
- Changed value_of_min_radian_position to -740 and min_radian to -1.099 in omy_end.model and rh_p12_rn.model for handling negative values
…t control

- Updated ReadMultiDxlData, GetDxlValueFromSyncRead, and GetDxlValueFromBulkRead to accept a period_ms parameter.
- Introduced ProcessReadCommunication and ProcessReadData functions for better data handling and communication management.
- Enhanced error handling and logging for read operations.
Signed-off-by: Wonho Yun <ywh@robotis.com>
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @yun-goon, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request focuses on updating the torque disable functionality within the dynamixel hardware interface. It introduces a global torque enable parameter, adds controller type identification, and refactors the read data processing. Additionally, it includes new dynamixel model files and modifies the dynamixel communication process to include a timeout based on the period.

Highlights

  • Global Torque Enable: A global torque enable parameter is introduced, allowing users to disable torque for all dynamixels. This is controlled by the torque_enable parameter in the hardware configuration.
  • Controller Type Identification: The code now identifies controller type dynamixels, allowing for specific initialization and handling of these devices.
  • Read Data Processing Refactor: The read data processing is refactored into separate functions for communication and data conversion, improving code readability and maintainability. The read functions now take a period_ms parameter.
  • Dynamixel Model Files: New dynamixel model files (omy_hat.model and omy_end.model) are added, and the .gitignore file is updated to include *.model files.

Changelog

Click here to see the changelog
  • .gitignore
    • Added a rule to ignore Dynamixel model files (*.model).
  • include/dynamixel_hardware_interface/dynamixel/dynamixel.hpp
    • Added <functional> include.
    • Modified ReadMultiDxlData, GetDxlValueFromSyncRead, and GetDxlValueFromBulkRead functions to accept a double period_ms parameter.
    • Added ProcessReadData and ProcessReadCommunication functions for handling data processing and communication.
    • Added ResetIndirectRead function.
  • include/dynamixel_hardware_interface/dynamixel_hardware_interface.hpp
    • Added global_torque_enable_ member variable.
    • Added controller_id_ and controller_item_ member variables.
    • Added initItems, retryWriteItem, and InitControllerItems helper functions.
    • Added is_set_hdl_ member variable.
  • param/dxl_model/dynamixel.model
    • Added omy_hat.model and omy_end.model to the list of available dynamixel models.
  • param/dxl_model/omy_end.model
    • Added a new dynamixel model file for omy_end.
  • param/dxl_model/omy_hat.model
    • Added a new dynamixel model file for omy_hat.
  • param/dxl_model/rh_p12_rn.model
    • Updated value_of_min_radian_position to -740 and min_radian to -1.099.
  • src/dynamixel/dynamixel.cpp
    • Added <functional> include.
    • Modified DynamixelDisable to return DxlError result instead of exiting on first error.
    • Modified ReadMultiDxlData to call GetDxlValueFromSyncRead or GetDxlValueFromBulkRead with the period_ms parameter.
    • Modified GetDxlValueFromSyncRead and GetDxlValueFromBulkRead to use ProcessReadData and ProcessReadCommunication.
    • Modified SetBulkReadItemAndHandler to return DxlError::BULK_READ_FAIL instead of DxlError::SYNC_READ_FAIL.
    • Added ProcessReadCommunication function to handle communication for SyncRead and BulkRead.
    • Added ProcessReadData function to handle data processing for SyncRead and BulkRead.
    • Added ResetIndirectRead function.
  • src/dynamixel_hardware_interface.cpp
    • Added parsing of torque_enable parameter from hardware parameters.
    • Added handling for controller type in on_init.
    • Modified on_init to initialize controller items before dxl items.
    • Modified start to enable torque only if global_torque_enable_ is true.
    • Modified read to pass period_ms to ReadMultiDxlData.
    • Modified CommReset to initialize controller items.
    • Added retryWriteItem function to retry writing items.
    • Added initItems function to initialize items for a specific type.
    • Added InitControllerItems function.
    • Modified InitDxlItems to also initialize sensor items.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


In realms of code, where robots roam,
Torque's control finds a new home.
With bits and bytes, a gentle hand,
To guide the motors 'cross the land.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces several updates to the dynamixel_hardware_interface, including adding a global torque enable parameter, controller items, and refactoring read data processing. The changes seem well-structured and aim to improve the flexibility and maintainability of the interface. However, there are some areas that could benefit from further review and refinement.

Summary of Findings

  • Error Handling in DynamixelDisable: The DynamixelDisable function in src/dynamixel/dynamixel.cpp accumulates errors but always returns the last error encountered. This could mask earlier errors. Consider returning a combined error status or logging all errors.
  • Redundant Initialization of Communication: The on_init function in src/dynamixel_hardware_interface.cpp initializes the communication port separately for controller and DXL/sensor IDs. This could lead to redundant initialization and potential conflicts. Consider unifying the initialization process.
  • Missing Error Handling in InitDxlItems: The InitDxlItems function in src/dynamixel_hardware_interface.cpp initializes Dynamixel items but lacks comprehensive error handling for write operations. Consider adding retry mechanisms or logging failures for individual item writes.
  • Inconsistent use of RCLCPP_INFO_STREAM: There are several instances where RCLCPP_INFO_STREAM is used for logging. Consider using RCLCPP_DEBUG_STREAM for less critical information to reduce verbosity in production.

Merge Readiness

The pull request introduces significant changes that require careful review. While the changes seem to improve the interface's functionality, the error handling and initialization processes need further attention. I recommend addressing the identified issues before merging. I am unable to directly approve this pull request, and users should have others review and approve this code before merging, particularly after the changes requested are implemented.

Comment on lines 307 to +309
if (WriteItem(it_id, "Torque Enable", TORQUE_OFF) < 0) {
fprintf(stderr, "[ID:%03d] Cannot write \"Torque Off\" command!\n", it_id);
return DxlError::ITEM_WRITE_FAIL;
result = DxlError::ITEM_WRITE_FAIL;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The function currently overwrites the result variable in each iteration, potentially masking earlier errors. It might be better to either return immediately on the first error or accumulate all errors and return a combined status. What if the first few motors failed to disable torque, but the last one succeeded? The error would be masked.

Suggested change
if (WriteItem(it_id, "Torque Enable", TORQUE_OFF) < 0) {
fprintf(stderr, "[ID:%03d] Cannot write \"Torque Off\" command!\n", it_id);
return DxlError::ITEM_WRITE_FAIL;
result = DxlError::ITEM_WRITE_FAIL;
if (WriteItem(it_id, "Torque Enable", TORQUE_OFF) < 0) {
fprintf(stderr, "[ID:%03d] Cannot write \"Torque Off\" command!\n", it_id);
if (result == DxlError::OK) {
result = DxlError::ITEM_WRITE_FAIL; // Only set if no previous error
}
}

Comment on lines +131 to +148
if (controller_id_.size() > 0) {
while (trying_connect) {
std::vector<uint8_t> id_arr;
for (auto controller : controller_id_) {
id_arr.push_back(controller);
}
if (dxl_comm_->InitDxlComm(id_arr, port_name_, baud_rate_) == DxlError::OK) {
RCLCPP_INFO_STREAM(logger_, "Trying to connect to the communication port...");
trying_connect = false;
} else {
sleep(1);
cnt++;
if (cnt > trying_cnt) {
RCLCPP_ERROR_STREAM(logger_, "Cannot connect communication port! :(");
cnt = 0;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This block of code initializes the communication port for controller IDs. It's duplicated later for DXL/sensor IDs. Consider refactoring this into a separate function to avoid redundancy and potential inconsistencies. Also, the trying_connect variable is not reset to true before the second while loop, which could cause issues if the first connection attempt fails.

Comment on lines +672 to 674
if (!retryWriteItem(id, it.first, static_cast<uint32_t>(stoi(it.second)))) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding a retry mechanism or logging a warning if the write operation fails. Without this, a single failed write can cause the entire initialization to fail, which is not ideal.

@yun-goon yun-goon requested a review from robotpilot April 4, 2025 11:47
@yun-goon yun-goon self-assigned this Apr 4, 2025
yun-goon added 3 commits April 4, 2025 20:57
Signed-off-by: Wonho Yun <ywh@robotis.com>
Signed-off-by: Wonho Yun <ywh@robotis.com>
Signed-off-by: Wonho Yun <ywh@robotis.com>
@robotpilot robotpilot added the enhancement New feature or request label Apr 4, 2025
@robotpilot robotpilot assigned robotpilot and unassigned yun-goon Apr 4, 2025
Copy link
Member

@robotpilot robotpilot left a comment

Choose a reason for hiding this comment

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

LGTM

@robotpilot robotpilot merged commit b981138 into main Apr 5, 2025
11 checks passed
@robotpilot robotpilot deleted the feature-omy branch April 5, 2025 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants