Input controller API | Component APIs

Input controller API

The input controller API allows you to give commands to your input controller components for configuring callbacks for events, allowing you to configure input devices to control your machines.

The input controller component supports the following methods:

Method Name Description
GetControls Get a list of the Controls that your controller provides.
GetEvents This method returns the current state of the controller as a map of Event Objects, representing the most recent event that has occurred on each available Control.
TriggerEvent Directly send an Event Object from external code.
GetGeometries Get all the geometries associated with the input controller in its current configuration, in the frame of the input controller.
RegisterControlCallback Defines a callback function to execute whenever one of the EventTypes selected occurs on the given Control.
Reconfigure Reconfigure this resource.
DoCommand Execute model-specific commands that are not otherwise defined by the component API.
GetResourceName Get the ResourceName for this input controller.
Close Safely shut down the resource and prevent further use.

API

GetControls

Get a list of the Controls that your controller provides.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

Parameters:

Returns:

Example:


For more information, see the Go SDK Docs.

GetEvents

This method returns the current state of the controller as a map of Event Objects, representing the most recent event that has occurred on each available Control.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

Parameters:

Returns:

Example:


For more information, see the Go SDK Docs.

Parameters:

Returns:

Example:


For more information, see the TypeScript SDK Docs.

TriggerEvent

Directly send an Event Object from external code.

Support Notice

This method is currently only supported for input controllers of model webgamepad.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

Parameters:

Returns:

For more information, see the Go SDK Docs.

Parameters:

Returns:

Example:


For more information, see the TypeScript SDK Docs.

GetGeometries

Get all the geometries associated with the input controller in its current configuration, in the frame of the input controller. The motion and navigation services use the relative position of inherent geometries to configured geometries representing obstacles for collision detection and obstacle avoidance while motion planning.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

RegisterControlCallback

Defines a callback function to execute whenever one of the EventTypes selected occurs on the given Control.

You can only register one callback function per Event for each Control. A second call to register a callback function for a EventType on a Control replaces any function that was already registered.

You can pass a nil function here to “deregister” a callback.

Tip

Registering a callback for the ButtonChange EventType is merely a convenience for filtering. Doing so registers the same callback to both ButtonPress and ButtonRelease, but ButtonChange is not reported in an actual Event Object.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

Parameters:

Returns:

Example:


For more information, see the Go SDK Docs.

Reconfigure

Reconfigure this resource. Reconfigure must reconfigure the resource atomically and in place.

Parameters:

Returns:

For more information, see the Go SDK Docs.

DoCommand

Execute model-specific commands that are not otherwise defined by the component API. Most models do not implement DoCommand. Any available model-specific commands should be covered in the model’s documentation. If you are implementing your own input controller and want to add features that have no corresponding built-in API method, you can implement them with DoCommand.

Parameters:

Returns:

Raises:

Example:


For more information, see the Python SDK Docs.

Parameters:

Returns:

Example:


For more information, see the Go SDK Docs.

GetResourceName

Get the ResourceName for this input controller.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

Parameters:

Returns:

Example:


For more information, see the Go SDK Docs.

Parameters:

Returns:

Example:


For more information, see the TypeScript SDK Docs.

Close

Safely shut down the resource and prevent further use.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

Parameters:

Returns:

Example:


For more information, see the Go SDK Docs.

API types

The input API defines the following types:

Event object

Each Event object represents a singular event from the input device, and has four fields:

  1. Time: time.Time the event occurred.
  2. Event: EventType indicating the type of event (for example, a specific button press or axis movement).
  3. Control: Control indicating which Axis, Button, or Pedal on the controller has been changed.
  4. Value: float64 indicating the position of an Axis or the state of a Button on the specified control.

EventType field

A string-like type indicating the specific type of input event, such as a button press or axis movement.

Registered EventTypes definitions:


Copy

See the Python SDK Docs for the most current version of supported EventTypes.


Copy

See the Viam RDK for the most current version of supported EventTypes.

Control field

A string representing the physical input location, like a specific axis or button, of your Controller that the Event Object is coming from.

Registered Control types are defined as follows:


Copy

See the Python SDK Docs for the most current version of supported Control types.


Copy

See GitHub for the most current version of supported Control types.

Axis controls

Support Notice

Currently, only Absolute axes are supported.

Relative axes, reporting a relative change in distance, used by devices like mice and trackpads, will be supported in the future.

Analog devices like joysticks and thumbsticks which return to center/neutral on their own use Absolute axis control types.

