Created
October 26, 2020 13:59
-
-
Save peci1/501ad6decba37e1f72eeb31898fc3aad to your computer and use it in GitHub Desktop.
Launcher for path_tracer subt script that automatically records a video, autoconfigures the top-view camera to view exactly the explored space, zooms out several levels in the end to show the whole world, and repeats the last frames of the video a few times for easier inspection of what the state was in the very end.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
[ $# -lt 1 ] && echo "Provide path to simulator logs" && exit 1 | |
dir=$1 | |
[ ! -f "${dir}/state.tlog" ] && echo "The given path is incorrect, it doesn't contain file state.tlog" && exit 1 | |
tracer_conf="${dir}/../../path_tracer.yml" | |
[ $# -gt 1 ] && tracer_conf="$2" | |
world="$(cat "${dir}/run.yml" | grep "world_name" | cut -d: -f 2 | tr -d "[:space:]")" | |
min_x=$(cat "${dir}"/pos-data/*.data | cut -d " " -f 3 | sort -n | head -n1) | |
max_x=$(cat "${dir}"/pos-data/*.data | cut -d " " -f 3 | sort -n | tail -n1) | |
min_y=$(cat "${dir}"/pos-data/*.data | cut -d " " -f 4 | sort -n | head -n1) | |
max_y=$(cat "${dir}"/pos-data/*.data | cut -d " " -f 4 | sort -n | tail -n1) | |
range_x=$(python -c "print($max_x - $min_x)") | |
range_y=$(python -c "print($max_y - $min_y)") | |
center_x=$(python -c "print($range_x/2.0 + $min_x)") | |
center_y=$(python -c "print($range_y/2.0 + $min_y)") | |
[ -z "$zoom" ] && zoom=0.8 | |
# we assume 16:9 simulator window | |
zoom_x=$(python -c "print($range_x * $zoom * 9 / 16)") | |
zoom_y=$(python -c "print($range_y * $zoom)") | |
zoom_z=$(python -c "print(max($zoom_x, $zoom_y))") | |
mkdir -p $HOME/.ignition/launch | |
mv $HOME/.ignition/launch/gui.config{,.bak} | |
cat << END > $HOME/.ignition/launch/gui.config | |
<window> | |
<width>1920</width> | |
<height>1080</height> | |
<style | |
material_theme='Light' | |
material_primary='DeepOrange' | |
material_accent='LightBlue' | |
toolbar_color_light='#f3f3f3' | |
toolbar_text_color_light='#111111' | |
toolbar_color_dark='#414141' | |
toolbar_text_color_dark='#f3f3f3' | |
plugin_toolbar_color_light='#bbdefb' | |
plugin_toolbar_text_color_light='#111111' | |
plugin_toolbar_color_dark='#607d8b' | |
plugin_toolbar_text_color_dark='#eeeeee' | |
/> | |
<menus> | |
<drawer default='false'> | |
</drawer> | |
</menus> | |
</window> | |
END | |
IGN_PARTITION=PATH_TRACER ign launch -v 4 path_tracer.ign worldName:=${world} & | |
sim_pid=$! | |
sleep 30 | |
mv $HOME/.ignition/launch/gui.config{.bak,} | |
IGN_PARTITION=PATH_TRACER ign service -s /gui/move_to/pose --reqtype ignition.msgs.GUICamera --reptype ignition.msgs.Boolean --timeout 2000 --req "pose: {position: {x: ${center_x}, y: ${center_y}, z: ${zoom_z}}}" | |
IGN_PARTITION=PATH_TRACER ign service -s /gui/record_video --reqtype ignition.msgs.VideoRecord --reptype ignition.msgs.Boolean --timeout 2000 --req "start: true, format: 'mp4', save_filename: '$dir/path_trace.tmp.mp4'" | |
path_tracer "${dir}" "${tracer_conf}" | tee "${dir}"/tracer.log | |
# fly into the sky in the end | |
z=${zoom_z} | |
for i in $(seq 1 4); do | |
sleep 10 | |
z=$(python -c "print($z + 50)") | |
IGN_PARTITION=PATH_TRACER ign service -s /gui/move_to/pose --reqtype ignition.msgs.GUICamera --reptype ignition.msgs.Boolean --timeout 2000 --req "pose: {position: {x: ${center_x}, y: ${center_y}, z: ${z}}}" | |
done | |
sleep 20 | |
IGN_PARTITION=PATH_TRACER ign service -s /gui/record_video --reqtype ignition.msgs.VideoRecord --reptype ignition.msgs.Boolean --timeout 2000 --req 'stop: true' | |
sleep 10 | |
kill $sim_pid | |
killall atop | |
killall bwm-ng | |
# extend the video with its last frame by 10 seconds so that it's easier to see the artifact reports in the end | |
ffmpeg -y -i "${dir}"/path_trace.tmp.mp4 -filter_complex "[0]trim=0:10[hold];[0][hold]concat[extended];[extended][0]overlay" "${dir}"/path_trace.mp4 | |
rm "${dir}"/path_trace.tmp.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment