diff --git a/CHANGELOG.md b/CHANGELOG.md index ea38956c5..1378e7803 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,12 +10,12 @@ * Added PythonAPI `carla.world.get_vehicles_light_states` to get all the car light states at once * OpenDRIVE ingestion bugfixes * Added Dynamic Vision Sensor (DVS) camera based on ESIM simulation http://rpg.ifi.uzh.ch/esim.html + * Added support for additional TraCI clients in Sumo co-simulation * Added API functions `get_right_vector` and `get_up_vector` * Added parameter to enable/disable pedestrian navigation in standalone mode * Improved mesh split in standalone mode * Fixed large RAM usage when loading polinomial geometry from OpenDRIVE - ## CARLA 0.9.9 * Introduced hybrid mode for Traffic Manager diff --git a/Co-Simulation/Sumo/run_synchronization.py b/Co-Simulation/Sumo/run_synchronization.py index 1fc6e0804..b5b28d9af 100644 --- a/Co-Simulation/Sumo/run_synchronization.py +++ b/Co-Simulation/Sumo/run_synchronization.py @@ -231,7 +231,7 @@ def synchronization_loop(args): Entry point for sumo-carla co-simulation. """ sumo_simulation = SumoSimulation(args.sumo_cfg_file, args.step_length, args.sumo_host, - args.sumo_port, args.sumo_gui) + args.sumo_port, args.sumo_gui, args.client_order) carla_simulation = CarlaSimulation(args.carla_host, args.carla_port, args.step_length) synchronization = SimulationSynchronization(sumo_simulation, carla_simulation, args.tls_manager, @@ -282,6 +282,11 @@ if __name__ == '__main__': default=0.05, type=float, help='set fixed delta seconds (default: 0.05s)') + argparser.add_argument('--client-order', + metavar='TRACI_CLIENT_ORDER', + default=1, + type=int, + help='client order number for the co-simulation TraCI connection (default: 1)') argparser.add_argument('--sync-vehicle-lights', action='store_true', help='synchronize vehicle lights state (default: False)') diff --git a/Co-Simulation/Sumo/spawn_npc_sumo.py b/Co-Simulation/Sumo/spawn_npc_sumo.py index 62a760c8d..7ea81c749 100644 --- a/Co-Simulation/Sumo/spawn_npc_sumo.py +++ b/Co-Simulation/Sumo/spawn_npc_sumo.py @@ -66,7 +66,7 @@ from util.netconvert_carla import netconvert_carla # ================================================================================================== -def write_sumocfg_xml(cfg_file, net_file, vtypes_file, viewsettings_file): +def write_sumocfg_xml(cfg_file, net_file, vtypes_file, viewsettings_file, additional_traci_clients=0): """ Writes sumo configuration xml file. """ @@ -79,6 +79,8 @@ def write_sumocfg_xml(cfg_file, net_file, vtypes_file, viewsettings_file): gui_tag = ET.SubElement(root, 'gui_only') ET.SubElement(gui_tag, 'gui-settings-file', {'value': viewsettings_file}) + ET.SubElement(root, 'num-clients', {'value': str(additional_traci_clients+1)}) + tree = ET.ElementTree(root) tree.write(cfg_file, pretty_print=True, encoding='UTF-8', xml_declaration=True) @@ -109,14 +111,15 @@ def main(args): cfg_file = os.path.join(tmpdir, current_map.name + '.sumocfg') vtypes_file = os.path.join(basedir, 'examples', 'carlavtypes.rou.xml') viewsettings_file = os.path.join(basedir, 'examples', 'viewsettings.xml') - write_sumocfg_xml(cfg_file, net_file, vtypes_file, viewsettings_file) + write_sumocfg_xml(cfg_file, net_file, vtypes_file, viewsettings_file, args.additional_traci_clients) sumo_net = sumolib.net.readNet(net_file) sumo_simulation = SumoSimulation(cfg_file, args.step_length, host=None, port=None, - sumo_gui=args.sumo_gui) + sumo_gui=args.sumo_gui, + client_order=args.client_order) # --------------- # synchronization @@ -240,6 +243,16 @@ if __name__ == '__main__': default=0.05, type=float, help='set fixed delta seconds (default: 0.05s)') + argparser.add_argument('--additional-traci-clients', + metavar='TRACI_CLIENTS', + default=0, + type=int, + help='number of additional TraCI clients to wait for (default: 0)') + argparser.add_argument('--client-order', + metavar='TRACI_CLIENT_ORDER', + default=1, + type=int, + help='client order number for the co-simulation TraCI connection (default: 1)') argparser.add_argument('--sync-vehicle-lights', action='store_true', help='synchronize vehicle lights state (default: False)') @@ -266,4 +279,4 @@ if __name__ == '__main__': else: logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) - main(args) \ No newline at end of file + main(args) diff --git a/Co-Simulation/Sumo/sumo_integration/sumo_simulation.py b/Co-Simulation/Sumo/sumo_integration/sumo_simulation.py index 5fb8f9190..05d38a2f2 100644 --- a/Co-Simulation/Sumo/sumo_integration/sumo_simulation.py +++ b/Co-Simulation/Sumo/sumo_integration/sumo_simulation.py @@ -308,7 +308,7 @@ class SumoSimulation(object): """ SumoSimulation is responsible for the management of the sumo simulation. """ - def __init__(self, cfg_file, step_length, host=None, port=None, sumo_gui=False): + def __init__(self, cfg_file, step_length, host=None, port=None, sumo_gui=False, client_order=1): if sumo_gui is True: sumo_binary = sumolib.checkBinary('sumo-gui') else: @@ -330,6 +330,8 @@ class SumoSimulation(object): logging.info('Connection to sumo server. Host: %s Port: %s', host, port) traci.init(host=host, port=port) + traci.setOrder(client_order) + # Retrieving net from configuration file. self.net = _get_sumo_net(cfg_file)