5 Current script generates rviz files based on the templates files of 6 rviz/templates and usign the current computer's hostname for determining the 7 namespaces of the topics. This is a required step for visualizing multi-robot 8 graphSLAM when running based on rosbags or based on measurements from Gazebo 9 since each multi-robot agent runs on a separate ROS core to simulate as much as 10 possible a real-time setup. 19 from colorlog
import ColoredFormatter
21 LOG_LEVEL = logging.DEBUG
22 LOGFORMAT = (
"%(log_color)s%(levelname)-5s%(reset)s " 23 "| %(log_color)s%(message)s%(reset)s")
25 logging.root.setLevel(LOG_LEVEL)
26 formatter = ColoredFormatter(LOGFORMAT)
27 stream = logging.StreamHandler()
28 stream.setLevel(LOG_LEVEL)
29 stream.setFormatter(formatter)
31 logger = logging.getLogger(
"RvizRenamer")
32 logger.setLevel(LOG_LEVEL)
33 logger.addHandler(stream)
38 """Read from a single template file and write the modified contents to an 39 actual rviz file one directory prior to the templates directory. 42 with open(templ_file,
'r') as templ: 43 templ_lines = templ.readlines() 44 head, tail = os.path.split(templ_file) 47 actual_file = os.path.join(os.path.dirname(head), tail)
48 logger.info(
"Writing file: %s" % os.path.abspath(actual_file))
49 with open(actual_file,
'w')
as f:
52 f.writelines([l.format(**replace_dict)
for l
in templ_lines])
56 """Make sure that the user understands what the script does.""" 59 logger.warning(
"Current script modifies the template rviz files " 60 "found in rviz/templates so that their topics match the " 61 "running computer's hostname.\n" 62 "Run this without any additional arguments.")
63 logger.warning(
"Exiting...")
70 logger.info(
"Initializing...")
74 script_dir = os.path.dirname(os.path.realpath(__file__))
75 rviz_dir_path = os.path.join(script_dir,
"..",
"rviz",
"templates")
77 rviz_templ_files = [os.path.join(rviz_dir_path, i)
78 for i
in os.listdir(rviz_dir_path)]
83 rviz_templ_files = filter(
lambda name:
"bag" in name
or "gazebo" in name,
86 curr_hostname = socket.gethostname()
87 replace_dict = {
"HOSTNAME_PLACEHOLDER": curr_hostname}
89 logger.info(
"Rviz files to operate on:\n%s\n\n" %
90 os.linesep.join([os.path.abspath(f)
91 for f
in rviz_templ_files]))
94 logger.info(
"Replacing: %s ==> %s" % replace_dict.items()[0])
96 for templ_file
in rviz_templ_files:
98 logger.info(
"All done.")
101 if __name__ ==
"__main__":
def rename_topics_in_rviz_file(templ_file, replace_dict)