def reset(self): self.fluidsim.set_state(fluids.State(**self.state_args)) car_keys = list(self.fluidsim.get_control_keys()) assert len(car_keys) == 1 obs = self.fluidsim.get_observations(car_keys) return obs[car_keys[0]].get_array()
import fluids import pygame import numpy as np simulator = fluids.FluidSim( visualization_level=1, # How much debug visualization you want to enable. Set to 0 for no vis fps=0, # If set to non 0, caps the FPS. Target is 30 obs_space=fluids.OBS_GRID, # OBS_BIRDSEYE, OBS_GRID, or OBS_NONE background_control=fluids.BACKGROUND_CSP, ) # BACKGROUND_CSP or BACKGROUND_NULL state = fluids.State( layout=fluids.STATE_CITY, background_cars=10, # How many background cars background_peds=10, controlled_cars=1, # How many cars to control. Set to 0 for background cars only ) simulator.set_state(state) car_keys = simulator.get_control_keys() while True: actions = {} # Uncomment any of these lines. # VelocityAction is vel for car to move along trajectory # SteeringAction is steer, acc control # KeyboardAction is use keyboard input # SteeringVelAction is steer, vel control
obs = { "none": fluids.OBS_NONE, "birdseye": fluids.OBS_BIRDSEYE, "grid": fluids.OBS_GRID, "qlidar": fluids.OBS_QLIDAR }[args.o] simulator = fluids.FluidSim(visualization_level=args.v, fps=args.fps, obs_space=obs, screen_dim=args.screen_dim, background_control=fluids.BACKGROUND_CSP) state = fluids.State(layout=args.state, background_cars=args.b, controlled_cars=args.c, background_peds=args.p, use_traffic_lights=args.trafficlights, use_ped_lights=args.pedlights) simulator.set_state(state) if args.datasaver != "": data_saver = fluids.DataSaver(fluid_sim=simulator, file_path=args.datasaver, batch_size=4) simulator.set_data_saver(data_saver) t = 0 while not args.time or t < args.time: actions = { k: fluids.KeyboardAction()
"unlimited" if not args.time else args.time)) fluids_print("") obs = { "none": fluids.OBS_NONE, "birdseye": fluids.OBS_BIRDSEYE, "grid": fluids.OBS_GRID }[args.o] simulator = fluids.FluidSim(visualization_level=args.v, fps=0, obs_space=obs, background_control=fluids.BACKGROUND_CSP) state = fluids.State(layout=args.state, background_cars=args.b, controlled_cars=args.c, background_peds=args.p) simulator.set_state(state) t = 0 while not args.time or t < args.time: actions = { k: fluids.KeyboardAction() for k in simulator.get_control_keys() } rew = simulator.step(actions) obs = simulator.get_observations(simulator.get_control_keys()) simulator.render() t = t + 1
def reset(self): self.fluidsim.set_state(fluids.State(**STATE_ARGS)) car_keys = list(self.fluidsim.get_control_keys()) assert (len(car_keys) == 1) obs = self.fluidsim.get_observations(car_keys) return obs[car_keys[0]].get_array()