mirror of
https://github.com/apirrone/Open_Duck_Mini_Runtime.git
synced 2025-09-03 03:33:54 +00:00
aze
This commit is contained in:
parent
2361f2af9e
commit
6b6e726433
3 changed files with 48 additions and 3 deletions
|
@ -1,3 +1,4 @@
|
|||
from abc import update_abstractmethods
|
||||
import pygame
|
||||
from threading import Thread
|
||||
from queue import Queue
|
||||
|
@ -41,6 +42,7 @@ class XBoxController:
|
|||
def get_commands(self):
|
||||
A_pressed = False
|
||||
X_pressed = False
|
||||
LB_pressed = False
|
||||
last_commands = self.last_commands
|
||||
left_trigger = self.last_left_trigger
|
||||
right_trigger = self.last_right_trigger
|
||||
|
@ -116,6 +118,9 @@ class XBoxController:
|
|||
if self.p1.get_button(3): # X button
|
||||
X_pressed = True
|
||||
|
||||
if self.p1.get_button(6): # LB button
|
||||
LB_pressed = True
|
||||
|
||||
# for i in range(10):
|
||||
# if self.p1.get_button(i):
|
||||
# print(f"Button {i} pressed")
|
||||
|
@ -123,27 +128,33 @@ class XBoxController:
|
|||
if self.p1.get_button(4): # Y button
|
||||
self.head_control_mode = not self.head_control_mode
|
||||
|
||||
up_down = self.p1.get_hat(0)[1]
|
||||
pygame.event.pump() # process event queue
|
||||
|
||||
return (
|
||||
np.around(last_commands, 3),
|
||||
A_pressed,
|
||||
X_pressed,
|
||||
LB_pressed,
|
||||
left_trigger,
|
||||
right_trigger,
|
||||
up_down
|
||||
)
|
||||
|
||||
def get_last_command(self):
|
||||
A_pressed = False
|
||||
X_pressed = False
|
||||
|
||||
LB_pressed = False
|
||||
up_down = 0
|
||||
try:
|
||||
(
|
||||
self.last_commands,
|
||||
A_pressed,
|
||||
X_pressed,
|
||||
LB_pressed,
|
||||
self.last_left_trigger,
|
||||
self.last_right_trigger,
|
||||
up_down
|
||||
) = self.cmd_queue.get(
|
||||
False
|
||||
) # non blocking
|
||||
|
@ -154,8 +165,10 @@ class XBoxController:
|
|||
self.last_commands,
|
||||
A_pressed,
|
||||
X_pressed,
|
||||
LB_pressed,
|
||||
self.last_left_trigger,
|
||||
self.last_right_trigger,
|
||||
up_down
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -214,7 +214,7 @@ messages = [
|
|||
# },
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Explore, and when you see a person, play the happy sound",
|
||||
"content": "Find the waste bin and turn around it. Play the happy sound when you are done",
|
||||
},
|
||||
]
|
||||
|
||||
|
|
|
@ -132,6 +132,7 @@ class RLWalk:
|
|||
self.PRM = PolyReferenceMotion("./polynomial_coefficients.pkl")
|
||||
self.imitation_i = 0
|
||||
self.imitation_phase = np.array([0, 0])
|
||||
self.phase_frequency_factor = 1.0
|
||||
|
||||
def add_fake_head(self, pos):
|
||||
# add just the antennas now
|
||||
|
@ -200,6 +201,17 @@ class RLWalk:
|
|||
|
||||
time.sleep(2)
|
||||
|
||||
def get_phase_frequency_factor(self, x_velocity):
|
||||
|
||||
max_phase_frequency = 1.2
|
||||
min_phase_frequency = 1.0
|
||||
|
||||
|
||||
# Perform linear interpolation
|
||||
freq = min_phase_frequency + (abs(x_velocity) / 0.15) * (max_phase_frequency - min_phase_frequency)
|
||||
|
||||
return freq
|
||||
|
||||
def run(self):
|
||||
i = 0
|
||||
try:
|
||||
|
@ -208,8 +220,10 @@ class RLWalk:
|
|||
while True:
|
||||
A_pressed = False
|
||||
X_pressed = False
|
||||
LB_pressed = False
|
||||
left_trigger = 0
|
||||
right_trigger = 0
|
||||
up_down = 0
|
||||
t = time.time()
|
||||
|
||||
if self.commands:
|
||||
|
@ -217,10 +231,28 @@ class RLWalk:
|
|||
self.last_commands,
|
||||
A_pressed,
|
||||
X_pressed,
|
||||
LB_pressed,
|
||||
left_trigger,
|
||||
right_trigger,
|
||||
up_down
|
||||
) = self.xbox_controller.get_last_command()
|
||||
|
||||
if up_down == 1:
|
||||
self.phase_frequency_factor += 0.05
|
||||
print(f"Phase frequency factor {self.phase_frequency_factor}")
|
||||
elif up_down == -1:
|
||||
self.phase_frequency_factor -= 0.05
|
||||
print(f"Phase frequency factor {self.phase_frequency_factor}")
|
||||
|
||||
|
||||
# if LB_pressed:
|
||||
# self.phase_frequency_factor = 1.2
|
||||
# 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 X_pressed:
|
||||
self.sounds.play_random_sound()
|
||||
self.projector.switch()
|
||||
|
@ -243,7 +275,7 @@ class RLWalk:
|
|||
if obs is None:
|
||||
continue
|
||||
|
||||
self.imitation_i += 1
|
||||
self.imitation_i += 1 * self.phase_frequency_factor
|
||||
self.imitation_i = self.imitation_i % self.PRM.nb_steps_in_period
|
||||
self.imitation_phase = np.array(
|
||||
[
|
||||
|
|
Loading…
Reference in a new issue