surrortg.inputs

Classes

surrortg.inputs.delayed_switch

class DelayedSwitch

Bases: surrortg.inputs.input.Input

A class for using a switch with a delay

abstract async set_state(state, delay, seat)

Set switch to ‘up’ or ‘down’ state after a user implemented delay

Parameters
  • state (str) – ‘up’ or ‘down’

  • delay (float) – User implemented delay amount in seconds

  • seat (int) – Robot seat

async reset(seat)

DelayedSwitch reset functionality

Defaults to setting the switch state to up

Parameters

seat (int) – Robot seat

get_name()

Returns the name of the input

Returns

name of the input

Return type

str

surrortg.inputs.input

class Input

Bases: abc.ABC

Base class for all user inputs

abstract async reset(seat)

Reset functionality for the Input

Parameters

seat (int) – Robot seat

async shutdown(seat)

Input shutdown method. Defaults to calling reset.

Parameters

seat (int) – Robot seat

abstract get_name()

Returns the name of the input

Returns

name of the input

Return type

str

surrortg.inputs.joystick

class Directions(value)

Bases: enum.Enum

Emun for Joystick.get_direction_8() and get_direction_4() results

MIDDLE = 1
TOP = 2
BOTTOM = 3
LEFT = 4
RIGHT = 5
TOP_LEFT = 6
TOP_RIGHT = 7
BOTTOM_LEFT = 8
BOTTOM_RIGHT = 9
class Joystick

Bases: surrortg.inputs.input.Input

Joystick input class

Implement custom logic based on directions and amounts or x/y coordinates.

set_min_amount(min_amount)

Set joystick min_amount parameter

Parameters

min_amount (float) – if the input amount is less than this middle () is called

async handle_coordinates(x, y, seat)

Coordinate based Joystick control

Middle position means x=0, y=0. Right means x is positive, left means x is negative. Top means y is positive, bottom means y is negative.

Parameters
  • x (float) – x-coordinate, between -1.0 and 1.0

  • y (float) – y-coordinate, between -1.0 and 1.0

  • seat (int) – Robot seat

get_direction_8(x, y)

Get the current direction from 8 main directions + middle

Result Directions.MIDDLE means that Joystick distance from the center point is less than 0.1 or some other threshold set with set_min_amount.

Other possible results: Directions.TOP, BOTTOM, LEFT, RIGHT, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT.

Parameters
  • x (float) – x-coordinate, between -1.0 and 1.0

  • y (float) – y-coordinate, between -1.0 and 1.0

Returns

Current direction

Return type

Directions

get_direction_4(x, y)

Get the current direction from 4 main directions + middle

Result Directions.MIDDLE means that Joystick distance from the center point is less than 0.1 or some other threshold set with set_min_amount.

Other possible results: Directions.TOP, BOTTOM, LEFT, RIGHT.

Parameters
  • x (float) – x-coordinate, between -1.0 and 1.0

  • y (float) – y-coordinate, between -1.0 and 1.0

Returns

Current direction

Return type

Directions

get_direction_and_amount(x, y)

Get exact direction and amount from the x/y coordinates

This method is good when neither get_direction_8 or get_direction_4 are not accurate enough.

Parameters
  • x (float) – x-coordinate, between -1.0 and 1.0

  • y (float) – y-coordinate, between -1.0 and 1.0

Returns

direction and amount in radians, from -pi to +pi

Return type

(float, float)

async reset(seat)

Joystick reset functionality

Defaults to x=0, y=0

Parameters

seat (int) – Robot seat

get_name()

Returns the name of the input

Returns

name of the input

Return type

str

get_default_keybinds()

Return a dict or list of dicts with keybinds.

Joysticks are bound to WASD and arrow keys by default.

To override the defaults, override this method in your joystick subclass and return different keybinds.

class MouseJoystick

Bases: surrortg.inputs.joystick.Joystick

async handle_coordinates(x, y, seat, dx=None, dy=None)

Coordinate based Joystick control

Middle position means x=0, y=0. Right means x is positive, left means x is negative. Top means y is positive, bottom means y is negative. If mouse is used, dx and dy contains mouse position change relative to previous position.

