Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/carla mosaic bridge #71

Merged
merged 1 commit into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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