These controls report a PositionChangeAbs EventType.

Value: A float64 between -1.0 and +1.0.

AbsoluteXY axes

If your input controller has an analog stick, this is what the stick’s controls report as.

Alternatively, if your input controller has two analog sticks, this is what the left joystick’s controls report as.

Name -1.0 0.0 1.0
AbsoluteX Stick Left Neutral Stick Right
AbsoluteY Stick Forward Neutral Stick Backwards

AbsoluteR-XY axes

If your input controller has two analog sticks, this is what the right joystick’s controls report as.

Name -1.0 0.0 1.0
AbsoluteRX Stick Left Neutral Stick Right
AbsoluteRY Stick Forward Neutral Stick Backwards

Hat/D-Pad axes

If your input controller has a directional pad with analog buttons on the pad, this is what those controls report as.

Name -1.0 0.0 1.0
AbsoluteHat0X Left DPAD Button Press Neutral Right DPAD Button Press
AbsoluteHat0Y Up DPAD Button Press Neutral Down DPAD Button Press

Z axes (analog trigger sticks)

Info

Devices like analog triggers and gas or brake pedals use Absolute axes, but they only report position change in the positive direction. The neutral point of the axes is still 0.0.

Name -1.0 0.0 1.0
AbsoluteZ Neutral Stick Pulled
AbsoluteRZ Neutral Stick Pulled

Z axes are usually not present on most controller joysticks.

If present, they are typically analog trigger sticks, and unidirectional, scaling only from 0 to 1.0 as they are pulled, as shown above.

AbsoluteZ is reported if there is one trigger stick, and AbsoluteZ (left) and AbsoluteRZ (right) is reported if there are two trigger sticks.

Z axes can be present on flight-style joysticks, reporting yaw, or left/right rotation, as shown below. This is not common.

Name -1.0 0.0 1.0
AbsoluteZ Stick Left Yaw Neutral Stick Right Yaw
AbsoluteRZ Stick Left Yaw Neutral Stick Right Yaw

Button controls

Button Controls report either ButtonPress or ButtonRelease as their EventType.

Value:

Action buttons (ABXY)

If your input controller is a gamepad with digital action buttons, this is what the controls for these buttons report as.

Tip

As different systems label the actual buttons differently, we use compass directions for consistency.

Diamond 4-Action Button Pad Rectangle 4-Action Button Pad
Name
--- ---
ButtonNorth Top
ButtonSouth Bottom
ButtonEast Right
ButtonWest Left
--- ---
ButtonNorth Top-left
ButtonSouth Bottom-right
ButtonEast Top-right
ButtonWest Bottom-left
--- ---
Horizontal 3-Action Button Pad Vertical 3-Action Button Pad
--- ---
Name
--- ---
ButtonWest Left
ButtonSouth Center
ButtonEast Right
--- ---
ButtonWest Top
ButtonSouth Center
ButtonEast Bottom

Trigger buttons (bumpers)

If your input controller is a gamepad with digital trigger buttons, this is what the controls for those buttons report as.

2-Trigger Button Pad 4-Trigger Button Pad
Name
--- ---
ButtonLT Left
ButtonRT Right
--- ---
ButtonLT Top-left
ButtonRT Top-right
ButtonLT2 Bottom-left
ButtonRT2 Bottom-right

Digital buttons for sticks

If your input controller is a gamepad with “clickable” thumbsticks, this is what thumbstick presses report as.

Name Description
ButtonLThumb Left or upper button for stick
ButtonRThumb Right or lower button for stick

Miscellaneous buttons

Many devices have additional buttons. If your input controller is a gamepad with these common buttons, this is what the controls for those buttons report as.

Name Description
ButtonSelect Select or -
ButtonStart Start or +
ButtonMenu Usually the central “Home” or Xbox/PS “Logo” button
ButtonRecord Recording
ButtonEStop Emergency Stop (on some industrial controllers)

Usage examples

Control a wheeled base with a Logitech G920 steering wheel controller

The following Python code is an example of controlling a wheeled base with a Logitech G920 steering wheel controller, configured as a gamepad input controller.


Drive a robot with four wheels and a skid steer platform

The following Go code is part of an example of using an input controller to drive a robot with four wheels & a skid steer platform. The motorCtl callback function controls 5 motors: left front & back FL BL, right front & back FL BL, and a winder motor that raises and lowers a front-end like a bulldozer. The event.Control logic is registered as a callback function to determine the case for setting the power of each motor from which button is pressed on the input controller.