viam.components.input

Submodules

Package Contents

Classes

Control

Control identifies the input (specific Axis or Button) of a controller.

Controller

Controller is a logical "container" more than an actual device

Event

EventType

Represents the type of input event.

Attributes

ControlFunction

class viam.components.input.Control[source]

Bases: str, enum.Enum

Control identifies the input (specific Axis or Button) of a controller.

ABSOLUTE_X = 'AbsoluteX'
ABSOLUTE_Y = 'AbsoluteY'
ABSOLUTE_Z = 'AbsoluteZ'
ABSOLUTE_RX = 'AbsoluteRX'
ABSOLUTE_RY = 'AbsoluteRY'
ABSOLUTE_RZ = 'AbsoluteRZ'
ABSOLUTE_HAT0_X = 'AbsoluteHat0X'
ABSOLUTE_HAT0_Y = 'AbsoluteHat0Y'
BUTTON_SOUTH = 'ButtonSouth'
BUTTON_EAST = 'ButtonEast'
BUTTON_WEST = 'ButtonWest'
BUTTON_NORTH = 'ButtonNorth'
BUTTON_LT = 'ButtonLT'
BUTTON_RT = 'ButtonRT'
BUTTON_LT2 = 'ButtonLT2'
BUTTON_RT2 = 'ButtonRT2'
BUTTON_L_THUMB = 'ButtonLThumb'
BUTTON_R_THUMB = 'ButtonRThumb'
BUTTON_SELECT = 'ButtonSelect'
BUTTON_START = 'ButtonStart'
BUTTON_MENU = 'ButtonMenu'
BUTTON_RECORD = 'ButtonRecord'
BUTTON_E_STOP = 'ButtonEStop'
ABSOLUTE_PEDAL_ACCELERATOR = 'AbsolutePedalAccelerator'
ABSOLUTE_PEDAL_BRAKE = 'AbsolutePedalBrake'
ABSOLUTE_PEDAL_CLUTCH = 'AbsolutePedalClutch'
viam.components.input.ControlFunction
class viam.components.input.Controller(name: str)[source]

Bases: viam.components.component_base.ComponentBase

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.

SUBTYPE: Final
abstract async get_controls(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) List[Control][source]

Returns a list of Controls provided by the Controller

Returns:

List of controls provided by the Controller

Return type:

List[Control]

abstract async get_events(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) Dict[Control, Event][source]

Returns the most recent Event for each input (which should be the current state)

Returns:

The most recent event for each input

Return type:

Dict[Control, Event]

abstract register_control_callback(control: Control, triggers: List[EventType], function: Optional[ControlFunction], *, extra: Optional[Dict[str, Any]] = None, **kwargs)[source]

Register a function that will fire on given EventTypes for a given Control

Parameters:
  • control (Control) – The control to register the function for

  • triggers (List[EventType]) – The events that will trigger the function

  • function (ControlFunction) – The function to run on specific triggers

async trigger_event(event: Event, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs)[source]

Directly send an Event (such as a button press) from external code

Parameters:

event (Event) – The event to trigger

classmethod from_robot(robot: viam.robot.client.RobotClient, name: str) typing_extensions.Self

Get the component named name from the provided robot.

Parameters:
  • robot (RobotClient) – The robot

  • name (str) – The name of the component

Returns:

The component, if it exists on the robot

Return type:

Self

abstract async do_command(command: Mapping[str, ValueTypes], *, timeout: Optional[float] = None, **kwargs) Mapping[str, ValueTypes]

Send/Receive arbitrary commands to the Resource

Parameters:

command (Mapping[str, ValueTypes]) – The command to execute

Raises:

NotImplementedError – Raised if the Resource does not support arbitrary commands

Returns:

Result of the executed command

Return type:

Mapping[str, ValueTypes]

classmethod get_resource_name(name: str) viam.proto.common.ResourceName

Get the ResourceName for this Resource with the given name

Parameters:

name (str) – The name of the Resource

get_operation(kwargs: Mapping[str, Any]) viam.operations.Operation

Get the Operation associated with the currently running function.

When writing custom resources, you should get the Operation by calling this function and check to see if it’s cancelled. If the Operation is cancelled, then you can perform any necessary (terminating long running tasks, cleaning up connections, etc. ).

Parameters:

kwargs (Mapping[str, Any]) – The kwargs object containing the operation

Returns:

The operation associated with this function

Return type:

viam.operations.Operation

class viam.components.input.Event[source]
property proto
time: float

seconds since epoch

event: EventType
control: Control
value: float

0 or 1 for buttons, -1.0 to +1.0 for axes

classmethod from_proto(proto: viam.proto.component.inputcontroller.Event) typing_extensions.Self[source]
class viam.components.input.EventType[source]

Bases: str, enum.Enum

Represents the type of input event.

ALL_EVENTS = 'AllEvents'

Callbacks registered for this event will be called in ADDITION to other registered event callbacks.

CONNECT = 'Connect'

Sent at controller initialization, and on reconnects.

DISCONNECT = 'Disconnect'

If unplugged, or wireless/network times out.

BUTTON_PRESS = 'ButtonPress'

Typical key press.

BUTTON_RELEASE = 'ButtonRelease'

Key release.

BUTTON_HOLD = 'ButtonHold'

Key is held down. This wil likely be a repeated event.

BUTTON_CHANGE = 'ButtonChange'

Both up and down for convenience during registration, not typically emitted.

POSITION_CHANGE_ABSOLUTE = 'PositionChangeAbs'

Absolute position is reported via Value, a la joysticks.

POSITION_CHANGE_RELATIVE = 'PositionChangeRel'

Relative position is reported via Value, a la mice, or simulating axes with up/down buttons.