Merge pull request #15 from apirrone/14-integrate-buttons-into-xboxcontroller

14 integrate buttons into xboxcontroller
This commit is contained in:
Antoine Pirrone 2025-04-19 04:43:17 -07:00 committed by GitHub
commit c1876c57ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 58 deletions

0
aze
View file

View file

@ -1,9 +1,9 @@
from abc import update_abstractmethods
import pygame
from threading import Thread
from queue import Queue
import time
import numpy as np
from mini_bdx_runtime.buttons import Buttons
X_RANGE = [-0.15, 0.15]
@ -39,6 +39,8 @@ class XBoxController:
self.LB_pressed = False
self.RB_pressed = False
self.buttons = Buttons()
Thread(target=self.commands_worker, daemon=True).start()
def commands_worker(self):
@ -192,19 +194,23 @@ class XBoxController:
except Exception:
pass
return (
self.last_commands,
self.buttons.update(
A_pressed,
B_pressed,
X_pressed,
Y_pressed,
LB_pressed,
RB_pressed,
self.last_left_trigger,
self.last_right_trigger,
up_down,
up_down == 1,
up_down == -1,
)
return (
self.last_commands,
self.buttons,
self.last_left_trigger,
self.last_right_trigger,
)
if __name__ == "__main__":
controller = XBoxController(20)

View file

@ -7,7 +7,6 @@ import numpy as np
from mini_bdx_runtime.rustypot_position_hwi import HWI
from mini_bdx_runtime.duck_config import DuckConfig
from mini_bdx_runtime.xbox_controller import XBoxController
from mini_bdx_runtime.buttons import Buttons
from mini_bdx_runtime.eyes import Eyes
@ -18,7 +17,6 @@ from mini_bdx_runtime.projector import Projector
duck_config = DuckConfig()
xbox_controller = XBoxController(50, only_head_control=True)
buttons = Buttons()
if duck_config.speaker:
sounds = Sounds(volume=1.0, sound_directory="../mini_bdx_runtime/assets/")
@ -47,28 +45,9 @@ limits = {
try:
while True:
(
last_commands,
A_pressed,
B_pressed,
X_pressed,
Y_pressed,
LB_pressed,
RB_pressed,
left_trigger,
right_trigger,
up_down,
) = xbox_controller.get_last_command()
buttons.update(
A_pressed,
B_pressed,
X_pressed,
Y_pressed,
LB_pressed,
RB_pressed,
up_down == 1,
up_down == -1,
last_commands, buttons, left_trigger, right_trigger = (
xbox_controller.get_last_command()
)
l_x = last_commands[5]

View file

@ -14,7 +14,6 @@ from mini_bdx_runtime.sounds import Sounds
from mini_bdx_runtime.antennas import Antennas
from mini_bdx_runtime.projector import Projector
from mini_bdx_runtime.rl_utils import make_action_dict, LowPassActionFilter
from mini_bdx_runtime.buttons import Buttons
from mini_bdx_runtime.duck_config import DuckConfig
import os
@ -98,7 +97,6 @@ class RLWalk:
self.command_freq = 20 # hz
if self.commands:
self.xbox_controller = XBoxController(self.command_freq)
self.buttons = Buttons()
# Reference motion, but we only really need the length of one phase
# TODO
@ -206,34 +204,12 @@ class RLWalk:
while True:
left_trigger = 0
right_trigger = 0
up_down = 0
t = time.time()
if self.commands:
(
self.last_commands,
A_pressed,
B_pressed,
X_pressed,
Y_pressed,
LB_pressed,
RB_pressed,
left_trigger,
right_trigger,
up_down,
) = self.xbox_controller.get_last_command()
self.buttons.update(
A_pressed,
B_pressed,
X_pressed,
Y_pressed,
LB_pressed,
RB_pressed,
up_down == 1,
up_down == -1,
self.last_commands, self.buttons, left_trigger, right_trigger = (
self.xbox_controller.get_last_command()
)
if self.buttons.dpad_up.triggered:
self.phase_frequency_factor_offset += 0.05
print(
@ -251,9 +227,6 @@ class RLWalk:
else:
self.phase_frequency_factor = 1.0
# self.phase_frequency_factor = self.get_phase_frequency_factor(self.last_commands[0])
# print(f"Phase frequency factor {self.phase_frequency_factor}")
if self.buttons.X.triggered:
if self.duck_config.projector:
self.projector.switch()