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

Add RobotState msg #82

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

Add RobotState msg #82

wants to merge 3 commits into from

Conversation

rafal-gorecki
Copy link
Contributor

@rafal-gorecki rafal-gorecki commented Oct 18, 2024

Summary by CodeRabbit

  • New Features
    • Introduced a new RobotState message definition to enhance robot state communication.
    • Added integer constants for various robot states: ERROR, E_STOP, STANDBY, DOCKING, and SUCCESS.
    • Included a standard header for timestamping and frame information.

Copy link

coderabbitai bot commented Oct 18, 2024

Walkthrough

The changes introduce a new message definition for RobotState in the msg/RobotState.msg file. This definition includes several integer constants representing various robot states such as ERROR, E_STOP, STANDBY, DOCKING, and SUCCESS, each associated with a specific integer value. The message also contains a standard header of type std_msgs/Header for timestamping and frame information, along with an integer field state_id to indicate the current state of the robot.

Changes

File Change Summary
msg/RobotState.msg Added new message definition RobotState with integer constants for robot states and a header.

Sequence Diagram(s)

sequenceDiagram
    participant Robot
    participant StateManager
    Robot->>StateManager: Request current state
    StateManager->>Robot: Respond with RobotState
    Robot->>Robot: Update internal state using state_id
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>, 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 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

@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 (3)
msg/RobotState.msg (3)

1-5: LGTM! Consider adding comments for clarity.

The constant definitions look good. The use of int8 is appropriate for this small set of states, and the naming convention is consistent. The order of states is logical, with ERROR being -1 and E_STOP (Emergency Stop) being 0, which is a common practice.

Consider adding brief comments to explain what each state represents, especially for less obvious ones like DOCKING. This would improve the self-documentation of the message. For example:

 int8 ERROR = -1
 int8 E_STOP = 0  # Emergency Stop
 int8 STANDBY = 1
-int8 DOCKING = 2
+int8 DOCKING = 2  # Robot is in the process of docking
 int8 SUCCESS = 3

7-8: LGTM! Consider adding comments for clarity.

The message fields are well-defined. The use of int8 for state_id matches the type used for the constants, and the inclusion of a string state_name allows for a human-readable representation of the state.

Consider adding brief comments to explain the purpose of these fields. For example:

+# Numeric identifier of the robot's current state
 int8 state_id
+# Human-readable name of the robot's current state
 string state_name

This would improve the self-documentation of the message and make it clearer for other developers using this message type.


1-8: Overall structure looks good. Consider future maintainability.

The message structure is clear and provides a good balance between efficiency (using int8 for state_id) and readability (using string for state_name). This design allows for easy extension with additional states in the future.

For future consideration:

  1. Ensure that the code using this message maintains consistency between state_id and state_name. You might want to consider creating a utility function or enum-like structure in your codebase to manage this relationship and prevent inconsistencies.
  2. If the number of states grows significantly in the future, you might want to consider using a separate configuration file or message to define the mapping between state_id and state_name. This would allow for easier maintenance and potentially dynamic updating of state definitions.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a2412cb and 6eb04e3.

📒 Files selected for processing (2)
  • CMakeLists.txt (1 hunks)
  • msg/RobotState.msg (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
CMakeLists.txt (1)

23-23: LGTM! The new RobotState message is correctly added.

The addition of "msg/RobotState.msg" to the rosidl_generate_interfaces function is correct and consistent with the existing structure. The placement and formatting align well with other message definitions.

To ensure the RobotState.msg file exists and is properly located, you can run the following command:

✅ Verification successful

Verified: RobotState.msg file exists in the correct location.

The addition of "msg/RobotState.msg" to the rosidl_generate_interfaces function is correctly implemented and aligns with the existing structure.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the existence of RobotState.msg file
if [ -f "msg/RobotState.msg" ]; then
    echo "RobotState.msg file exists in the correct location."
else
    echo "Error: RobotState.msg file not found in the expected location."
fi

Length of output: 144

@@ -20,6 +20,7 @@ rosidl_generate_interfaces(
"msg/LEDAnimationQueue.msg"
"msg/LEDImageAnimation.msg"
"msg/MotorControllerState.msg"
"msg/RobotState.msg"
Copy link
Contributor

@delihus delihus Oct 18, 2024

Choose a reason for hiding this comment

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

I'm not so sure about this name RobotState . It will be great to precise what the state means but I cannot find any alternatives for now.

I just leave it here ;)

int8 SUCCESS = 3

int8 state_id
string state_name
Copy link
Contributor

Choose a reason for hiding this comment

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

The state_name is necessary? What is the reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had some idea, but right now, you are right, it's not necessary

@@ -0,0 +1,8 @@
int8 ERROR = -1
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add a std_msgs/Header for timestamp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea

@@ -0,0 +1,8 @@
int8 ERROR = -1
int8 E_STOP = 0
int8 STANDBY = 1
Copy link
Contributor

Choose a reason for hiding this comment

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

What about IDLE or RUNNING? Nevertheless, STANDBY is also ok ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

The animation of leds is READY_ANIM_ID so READY also sounds good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO STANDBY is the most precise.
image

Copy link
Contributor Author

@rafal-gorecki rafal-gorecki Oct 24, 2024

Choose a reason for hiding this comment

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

Additional states could be: CHARGING, AUTONOMY, TELEOP, SLEEP.

Copy link

@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 (1)
msg/RobotState.msg (1)

9-9: Add documentation for the state_id field.

Consider adding a comment to clarify that this field should contain one of the defined state constants.

+# Current robot state. Valid values are defined by the constants above.
 int8 state_id
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6eb04e3 and 0684e16.

📒 Files selected for processing (1)
  • msg/RobotState.msg (1 hunks)
🔇 Additional comments (1)
msg/RobotState.msg (1)

7-7: LGTM! Good use of standard header.

Including std_msgs/Header is a good practice for timestamping and frame information.

Comment on lines +1 to +5
int8 ERROR = -1
int8 E_STOP = 0
int8 STANDBY = 1
int8 DOCKING = 2
int8 SUCCESS = 3
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider revising the state definitions for completeness and clarity.

The current state definitions could be improved in several ways:

  1. Missing common robot operational states (e.g., CHARGING, AUTONOMY, TELEOP)
  2. SUCCESS seems more like an operation result than a robot state
  3. State values could be better organized (e.g., grouping error states, operational states)

Consider reorganizing the states like this:

-int8 ERROR = -1
-int8 E_STOP = 0
-int8 STANDBY = 1
-int8 DOCKING = 2
-int8 SUCCESS = 3
+# Error states
+int8 ERROR = -2
+int8 E_STOP = -1
+
+# Operational states
+int8 STANDBY = 0
+int8 AUTONOMY = 1
+int8 TELEOP = 2
+int8 CHARGING = 3
+int8 DOCKING = 4

Also, consider adding comments to document what each state represents.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
int8 ERROR = -1
int8 E_STOP = 0
int8 STANDBY = 1
int8 DOCKING = 2
int8 SUCCESS = 3
# Error states
int8 ERROR = -2
int8 E_STOP = -1
# Operational states
int8 STANDBY = 0
int8 AUTONOMY = 1
int8 TELEOP = 2
int8 CHARGING = 3
int8 DOCKING = 4

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