test_route_repair.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 import os
00003 import argparse
00004 import rospkg
00005 import rospy
00006 import time
00007 import ConfigParser
00008 import random
00009 import socket
00010 
00011 parser = argparse.ArgumentParser(description="Create and run multi-robot simulation.")
00012 parser.add_argument("-n", "--number-of-robots", dest="number_of_robots", type=int,
00013                     help="Number of robots to simulate", metavar="N", default=[2],
00014                    nargs=1)
00015 parser.add_argument("-d", "--distance", metavar="D", default=[10],
00016                     dest="distance", nargs=1, help="The name of the 'time'-directory for the log path.")
00017 
00018 args, unknown = parser.parse_known_args()
00019 
00020 
00021 if len(unknown) > 0:
00022     print "error: unrecognized arguments: %s" %unknown
00023     print "Please check the new syntax of this script.\n"
00024     parser.print_help()
00025     exit(0)
00026 
00027 rospack = rospkg.RosPack()
00028 package_path = rospack.get_path("adhoc_communication")
00029 launch_file = "test_route_repair.launch"
00030 launch_path = os.path.join(package_path, "launch", launch_file)
00031 num_robots = args.number_of_robots[0]
00032 distance = args.distance[0]
00033 
00034 robot_macs = []
00035 for num_robot in range(0,num_robots):
00036     robot_macs.append("02:%02d:00:00:00:00" %(num_robot + 1))
00037 
00038 
00039 date = time.strftime("%y-%m-%d", time.localtime())
00040 ttime = time.strftime("%H-%M-%S", time.localtime())
00041 log_path = os.path.join(rospack.get_path("multi_robot_analyzer"), "logs", date, ttime)
00042 
00043 
00044 fh_launch_file = open(launch_path,"w")
00045 fh_launch_file.truncate()
00046 
00047 fh_launch_file.write("<?xml version=\"1.0\"?>\n")
00048 fh_launch_file.write("<launch>\n")
00049 fh_launch_file.write("<node pkg=\"adhoc_communication\" name=\"simple_simulator\" type=\"simple_simulator.py\" output=\"screen\" > \n")
00050 fh_launch_file.write("\t<param name=\"num_robots\" value=\"%i\" /> \n"%num_robots)
00051 fh_launch_file.write("\t<param name=\"distance\" value=\"%i\" /> \n"%distance)
00052 fh_launch_file.write("</node> \n")
00053 for num_robot in range(0,num_robots):
00054         fh_launch_file.write("\t<group ns=\"robot_%i\">\n"% num_robot)
00055         fh_launch_file.write("\t\t<include file=\"$(find adhoc_communication)/launch/adhoc_communication.launch\">\n")
00056         fh_launch_file.write("\t\t\t<arg name=\"use_sim_time\" value=\"false\" />\n")
00057         fh_launch_file.write("\t\t\t<arg name=\"num_of_robots\" value=\"%s\" />\n" % args.number_of_robots[0])
00058         fh_launch_file.write("\t\t\t<arg name=\"log_path\" value=\"%s\" />\n" %log_path)
00059         fh_launch_file.write("\t\t\t<arg name=\"emulate\" value=\"false\" />\n") 
00060         fh_launch_file.write("\t\t\t<arg name=\"hostname\" value=\"robot_%i\" />\n"%num_robot) 
00061         fh_launch_file.write("\t\t\t<arg name=\"interface\" value=\"lo\" />\n")
00062         fh_launch_file.write("\t\t\t<arg name=\"simulation_mode\" value=\"true\" />\n") 
00063         fh_launch_file.write("\t\t\t<arg name=\"mac\" value=\"%s\" />\n" %robot_macs[num_robot])
00064         fh_launch_file.write("\t\t</include>\n")
00065         fh_launch_file.write("\t</group>\n")
00066 fh_launch_file.write("</launch>")
00067 fh_launch_file.close()
00068 os.system("roslaunch adhoc_communication test_route_repair.launch")
00069 
00070 


adhoc_communication
Author(s): Guenter Cwioro , Torsten Andre
autogenerated on Thu Aug 27 2015 11:56:40