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

529 - Implement service for planning - acting communication #549

Merged

Conversation

seefelke
Copy link
Collaborator

@seefelke seefelke commented Dec 5, 2024

Description

Implemented service "RequestBehaviourChange" for Acting - Planning communication.

This allows Acting to request a specific behaviour. The node will then decide whether to grant that request.
Handling a requested behaviour is not yet implemented in the behaviour tree.

For usage check the new documentation file.

The logic in handle_request_behaviour_change whether to grant the request is temporary and will be updated once we refurbish the behaviour tree.

Fixes # 529

Type of change

  • New feature (non-breaking change which adds functionality)
  • Documentation update

Does this PR introduce a breaking change?

No

Most important changes

RequestBehaviourChangeService.py
RequestBehaviourChange.srv

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Summary by CodeRabbit

  • New Features

    • Introduced a new service for handling behavior change requests in the robotic system.
    • Added a new node to the launch configuration for the behavior change service.
    • Implemented a communication protocol for requests and responses in the new service.
  • Documentation

    • Added comprehensive documentation for the RequestBehaviourChangeService, including usage instructions and examples.
  • Bug Fixes

    • Resolved issues related to service file generation and node declarations.

@seefelke seefelke added this to the Sprint 03 2024-12-16 milestone Dec 5, 2024
@seefelke seefelke self-assigned this Dec 5, 2024
@seefelke seefelke linked an issue Dec 5, 2024 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

Walkthrough

The pull request introduces a new service for behavior change requests in the planning project. Key modifications include updating the CMakeLists.txt to add service files, the creation of a new ROS service class in RequestBehaviourChangeService.py, and the addition of a service definition file RequestBehaviourChange.srv. Additionally, a new node is declared in the launch file planning.launch to facilitate the service. Documentation for the service is also provided, detailing its usage and functionality.

Changes

File Path Change Summary
code/planning/CMakeLists.txt Added service files for RequestBehaviourChange.srv, updated catkin_package dependencies.
code/planning/launch/planning.launch Added a new node for RequestBehaviourChangeService.py with parameters for role_name and control_loop_rate.
code/planning/src/behavior_agent/RequestBehaviourChangeService.py Implemented the RequestBehaviourChangeService class with methods for handling behavior change requests.
code/planning/srv/RequestBehaviourChange.srv Introduced a new service definition with fields uint8 request and bool answer.
doc/planning/RequestBehaviourChangeService.md Documented the RequestBehaviourChangeService, including usage instructions and example code snippets.

Possibly related PRs

  • Added new message types Trajectory and Navigation Point. #515: This PR modifies the CMakeLists.txt file in the planning project, similar to the main PR, and also involves the addition of message types, which is directly related to the changes made in the main PR regarding service file generation and message handling.

Suggested reviewers

  • johannaschwarz

🐰 In the planning project, a change so bright,
A service for behavior, now takes flight.
With messages and nodes, all set to play,
Requesting new behaviors, in a seamless way.
Hop along, dear friends, let’s celebrate this feat,
For in the world of code, we make it sweet! 🐇✨


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

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

🧹 Outside diff range and nitpick comments (5)
code/planning/srv/RequestBehaviourChange.srv (1)

1-3: Add field documentation to improve service definition clarity.

The service definition would benefit from comments explaining:

  • Valid ranges/values for the request field
  • Meaning of the answer field values (true/false)
  • Any enum values that correspond to specific behaviors

Example improvement:

+# Request a behavior change
+# request: Behavior ID (enum)
+#   0: FOLLOW_LANE
+#   1: CHANGE_LANE_LEFT
+#   ... (add other valid behaviors)
 uint8 request
 ---
+# Response indicating if behavior change was granted
+# answer: true if granted, false if rejected
 bool answer
doc/planning/RequestBehaviourChangeService.md (2)

9-13: Add language specifiers to code blocks and improve example.

-```
+```python
 rospy.wait_for_service('RequestBehaviourChange')
 
 name = rospy.ServiceProxy('RequestBehaviourChange', RequestBehaviourChange)

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint (0.35.0)</summary>

9-9: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

---

`17-22`: **Enhance error handling documentation.**

