MCPcopy Create free account
hub / github.com/AdaCompNUS/summit / spawn_destroy_loop

Function spawn_destroy_loop

PythonAPI/examples/gamma_crowd.py:1217–1252  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

1215
1216
1217def spawn_destroy_loop(args):
1218 try:
1219 # Wait for crowd service.
1220 time.sleep(3)
1221 c = Context(args)
1222
1223 # Upload bounds.
1224 c.crowd_service.simulation_bounds = (c.bounds_min, c.bounds_max)
1225
1226 last_bounds_update = None
1227
1228 print('Spawn-destroy loop running.')
1229
1230 while True:
1231 start = time.time()
1232
1233 # Download bounds
1234 if last_bounds_update is None or start - last_bounds_update > 1.0:
1235 new_bounds = c.crowd_service.simulation_bounds
1236 if (new_bounds[0] is not None and new_bounds[0] != c.bounds_min) or \
1237 (new_bounds[1] is not None and new_bounds[1] != c.bounds_max):
1238 c.bounds_min = new_bounds[0]
1239 c.bounds_max = new_bounds[1]
1240 c.bounds_occupancy = carla.OccupancyMap(c.bounds_min, c.bounds_max)
1241 c.sumo_network_spawn_segments = c.sumo_network_segments.intersection(carla.OccupancyMap(c.bounds_min, c.bounds_max))
1242 c.sumo_network_spawn_segments.seed_rand(c.rng.getrandbits(32))
1243 c.sidewalk_spawn_segments = c.sidewalk_segments.intersection(carla.OccupancyMap(c.bounds_min, c.bounds_max))
1244 c.sidewalk_spawn_segments.seed_rand(c.rng.getrandbits(32))
1245 last_bounds_update = time.time()
1246
1247 do_spawn(c)
1248 do_destroy(c)
1249 time.sleep(max(0, 1 / SPAWN_DESTROY_MAX_RATE - (time.time() - start)))
1250 # print('({}) Spawn-destroy rate: {} Hz'.format(os.getpid(), 1 / max(time.time() - start, 0.001)))
1251 except Pyro4.errors.ConnectionClosedError:
1252 pass
1253
1254
1255def control_loop(args):

Callers

nothing calls this directly

Calls 4

ContextClass · 0.85
do_spawnFunction · 0.85
do_destroyFunction · 0.85
OccupancyMapMethod · 0.80

Tested by

no test coverage detected