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

APP-7497: Add Button and Switch APIs #619

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ethanlookpotts
Copy link
Member

@ethanlookpotts ethanlookpotts commented Jan 23, 2025

This adds the APIs for two new components: Button and Switch. Request from Eliot.

Next:

  1. Add fake components to RDK for each
  2. Add control cards to App for each

Review requests

  • Do you like the API? Anything about it you would change?

@github-actions github-actions bot added the safe to test committer is a member of this org label Jan 23, 2025

// DoCommand sends/receives arbitrary commands
rpc DoCommand(common.v1.DoCommandRequest) returns (common.v1.DoCommandResponse) {
option (google.api.http) = {post: "/viam/api/v1/component/gripper/{name}/do_command"};
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
option (google.api.http) = {post: "/viam/api/v1/component/gripper/{name}/do_command"};
option (google.api.http) = {post: "/viam/api/v1/component/switch/{name}/do_command"};

Copy link
Member Author

Choose a reason for hiding this comment

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

Great catches, ty

Copy link
Member Author

Choose a reason for hiding this comment

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


// DoCommand sends/receives arbitrary commands
rpc DoCommand(common.v1.DoCommandRequest) returns (common.v1.DoCommandResponse) {
option (google.api.http) = {post: "/viam/api/v1/component/gripper/{name}/do_command"};
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
option (google.api.http) = {post: "/viam/api/v1/component/gripper/{name}/do_command"};
option (google.api.http) = {post: "/viam/api/v1/component/button/{name}/do_command"};

Copy link
Member Author

Choose a reason for hiding this comment

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

copy pasta

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@stevebriskin stevebriskin left a comment

Choose a reason for hiding this comment

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

one request. lgtm otherwise

proto/viam/component/switch/v1/switch.proto Show resolved Hide resolved
service SwitchService {
// Turns on the switch
rpc On(OnRequest) returns (OnResponse) {
option (common.v1.safety_heartbeat_monitored) = true;
Copy link
Member

Choose a reason for hiding this comment

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

why is this heartbeat monitored? I think we're pushing to only do this for actuators.

Copy link
Member

Choose a reason for hiding this comment

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

why is this heartbeat monitored? I think we're pushing to only do this for actuators.

I originally commented on this as well and deleted the comment. Maybe a button press can trigger some long-running task that needs to be stopped if the session drops. Not sure how that'll actually work without a Stop function...figured this isn't worth a discussion now as there's no harm in this.

Copy link
Member

Choose a reason for hiding this comment

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

It seems like this is analogous to board's SetGPIO API, which isn't session monitored, and, actually, DoCommand itself. will it break anything if we want to remove it in the future? If so, let's just remove it now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm happy to remove this for now - I had the same thought when copy-pasting gripper. It's easy enough to add in the future and there's not yet clear value.

Copy link
Member Author

Choose a reason for hiding this comment

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

string name = 1;
uint32 position = 2;
Copy link
Member

Choose a reason for hiding this comment

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

hmm, do we want to allow negatives too?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see a reason to - position should just be a non-negative index representing the possible positions. The only case I can think of is if we wanted a negative position to be an error state, but I don't see that being useful. In error cases, the handlers should return errors.

Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking of the most common toggle switch to me - the power drill direction - where that switch makes sense to me as a -1, 0, 1 switch. But meh 🤷🏼‍♀️

Comment on lines +17 to +24
rpc SetPosition(SetPositionRequest) returns (SetPositionResponse) {
option (google.api.http) = {put: "/viam/api/v1/component/switch/{name}/set_position"};
}

// Get the position of the switch
rpc GetPosition(GetPositionRequest) returns (GetPositionResponse) {
option (google.api.http) = {put: "/viam/api/v1/component/switch/{name}/get_position"};
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't love these API names, since it's more ambiguous than ToggleTo and ToggleActive but I don't care about this API enough to argue this, and I hope fleet enjoys owning their two new component APIs 😈

Copy link
Member Author

Choose a reason for hiding this comment

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

Like we chatted about, I'm happy to change the names but don't feel strongly. Will leave as-is.

Copy link
Member

Choose a reason for hiding this comment

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

@stevebriskin we'll defer to you here.

Copy link
Member

Choose a reason for hiding this comment

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

IMO, all names are good enough and not worth debating in the interest of speed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test committer is a member of this org
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants