Add get_gripper_action method to GamepadController
This commit is contained in:
parent
7452f9baaa
commit
2c1e5fa28b
|
@ -312,6 +312,31 @@ class GamepadController(InputController):
|
||||||
logging.error("Error reading gamepad. Is it still connected?")
|
logging.error("Error reading gamepad. Is it still connected?")
|
||||||
return 0.0, 0.0, 0.0
|
return 0.0, 0.0, 0.0
|
||||||
|
|
||||||
|
def get_gripper_action(self):
|
||||||
|
"""
|
||||||
|
Get gripper action using L3/R3 buttons.
|
||||||
|
Press left stick (L3) to open the gripper.
|
||||||
|
Press right stick (R3) to close the gripper.
|
||||||
|
"""
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Check if buttons are pressed
|
||||||
|
l3_pressed = self.joystick.get_button(9)
|
||||||
|
r3_pressed = self.joystick.get_button(10)
|
||||||
|
|
||||||
|
# Determine action based on button presses
|
||||||
|
if r3_pressed:
|
||||||
|
return 1.0 # Close gripper
|
||||||
|
elif l3_pressed:
|
||||||
|
return -1.0 # Open gripper
|
||||||
|
else:
|
||||||
|
return 0.0 # No change
|
||||||
|
|
||||||
|
except pygame.error:
|
||||||
|
logging.error(f"Error reading gamepad. Is it still connected?")
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
|
||||||
class GamepadControllerHID(InputController):
|
class GamepadControllerHID(InputController):
|
||||||
"""Generate motion deltas from gamepad input using HIDAPI."""
|
"""Generate motion deltas from gamepad input using HIDAPI."""
|
||||||
|
|
Loading…
Reference in New Issue