Parameters
  • x (float) – x-coordinate, between -1.0 and 1.0

  • y (float) – y-coordinate, between -1.0 and 1.0

  • seat (int) – Robot seat

  • dx (None or int) – Mouse x-axis movement relative to previous position

  • dy (None or int) – Mouse y-axis movement relative to previous position

surrortg.inputs.keycodes

class KeyCode(value)

Bases: enum.Enum

These are the keycodes which work with Surrogate.tv. To check which key matches which keycode, see https://keycode.info/ on Chrome.

KEY_A = 'KeyA'
KEY_B = 'KeyB'
KEY_C = 'KeyC'
KEY_D = 'KeyD'
KEY_E = 'KeyE'
KEY_F = 'KeyF'
KEY_G = 'KeyG'
KEY_H = 'KeyH'
KEY_I = 'KeyI'
KEY_J = 'KeyJ'
KEY_K = 'KeyK'
KEY_L = 'KeyL'
KEY_M = 'KeyM'
KEY_N = 'KeyN'
KEY_O = 'KeyO'
KEY_P = 'KeyP'
KEY_Q = 'KeyQ'
KEY_R = 'KeyR'
KEY_S = 'KeyS'
KEY_T = 'KeyT'
KEY_U = 'KeyU'
KEY_V = 'KeyV'
KEY_W = 'KeyW'
KEY_X = 'KeyX'
KEY_Y = 'KeyY'
KEY_Z = 'KeyZ'
KEY_0 = 'Digit0'
KEY_1 = 'Digit1'
KEY_2 = 'Digit2'
KEY_3 = 'Digit3'
KEY_4 = 'Digit4'
KEY_5 = 'Digit5'
KEY_6 = 'Digit6'
KEY_7 = 'Digit7'
KEY_8 = 'Digit8'
KEY_9 = 'Digit9'
KEY_SHIFT_LEFT = 'ShiftLeft'
KEY_SHIFT_RIGHT = 'ShiftRight'
KEY_CTRL_LEFT = 'ControlLeft'
KEY_CTRL_RIGHT = 'ControlRight'
KEY_ALT_LEFT = 'AltLeft'
KEY_ALT_RIGHT = 'AltRight'
KEY_BACKQUOTE = 'Backquote'
KEY_MINUS = 'Minus'
KEY_EQUAL = 'Equal'
KEY_COMMA = 'Comma'
KEY_PERIOD = 'Period'
KEY_SLASH = 'Slash'
KEY_SEMICOLON = 'Semicolon'
KEY_QUOTE = 'Quote'
KEY_BACKSLASH = 'Backslash'
KEY_BRACKET_LEFT = 'BracketLeft'
KEY_BRACKET_RIGHT = 'BracketRight'
KEY_ARROW_UP = 'ArrowUp'
KEY_ARROW_DOWN = 'ArrowDown'
KEY_ARROW_LEFT = 'ArrowLeft'
KEY_ARROW_RIGHT = 'ArrowRight'

surrortg.inputs.linear_actuator

class LinearActuator

Bases: surrortg.inputs.input.Input

A class for moving linear actuators

abstract async drive_actuator(val, seat)

Drive actuator to parameter val

Parameters
  • val (float) – actuator position value, must be between -1.0 and 1.0

  • seat (int) – Robot seat

async reset(seat)

LinearActuator reset functionality

Defaults to driving the actuator to value 0

Parameters

seat (int) – Robot seat

get_name()

Returns the name of the input

Returns

name of the input

Return type

str

get_default_keybinds()

Return a dict or list of dicts with keybinds.

Linear actuators are bound to W and S keys by default.

To override the defaults, override this method in your linear actuator subclass and return different keybinds.

surrortg.inputs.switch

class Switch

Bases: surrortg.inputs.input.Input

Switch input class

Implement custom on() and off() logic

abstract async on(seat)

Switch turned on functionality

Parameters

seat (int) – Robot seat

abstract async off(seat)

Switch turned off functionality

Parameters

seat (int) – Robot seat

async reset(seat)

Switch reset functionality

Defaults to calling off()

Parameters

seat (int) – Robot seat

get_name()

Returns the name of the input

Returns

name of the input

Return type

str

get_default_keybinds()

Returns a single keybind or a list of keybinds.

Switches are bound to the space key by default.

To override the defaults, override this method in your switch subclass and return different keybinds.