support resource file read

This commit is contained in:
mumuhhh 2025-05-09 12:25:28 +08:00
parent 34c60ef80c
commit ba20e5f85c
30 changed files with 19 additions and 7 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
__pycache__/ __pycache__/
mini_bdx_runtime.egg-info/ mini_bdx_runtime.egg-info/
build
dist

View file

@ -2,6 +2,7 @@ import pygame
import time import time
import os import os
import random import random
from importlib.resources import files
class Sounds: class Sounds:
@ -50,7 +51,8 @@ class Sounds:
# Example usage # Example usage
if __name__ == "__main__": if __name__ == "__main__":
sound_player = Sounds(1.0, "../assets/") assets_dir = files("mini_bdx_runtime") / "assets"
sound_player = Sounds(1.0, assets_dir.__str__())
time.sleep(1) time.sleep(1)
while True: while True:
# sound_player.play_random_sound() # sound_player.play_random_sound()

View file

@ -19,7 +19,9 @@ duck_config = DuckConfig()
xbox_controller = XBoxController(50, only_head_control=True) xbox_controller = XBoxController(50, only_head_control=True)
if duck_config.speaker: if duck_config.speaker:
sounds = Sounds(volume=1.0, sound_directory="../mini_bdx_runtime/assets/") from importlib.resources import files
assets_dir = files("mini_bdx_runtime") / "assets"
sounds = Sounds(volume=1.0, sound_directory=assets_dir.__str__())
if duck_config.antennas: if duck_config.antennas:
antennas = Antennas() antennas = Antennas()
if duck_config.eyes: if duck_config.eyes:

View file

@ -100,7 +100,9 @@ class RLWalk:
# Reference motion, but we only really need the length of one phase # Reference motion, but we only really need the length of one phase
# TODO # TODO
self.PRM = PolyReferenceMotion("./polynomial_coefficients.pkl") from pathlib import Path
polynomial_coefficients = Path(__file__).parent / "polynomial_coefficients.pkl"
self.PRM = PolyReferenceMotion(polynomial_coefficients.as_posix())
self.imitation_i = 0 self.imitation_i = 0
self.imitation_phase = np.array([0, 0]) self.imitation_phase = np.array([0, 0])
self.phase_frequency_factor = 1.0 self.phase_frequency_factor = 1.0
@ -114,8 +116,10 @@ class RLWalk:
if self.duck_config.projector: if self.duck_config.projector:
self.projector = Projector() self.projector = Projector()
if self.duck_config.speaker: if self.duck_config.speaker:
from importlib.resources import files
assets_dir = files("mini_bdx_runtime") / "assets"
self.sounds = Sounds( self.sounds = Sounds(
volume=1.0, sound_directory="../mini_bdx_runtime/assets/" volume=1.0, sound_directory=assets_dir.__str__()
) )
if self.duck_config.antennas: if self.duck_config.antennas:
self.antennas = Antennas() self.antennas = Antennas()

View file

@ -14,7 +14,7 @@ packages = find:
zip_safe = True zip_safe = True
include_package_data = True include_package_data = True
package_dir= package_dir=
=mini_bdx_runtime =mini_bdx_runtime_src
install_requires = install_requires =
rustypot==0.1.0 rustypot==0.1.0
onnxruntime==1.18.1 onnxruntime==1.18.1
@ -28,9 +28,11 @@ install_requires =
# adafruit_extended_bus # adafruit_extended_bus
[options.packages.find] [options.packages.find]
where=mini_bdx_runtime where=mini_bdx_runtime_src
[options.package_data] [options.package_data]
mini_bdx_runtime =
assets/*.wav
[options.extras_require] [options.extras_require]