surrortg.devices.udp

Classes

surrortg.devices.udp.udp_actuator

class UdpActuator(cmd, multiplier=1.0, repeat_commands=False)

Bases: surrortg.inputs.linear_actuator.LinearActuator, surrortg.devices.udp.udp_input.UdpInput

Class for udp-controlled actuator.

Parameters
  • cmd (int) – udp byte that identifies the control id

  • multiplier (float, optional) – multiplier of the value, defaults to 1.0

  • repeat_commands (bool, optional) – defines if commands should be repeated, defaults to False

async drive_actuator(val, seat, unscaled=False)

Drive actuator by sending value as a udp command

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

  • seat (int) – Robot seat

  • unscaled (bool, optional) – defines if value should be unscaled, defaults to False

surrortg.devices.udp.udp_bot

class UdpBot

Bases: object

Base class for all bots that are controlled with udp commands

async handle_config(config)

Handle robot configuration

Parameters

config (dict) – Configuration from game engine

Returns

Current set and bots in current set, mapped by seats

Return type

(int, dict)

get_bots_in_current_set()

Returns all the enabled bots of the currently selected set

Returns

Enabled robots in the currently selected set

Return type

dict

async select_set()

Reads the set from the set file and returns it

Returns

Newly selected set number

Return type

int

add_input(new_input)

Appends the given input to the bot’s input configuration

Does not override previous configurations

Parameters

new_input (dict) – Input to append to the existing ones

async shutdown()

Resets all registered inputs for all bots, and then closes all endpoints

surrortg.devices.udp.udp_car

class UdpCar(throttle_mult=1.0, steering_mult=1.0, repeat_commands=False)

Bases: surrortg.devices.udp.udp_bot.UdpBot

Class for car-like udp-controlled bots

Default inputs include throttle and steering, defined as two separate actuators

Parameters
  • throttle_mult (float, optional) – multiplier for throttle value, defaults to 1.0

  • steering_mult (float, optional) – multiplier for steering value, defaults to 1.0

  • repeat_commands (bool, optional) – defines if commands should be repeated, defaults to False

threadsafe_throttle(val, seat)

Threadsafe helper method for using throttle

Can be used to access the UdpCar’s throttle actuator :param val: Actuator position value, between -1.0 and 1.0 :type val: float :param seat: Robot seat :type seat: int

threadsafe_steer(val, seat)

Threadsafe helper method for using steering

Can be used to access the UdpCar’s steering actuator :param val: Actuator position value, between -1.0 and 1.0 :type val: float :param seat: Robot seat :type seat: int

surrortg.devices.udp.udp_input

class UdpInput

Bases: surrortg.inputs.input.Input

A base class for all udp-controlled inputs, where endpoints need to be updated after constructor

set_endpoints(endpoints)

Set endpoints for this input, overriding existing ones.

Parameters

endpoints (dict) – endpoint information with seats as keys

surrortg.devices.udp.udp_protocol

Provide high-level UDP endpoints for asyncio. Example:

async def main():
    # Create a local UDP endpoint
    local = await open_local_endpoint('localhost', 8888)
    # Create a remote UDP endpoint, pointing to the first one
    remote = await open_remote_endpoint(*local.address)
    # The remote endpoint sends a datagram
    remote.send(b'Hey Hey, My My')
    # The local endpoint receives the datagram, along with the address
    data, address = await local.receive()
    # This prints: Got 'Hey Hey, My My' from 127.0.0.1 port 8888
    print(f"Got {data!r} from {address[0]} port {address[1]}")
async open_local_endpoint(host='0.0.0.0', port=0, *, queue_size=None, **kwargs)

Open and return a local datagram endpoint. An optional queue size argument can be provided. Extra keyword arguments are forwarded to loop.create_datagram_endpoint.

async open_remote_endpoint(host, port, *, queue_size=None, **kwargs)

Open and return a remote datagram endpoint. An optional queue size argument can be provided. Extra keyword arguments are forwarded to loop.create_datagram_endpoint.