def _prepare_sensors_for_agent_control(self, sim, vehicle_id, agent_id, agent_interface, bubble): plan = Plan(sim.road_map, None, find_route=False) vehicle = sim.vehicle_index.start_agent_observation( sim, vehicle_id, agent_id, agent_interface, plan, boid=bubble.is_boid, ) # Setup mission (also used for observations) # XXX: this is not quite right. route may not be what the agent wants to take. route = sim.traffic_sim.vehicle_route(vehicle_id=vehicle.id) if len(route) > 0: goal = PositionalGoal.from_road(route[-1], sim.scenario.road_map) else: goal = EndlessGoal() mission = Mission(start=Start(vehicle.position[:2], vehicle.heading), goal=goal) plan.create_route(mission)
def attach_sensors_to_vehicles(self, sim, agent_interface, vehicle_ids): """Attach the interface required sensors to the given vehicles""" for sv_id in vehicle_ids: if sv_id in self._vehicle_with_sensors: continue plan = Plan(sim.road_map, None) agent_id = f"Agent-{sv_id}" self._vehicle_with_sensors[sv_id] = agent_id self._agent_interfaces[agent_id] = agent_interface sim.vehicle_index.attach_sensors_to_vehicle( sim, sv_id, agent_interface, plan)
def test_waypoints_sensor(scenarios): scenario = next(scenarios) sim = mock.Mock() vehicle = mock.Mock() vehicle.pose = Pose( position=np.array([33, -65, 0]), orientation=np.array([0, 0, 0, 0]), heading_=Heading(0), ) mission = scenario.missions[AGENT_ID] plan = Plan(scenario.road_map, mission) sensor = WaypointsSensor(vehicle, plan) waypoints = sensor() assert len(waypoints) == 3
def add_trap_for_agent(self, agent_id: str, mission: Mission, road_map) -> bool: """Add a new trap to capture an actor for the given agent.""" if mission is None: mission = Mission.random_endless_mission(road_map) if not mission.entry_tactic: mission = replace(mission, entry_tactic=default_entry_tactic()) if (not isinstance(mission.entry_tactic, TrapEntryTactic) and mission.entry_tactic): return False plan = Plan(road_map, mission) trap = self._mission2trap(road_map, plan.mission) self._traps[agent_id] = trap return True
def _make_vehicle(sim, agent_id, mission, initial_speed): agent_interface = sim.agent_manager.agent_interface_for_agent_id( agent_id) plan = Plan(sim.road_map, mission) # 3. Apply agent vehicle association. vehicle = sim.vehicle_index.build_agent_vehicle( sim, agent_id, agent_interface, plan, sim.scenario.vehicle_filepath, sim.scenario.tire_parameters_filepath, True, sim.scenario.surface_patches, initial_speed=initial_speed, boid=False, ) return vehicle
def _add_agent(self, agent_id, agent_interface, agent_model, sim, boid=False, trainable=True): # TODO: Disentangle what is entangled below into: # 1. AgentState initialization, # 2. Agent vehicle initialization, which should live elsewhere, and # 3. Provider related state initialization, which does not belong here. # # A couple of things forced the current unhappy state -- # # 1. SMARTS internal coordinate system should be 100% unified. Coordinate # transformation should happen only at the interface between SMARTS and # its providers. For example, mission start pose should just be vehicle # initial pose. # 2. AgentState should be allowed to fully initialized (setup) without vehicle # information. We currently rely on the creation of the Vehicle instance to # do the coordinate transformation. :-( # 3. Providers should not be creating vehicles. They do need to get notified # about new vehicles entering their territory through the VehicleState # message. But that does not need to happen at Agent instantiation. assert isinstance(agent_id, str) # SUMO expects strings identifiers scenario = sim.scenario mission = scenario.mission(agent_id) plan = Plan(sim.road_map, mission) vehicle = sim.vehicle_index.build_agent_vehicle( sim, agent_id, agent_interface, plan, scenario.vehicle_filepath, scenario.tire_parameters_filepath, trainable, scenario.surface_patches, agent_model.initial_speed, boid=boid, ) matching_providers = [ provider for provider in sim.providers if agent_interface.action_space in provider.action_spaces ] if matching_providers: assert ( len(matching_providers) == 1 ), f"Found {matching_providers} for action space {agent_interface.action_space}" provider = matching_providers[0] provider.create_vehicle( VehicleState( vehicle_id=vehicle.id, vehicle_type=vehicle.vehicle_type, vehicle_config_type= "passenger", # XXX: vehicles in history missions will have a type pose=vehicle.pose, dimensions=vehicle.chassis.dimensions, source="NEW-AGENT", )) self._agent_interfaces[agent_id] = agent_interface self._social_agent_data_models[agent_id] = agent_model