5 from datetime
import datetime
6 from pathlib
import Path
10 Configuration and commandline parameter for a sick_scan_xd simulation
15 Initializing constructor
22 self.
config_file =
"./src/sick_scan_xd/test/docker/data/multiscan_compact_test01_cfg.json"
23 self.
log_folder = f
"./log/sick_scan_xd_simu/{simu_start_time.strftime('%Y%m%d_%H%M%S')}"
24 parser = argparse.ArgumentParser(description=
"Run a sick_scan_xd simulation")
25 parser.add_argument(
'--os', type=str, help=
"OS (linux or windows)", default=os_name, choices=[
"linux",
"windows"])
26 parser.add_argument(
'--ros', type=str, help=
"ROS version (none, noetic, foxy or humble)", default=
"noetic", choices=[
"none",
"noetic",
"foxy",
"humble"])
27 parser.add_argument(
'--cfg', type=str, help=
"configuration file", default=self.
config_file)
28 parser.add_argument(
'--log_folder', type=str, help=
"log folder", default=self.
log_folder)
29 parser.add_argument(
'--save_messages_jsonfile', type=str, help=
"optional jsonfile to save all received messages", default=
"")
30 parser.add_argument(
'--run_seconds', type=int, help=
"run simulation in seconds, delay before shutdown", default=-1)
32 args = parser.parse_args()
49 json_config = json.load(file_stream)
50 reference_messages_jsonfile = json_config[
"reference_messages_jsonfile"]
53 sick_scan_xd_pointcloud_topics = json_config[
"sick_scan_xd_pointcloud_topics"]
54 sick_scan_xd_laserscan_topics = json_config[
"sick_scan_xd_laserscan_topics"]
55 sick_scan_xd_imu_topics = json_config[
"sick_scan_xd_imu_topics"]
56 args_sick_scan_xd_launch = json_config[
"args_sick_scan_xd_launch"]
57 args_udp_scandata_sender = json_config[
"args_udp_scandata_sender"]
58 args_sopas_server = json_config[
"args_sopas_server"]
61 args_shutdown_nodes = json_config[
"args_shutdown_nodes"]
62 args_shutdown_server = json_config[
"args_shutdown_server"]
64 if len(args.save_messages_jsonfile) > 0:
70 if args.run_seconds >= 0:
74 except Exception
as exc:
75 self.
error_messages.
append(f
"## ERROR SickScanXdSimuConfig: exception {exc}, check configuration file \"{self.config_file}\"")
80 self.
error_messages.
append(f
"## ERROR SickScanXdSimuConfig: could not create output folder \"{self.log_folder}\"")
92 for arg_sick_scan_xd_launch
in args_sick_scan_xd_launch:
93 self.
cmd_sick_scan_xd.
append(f
"./src/sick_scan_xd/build/sick_scan_xd_api_dockertest ./src/sick_scan_xd/launch/{arg_sick_scan_xd_launch} _jsonfile:={self.log_folder}/{self.save_messages_jsonfile}")
95 self.
error_messages.
append(f
"## ERROR SickScanXdSimuConfig: sick_scan_xd launch parameter not configured, check configuration file \"{self.config_file}\"")
98 for arg_shutdown_server
in args_shutdown_server:
107 for arg_rviz
in args_rviz:
111 for arg_sick_scan_xd_launch
in args_sick_scan_xd_launch:
114 self.
error_messages.
append(f
"## ERROR SickScanXdSimuConfig: sick_scan_xd launch parameter not configured, check configuration file \"{self.config_file}\"")
116 for arg_shutdown_nodes
in args_shutdown_nodes:
120 for arg_shutdown_server
in args_shutdown_server:
123 for sick_scan_xd_pointcloud_topic
in sick_scan_xd_pointcloud_topics:
125 for sick_scan_xd_laserscan_topic
in sick_scan_xd_laserscan_topics:
127 for sick_scan_xd_imu_topic
in sick_scan_xd_imu_topics:
136 for arg_rviz
in args_rviz:
140 for arg_sick_scan_xd_launch
in args_sick_scan_xd_launch:
141 arg_sick_scan_xd_launch = arg_sick_scan_xd_launch.replace(
".launch",
".launch.py")
144 self.
error_messages.
append(f
"## ERROR SickScanXdSimuConfig: sick_scan_xd launch parameter not configured, check configuration file \"{self.config_file}\"")
148 for arg_shutdown_server
in args_shutdown_server:
151 for sick_scan_xd_pointcloud_topic
in sick_scan_xd_pointcloud_topics:
153 for sick_scan_xd_laserscan_topic
in sick_scan_xd_laserscan_topics:
155 for sick_scan_xd_imu_topic
in sick_scan_xd_imu_topics:
158 elif self.
os_name ==
"windows":
162 for arg_sopas_server
in args_sopas_server:
165 print(f
"SickScanXdSimuConfig: sopas server parameter not configured, sopas server not started. This is a valid option for error testcases, but check configuration file \"{self.config_file}\" if this is not intended.")
168 for arg_udp_scandata_sender
in args_udp_scandata_sender:
172 if len(reference_messages_jsonfile) > 0
and os.path.exists(reference_messages_jsonfile):
173 shutil.copy(reference_messages_jsonfile, self.
log_folder)