mirror of
https://github.com/huggingface/lerobot.git
synced 2026-05-23 04:30:10 +00:00
chore(busy_wait): renaming busy_wait into precise_sleep
This commit is contained in:
@@ -29,7 +29,7 @@ from lerobot.microphones.utils import (
|
|||||||
make_microphones_from_configs,
|
make_microphones_from_configs,
|
||||||
)
|
)
|
||||||
from lerobot.utils.robot_utils import (
|
from lerobot.utils.robot_utils import (
|
||||||
busy_wait,
|
precise_sleep,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ def main(
|
|||||||
|
|
||||||
# Record audio chunks
|
# Record audio chunks
|
||||||
for j in range(audio_chunks_number):
|
for j in range(audio_chunks_number):
|
||||||
busy_wait(audio_chunks_duration)
|
precise_sleep(audio_chunks_duration)
|
||||||
|
|
||||||
for microphone_key, microphone in microphones.items():
|
for microphone_key, microphone in microphones.items():
|
||||||
audio_chunk = microphone.read()
|
audio_chunk = microphone.read()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ from lerobot.microphones.utils import (
|
|||||||
make_microphones_from_configs,
|
make_microphones_from_configs,
|
||||||
)
|
)
|
||||||
from lerobot.utils.robot_utils import (
|
from lerobot.utils.robot_utils import (
|
||||||
busy_wait,
|
precise_sleep,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ def main(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Record audio chunks
|
# Record audio chunks
|
||||||
busy_wait(10.0)
|
precise_sleep(10.0)
|
||||||
|
|
||||||
for sensor_key, sensor in sensors.items():
|
for sensor_key, sensor in sensors.items():
|
||||||
data_chunk = sensor.read()
|
data_chunk = sensor.read()
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ from typing import Any
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from sounddevice import PortAudioError
|
from sounddevice import PortAudioError
|
||||||
|
|
||||||
from lerobot.utils.robot_utils import busy_wait
|
from lerobot.utils.robot_utils import precise_sleep
|
||||||
|
|
||||||
|
|
||||||
# --- Interface definitions for InputStream ---
|
# --- Interface definitions for InputStream ---
|
||||||
@@ -335,7 +335,7 @@ class FakeSounddeviceSDKAdapter(ISounddeviceSDK):
|
|||||||
def _streaming_loop(self):
|
def _streaming_loop(self):
|
||||||
if self.callback is not None:
|
if self.callback is not None:
|
||||||
while not self._streaming_thread_stop_event.is_set():
|
while not self._streaming_thread_stop_event.is_set():
|
||||||
busy_wait(self.latency)
|
precise_sleep(self.latency)
|
||||||
tmp_data = self._simulated_audio_data()
|
tmp_data = self._simulated_audio_data()
|
||||||
self.callback(
|
self.callback(
|
||||||
tmp_data,
|
tmp_data,
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ class PortAudioMicrophone(Microphone):
|
|||||||
self.audio_callback_start_event.clear()
|
self.audio_callback_start_event.clear()
|
||||||
|
|
||||||
# Create and start an audio input stream with a recording callback
|
# Create and start an audio input stream with a recording callback
|
||||||
# Remark: this is done in a separate process so that audio recording is not impacted by the main thread CPU usage, especially the busy_wait function.
|
# Remark: this is done in a separate process so that audio recording is not impacted by the main thread CPU usage, especially the precise_sleep function.
|
||||||
process_init_event = process_Event()
|
process_init_event = process_Event()
|
||||||
self.record_process = Process(
|
self.record_process = Process(
|
||||||
target=self._record_process,
|
target=self._record_process,
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ class TouchLabSensor(Microphone):
|
|||||||
self.audio_callback_start_event.clear()
|
self.audio_callback_start_event.clear()
|
||||||
|
|
||||||
# Create and start an audio input stream with a recording callback
|
# Create and start an audio input stream with a recording callback
|
||||||
# Remark: this is done in a separate process so that audio recording is not impacted by the main thread CPU usage, especially the busy_wait function.
|
# Remark: this is done in a separate process so that audio recording is not impacted by the main thread CPU usage, especially the precise_sleep function.
|
||||||
process_init_event = process_Event()
|
process_init_event = process_Event()
|
||||||
self.record_process = Process(
|
self.record_process = Process(
|
||||||
target=self._record_process,
|
target=self._record_process,
|
||||||
|
|||||||
@@ -363,7 +363,7 @@ def record_loop(
|
|||||||
# This initial wait might be longer than the audio chunk duration to
|
# This initial wait might be longer than the audio chunk duration to
|
||||||
# (1) ensure that the audio buffers are filled with enough data
|
# (1) ensure that the audio buffers are filled with enough data
|
||||||
# (2) add additional initial samples to the dataset in case of variable audio chunk duration during training
|
# (2) add additional initial samples to the dataset in case of variable audio chunk duration during training
|
||||||
busy_wait(DEFAULT_INITIAL_AUDIO_BUFFER_DURATION)
|
precise_sleep(DEFAULT_INITIAL_AUDIO_BUFFER_DURATION)
|
||||||
for microphone_name, microphone in robot.microphones.items():
|
for microphone_name, microphone in robot.microphones.items():
|
||||||
audio_chunk = microphone.read()
|
audio_chunk = microphone.read()
|
||||||
audio_buffer[microphone_name] = rolling_vstack(audio_buffer[microphone_name], audio_chunk)
|
audio_buffer[microphone_name] = rolling_vstack(audio_buffer[microphone_name], audio_chunk)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ from lerobot.utils.errors import (
|
|||||||
DeviceNotConnectedError,
|
DeviceNotConnectedError,
|
||||||
DeviceNotRecordingError,
|
DeviceNotRecordingError,
|
||||||
)
|
)
|
||||||
from lerobot.utils.robot_utils import busy_wait
|
from lerobot.utils.robot_utils import precise_sleep
|
||||||
|
|
||||||
MODULE_PATH = "lerobot.microphones.portaudio.microphone_portaudio"
|
MODULE_PATH = "lerobot.microphones.portaudio.microphone_portaudio"
|
||||||
RECORDING_DURATION = 1.0
|
RECORDING_DURATION = 1.0
|
||||||
@@ -302,7 +302,7 @@ def test_stop_recording_success(default_config, test_sdk, multiprocessing):
|
|||||||
microphone = PortAudioMicrophone(default_config, sounddevice_sdk=test_sdk)
|
microphone = PortAudioMicrophone(default_config, sounddevice_sdk=test_sdk)
|
||||||
microphone.connect()
|
microphone.connect()
|
||||||
microphone.start_recording(multiprocessing=multiprocessing)
|
microphone.start_recording(multiprocessing=multiprocessing)
|
||||||
busy_wait(RECORDING_DURATION)
|
precise_sleep(RECORDING_DURATION)
|
||||||
microphone.stop_recording()
|
microphone.stop_recording()
|
||||||
|
|
||||||
assert not microphone.is_recording
|
assert not microphone.is_recording
|
||||||
@@ -316,7 +316,7 @@ def test_stop_writing_success(tmp_path, default_config, test_sdk, multiprocessin
|
|||||||
microphone = PortAudioMicrophone(default_config, sounddevice_sdk=test_sdk)
|
microphone = PortAudioMicrophone(default_config, sounddevice_sdk=test_sdk)
|
||||||
microphone.connect()
|
microphone.connect()
|
||||||
microphone.start_recording(output_file=tmp_path / "test.wav", multiprocessing=multiprocessing)
|
microphone.start_recording(output_file=tmp_path / "test.wav", multiprocessing=multiprocessing)
|
||||||
busy_wait(RECORDING_DURATION)
|
precise_sleep(RECORDING_DURATION)
|
||||||
microphone.stop_recording()
|
microphone.stop_recording()
|
||||||
|
|
||||||
assert not microphone.is_recording
|
assert not microphone.is_recording
|
||||||
@@ -348,7 +348,7 @@ def test_disconnect_while_recording(default_config, test_sdk, multiprocessing):
|
|||||||
microphone = PortAudioMicrophone(default_config, sounddevice_sdk=test_sdk)
|
microphone = PortAudioMicrophone(default_config, sounddevice_sdk=test_sdk)
|
||||||
microphone.connect()
|
microphone.connect()
|
||||||
microphone.start_recording(multiprocessing=multiprocessing)
|
microphone.start_recording(multiprocessing=multiprocessing)
|
||||||
busy_wait(RECORDING_DURATION)
|
precise_sleep(RECORDING_DURATION)
|
||||||
microphone.disconnect()
|
microphone.disconnect()
|
||||||
|
|
||||||
assert not microphone.is_connected
|
assert not microphone.is_connected
|
||||||
@@ -362,7 +362,7 @@ def test_disconnect_while_writing(tmp_path, default_config, test_sdk, multiproce
|
|||||||
microphone = PortAudioMicrophone(default_config, sounddevice_sdk=test_sdk)
|
microphone = PortAudioMicrophone(default_config, sounddevice_sdk=test_sdk)
|
||||||
microphone.connect()
|
microphone.connect()
|
||||||
microphone.start_recording(output_file=tmp_path / "test.wav", multiprocessing=multiprocessing)
|
microphone.start_recording(output_file=tmp_path / "test.wav", multiprocessing=multiprocessing)
|
||||||
busy_wait(RECORDING_DURATION)
|
precise_sleep(RECORDING_DURATION)
|
||||||
microphone.disconnect()
|
microphone.disconnect()
|
||||||
|
|
||||||
assert not microphone.is_connected
|
assert not microphone.is_connected
|
||||||
@@ -378,7 +378,7 @@ def test_read_success(default_config, test_sdk, multiprocessing):
|
|||||||
microphone.connect()
|
microphone.connect()
|
||||||
microphone.start_recording(multiprocessing=multiprocessing)
|
microphone.start_recording(multiprocessing=multiprocessing)
|
||||||
|
|
||||||
busy_wait(RECORDING_DURATION)
|
precise_sleep(RECORDING_DURATION)
|
||||||
|
|
||||||
data = microphone.read()
|
data = microphone.read()
|
||||||
|
|
||||||
@@ -398,7 +398,7 @@ def test_writing_success(tmp_path, default_config, test_sdk, multiprocessing):
|
|||||||
microphone.connect()
|
microphone.connect()
|
||||||
microphone.start_recording(output_file=tmp_path / "test.wav", multiprocessing=multiprocessing)
|
microphone.start_recording(output_file=tmp_path / "test.wav", multiprocessing=multiprocessing)
|
||||||
|
|
||||||
busy_wait(RECORDING_DURATION)
|
precise_sleep(RECORDING_DURATION)
|
||||||
|
|
||||||
microphone.stop_recording()
|
microphone.stop_recording()
|
||||||
|
|
||||||
@@ -420,7 +420,7 @@ def test_read_while_writing(tmp_path, default_config, test_sdk, multiprocessing)
|
|||||||
microphone.connect()
|
microphone.connect()
|
||||||
microphone.start_recording(output_file=tmp_path / "test.wav", multiprocessing=multiprocessing)
|
microphone.start_recording(output_file=tmp_path / "test.wav", multiprocessing=multiprocessing)
|
||||||
|
|
||||||
busy_wait(RECORDING_DURATION)
|
precise_sleep(RECORDING_DURATION)
|
||||||
|
|
||||||
read_data = microphone.read()
|
read_data = microphone.read()
|
||||||
microphone.stop_recording()
|
microphone.stop_recording()
|
||||||
|
|||||||
Reference in New Issue
Block a user