The example should include proper error handling and logging.

```diff
-```
+```python
 try:
     response = name(input)
 except rospy.ServiceException as e:
-    # handle exception
+    rospy.logerr(f"Service call failed: {e}")
+    # Consider appropriate error recovery actions

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint (0.35.0)</summary>

17-17: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

</blockquote></details>
<details>
<summary>code/planning/src/behavior_agent/RequestBehaviourChangeService.py (2)</summary><blockquote>

`2-2`: **Remove or implement the commented import**

The commented import of `BehaviourEnum` suggests that behavior values might be better represented as an enum rather than strings. This would provide type safety and prevent typos in behavior names.

---

`11-19`: **Add type hints for class variables**

Consider adding type hints to improve code clarity and enable better IDE support:

```diff
 class RequestBehaviourChangeService(CompatibleNode):
     def __init__(self):
         super(RequestBehaviourChangeService, self).__init__(
             "RequestBehaviourChangeService"
         )
-        self.role_name = self.get_param("role_name", "hero")
-        self.control_loop_rate = self.get_param("control_loop_rate", 1)
-        self.__curr_behavior = None
+        self.role_name: str = self.get_param("role_name", "hero")
+        self.control_loop_rate: int = self.get_param("control_loop_rate", 1)
+        self.__curr_behavior: str | None = None
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 149403b and b807fea.

📒 Files selected for processing (5)
  • code/planning/CMakeLists.txt (1 hunks)
  • code/planning/launch/planning.launch (2 hunks)
  • code/planning/src/behavior_agent/RequestBehaviourChangeService.py (1 hunks)
  • code/planning/srv/RequestBehaviourChange.srv (1 hunks)
  • doc/planning/RequestBehaviourChangeService.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
doc/planning/RequestBehaviourChangeService.md

[uncategorized] ~24-~24: Possible missing comma found.
Context: ...` For communication with the behaviour tree this node publishes a granted request t...

(AI_HYDRA_LEO_MISSING_COMMA)

🪛 Markdownlint (0.35.0)
doc/planning/RequestBehaviourChangeService.md

9-9: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


17-17: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


1-1: null
First line in a file should be a top-level heading

(MD041, first-line-heading, first-line-h1)

🔇 Additional comments (2)
code/planning/launch/planning.launch (1)

38-41: LGTM! Node configuration follows existing patterns.

The new service node is properly configured with consistent parameters and follows the established pattern in the launch file.

Let's verify the node's package and script existence:

code/planning/CMakeLists.txt (1)

61-66: LGTM! Service file properly configured

The service file is correctly added to the build system and follows ROS CMake conventions.

Comment on lines +1 to +6
This service is hosted in the node RequestBehaviourChangeService.

Calling it requires a behaviour ID integer (based on the corresponding enum) and returns a bool depending on whether the request is granted.

To use it, import RequestBehaviourChange from planning.srv.

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance service documentation with behavior ID details.

The documentation should specify:

  • List of available behavior IDs and their meanings
  • Valid range of behavior IDs
  • Any preconditions for requesting specific behaviors
🧰 Tools
🪛 Markdownlint (0.35.0)

1-1: null
First line in a file should be a top-level heading

(MD041, first-line-heading, first-line-h1)

# handle exception
```

For communication with the behaviour tree this node publishes a granted request to a topic behaviour_request.
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add details about behaviour_request topic.

The documentation should specify:

  • Message type used for the behaviour_request topic
  • Format/fields of the published messages
  • Frequency of publications
  • Any subscribers that need to handle these messages
🧰 Tools
🪛 LanguageTool

