Gamepad

Subscribing to Gamepad Events

import omni.appwindow
from carb.input import GamepadInput

app_window = omni.appwindow.get_default_app_window()
self.gamepad = self._app_window.get_gamepad(0)

self.input = carb.input.acquire_input_interface()
self.gamepad_event_sub = self.input.subscribe_to_gamepad_events(self.gamepad, self.on_gamepad_event)

Handling Gamepad Events for a vehicle

def on_gamepad_event(self, event: carb.input.GamepadEvent):

    # D-pad Up for accelerating
    if event.input == GamepadInput.DPAD_UP:
        if event.value > 0.5: self.throttle = 1
        else: self.throttle = 0

    # D-pad Down for braking
    elif event.input == GamepadInput.DPAD_DOWN:
        if event.value > 0.5: self.brakes = 1
        else: self.brakes = 0

    cur_val = event.value
    absval = abs(event.value)

    # Ignore 0 since it signifies the movement  of the stick has stopped,
    # but doesn't mean it's at center...could be being held steady
    if absval == 0:
        return
    if absval < 0.001:
        cur_val = 0

    # Use right stick for steering
    if event.input == GamepadInput.RIGHT_STICK_RIGHT:
        self.steering = cur_val
    elif event.input == GamepadInput.RIGHT_STICK_LEFT:
        self.steering = -1 * cur_val

Unsubscribing the Gamepad Event Handler

self.input.unsubscribe_to_gamepad_events(self.gamepad, self.gp_event_sub)