Created
October 27, 2021 12:07
-
-
Save peci1/6599f7236585a5a4bece11f7b78e1798 to your computer and use it in GitHub Desktop.
subt virtual path_tracer launcher script
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="$(d="${dir}"; while [ "$d" != "/" ]; do if [ -f "${d}/path_tracer.yml" ]; then echo "${d}/path_tracer.yml"; break; else d="$(dirname "$d")"; fi; done)" | |
[ -z "${tracer_conf}" ] && echo "path_tracer.yml not found in the given or any parent directory" >&2 && exit 1 | |
echo "Using path tracer configuration from ${tracer_conf}" | tee "${dir}"/tracer.log | |
grep rtf "${tracer_conf}" | tee -a "${dir}"/tracer.log | |
tracer_partition="${IGN_PARTITION}PATH_TRACER" | |
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="${tracer_partition}" ign launch -v 4 path_tracer.ign worldName:=${world} & | |
sim_pid=$! | |
mv $HOME/.ignition/launch/gui.config{.bak,} | |
sleep_time=180 | |
echo "Sleeping for $sleep_time" | |
sleep $sleep_time | |
rosrun subt_ign path_tracer "${dir}" "${tracer_conf}" "${tracer_partition}" "${center_x} ${center_y} ${zoom_z}" "${world}" 2>&1 | tee -a "${dir}"/tracer.log | |
kill $sim_pid | |
killall atop | |
killall bwm-ng | |
# extract the end of the video as a jpeg | |
ffmpeg -y -sseof -15 -t 1 -i "${dir}"/path_trace.mp4 -vsync 0 -q:v 2 -update true "${dir}"/path_trace.jpg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment