Skip to content

Commit

Permalink
Merge pull request #71 from usdot-fhwa-stol/update/carla_mosaic_bridge
Browse files Browse the repository at this point in the history
Update/carla mosaic bridge
  • Loading branch information
kjrush authored Jun 29, 2022
2 parents ea707db + 71a28e2 commit 54b0b6c
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 5,317 deletions.
3 changes: 0 additions & 3 deletions co-simulation/bridge/bridge.bat

This file was deleted.

7 changes: 0 additions & 7 deletions co-simulation/bridge/bridge.sh

This file was deleted.

2 changes: 1 addition & 1 deletion co-simulation/bridge/carla_integration/carla_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, host, port, step_length):
except:
print("reconnect carla")
connected=False

if connected:
print("CARLA simulator connected")
break
Expand Down
19 changes: 9 additions & 10 deletions co-simulation/bridge/carla_integration/sumo_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ def __init__(self):
self._current_program = {} # {tlid: program_id}
self._current_phase = {} # {tlid: index_phase}


for tlid in traci.trafficlight.getIDList():
#self.subscribe(tlid)
self.subscribe(tlid)

self._tls[tlid] = {}
for tllogic in traci.trafficlight.getAllProgramLogics(tlid):
Expand Down Expand Up @@ -269,14 +268,14 @@ def tick(self):
Tick to traffic light manager
"""
if self._off is False:
for tl_id in traci.trafficlight.getIDList():
for tl_id in traci.trafficlight.getIDList():
current_program = traci.trafficlight.getProgram(tl_id)
current_phase = traci.trafficlight.getPhase(tl_id)

if current_program != 'online':
self._current_program[tl_id] = current_program
self._current_phase[tl_id] = current_phase


# ==================================================================================================
# -- sumo simulation -------------------------------------------------------------------------------
Expand All @@ -290,7 +289,7 @@ def __init__(self, sumo_net, step_length, host=None, port=None):

logging.info('Connection to bridge server. Host: %s Port: %s', host, port)
traci.init(host=host, port=port)

self.net = sumo_net

# Variable to asign an id to new added actors.
Expand All @@ -299,7 +298,7 @@ def __init__(self, sumo_net, step_length, host=None, port=None):
# Structures to keep track of the spawned and destroyed vehicles at each time step.
self.spawned_actors = set()
self.destroyed_actors = set()

# Traffic light manager.
self.traffic_light_manager = None

Expand Down Expand Up @@ -355,9 +354,9 @@ def get_actor(actor_id):
"""
Accessor for sumo actor.
"""
type_id = traci.vehicle.getTypeID(actor_id)
type_id = traci.vehicle.getTypeID(actor_id)
vclass = SumoActorClass(traci.vehicle.getVehicleClass(actor_id))
color = traci.vehicle.getColor(actor_id)
color = traci.vehicle.getColor(actor_id)

length = traci.vehicle.getLength(actor_id)
width = traci.vehicle.getWidth(actor_id)
Expand Down Expand Up @@ -454,7 +453,7 @@ def tick(self):
self.traffic_light_manager = SumoTLManager()
self.firstTime = False
traci.simulationStep()
#self.traffic_light_manager.tick()
self.traffic_light_manager.tick()
# Update data structures for the current frame.
self.spawned_actors = set(traci.simulation.getDepartedIDList())
self.destroyed_actors = set(traci.simulation.getArrivedIDList())
Expand All @@ -466,7 +465,7 @@ def tick(self):
print(message)

# Send V2x message to CARLA ambassador
if self.sendV2xInterval == 10:
if self.sendV2xInterval == 10:
traci.setV2xMessage("carla_0; A V2X messages from CARLA simulator.")
self.sendV2xInterval = 0

Expand Down
9 changes: 5 additions & 4 deletions co-simulation/bridge/carla_mosaic_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def main(args):
else:
world = carla_simulation.client.get_world()

carla_simulation = CarlaSimulation(args.host, args.port, args.step_length)
# ---------------
# sumo simulation
# ---------------
Expand All @@ -78,7 +79,7 @@ def main(args):
print("load net file")
else:
# Temporal folder to save intermediate files.
tmpdir = tempfile.mkdtemp()
tmpdir = tempfile.mkdtemp()
current_map = world.get_map()
xodr_file = os.path.join(tmpdir, current_map.name + '.xodr')
current_map.save_to_disk(xodr_file)
Expand Down Expand Up @@ -108,7 +109,7 @@ def main(args):
print("Socket server closed")

finally:
try:
try:
synchronization.close()
except:
print("Connection closed")
Expand Down Expand Up @@ -137,10 +138,10 @@ def main(args):
default=8913,
type=int,
help='TCP port to listen to (default: None)')
argparser.add_argument('-m',
argparser.add_argument('-m',
'--map',
help='load a new map')
argparser.add_argument('net_file',
argparser.add_argument('net_file',
type=str,
default=None,
help='load the net file')
Expand Down
Loading

0 comments on commit 54b0b6c

Please sign in to comment.