nepyope commited on
Commit
71956a6
·
verified ·
1 Parent(s): 3efb4cc

auto-detect controller

Browse files
Files changed (1) hide show
  1. 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 > 0:
284
- self.joystick = pygame.joystick.Joystick(device_id)
285
- self.joystick.init()
286
- else:
287
- print("No gamepad detected.")
288
- sys.exit()
 
 
 
 
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"):