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

battery node reads from /dev/battery | lights are read from symlink #347

Merged
merged 3 commits into from
Jul 1, 2024

Conversation

delihus
Copy link
Contributor

@delihus delihus commented Jun 14, 2024

Description

Added symlinks to the os image https://github.com/husarion/panther-rpi-os-img/pull/94.
Updating devices and params parcsing after adding symlinks to leds and batteries ADS measurements.

Summary by CodeRabbit

  • New Features

    • Enhanced battery path retrieval with the new GetBatteryPath method.
  • Bug Fixes

    • Corrected typos in error messages across multiple components to "An exception occurred."
  • Improvements

    • Updated ADC device paths for better hardware interfacing in battery and light drivers.
    • Improved exception handling and logging in battery initialization processes.
  • Refactor

    • Adjusted parameter names and paths for clearer and more consistent code structure in battery node initialization functions.

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
Copy link
Contributor

coderabbitai bot commented Jun 14, 2024

Walkthrough

This update enhances several components of the Panther system by adding a new method for retrieving battery paths, improving error handling, and refining device path updates. Key changes include the addition of the GetBatteryPath method in the BatteryNode class for better path management and correction of typos in error messages across multiple files for clarity and consistency.

Changes

File Path (Shortened) Change Summary
panther_battery/include/panther_battery/... Added GetBatteryPath method; updated InitializeWithRoboteqBattery.
panther_battery/src/battery_node.cpp Enhanced exception handling in Initialize; updated device paths in InitializeWithADCBattery, added GetBatteryPath method.
panther_battery/src/battery_publisher.cpp Corrected typo in error message in Publish() method.
panther_diagnostics/src/system_status_node.cpp Fixed a typo in an error message in GetCPUTemperature function.
panther_hardware_interfaces/src/... Updated error messages in Initialize(), BootDrivers(), OperationWithAttempts() and other methods to fix typos.
panther_lights/src/driver_node.cpp Updated channel device paths in DriverNode constructor.

Sequence Diagram(s)

Battery Node Initialization with ADC Battery

sequenceDiagram
    autonote over User, BatteryNode: Initialize with ADC Battery (Updated)
    User ->> BatteryNode: Initialize()
    BatteryNode ->> BatteryNode: declare_parameter("adc/device0", "/dev/battery1")
    BatteryNode ->> BatteryNode: declare_parameter("adc/device1", "/dev/battery2")
    BatteryNode ->> BatteryNode: get_parameter("adc/device0")
    BatteryNode ->> BatteryNode: get_parameter("adc/device1")
    BatteryNode ->> BatteryNode: GetBatteryPath("/dev/battery1")
    BatteryNode ->> BatteryNode: GetBatteryPath("/dev/battery2")
    BatteryNode ->> ADCDataReader: Instantiate with adc0_device_path
    BatteryNode ->> ADCDataReader: Instantiate with adc1_device_path
    autonote over User, BatteryNode: Initialization complete
Loading

Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are currently opted into early access features by default.

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 Configration 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.

@delihus
Copy link
Contributor Author

delihus commented Jun 14, 2024

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jun 14, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@delihus delihus marked this pull request as ready for review June 19, 2024 19:10
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 and nitpick comments (2)
panther_battery/include/panther_battery/battery_node.hpp (1)

46-46: Add a method comment to GetBatteryPath.

A method comment explaining the purpose and the expected behavior of GetBatteryPath would enhance the readability and maintainability of the code, especially for future developers or for those unfamiliar with the codebase.

panther_battery/src/battery_node.cpp (1)

85-97: Ensure parameter naming consistency.

The parameters for device paths (adc/device0 and adc/device1) are well-named, but consider ensuring consistency in naming convention across all parameters to enhance readability and prevent confusion. For example, adc/ma_window_len/temp could be renamed to maintain the same level of detail as the device path parameters.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5e0dcf3 and 4088d98.

Files selected for processing (9)
  • panther_battery/include/panther_battery/battery_node.hpp (1 hunks)
  • panther_battery/src/battery_node.cpp (3 hunks)
  • panther_battery/src/battery_publisher.cpp (1 hunks)
  • panther_diagnostics/src/system_status_node.cpp (1 hunks)
  • panther_hardware_interfaces/src/canopen_controller.cpp (4 hunks)
  • panther_hardware_interfaces/src/gpio_driver.cpp (2 hunks)
  • panther_hardware_interfaces/src/panther_system_ros_interface.cpp (1 hunks)
  • panther_hardware_interfaces/src/utils.cpp (1 hunks)
  • panther_lights/src/driver_node.cpp (1 hunks)
