Gamepad#

class genesis_forge.gamepads.Gamepad(config: GamepadConfig = None, vendor_id=None, product_id=None, debug=False)[source]#

Bases: object

General gamepad controller, which automatically attempts to connect to known gamepads (currentlyLogitech F710 and F310).

Example:

>>> gamepad = Gamepad()
>>> gamepad.state
GamepadState(axis=[0.0, 0.0, 0.0, 0.0], buttons=[A], dpad=UP)
>>> gamepad.state.axis
[0.0, 0.0, 0.0, 0.0]
>>> gamepad.state.buttons
["A"]
>>> gamepad.state.dpad
"UP"
>>> gamepad.state.buttons = [Button.A]

Example connecting to a specific gamepad:

>>> gamepad = Gamepad(config=LOGITECH_F710_CONFIG)

Adapted from: google-deepmind/mujoco_playground.

auto_connect()[source]#

Loop through the known gamepad configs until one connects.

connect(vendor_id=None, product_id=None)[source]#

Attempt to connect to a gamepad.

Parameters:
  • vendor_id – The vendor id of the gamepad to connect to.

  • product_id – The product id of the gamepad to connect to.

Returns:

True if the gamepad connected successfully, False otherwise.

stop()[source]#

Stop reading gamepad input.

property state: GamepadState#

The current state of the gamepad.