This commit is contained in:
apirrone 2025-03-10 16:07:19 +01:00
parent 511063e4d7
commit 868e1fec76
2 changed files with 21 additions and 4 deletions

View file

@ -39,6 +39,7 @@ class XBoxController:
def get_commands(self):
A_pressed = False
X_pressed = False
last_commands = self.last_commands
for event in pygame.event.get():
l_x = -1 * self.p1.get_axis(0)
@ -100,22 +101,30 @@ class XBoxController:
if self.p1.get_button(0): # A button
A_pressed = True
if self.p1.get_button(3): # X button
X_pressed = True
# for i in range(10):
# if self.p1.get_button(i):
# print(f"Button {i} pressed")
if self.p1.get_button(4): # Y button
self.head_control_mode = not self.head_control_mode
pygame.event.pump() # process event queue
return np.around(last_commands, 3), A_pressed
return np.around(last_commands, 3), A_pressed, X_pressed
def get_last_command(self):
A_pressed = False
X_pressed = False
try:
self.last_commands, A_pressed = self.cmd_queue.get(False) # non blocking
self.last_commands, A_pressed, X_pressed = self.cmd_queue.get(False) # non blocking
except Exception:
pass
return self.last_commands, A_pressed
return self.last_commands, A_pressed, X_pressed
if __name__ == "__main__":

View file

@ -16,6 +16,7 @@ from mini_bdx_runtime.poly_reference_motion import PolyReferenceMotion
from mini_bdx_runtime.xbox_controller import XBoxController
from mini_bdx_runtime.feet_contacts import FeetContacts
from mini_bdx_runtime.eyes import Eyes
from mini_bdx_runtime.sounds import Sounds
joints_order = [
"left_hip_yaw",
@ -116,6 +117,8 @@ class RLWalk:
self.paused = False
self.sounds = Sounds(volume=1.0, sound_directory="../mini_bdx_runtime/assets/")
self.command_freq = 10 # hz
if self.commands:
self.xbox_controller = XBoxController(self.command_freq, self.standing)
@ -214,13 +217,18 @@ class RLWalk:
print("Starting")
start_t = time.time()
while True:
A_pressed = False
X_pressed = False
t = time.time()
if self.commands:
self.last_commands, A_pressed = (
self.last_commands, A_pressed, X_pressed = (
self.xbox_controller.get_last_command()
)
if X_pressed:
self.sounds.play_random_sound()
if A_pressed and not self.paused:
self.paused = True
print("PAUSE")