[uncategorized] ~24-~24: Possible missing comma found.
Context: ...` For communication with the behaviour tree this node publishes a granted request t...

(AI_HYDRA_LEO_MISSING_COMMA)

Comment on lines +39 to +40
self.behaviour_pub.publish(0)
rospy.spin()
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Document initial behavior request and remove blocking spin()

The initial behavior request of 0 needs documentation explaining its purpose. Also, rospy.spin() in __init__ will block initialization and makes the run() method redundant.

+        # Initialize with default cruise behavior (0)
         self.behaviour_pub.publish(0)
-        rospy.spin()
📝 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
self.behaviour_pub.publish(0)
rospy.spin()
# Initialize with default cruise behavior (0)
self.behaviour_pub.publish(0)

Comment on lines 42 to 47
def __set_curr_behavior(self, data: String):
"""
Sets the received current behavior of the vehicle.
If the behavior is an overtake behavior, a trajectory change is triggered.
"""
self.__curr_behavior = data.data
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect docstring

The docstring mentions triggering a trajectory change, but this functionality is not implemented in the method.

     def __set_curr_behavior(self, data: String):
         """
         Sets the received current behavior of the vehicle.
-        If the behavior is an overtake behavior, a trajectory change is triggered.
         """
         self.__curr_behavior = data.data
📝 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
def __set_curr_behavior(self, data: String):
"""
Sets the received current behavior of the vehicle.
If the behavior is an overtake behavior, a trajectory change is triggered.
"""
self.__curr_behavior = data.data
def __set_curr_behavior(self, data: String):
"""
Sets the received current behavior of the vehicle.
"""
self.__curr_behavior = data.data

Comment on lines +20 to +24
self.service = rospy.Service(
"RequestBehaviourChange",
RequestBehaviourChange,
self.handle_request_behaviour_change,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Include role_name in service name for multi-robot scenarios

The service name should be namespaced with role_name to support multiple robots:

         self.service = rospy.Service(
-            "RequestBehaviourChange",
+            f"/paf/{self.role_name}/RequestBehaviourChange",
             RequestBehaviourChange,
             self.handle_request_behaviour_change,
         )

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +61 to +68
def run(self):
"""
Control loop

:return:
"""

self.spin()
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Implement control loop in run method

The run method's docstring mentions a control loop but doesn't implement one. Either implement the loop or update the docstring.

     def run(self):
         """
-        Control loop
-
-        :return:
+        Runs the node's main loop using ROS spin.
         """
         self.spin()
📝 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
def run(self):
"""
Control loop
:return:
"""
self.spin()
def run(self):
"""
Runs the node's main loop using ROS spin.
"""
self.spin()

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 (1)
doc/planning/RequestBehaviourChangeService.md (1)

11-24: Improve code examples with error handling and type hints.

The code examples should be enhanced to be more production-ready:

 ```python
+from planning.srv import RequestBehaviourChange
+from typing import Union
+
 rospy.wait_for_service('RequestBehaviourChange')
 
-name = rospy.ServiceProxy('RequestBehaviourChange', RequestBehaviourChange)
+service_proxy = rospy.ServiceProxy('RequestBehaviourChange', RequestBehaviourChange)
try:
-    response = name(input)
+    response = service_proxy(behavior_id)  # behavior_id: int
+    if response.answer:  # Assuming 'answer' is the response field
+        rospy.loginfo(f"Behavior change request {behavior_id} granted")
+    else:
+        rospy.logwarn(f"Behavior change request {behavior_id} denied")
except rospy.ServiceException as e:
-    # handle exception
+    rospy.logerr(f"Service call failed: {e}")

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between b807fea91b55fcf56ce0d85697638f047cbf9501 and 391a113dbb2e661b4f63d7cee9c07f51ea5aca1a.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `doc/planning/RequestBehaviourChangeService.md` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 LanguageTool</summary>

<details>
<summary>doc/planning/RequestBehaviourChangeService.md</summary>

[uncategorized] ~26-~26: Possible missing comma found.
Context: ...`  For communication with the behaviour tree this node publishes a granted request t...

(AI_HYDRA_LEO_MISSING_COMMA)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (2)</summary>

<details>
<summary>doc/planning/RequestBehaviourChangeService.md (2)</summary>

`1-6`: **Enhance service documentation with behavior ID details.**

The documentation should specify:
- List of available behavior IDs and their meanings
- Valid range of behavior IDs
- Any preconditions for requesting specific behaviors

---

`26-26`: _:hammer_and_wrench: Refactor suggestion_

**Add details about behaviour_request topic and fix grammar.**

The documentation needs improvement in two areas:
1. Missing comma after "behaviour tree"
2. Insufficient details about the behaviour_request topic


```diff
-For communication with the behaviour tree this node publishes a granted request to a topic behaviour_request.
+For communication with the behaviour tree, this node publishes a granted request to the topic `behaviour_request`. The topic:
+- Message Type: <specify_message_type>
+- Published Fields: <list_fields_and_types>
+- Publication Frequency: <specify_frequency>
+- Subscribers: <list_subscribers>
🧰 Tools
🪛 LanguageTool