Files skipped from review due to trivial changes (6)
  • panther_battery/src/battery_publisher.cpp
  • panther_diagnostics/src/system_status_node.cpp
  • panther_hardware_interfaces/src/canopen_controller.cpp
  • panther_hardware_interfaces/src/gpio_driver.cpp
  • panther_hardware_interfaces/src/panther_system_ros_interface.cpp
  • panther_hardware_interfaces/src/utils.cpp
Additional comments not posted (1)
panther_lights/src/driver_node.cpp (1)

43-44: Verify device path updates.

Ensure that the updated device paths in DriverNode constructor are correctly configured and accessible. This is crucial for the proper operation of the lighting system.

Comment on lines 67 to 73
this->get_logger(),
"An exception occurred while initializing with ADC: " << e.what()
<< " Falling back to "
"using Roboteq "
"drivers to "
"publish battery "
"data.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor exception handling for clarity.

The exception handling block within BatteryNode::Initialize could be refactored for better clarity and maintainability. Consider encapsulating the fallback logic into a separate method or improving the logging details to provide more context about the failure.

@pawelirh pawelirh self-requested a review June 21, 2024 07:53
panther_battery/src/battery_node.cpp Outdated Show resolved Hide resolved
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: 3

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4088d98 and 3a2a5bd.

Files selected for processing (1)
  • panther_battery/src/battery_node.cpp (3 hunks)

@@ -64,7 +64,7 @@ void BatteryNode::Initialize()
return;
} catch (const std::runtime_error & e) {
RCLCPP_WARN_STREAM(
this->get_logger(), "An exception ocurred while initializing with ADC: "
this->get_logger(), "An exception occurred while initializing with ADC: "
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor exception handling for clarity.

The exception handling block within BatteryNode::Initialize could be refactored for better clarity and maintainability. Consider encapsulating the fallback logic into a separate method or improving the logging details to provide more context about the failure.

Comment on lines +166 to +177
std::string BatteryNode::GetBatteryPath(const std::string & adc_device_path) const
{
std::string battery_device_name;

if (std::filesystem::is_symlink(adc_device_path)) {
battery_device_name = std::filesystem::read_symlink(adc_device_path).string();
} else {
battery_device_name = std::filesystem::path(adc_device_path).filename().string();
}

return std::string("/sys/bus/iio/devices/") + battery_device_name;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM! But consider adding error handling for invalid paths.

The code changes are approved.

However, consider adding error handling for invalid paths to enhance robustness.

std::string BatteryNode::GetBatteryPath(const std::string & adc_device_path) const
{
  std::string battery_device_name;

  if (std::filesystem::is_symlink(adc_device_path)) {
    battery_device_name = std::filesystem::read_symlink(adc_device_path).string();
  } else {
    battery_device_name = std::filesystem::path(adc_device_path).filename().string();
  }

  // Add error handling for invalid paths
  if (battery_device_name.empty()) {
    RCLCPP_ERROR(this->get_logger(), "Invalid ADC device path: %s", adc_device_path.c_str());
    throw std::runtime_error("Invalid ADC device path");
  }

  return std::string("/sys/bus/iio/devices/") + battery_device_name;
}

Comment on lines +81 to +82
this->declare_parameter<std::string>("adc/device0", "/dev/battery1");
this->declare_parameter<std::string>("adc/device1", "/dev/battery2");
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Device paths /dev/battery1 and /dev/battery2 do not exist.

The device paths specified in the code (/dev/battery1 and /dev/battery2) are not present in the system. This will cause the initialization to fail.

  • Ensure that the device paths /dev/battery1 and /dev/battery2 are correctly set up and accessible before running the code.
Analysis chain

LGTM! But verify the device paths.

The code changes are approved.

However, ensure that the new device paths (/dev/battery1 and /dev/battery2) are correctly set up and accessible.

Also applies to: 86-87, 89-93

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the new device paths are correctly set up and accessible.

# Test: Check if the device paths exist. Expect: Paths exist.
test -e /dev/battery1 && echo "/dev/battery1 exists" || echo "/dev/battery1 does not exist"
test -e /dev/battery2 && echo "/dev/battery2 exists" || echo "/dev/battery2 does not exist"

Length of output: 181

@pawelirh pawelirh merged commit 0d722e7 into ros2-devel Jul 1, 2024
@pawelirh pawelirh deleted the ros2-symlinks branch July 1, 2024 13:21
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