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 generic and gripper FromDependencies methods #4747

Merged
merged 3 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func Named(name string) resource.Name {
return resource.NewName(API, name)
}

// FromDependencies is a helper for getting the named generic from a collection of
// dependencies.
func FromDependencies(deps resource.Dependencies, name string) (resource.Resource, error) {
return resource.FromDependencies[resource.Resource](deps, Named(name))
}

// FromRobot is a helper for getting the named Generic from the given Robot.
func FromRobot(r robot.Robot, name string) (resource.Resource, error) {
return robot.ResourceFromRobot[resource.Resource](r, Named(name))
Expand Down
6 changes: 6 additions & 0 deletions components/gripper/gripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func FromRobot(r robot.Robot, name string) (Gripper, error) {
return robot.ResourceFromRobot[Gripper](r, Named(name))
}

// FromDependencies is a helper for getting the named sensor from a collection of
// dependencies.
randhid marked this conversation as resolved.
Show resolved Hide resolved
func FromDependencies(deps resource.Dependencies, name string) (Gripper, error) {
return resource.FromDependencies[Gripper](deps, Named(name))
}

// NamesFromRobot is a helper for getting all gripper names from the given Robot.
func NamesFromRobot(r robot.Robot) []string {
Copy link
Member

Choose a reason for hiding this comment

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

ngl didn't know this was a method on some of the apis either

Copy link
Member Author

Choose a reason for hiding this comment

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

makes sense - none of the services have this so it's a components-only helper ™️

Copy link
Member Author

Choose a reason for hiding this comment

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

plus you joined components after we added all this noise.

return robot.NamesByAPI(r, API)
Expand Down
Loading