[uncategorized] ~26-~26: Possible missing comma found.
Context: ...` For communication with the behaviour tree this node publishes a granted request t...

(AI_HYDRA_LEO_MISSING_COMMA)

Comment on lines +1 to +26
# Request Behaviour Change Service

This service is hosted in the node RequestBehaviourChangeService.

Calling it requires a behaviour ID integer (based on the corresponding enum) and returns a bool depending on whether the request is granted.

To use it, import RequestBehaviourChange from planning.srv.

To call it, create a callable instance with:

```python
rospy.wait_for_service('RequestBehaviourChange')

name = rospy.ServiceProxy('RequestBehaviourChange', RequestBehaviourChange)
```

Then, you can just use this instance in a try setup:

```python
try:
response = name(input)
except rospy.ServiceException as e:
# handle exception
```

For communication with the behaviour tree this node publishes a granted request to a topic behaviour_request.
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add missing sections to complete the documentation.

The documentation should include additional sections:

  1. Prerequisites/Dependencies
  2. Service Definition (fields and types)
  3. Return Values and Error Codes
  4. Configuration Parameters (if any)
  5. Examples of Common Use Cases
  6. Troubleshooting Guide

Would you like me to help generate content for these sections?

🧰 Tools
🪛 LanguageTool

[uncategorized] ~26-~26: Possible missing comma found.
Context: ...` For communication with the behaviour tree this node publishes a granted request t...

(AI_HYDRA_LEO_MISSING_COMMA)

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)
code/planning/src/behavior_agent/RequestBehaviourChangeService.py (2)

2-2: Remove the commented-out import statement

The import statement BehaviourEnum is commented out. If it's not required, consider removing it to keep the code clean.


39-39: Document the purpose of the initial behavior request

Adding documentation for the initial behavior request self.behaviour_pub.publish(0) will help others understand its purpose in the initialization process.

Apply this diff to add a comment:

 self.behaviour_pub.publish(0)
+# Publishing initial behavior request of 0 to set default state
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 391a113 and 3336a2f.

📒 Files selected for processing (1)
  • code/planning/src/behavior_agent/RequestBehaviourChangeService.py (1 hunks)
🔇 Additional comments (4)
code/planning/src/behavior_agent/RequestBehaviourChangeService.py (4)

20-24: Include role_name in the service name for multi-robot scenarios

To support multiple robots, the service name should be namespaced with self.role_name.

Apply this diff to update the service name:

 self.service = rospy.Service(
-    "RequestBehaviourChange",
+    f"/paf/{self.role_name}/RequestBehaviourChange",
     RequestBehaviourChange,
     self.handle_request_behaviour_change,
 )

39-40: Avoid blocking initialization with rospy.spin() in __init__

Calling rospy.spin() inside the __init__ method blocks the initialization and renders the run() method redundant. Consider moving rospy.spin() to the run() method.

Apply this diff to adjust the code:

 def __init__(self):
     ...
     self.behaviour_pub.publish(0)
-    rospy.spin()
 def run(self):
     """
     Control loop
     """
+    rospy.spin()

48-58: Improve behavior handling by using constants and adding validation

Enhance the robustness of behavior handling by:

  1. Using constants or enums for behavior strings to avoid typos and improve maintainability.
  2. Validating request values to ensure they are within the expected range.
  3. Adding logging to monitor behavior changes and aid in debugging.

Apply this diff to implement the improvements:

+from enum import Enum
+
+# Define an enum for behaviors
+class Behavior(Enum):
+    US_UNSTUCK = "us_unstuck"
+    US_STOP = "us_stop"
+    US_OVERTAKE = "us_overtake"
+    CRUISE = "Cruise"

 def handle_request_behaviour_change(self, req):
