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

[SW-957] make decorator for trigger services #578

Merged

Conversation

tcappellari-bdai
Copy link
Collaborator

Change Overview

Made a descriptor class for trigger services to reduce boilerplate + copy/paste code in trigger service handlers

Testing Done

Tested all trigger services on robot. Found a bug with estop handling within spot_wrapper (will make a new ticket to track this but out of scope for this PR)

Please create a checklist of tests you plan to do and check off the ones that have been completed successfully. Ensure that ROS 2 tests use domain_coordinator to prevent port conflicts. Further guidance for testing can be found on the ros utilities wiki.

@coveralls
Copy link

coveralls commented Feb 13, 2025

Pull Request Test Coverage Report for Build 13336683414

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 576 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+1.2%) to 52.501%

Files with Coverage Reduction New Missed Lines %
spot_ros2/spot_ros2/spot_driver/spot_driver/ros_helpers.py 54 25.2%
spot_ros2/spot_ros2/spot_driver/spot_driver/spot_ros2.py 522 45.99%
Totals Coverage Status
Change from base Build 13314913643: 1.2%
Covered Lines: 1952
Relevant Lines: 3718

💛 - Coveralls

Copy link
Contributor

@bjin-bdai bjin-bdai left a comment

Choose a reason for hiding this comment

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

Variable naming for obj: Any might be a little too vague

kwargs: Optional[dict | None] = None

def __init__(
self, service_func: Callable, service_name: str, *args: Optional[Any], **kwargs: Optional[Any | None]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self, service_func: Callable, service_name: str, *args: Optional[Any], **kwargs: Optional[Any | None]
self, service_func: Callable, service_name: str, *args: Optional[Any], **kwargs: Optional[Any]

nit: does Any cover the None type?

self.args = args
self.kwargs = kwargs or {}

def create_service(self, obj: Any, group: CallbackGroup) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

obj: Any is pretty vague. Based on the naming as well it seems like this obj type is limited to a set of Spot objects?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ya its supposed to be SpotRos object but that would cause a circular dependency. Was unsure best way around that and keep mypy happy

obj.create_service(Trigger, self.service_name, self.callback, callback_group=group)

def callback(self, request: Trigger.Request, response: Trigger.Response) -> Trigger.Response:
if self.spot_ros.mock:
Copy link
Contributor

Choose a reason for hiding this comment

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

If this callback explcitly depends on SpotRos object, then does it make sense that TriggerServiceWrapper is its own class at all? Could the code duplication also be solved by moving these function to member functions of SpotRos? (and the member variables to this class can be stored as a dictionary, or wrapped in a function wrapper tool?)

The circular dependency comment suggests that there is a different way to implement this... and I'm thinking if this class specifically only works on SpotRos object, then they are functions/properties that belong to SpotRos class

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ya it makes sense to put it in spotROS. I just wanted to reduce the amount of code in it since its already m a s s i v e

@tcappellari-bdai tcappellari-bdai force-pushed the SW-957-make-decorator-for-trigger-services-in-spot-ros-2 branch from fb2e7cb to 2c2b71c Compare February 14, 2025 20:10
Copy link
Collaborator Author

tcappellari-bdai commented Feb 14, 2025

Merge activity

  • Feb 14, 3:10 PM EST: Graphite rebased this pull request as part of a merge.
  • Feb 14, 3:24 PM EST: A user merged this pull request with Graphite.

@tcappellari-bdai tcappellari-bdai merged commit 80cd3d7 into main Feb 14, 2025
4 of 5 checks passed
@tcappellari-bdai tcappellari-bdai deleted the SW-957-make-decorator-for-trigger-services-in-spot-ros-2 branch February 14, 2025 20:24
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.

6 participants