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

DOCS-2231-Add-Gripper-Input-Controller-snippets #3919

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
10 changes: 10 additions & 0 deletions components/gripper/gripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ func Named(name string) resource.Name {
}

// A Gripper represents a physical robotic gripper.
//
// Open example:
//
// // Open the gripper.
// err := myGripper.Open(context.Background(), nil)
//
// Grab example:
//
// // Grab with the gripper.
// grabbed, err := myGripper.Grab(context.Background(), nil)
type Gripper interface {
resource.Resource
resource.Shaped
Expand Down
55 changes: 55 additions & 0 deletions components/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,61 @@ func Named(name string) resource.Name {

// Controller is a logical "container" more than an actual device
// Could be a single gamepad, or a collection of digitalInterrupts and analogReaders, a keyboard, etc.
//
// Controls example:
//
// // Get the list of Controls provided by the controller.
// controls, err := myController.Controls(context.Background(), nil)
//
// Events example:
//
// // Get the most recent Event for each Control.
// recent_events, err := myController.Events(context.Background(), nil)
//
// RegisterControlCallback example:
//
// // Define a function that handles the controller.
// func handleController(ctx context.Context, logger logging.Logger, controller input.Controller) error {
// // Define a function to handle pressing the Start Menu button, "ButtonStart", on your controller and logging the start time
// printStartTime := func(ctx context.Context, event input.Event) {
// logger.Info("Start Menu Button was pressed at this time: %v", event.Time)
// }
//
// // Define the EventType "ButtonPress" to serve as the trigger for printStartTime.
// triggers := []input.EventType{input.ButtonPress}
//
// // Get the controller's Controls.
// controls, err := controller.Controls(ctx, nil)
//
// // If the "ButtonStart" Control is found, register the function printStartTime to fire when "ButtonStart" has the event "ButtonPress" occur.
// if !slices.Contains(controls, input.ButtonStart) {
// return errors.New("button `ButtonStart` not found; controller may be disconnected")
// }
// return controller.RegisterControlCallback(context.Background(), Control: input.ButtonStart, triggers, printStartTime, nil)
// }
//
// func main() {
// utils.ContextualMain(mainWithArgs, logging.NewLogger("client"))
// }
//
// func mainWithArgs(ctx context.Context, args []string, logger logging.Logger) error {
// // < Insert code sample from your machine's CONNECT tab >
//
// // Get the controller from the machine.
// myController, err := input.FromRobot(machine, "my_controller")
// if err != nil {
// return err
// }
//
// // Run the handleController function.
// if err = handleController(myController) {
// return err
// }
// // < Insert any other code for main function >
//
// <-ctx.Done()
// return nil
// }
type Controller interface {
resource.Resource

Expand Down
Loading