diff --git a/CHANGELOG.md b/CHANGELOG.md index 8722812610..3121d2d89c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this project are documented in this file. - Implement `MANNAutoregressive` class in `ML` component (https://github.com/ami-iit/bipedal-locomotion-framework/pull/659) - Implement`UkfState` class in `RobotDynamicsEstimator` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/669) - Implement `MANNTrajectoryGenerator` class in `ML` component (https://github.com/ami-iit/bipedal-locomotion-framework/pull/668) +- Implement a bash script to automatically log the audio along with the YarpRobotLoggerDevice (https://github.com/ami-iit/bipedal-locomotion-framework/pull/681) ### Changed - Restructure application folders of `YarpRobotLoggerDevice` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/670) diff --git a/devices/YarpRobotLoggerDevice/CMakeLists.txt b/devices/YarpRobotLoggerDevice/CMakeLists.txt index e1c887116e..38844d6a23 100644 --- a/devices/YarpRobotLoggerDevice/CMakeLists.txt +++ b/devices/YarpRobotLoggerDevice/CMakeLists.txt @@ -54,5 +54,10 @@ if(FRAMEWORK_COMPILE_YarpRobotLoggerDevice) BipedalLocomotion::SystemYarpImplementation tiny-process-library::tiny-process-library CONFIGURE_PACKAGE_NAME yarp_robot_logger_device) + + install(FILES scripts/blf-logger-with-audio.sh + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ + DESTINATION "${CMAKE_INSTALL_BINDIR}") + endif() diff --git a/devices/YarpRobotLoggerDevice/scripts/blf-logger-with-audio.sh b/devices/YarpRobotLoggerDevice/scripts/blf-logger-with-audio.sh new file mode 100755 index 0000000000..1d5b2ac440 --- /dev/null +++ b/devices/YarpRobotLoggerDevice/scripts/blf-logger-with-audio.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +input_port_audio=$1 + +# Function to handle SIGINT signal +function handle_sigint { + echo "Received SIGINT signal. Forwarding to background programs..." + # Forward SIGINT to the background program + kill -SIGINT $bg_pid1 $bg_pid2 +} + +function handle_exit { + echo "Renaming the audio" + + # get the latest matfile name + latest_file=$(find . -maxdepth 1 -type f -name "*.mat" -printf "%T@ %f\n" | sort -nr | head -n 1 | awk '{print $2}' | sed 's/\.mat$//') + mv audio_out.wav $latest_file.wav + + echo "Closing" + + exit +} + +# launch the audio device recorder +yarpdev --device AudioPlayerWrapper --name /YarpRobotLogger/audio --subdevice audioToFileDevice --start --file_name audio_out.wav --save_mode overwrite_file & +bg_pid1=$! +yarp wait /YarpRobotLogger/audio/audio:i +yarp connect $input_port_audio /YarpRobotLogger/audio/audio:i fast_tcp + +# launch the logger device +yarprobotinterface --config launch-yarp-robot-logger.xml & +bg_pid2=$! + +# register the signal handlers +trap handle_sigint SIGINT +trap handle_exit EXIT + +# wait for closing the application +wait "$bg_pid1" +bg_exit_status1=$? + +wait "$bg_pid2" +bg_exit_status2=$?