Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a bash script to automatically log the audio #681

Merged
merged 2 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions devices/YarpRobotLoggerDevice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

43 changes: 43 additions & 0 deletions devices/YarpRobotLoggerDevice/scripts/blf-logger-with-audio.sh
Original file line number Diff line number Diff line change
@@ -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=$?