auto-detect controller
Browse files- sim/unitree_sdk2py_bridge.py +10 -6
sim/unitree_sdk2py_bridge.py
CHANGED
|
@@ -280,12 +280,16 @@ class UnitreeSdk2Bridge:
|
|
| 280 |
pygame.init()
|
| 281 |
pygame.joystick.init()
|
| 282 |
joystick_count = pygame.joystick.get_count()
|
| 283 |
-
if joystick_count
|
| 284 |
-
|
| 285 |
-
self.joystick
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
|
| 290 |
if js_type == "xbox":
|
| 291 |
if sys.platform.startswith("linux"):
|
|
|
|
| 280 |
pygame.init()
|
| 281 |
pygame.joystick.init()
|
| 282 |
joystick_count = pygame.joystick.get_count()
|
| 283 |
+
if joystick_count == 0:
|
| 284 |
+
print("No gamepad detected — running without joystick.")
|
| 285 |
+
self.joystick = None
|
| 286 |
+
return
|
| 287 |
+
if device_id >= joystick_count:
|
| 288 |
+
print(f"Joystick device_id={device_id} out of range ({joystick_count} found) — using device 0.")
|
| 289 |
+
device_id = 0
|
| 290 |
+
self.joystick = pygame.joystick.Joystick(device_id)
|
| 291 |
+
self.joystick.init()
|
| 292 |
+
print(f"Joystick connected: {self.joystick.get_name()}")
|
| 293 |
|
| 294 |
if js_type == "xbox":
|
| 295 |
if sys.platform.startswith("linux"):
|