def check_simulation_one_step_conf(id_world, world, id_vehicle, vehicle): sim = VehicleSimulation(vehicle, world) dt = 1 try: sim.new_episode() cmds = random_commands(sim.vehicle.dynamics.get_commands_spec()) sim.simulate(cmds, dt) sim.compute_observations() except: logger.error('Error for vehicle=%s world=%s' % (id_vehicle, id_world)) raise
def set_commands(self, commands, commands_source): if not self.boot_episode_started: raise Exception('set_commands() called before new_episode().') self.commands_source = commands_source VehicleSimulation.simulate(self, commands, self.dt)
def run_simulation(task, vehicle, agent, log, dt, maxT): world = task.get_world() simulation = VehicleSimulation(world=world, vehicle=vehicle) directions = simulation.vehicle.sensors[0].sensor.directions vehicle_spec = VehicleSpec(directions=directions) agent.init(vehicle_spec) simulation.new_episode() tmp_log = log + '.active' ldir = os.path.dirname(log) #last = os.path.join(ldir, 'last.yaml') logger.info('Writing on log %r.' % log) #logger.info(' (also accessible as %r)' % last) if not os.path.exists(ldir): os.makedirs(ldir) #if os.path.exists(last): # os.unlink(last) logfile = open(tmp_log, 'w') #assert not os.path.exists(last) assert os.path.exists(tmp_log) #logger.info('Link %s, %s' % (tmp_log, last)) #os.symlink(tmp_log, last) logger.info('Simulation dt=%.3f max T: %.3f' % (dt, maxT)) while True: simulation.compute_observations() # TODO: perhaps this needs to be gerealized luminance = simulation.vehicle.sensors[0].current_observations['luminance'] observations = VehicleObservations(time=simulation.timestamp, dt=dt, luminance=luminance) agent.process_observations(observations) commands = agent.choose_commands() # TODO: check format if logfile is not None: y = simulation.to_yaml() y['commands'] = commands.tolist() logfile.write('---\n') yaml.dump(y, logfile, Dumper=Dumper) logger.info('t=%.3f pose: %s' % (simulation.timestamp, SE2.friendly(SE2_from_SE3(simulation.vehicle.get_pose())))) if task.end_condition(simulation): break if simulation.timestamp > maxT: # TODO: add why we finished break simulation.simulate(commands, dt) logfile.close() if os.path.exists(log): os.unlink(log) assert not os.path.exists(log) os.rename(tmp_log, log) assert not os.path.exists(tmp_log) assert os.path.exists(log)