How to move objects using xbox controller in usd

I’d like to try moving objects using a gamepad on omniverse usd. Is there any reference material or something? Also, is there a Python code. please help me

USD Composer and all of kit natively supports the xbox controller. It works very very well. You can use it to fly around your scene and explore. However, it does not work well for interacting with your scene like this. You will be better off using a mouse.

I want to know how to move the sphere with XBOX CONTROLLOER, but there are too many errors. I’ll show you the code I used

import omni.usd
import carb.input
import time

stage = omni.usd.get_context().get_stage()

TARGET_PRIM_PATH = “/World/TargetObject”

def get_gamepad_input():
“”“Gamepad�� �Է��� �޾� ���� ��ƽ�� x, y ���� ��ȯ�մϴ�.”“”
input_interface = carb.input.acquire_input_interface()
device_id = carb.input.GamepadInput.XBOX
if not input_interface.is_device_attached(device_id):
print(“Xbox gamepad not found!”)
return 0, 0

left_stick_x = input_interface.get_value(device_id, carb.input.GamepadAxis.LEFT_THUMB_X)
left_stick_y = input_interface.get_value(device_id, carb.input.GamepadAxis.LEFT_THUMB_Y)


movement_scale = 0.1  ale

def update_object_transform(prim_path, dx, dy):
“”“Gamepad �Է¿� ���� USD Prim�� ��ġ�� ������Ʈ�մϴ�.”“”
prim = stage.GetPrimAtPath(prim_path)
if not prim.IsValid():
print(f"Prim at path {prim_path} not found.")
return

xform = prim.GetAttribute("xformOp:translate")
if not xform.IsValid():
    print(f"No translate attribute found on prim {prim_path}.")
    return


current_translation = xform.Get()
if current_translation is None:
    current_translation = [0.0, 0.0, 0.0]  


new_translation = [
    current_translation[0] + dx,  
    current_translation[1] + dy, 
    current_translation[2]      
]


xform.Set(new_translation)

def main_loop():
“”“Gamepad �Է��� ���������� �����ϰ� ��� ������ ��ġ�� ������Ʈ�մϴ�.”“”
print(“Gamepad control started… Use left stick to move the object.”)

while True:
   
    dx, dy = get_gamepad_input()

   
    if dx != 0 or dy != 0: 
        update_object_transform(TARGET_PRIM_PATH, dx, dy)
        print(f"Moved object by dx={dx:.2f}, dy={dy:.2f}")

   
    time.sleep(0.01)

main_loop()

I will try to find out if we have any support for this. As I said, we support the Xbox controller for scene navigation. In theory you can write your own code to modify the buttons to do whatever you want but it may have errors. What kind of application and usage are you building? An interactive app just for use with an xbox controller?

I just want to move the sphere of the scene to the xbox controller. But I’m asking because I’m looking for a way to find a way because the camera is moving and the sphere is not moving. Is there a reference material for omniverse usd controller?

Here is a sample script as part of the “omni.kit.menu.utils” extension. It shows that you can add references to joystick/xbox controller buttons. Maybe this code can help you. Here is the help file for it omni.kit.menu.utils — Omniverse Kit 1.7.5 documentation

And here is the same code.
menu.py (4.5 KB)

I tried it with the code you sent me, but it doesn’t work… what wrong?

I am not sure. It should be working with that code. Are you getting an error message?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.