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

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.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

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