00001
00002 import os
00003 import argparse
00004 import rospkg
00005 import time
00006 import ConfigParser
00007 import socket
00008
00009 parser = argparse.ArgumentParser(description="Create and run multi-robot exploration.")
00010
00011 parser.add_argument("-t", "--time", metavar="HH-MM-SS", default=[time.strftime("%H-%M-%S", time.localtime())],
00012 dest="time", nargs=1, help="The name of the 'time'-directory for the log path.")
00013 parser.add_argument("-d", "--date", metavar="yy-mm-dd", default=[time.strftime("%y-%m-%d", time.localtime())],
00014 dest="date", nargs=1, help="The name of the 'time'-directory for the log path.")
00015 parser.add_argument("-i", "--sim-id", default=[1], nargs=1, metavar="ID",
00016 help="The ID of the execution run", dest="sim_id")
00017 parser.add_argument("--exp-strategy",dest="exploration_strategy",type=int,nargs="?",default=1,
00018 help="The strategy to be used for exploration.",choices=range(0,7))
00019 parser.add_argument("--screen-output",dest="screen_output",default=False,help="Set ROS output to screen.",
00020 action="store_true")
00021 parser.add_argument("--interface",dest='interface',nargs='?',type=str,default='wlan0')
00022
00023 args, unknown = parser.parse_known_args()
00024
00025
00026
00027 if args.screen_output:
00028 output_type = "screen"
00029 else:
00030 output_type = "log"
00031
00032 rospack = rospkg.RosPack()
00033 sim_id = args.sim_id[0]
00034
00035 package_path = rospack.get_path("explorer")
00036 launch_file = "auto_generated_launch_exploration.launch";
00037 launch_path = os.path.join(package_path, "launch", launch_file)
00038
00039 t = time.localtime()
00040 log_path = os.path.join(rospack.get_path("multi_robot_analyzer"), "logs", args.date[0], args.time[0], str(sim_id))
00041 fh_launch_file = open(launch_path,"w")
00042 fh_launch_file.truncate()
00043 print ("Writing File headers")
00044 fh_launch_file.write("<?xml version=\"1.0\"?>\n")
00045 fh_launch_file.write("<launch>\n")
00046
00047
00048 fh_launch_file.write("\t<include file=\"$(find explorer)/launch/simple_navigation_prerequisites_hydro_$(env ROBOT_PLATFORM).launch\">\n")
00049 fh_launch_file.write("\t\t<arg name=\"log_path\" value=\"%s\" />\n" % log_path)
00050 fh_launch_file.write("\t</include>\n\n")
00051
00052 fh_launch_file.write("\t<include file=\"$(find explorer)/launch/simple_navigation_$(env ROBOT_PLATFORM).launch\">\n")
00053 fh_launch_file.write("\t\t<arg name=\"frontier_selection\" value=\"%s\" />" %args.exploration_strategy)
00054 fh_launch_file.write("\t\t<arg name=\"log_path\" value=\"%s\" />\n" % log_path)
00055 fh_launch_file.write("\t</include>\n\n")
00056
00057 fh_launch_file.write("\t<include file=\"$(find adhoc_communication)/launch/adhoc_communication.launch\">\n")
00058 fh_launch_file.write("\t\t<arg name=\"log_path\" value=\"%s\" />\n" %log_path)
00059 fh_launch_file.write("\t\t<arg name=\"interface\" value=\"%s\" />\n" %args.interface)
00060 fh_launch_file.write("\t</include>\n\n")
00061
00062 fh_launch_file.write("\t<include file=\"$(find connection_manager)/launch/connection_manager.launch\">\n")
00063 fh_launch_file.write("\t\t<arg name=\"log_path\" value=\"%s\" />\n" %log_path)
00064 fh_launch_file.write("\t\t<arg name=\"output\" value=\"%s\" />\n" %output_type)
00065 fh_launch_file.write("\t</include>\n\n")
00066
00067 fh_launch_file.write("\t<include file=\"$(find map_merger)/launch/map_merger.launch\">\n")
00068 fh_launch_file.write("\t\t<arg name=\"output\" value=\"%s\" />\n" %output_type)
00069 fh_launch_file.write("\t\t<arg name=\"log_path\" value=\"%s\" />\n" %log_path)
00070 fh_launch_file.write("\t\t<arg name=\"use_sim_time\" value=\"false\" />\n")
00071 fh_launch_file.write("\t</include>\n\n")
00072
00073
00074 fh_launch_file.write("</launch>\n")
00075 fh_launch_file.close()
00076
00077 print("start_time_run_%s" %sim_id, "%s" %time.ctime())
00078 os.system("roslaunch explorer %s" %launch_file)