Skip to content

Commit

Permalink
added scripts for use_sim_time management (#183)
Browse files Browse the repository at this point in the history
Co-authored-by: hosokawa <hosokawa@sng-3f-ros2-eval.l.sng.tier4.jp>
  • Loading branch information
hosokawa-ikuto and hosokawa authored Mar 12, 2021
1 parent 0bead67 commit 700dcdc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scripts/add_aw_ros2_use_sim_time_into_launch_xml.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/perl

$use_sim_time_str='<param name="use_sim_time" value="$(env AW_ROS2_USE_SIM_TIME false)"/>' . "\n";

$out_line="";
while(<>){
if(/^(\s*)<\s*node\s/){
$indent=$1;
$out_line = $indent . " " . $use_sim_time_str;
if(/\/\s*>\s*$/){
$re_str = quotemeta($&);
~s/$re_str/ >\n/;
print;
$out_line = $out_line . $indent . "</node>\n";
print $out_line;
$out_line = "";
}else{
print;
}
}elsif($out_line ne ""){
if(/^\s*<\s*param\s*name.*use_sim_time.*AW_ROS2_USE_SIM_TIME/){
$out_line = "";
}elsif(/^\s*<\s*\/\s*node\s*>\s*$/){
print $out_line;
$out_line = "";
}
print;
}else{
print;
}
}
21 changes: 21 additions & 0 deletions scripts/add_aw_ros2_use_sim_time_into_launch_xml.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

if [ -n "$1" ]; then
find_dir=$1
else
echo "Usage: $0 <dir ('install' dir is recommended)>"
exit 0
fi

patch_script=$(dirname $(realpath $0))/$(basename $0 .sh).pl

for xml in $(find $find_dir -type f | grep launch.xml$); do
echo "mv $xml ${xml}.org_tmp"
eval "mv $xml ${xml}.org_tmp"
echo "$patch_script ${xml}.org_tmp > $xml"
eval "$patch_script ${xml}.org_tmp > $xml"
echo "rm ${xml}.org_tmp"
eval "rm ${xml}.org_tmp"
echo ""
done

8 changes: 8 additions & 0 deletions scripts/get_use_sim_time_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
( for node in $(ros2 run topic_tools node_list |& grep \/ | perl -pe "~s/^[^\/]\//\//")
#for node in $(ros2 param list|grep :)
do
#n=$(dirname $node)/$(basename $node :)
#echo "$n: use_sim_time: $(ros2 param get $n use_sim_time)"
echo "$node: use_sim_time: $(ros2 param get $node use_sim_time)"
done) |& grep \/

0 comments on commit 700dcdc

Please sign in to comment.