+    if self.__curr_behavior is None:
+        rospy.logwarn("Current behavior is not set yet.")
+        return RequestBehaviourChangeResponse(False)
+
+    # Validate request value
+    if not isinstance(req.request, int) or req.request < 0:
+        rospy.logwarn(f"Invalid behavior request value: {req.request}")
+        return RequestBehaviourChangeResponse(False)
+
     if (
-        self.__curr_behavior == "us_unstuck"
-        or self.__curr_behavior == "us_stop"
-        or self.__curr_behavior == "us_overtake"
-        or self.__curr_behavior == "Cruise"
+        self.__curr_behavior == Behavior.US_UNSTUCK.value
+        or self.__curr_behavior == Behavior.US_STOP.value
+        or self.__curr_behavior == Behavior.US_OVERTAKE.value
+        or self.__curr_behavior == Behavior.CRUISE.value
     ):
+        rospy.loginfo(f"Changing behavior to: {req.request}")
         self.behaviour_pub.publish(req.request)
         return RequestBehaviourChangeResponse(True)
     else:
+        rospy.loginfo(f"Behavior change rejected. Current behavior: {self.__curr_behavior}")
         return RequestBehaviourChangeResponse(False)

60-67: Update the run() method or its docstring to reflect functionality

The run() method's docstring mentions a control loop, but the method currently only calls self.spin(). Either implement the control loop logic or update the docstring to accurately describe the method's behavior.

Apply this diff to adjust the docstring:

 def run(self):
     """
-    Control loop
+    Runs the node's event loop
     """
     self.spin()

Comment on lines +48 to +58
def handle_request_behaviour_change(self, req):
if (
self.__curr_behavior == "us_unstuck"
or self.__curr_behavior == "us_stop"
or self.__curr_behavior == "us_overtake"
or self.__curr_behavior == "Cruise"
):
self.behaviour_pub.publish(req.request)
return RequestBehaviourChangeResponse(True)
else:
return RequestBehaviourChangeResponse(False)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle the case when __curr_behavior is None

If self.__curr_behavior is None, the comparisons with behavior strings will fail. Add a check to handle this scenario to prevent potential errors.

Apply this diff to incorporate the check:

 def handle_request_behaviour_change(self, req):
+    if self.__curr_behavior is None:
+        rospy.logwarn("Current behavior is not set yet.")
+        return RequestBehaviourChangeResponse(False)
     if (
         self.__curr_behavior == "us_unstuck"
         or self.__curr_behavior == "us_stop"
         or self.__curr_behavior == "us_overtake"
         or self.__curr_behavior == "Cruise"
     ):
         self.behaviour_pub.publish(req.request)
         return RequestBehaviourChangeResponse(True)
     else:
         return RequestBehaviourChangeResponse(False)
📝 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
def handle_request_behaviour_change(self, req):
if (
self.__curr_behavior == "us_unstuck"
or self.__curr_behavior == "us_stop"
or self.__curr_behavior == "us_overtake"
or self.__curr_behavior == "Cruise"
):
self.behaviour_pub.publish(req.request)
return RequestBehaviourChangeResponse(True)
else:
return RequestBehaviourChangeResponse(False)
def handle_request_behaviour_change(self, req):
if self.__curr_behavior is None:
rospy.logwarn("Current behavior is not set yet.")
return RequestBehaviourChangeResponse(False)
if (
self.__curr_behavior == "us_unstuck"
or self.__curr_behavior == "us_stop"
or self.__curr_behavior == "us_overtake"
or self.__curr_behavior == "Cruise"
):
self.behaviour_pub.publish(req.request)
return RequestBehaviourChangeResponse(True)
else:
return RequestBehaviourChangeResponse(False)

Copy link
Collaborator

@THDThieleT THDThieleT left a comment

Choose a reason for hiding this comment

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

Service starst correctly after building the catkin_ws again.
Service can be called and feedback works.
Does not change current architecture, therefore nothing changes on the current car behaviour.

@seefelke seefelke merged commit 727f1d5 into main Dec 12, 2024
4 checks passed
@seefelke seefelke deleted the 529-feature-implement-service-for-planning-acting-communication branch December 12, 2024 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[Feature]: Implement service for planning - acting communication
2 participants