code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
194
url
stringlengths
46
254
license
stringclasses
4 values
def switch_ego_agents(self, agent_interfaces: Dict[str, AgentInterface]): """Change the ego agents in the simulation. Effective on the next reset.""" self._check_valid() self._agent_manager.switch_initial_agents(agent_interfaces) self._is_setup = False
Change the ego agents in the simulation. Effective on the next reset.
switch_ego_agents
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def add_agent_with_mission( self, agent_id: str, agent_interface: AgentInterface, mission: NavigationMission ): """Add an agent to the simulation. The simulation will attempt to provide a vehicle for the agent. """ self._check_valid() # TODO: check that agent_id isn't already used... if self._trap_manager.add_trap_for_agent( agent_id, mission, self.road_map, self.elapsed_sim_time ): self._agent_manager.add_ego_agent(agent_id, agent_interface) else: self._log.warning( f"Unable to add entry trap for new agent '{agent_id}' with mission." )
Add an agent to the simulation. The simulation will attempt to provide a vehicle for the agent.
add_agent_with_mission
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def add_agent_and_switch_control( self, vehicle_id: str, agent_id: str, agent_interface: AgentInterface, mission: NavigationMission, ) -> Vehicle: """Add the new specified ego agent and then take over control of the specified vehicle.""" self._check_valid() self.agent_manager.add_ego_agent(agent_id, agent_interface, for_trap=False) vehicle = self.switch_control_to_agent( vehicle_id, agent_id, mission, recreate=False, is_hijacked=True ) self.create_vehicle_in_providers(vehicle, agent_id, True) return vehicle
Add the new specified ego agent and then take over control of the specified vehicle.
add_agent_and_switch_control
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def switch_control_to_agent( self, vehicle_id: str, agent_id: str, mission: NavigationMission, recreate: bool, is_hijacked: bool, ) -> Vehicle: """Give control of the specified vehicle to the given agent. It is not possible to take over a vehicle already controlled by another agent. """ self._check_valid() assert not self.vehicle_index.vehicle_is_hijacked( vehicle_id ), f"Vehicle has already been hijacked: {vehicle_id}" assert not vehicle_id in self.vehicle_index.agent_vehicle_ids(), ( f"`{agent_id}` can't hijack vehicle that is already controlled by an agent" f" `{self.agent_manager.agent_for_vehicle(vehicle_id)}`: {vehicle_id}" ) # Switch control to agent plan = Plan(self.road_map, mission) interface = self.agent_manager.agent_interface_for_agent_id(agent_id) self.vehicle_index.start_agent_observation( self, vehicle_id, agent_id, interface, plan, initialize_sensors=not recreate, ) vehicle = self.vehicle_index.switch_control_to_agent( self, vehicle_id, agent_id, boid=False, recreate=recreate, hijacking=is_hijacked, agent_interface=interface, ) return vehicle
Give control of the specified vehicle to the given agent. It is not possible to take over a vehicle already controlled by another agent.
switch_control_to_agent
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def create_vehicle_in_providers( self, vehicle: Vehicle, agent_id: str, is_ego: bool = False, ): """Notify providers of the existence of an agent-controlled vehicle, one of which should assume management of it.""" self._check_valid() prev_provider: Optional[Provider] = self.provider_for_actor(vehicle.id) self._stop_managing_with_providers(vehicle.id) role = ActorRole.EgoAgent if is_ego else ActorRole.SocialAgent interface = self.agent_manager.agent_interface_for_agent_id(agent_id) for provider in self.providers: if interface.action in provider.actions: state = VehicleState( actor_id=vehicle.id, source=provider.source_str, role=role, vehicle_config_type="passenger", pose=vehicle.pose, dimensions=vehicle.chassis.dimensions, speed=vehicle.speed, ) if provider.can_accept_actor(state): # just use the first provider we find that accepts it # (note that the vehicle will already have a mission plan # registered for it in its sensor state in the vehicle_index.) provider.add_actor(state, prev_provider) return # there should always be an AgentsProvider present, so we just assert here assert ( False ), f"could not find a provider to accept vehicle {vehicle.id} for agent {agent_id} with role={role.name}"
Notify providers of the existence of an agent-controlled vehicle, one of which should assume management of it.
create_vehicle_in_providers
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def vehicle_exited_bubble( self, vehicle_id: str, agent_id: str, teardown_agent: bool ): """Bubbles call this when a vehicle is exiting the bubble. Will try to find a new provider for the vehicle if necessary.""" original_agent_id = agent_id agent_id = None # FIXME: This only gets the first shadow agent and this shadow agent is not specific to a bubble!!!!!! shadow_agent_id = self._vehicle_index.shadower_id_from_vehicle_id(vehicle_id) if shadow_agent_id is not None: assert original_agent_id == shadow_agent_id if self._vehicle_index.vehicle_is_hijacked(vehicle_id): agent_id = self._vehicle_index.owner_id_from_vehicle_id(vehicle_id) assert agent_id == original_agent_id self._log.debug( "agent=%s relinquishing vehicle=%s (shadow_agent=%s)", agent_id, vehicle_id, shadow_agent_id, ) state, route = self._vehicle_index.relinquish_agent_control( self, vehicle_id, self.road_map ) new_prov = self._agent_releases_actor(agent_id, state, teardown_agent) if ( route is not None and route.road_length > 0 and isinstance(new_prov, TrafficProvider) ): new_prov.update_route_for_vehicle(vehicle_id, route) if shadow_agent_id: self._log.debug( "shadow_agent=%s will stop shadowing vehicle=%s", shadow_agent_id, vehicle_id, ) self._vehicle_index.stop_shadowing(shadow_agent_id, vehicle_id) if teardown_agent: self.teardown_social_agents([shadow_agent_id]) if self._vehicle_index.shadower_id_from_vehicle_id(vehicle_id) is None: self._sensor_manager.remove_actor_sensors_by_actor_id(vehicle_id)
Bubbles call this when a vehicle is exiting the bubble. Will try to find a new provider for the vehicle if necessary.
vehicle_exited_bubble
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def _agent_releases_actor( self, agent_id: str, state: ActorState, teardown_agent: bool, ) -> Optional[Provider]: """Find a new provider for an actor previously managed by an agent. Returns the new provider or None if a suitable one could not be found.""" current_provider = self.provider_for_actor(state.actor_id) new_provider = self.provider_releases_actor(current_provider, state) if teardown_agent: self.teardown_social_agents([agent_id]) return new_provider
Find a new provider for an actor previously managed by an agent. Returns the new provider or None if a suitable one could not be found.
_agent_releases_actor
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def teardown(self): """Clean up episode resources.""" if self._agent_manager is not None: self._agent_manager.teardown() if self._vehicle_index is not None: self._vehicle_index.teardown(self.renderer_ref) if self._sensor_manager is not None: self._sensor_manager.teardown(self.renderer_ref) if self._bullet_client is not None: self._bullet_client.resetSimulation() if self._renderer is not None: self._renderer.teardown() self._teardown_providers() if self._bubble_manager is not None: self._bubble_manager.teardown() self._bubble_manager = None for actor_capture_manager in self._actor_capture_managers: actor_capture_manager.teardown() if self._trap_manager is not None: self._trap_manager = None self._ground_bullet_id = None self._is_setup = False
Clean up episode resources.
teardown
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def destroy(self): """Destroy the simulation. Cleans up all remaining simulation resources.""" if self._is_destroyed: return self.teardown() if self._envision: self._envision.teardown() if self._visdom: self._visdom.teardown() if self._agent_manager is not None: self._agent_manager.destroy() self._agent_manager = None if self._vehicle_index is not None: self._vehicle_index = None for traffic_sim in self._provider_suite.get_all_by_type(TrafficProvider): if traffic_sim: traffic_sim.destroy() self._provider_suite.clear_type(TrafficProvider) if self._renderer is not None: self._renderer.destroy() self._renderer = None if self._bullet_client is not None: self._bullet_client.disconnect() self._bullet_client = None self._is_destroyed = True
Destroy the simulation. Cleans up all remaining simulation resources.
destroy
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def attach_sensors_to_vehicles( self, agent_interface: AgentInterface, vehicle_ids, overwrite_sensors=False, reset_sensors=False, ): """Set the specified vehicles with the sensors needed to satisfy the specified agent interface. See :attr:`smarts.core.smarts.SMARTS.prepare_observe_from`. Args: agent_interface (AgentInterface): The minimum interface generating the observations. vehicle_ids (Sequence[str]): The vehicles to target. overwrite_sensors (bool, optional): If to replace existing sensors (USE CAREFULLY). Defaults to False. reset_sensors (bool, optional): If to remove all existing sensors before adding sensors (USE **VERY** CAREFULLY). Defaults to False. """ self.prepare_observe_from( vehicle_ids, agent_interface, overwrite_sensors, reset_sensors )
Set the specified vehicles with the sensors needed to satisfy the specified agent interface. See :attr:`smarts.core.smarts.SMARTS.prepare_observe_from`. Args: agent_interface (AgentInterface): The minimum interface generating the observations. vehicle_ids (Sequence[str]): The vehicles to target. overwrite_sensors (bool, optional): If to replace existing sensors (USE CAREFULLY). Defaults to False. reset_sensors (bool, optional): If to remove all existing sensors before adding sensors (USE **VERY** CAREFULLY). Defaults to False.
attach_sensors_to_vehicles
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def prepare_observe_from( self, vehicle_ids: Sequence[str], interface: AgentInterface, overwrite_sensors, reset_sensors, ): """Assigns the given vehicle sensors as is described by the agent interface. Args: vehicle_ids (Sequence[str]): The vehicles to target. interface (AgentInterface): The minimum interface generating the observations. overwrite_sensors (bool, optional): If to replace existing sensors (USE CAREFULLY). reset_sensors (bool, optional): If to remove all existing sensors (USE **VERY** CAREFULLY). """ self._check_valid() for v_id in vehicle_ids: v = self._vehicle_index.vehicle_by_id(v_id) Vehicle.attach_sensors_to_vehicle( self.sensor_manager, self, v, interface, replace=overwrite_sensors, reset_sensors=reset_sensors, )
Assigns the given vehicle sensors as is described by the agent interface. Args: vehicle_ids (Sequence[str]): The vehicles to target. interface (AgentInterface): The minimum interface generating the observations. overwrite_sensors (bool, optional): If to replace existing sensors (USE CAREFULLY). reset_sensors (bool, optional): If to remove all existing sensors (USE **VERY** CAREFULLY).
prepare_observe_from
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def observe_from( self, vehicle_ids: Sequence[str], interface: AgentInterface, ) -> Tuple[Dict[str, Observation], Dict[str, bool]]: """Generate observations from the specified vehicles. Args: vehicle_ids (Sequence[str]): The vehicles to target. interface (AgentInterface): The intended interface generating the observations (this may be ignored.) Returns: Tuple[Dict[str, Observation], Dict[str, bool]]: A dictionary of observations and the hypothetical dones. """ self._check_valid() vehicles: Dict[str, Vehicle] = { v_id: self.vehicle_index.vehicle_by_id(v_id) for v_id in vehicle_ids } sensor_states = { vehicle.id: self._sensor_manager.sensor_state_for_actor_id(vehicle.id) or SensorState.invalid() for vehicle in vehicles.values() } return self.sensor_manager.observe_batch( self.cached_frame, self.local_constants, interface, sensor_states, vehicles, self.renderer_ref, self.bc, )
Generate observations from the specified vehicles. Args: vehicle_ids (Sequence[str]): The vehicles to target. interface (AgentInterface): The intended interface generating the observations (this may be ignored.) Returns: Tuple[Dict[str, Observation], Dict[str, bool]]: A dictionary of observations and the hypothetical dones.
observe_from
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def renderer(self) -> RendererBase: """The renderer singleton. On call, the sim will attempt to create it if it does not exist.""" if not self._renderer: try: from smarts.core.renderer_base import DEBUG_MODE from smarts.p3d.renderer import Renderer self._renderer = Renderer(self._sim_id, debug_mode=DEBUG_MODE.ERROR) except ImportError as exc: raise RendererException.required_to("use camera observations") from exc except Exception as exc: self._renderer = None raise RendererException("Unable to create renderer.") from exc if not self._renderer.is_setup: if self._scenario: self._renderer.setup(self._scenario) self._vehicle_index.begin_rendering_vehicles(self._renderer) assert self._renderer is not None return self._renderer
The renderer singleton. On call, the sim will attempt to create it if it does not exist.
renderer
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def renderer_ref(self) -> Optional[RendererBase]: """Get the reference of the renderer. This can be `None`.""" return self._renderer
Get the reference of the renderer. This can be `None`.
renderer_ref
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def is_rendering(self) -> bool: """If the simulation has image rendering active.""" return self._renderer is not None
If the simulation has image rendering active.
is_rendering
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def road_stiffness(self) -> Any: """The stiffness of the road.""" return self._bullet_client.getDynamicsInfo(self._ground_bullet_id, -1)[9]
The stiffness of the road.
road_stiffness
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def dynamic_action_spaces(self) -> Set[ActionSpaceType]: """The set of vehicle action spaces that use dynamics (physics).""" return self._agent_physics_provider.actions
The set of vehicle action spaces that use dynamics (physics).
dynamic_action_spaces
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def traffic_sims(self) -> List[TrafficProvider]: """The underlying traffic simulations.""" return self._provider_suite.get_all_by_type(TrafficProvider)
The underlying traffic simulations.
traffic_sims
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def traffic_history_provider(self) -> TrafficHistoryProvider: """The source of any traffic history data.""" return self._traffic_history_provider
The source of any traffic history data.
traffic_history_provider
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def road_map(self) -> RoadMap: """The road map api which allows lookup of road features.""" return self.scenario.road_map
The road map api which allows lookup of road features.
road_map
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def external_provider(self) -> ExternalProvider: """The external provider that can be used to inject vehicle states directly.""" return self._external_provider
The external provider that can be used to inject vehicle states directly.
external_provider
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def bc(self): """The bullet physics client instance.""" return self._bullet_client
The bullet physics client instance.
bc
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def envision(self) -> Optional[EnvisionClient]: """The envision instance""" return self._envision
The envision instance
envision
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def step_count(self) -> int: """The number of steps since the last reset.""" return self._step_count
The number of steps since the last reset.
step_count
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def elapsed_sim_time(self) -> float: """Elapsed time since simulation start.""" return self._elapsed_sim_time
Elapsed time since simulation start.
elapsed_sim_time
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def version(self) -> str: """SMARTS version.""" return VERSION
SMARTS version.
version
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def teardown_social_agents(self, agent_ids: Iterable[str]): """Tear-down agents in the given sequence. Args: agent_ids: A sequence of agent ids to terminate and release. """ agents_to_teardown = { id_ for id_ in agent_ids if not self.agent_manager.is_boid_agent(id_) or self.agent_manager.is_boid_done(id_) } self.agent_manager.teardown_social_agents(filter_ids=agents_to_teardown)
Tear-down agents in the given sequence. Args: agent_ids: A sequence of agent ids to terminate and release.
teardown_social_agents
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def teardown_social_agents_without_actors(self, agent_ids: Iterable[str]): """Tear-down agents in the given list that have no actors registered as controlled-by or shadowed-by (for each given agent.) Args: agent_ids: Sequence of agent ids """ self._check_valid() original_agents = set(agent_ids) agents_to_teardown = { agent_id for agent_id in original_agents # Only clean-up when there is no actor association left if len( self._vehicle_index.vehicles_by_owner_id( agent_id, include_shadowers=True ) ) == 0 } if self._log.isEnabledFor(logging.WARNING): skipped_agents = original_agents - agents_to_teardown if len(skipped_agents) > 0: self._log.warning( "Some agents were skipped because they still had vehicles: %s", skipped_agents, ) self.teardown_social_agents(agent_ids=agents_to_teardown)
Tear-down agents in the given list that have no actors registered as controlled-by or shadowed-by (for each given agent.) Args: agent_ids: Sequence of agent ids
teardown_social_agents_without_actors
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def vehicle_index(self) -> VehicleIndex: """The vehicle index for direct vehicle manipulation.""" return self._vehicle_index
The vehicle index for direct vehicle manipulation.
vehicle_index
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def agent_manager(self) -> AgentManager: """The agent manager for direct agent manipulation.""" return self._agent_manager
The agent manager for direct agent manipulation.
agent_manager
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def sensor_manager(self) -> SensorManager: """The sensor manager for direct manipulation.""" return self._sensor_manager
The sensor manager for direct manipulation.
sensor_manager
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def providers(self) -> List[Provider]: """The current providers controlling actors within the simulation.""" return self._provider_suite.instances
The current providers controlling actors within the simulation.
providers
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def get_provider_by_type(self, requested_type) -> Optional[Provider]: """Get The first provider that matches the requested type.""" self._check_valid() for provider in self.providers: if isinstance(provider, requested_type): return provider return None
Get The first provider that matches the requested type.
get_provider_by_type
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def get_provider_by_id(self, requested_id) -> Optional[Provider]: """Find the current provider by its identifier. Args: requested_id (str): The provider identifier. Returns: Optional[Provider]: The provider if it exists, otherwise `None`. """ self._check_valid() for provider in self.providers: if provider.provider_id() == requested_id: return provider return None
Find the current provider by its identifier. Args: requested_id (str): The provider identifier. Returns: Optional[Provider]: The provider if it exists, otherwise `None`.
get_provider_by_id
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def should_reset(self): """If the simulation requires a reset.""" return self._reset_required
If the simulation requires a reset.
should_reset
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def resetting(self) -> bool: """If the simulation is currently resetting""" return self._resetting
If the simulation is currently resetting
resetting
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def scenario(self) -> Scenario: """The current simulation scenario.""" return self._scenario
The current simulation scenario.
scenario
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def fixed_timestep_sec(self) -> float: """The simulation fixed time-step.""" # May be None if time deltas are externally driven return self._fixed_timestep_sec
The simulation fixed time-step.
fixed_timestep_sec
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def last_dt(self) -> float: """The last delta time.""" assert not self._last_dt or self._last_dt > 0 return self._last_dt
The last delta time.
last_dt
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def neighborhood_vehicles_around_vehicle( self, vehicle_id: str, radius: Optional[float] = None ) -> List[VehicleState]: """Find vehicles in the vicinity of the target vehicle.""" self._check_valid() vehicle = self._vehicle_index.vehicle_by_id(vehicle_id) return neighborhood_vehicles_around_vehicle( vehicle.state, self._vehicle_states, radius )
Find vehicles in the vicinity of the target vehicle.
neighborhood_vehicles_around_vehicle
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def local_constants(self): """Generate the frozen state that should not change until next reset.""" self._check_valid() road_map, road_map_hash = self.scenario.map_spec.builder_fn( self.scenario.map_spec ) return SimulationLocalConstants( road_map=road_map, road_map_hash=road_map_hash, )
Generate the frozen state that should not change until next reset.
local_constants
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def cached_frame(self) -> SimulationFrame: """Generate a frozen frame state of the simulation.""" self._check_valid() agent_actor_ids = self.vehicle_index.agent_vehicle_ids() actor_states = self._last_provider_state vehicles = dict(self.vehicle_index.vehicleitems()) vehicle_ids = set(vid for vid in vehicles) return SimulationFrame( actor_states=getattr(actor_states, "actors", {}), agent_interfaces=self.agent_manager.agent_interfaces.copy(), agent_vehicle_controls={ a_id: self.vehicle_index.owner_id_from_vehicle_id(a_id) for a_id in agent_actor_ids }, ego_ids=self.agent_manager.ego_agent_ids, pending_agent_ids=self.agent_manager.pending_agent_ids, elapsed_sim_time=self.elapsed_sim_time, fixed_timestep=self.fixed_timestep_sec, resetting=self.resetting, # road_map = self.road_map, map_spec=self.scenario.map_spec, last_dt=self.last_dt, last_provider_state=self._last_provider_state, step_count=self.step_count, vehicle_collisions=self._vehicle_collisions, vehicle_states={ vehicle_state.actor_id: vehicle_state for vehicle_state in self._vehicle_states }, vehicles_for_agents={ agent_id: self.vehicle_index.vehicle_ids_by_owner_id( agent_id, include_shadowers=True ) for agent_id in self.agent_manager.active_agents }, vehicle_ids=vehicle_ids, vehicle_sensors=self.sensor_manager.sensors_for_actor_ids(vehicle_ids), sensor_states=dict(self.sensor_manager.sensor_states_items()), _ground_bullet_id=self._ground_bullet_id, interest_filter=re.compile( self.scenario.metadata.get("actor_of_interest_re_filter", "") ), )
Generate a frozen frame state of the simulation.
cached_frame
python
huawei-noah/SMARTS
smarts/core/smarts.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/smarts.py
MIT
def state_update( self, vehicle_states: Sequence[VehicleState], step_delta: float, ): """Update vehicle states. Use `all_vehicle_states()` to look at previous states.""" self._ext_vehicle_states = [ replace(vs, source=self.source_str, role=ActorRole.External) for vs in vehicle_states ] self._last_step_delta = step_delta
Update vehicle states. Use `all_vehicle_states()` to look at previous states.
state_update
python
huawei-noah/SMARTS
smarts/core/external_provider.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/external_provider.py
MIT
def all_vehicle_states(self) -> List[VehicleState]: """Get all current vehicle states.""" result = [] for vehicle in self._vehicle_index.vehicles: if vehicle.subscribed_to_accelerometer_sensor: linear_acc, angular_acc, _, _ = vehicle.accelerometer_sensor( vehicle.state.linear_velocity, vehicle.state.angular_velocity, self._last_step_delta, ) result.append(vehicle.state) return result
Get all current vehicle states.
all_vehicle_states
python
huawei-noah/SMARTS
smarts/core/external_provider.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/external_provider.py
MIT
def actor_ids(self) -> Iterable[str]: """A set of actors that this provider manages. Returns: Iterable[str]: The actors this provider manages. """ return set(vs.actor_id for vs in self._ext_vehicle_states)
A set of actors that this provider manages. Returns: Iterable[str]: The actors this provider manages.
actor_ids
python
huawei-noah/SMARTS
smarts/core/external_provider.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/external_provider.py
MIT
def to_agent_spec(self) -> AgentSpec: """Generate an agent spec.""" return make(locator=self.agent_locator, **self.policy_kwargs)
Generate an agent spec.
to_agent_spec
python
huawei-noah/SMARTS
smarts/core/data_model.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/data_model.py
MIT
def act(self, obs): """Gives a future action based on observations.""" raise NotImplementedError
Gives a future action based on observations.
act
python
huawei-noah/SMARTS
smarts/core/buffer_agent.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/buffer_agent.py
MIT
def start(self, agent_spec: AgentSpec): """Begin operation of this agent.""" raise NotImplementedError
Begin operation of this agent.
start
python
huawei-noah/SMARTS
smarts/core/buffer_agent.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/buffer_agent.py
MIT
def terminate(self): """Clean up agent resources.""" raise NotImplementedError
Clean up agent resources.
terminate
python
huawei-noah/SMARTS
smarts/core/buffer_agent.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/buffer_agent.py
MIT
def linear_velocity_tuple(self) -> Optional[Tuple[float, float, float]]: """Generates a tuple representation of linear velocity with standard python types.""" return ( None if self.linear_velocity is None else tuple(float(f) for f in self.linear_velocity) )
Generates a tuple representation of linear velocity with standard python types.
linear_velocity_tuple
python
huawei-noah/SMARTS
smarts/core/vehicle_state.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_state.py
MIT
def angular_velocity_tuple(self) -> Optional[Tuple[float, float, float]]: """Generates a tuple representation of angular velocity with standard python types.""" return ( None if self.angular_velocity is None else tuple(float(f) for f in self.angular_velocity) )
Generates a tuple representation of angular velocity with standard python types.
angular_velocity_tuple
python
huawei-noah/SMARTS
smarts/core/vehicle_state.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_state.py
MIT
def bbox(self) -> Polygon: """Returns a bounding box around the vehicle.""" pos = self.pose.point half_len = 0.5 * self.dimensions.length half_width = 0.5 * self.dimensions.width poly = shapely_box( pos.x - half_width, pos.y - half_len, pos.x + half_width, pos.y + half_len, ) return shapely_rotate(poly, self.pose.heading, use_radians=True)
Returns a bounding box around the vehicle.
bbox
python
huawei-noah/SMARTS
smarts/core/vehicle_state.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_state.py
MIT
def neighborhood_vehicles_around_vehicle( vehicle_state, vehicle_states, radius: Optional[float] = None ): """Determines what vehicles are within the radius (if given).""" other_states = [v for v in vehicle_states if v.actor_id != vehicle_state.actor_id] if radius is None: return other_states other_positions = [state.pose.position for state in other_states] if not other_positions: return [] # calculate euclidean distances distances = np.linalg.norm(other_positions - vehicle_state.pose.position, axis=1) indices = np.argwhere(distances <= radius).flatten() return [other_states[i] for i in indices]
Determines what vehicles are within the radius (if given).
neighborhood_vehicles_around_vehicle
python
huawei-noah/SMARTS
smarts/core/vehicle_state.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_state.py
MIT
def control(self, *args, **kwargs): """Apply control values to the chassis.""" raise NotImplementedError
Apply control values to the chassis.
control
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def reapply_last_control(self): """Re-apply the last given control given to the chassis.""" raise NotImplementedError
Re-apply the last given control given to the chassis.
reapply_last_control
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def teardown(self): """Clean up resources.""" raise NotImplementedError
Clean up resources.
teardown
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def dimensions(self) -> Dimensions: """The fitted front aligned dimensions of the chassis.""" raise NotImplementedError
The fitted front aligned dimensions of the chassis.
dimensions
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def contact_points(self) -> Sequence: """The contact point of the chassis.""" raise NotImplementedError
The contact point of the chassis.
contact_points
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def bullet_id(self) -> str: """The physics id of the chassis physics body.""" raise NotImplementedError
The physics id of the chassis physics body.
bullet_id
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def velocity_vectors(self) -> Tuple[np.ndarray, np.ndarray]: """Returns linear velocity vector in m/s and angular velocity in rad/sec.""" raise NotImplementedError
Returns linear velocity vector in m/s and angular velocity in rad/sec.
velocity_vectors
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def speed(self) -> float: """The speed of the chassis in the facing direction of the chassis.""" raise NotImplementedError
The speed of the chassis in the facing direction of the chassis.
speed
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def set_pose(self, pose: Pose): """Use with caution since it disrupts the physics simulation. Sets the pose of the chassis. """ raise NotImplementedError
Use with caution since it disrupts the physics simulation. Sets the pose of the chassis.
set_pose
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def speed(self, speed: float): """Apply GCD from front-end.""" raise NotImplementedError
Apply GCD from front-end.
speed
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def pose(self) -> Pose: """The pose of the chassis.""" raise NotImplementedError
The pose of the chassis.
pose
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def steering(self) -> float: """The steering value of the chassis in radians [-math.pi, math.pi].""" raise NotImplementedError
The steering value of the chassis in radians [-math.pi, math.pi].
steering
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def yaw_rate(self) -> float: """The turning rate of the chassis in radians.""" raise NotImplementedError
The turning rate of the chassis in radians.
yaw_rate
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def inherit_physical_values(self, other: Chassis): """Apply GCD between the two chassis.""" raise NotImplementedError
Apply GCD between the two chassis.
inherit_physical_values
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def to_polygon(self) -> Polygon: """Convert the chassis to a 2D shape.""" p = self.pose.as_position2d() d = self.dimensions poly = shapely_box( p[0] - d.width * 0.5, p[1] - d.length * 0.5, p[0] + d.width * 0.5, p[1] + d.length * 0.5, ) return shapely_rotate(poly, self.pose.heading, use_radians=True)
Convert the chassis to a 2D shape.
to_polygon
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def step(self, current_simulation_time): """Update the chassis state.""" raise NotImplementedError
Update the chassis state.
step
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def state_override( self, dt: float, force_pose: Pose, linear_velocity: Optional[np.ndarray] = None, angular_velocity: Optional[np.ndarray] = None, ): """Use with care! In essence, this is tinkering with the physics of the world, and may have unintended behavioral or performance consequences.""" raise NotImplementedError
Use with care! In essence, this is tinkering with the physics of the world, and may have unintended behavioral or performance consequences.
state_override
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def set_pose(self, pose: Pose): """Use with caution since it disrupts the physics simulation. Sets the pose of the chassis.""" raise NotImplementedError
Use with caution since it disrupts the physics simulation. Sets the pose of the chassis.
set_pose
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def state_override( self, dt: float, force_pose: Pose, linear_velocity: Optional[np.ndarray] = None, angular_velocity: Optional[np.ndarray] = None, ): """Use with care! In essence, this is tinkering with the physics of the world, and may have unintended behavioral or performance consequences.""" if self._pose: self._last_heading = self._pose.heading self._last_dt = dt if linear_velocity is not None or angular_velocity is not None: assert linear_velocity is not None assert angular_velocity is not None self._speed = np.linalg.norm(linear_velocity) self._client.resetBaseVelocity( self.bullet_id, linearVelocity=linear_velocity, angularVelocity=angular_velocity, ) self.set_pose(force_pose)
Use with care! In essence, this is tinkering with the physics of the world, and may have unintended behavioral or performance consequences.
state_override
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def steering(self): """Current steering value in radians.""" steering_radians = np.mean( [ joint.position for joint in self._joint_states( ["front_left_steer_joint", "front_right_steer_joint"] ) ] ) # Convert to clockwise rotation to be consistent with our action # space where 1 is a right turn and -1 is a left turn. We'd expect # an action with a positive steering activation to result in # positive steering values read back from the vehicle. return -steering_radians
Current steering value in radians.
steering
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def speed(self) -> float: """Returns speed in m/s.""" velocity, _ = np.array(self._client.getBaseVelocity(self._bullet_id)) return math.sqrt(velocity.dot(velocity))
Returns speed in m/s.
speed
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def yaw_rate(self) -> float: """Returns 2-D rotational speed in rad/sec.""" _, velocity_rotational = np.array(self._client.getBaseVelocity(self._bullet_id)) return vec_to_radians(velocity_rotational[:2])
Returns 2-D rotational speed in rad/sec.
yaw_rate
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def longitudinal_lateral_speed(self): """Returns speed in m/s.""" velocity, _ = np.array(self._client.getBaseVelocity(self._bullet_id)) heading = self.pose.heading return ( (velocity[1] * math.cos(heading) - velocity[0] * math.sin(heading)), (velocity[1] * math.sin(heading) + velocity[0] * math.cos(heading)), )
Returns speed in m/s.
longitudinal_lateral_speed
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def front_rear_stiffness(self): """The front and rear stiffness values of the tires on this chassis.""" if self._tire_parameters is not None: return ( self._tire_parameters["C_alpha_front"], self._tire_parameters["C_alpha_rear"], ) else: raise ValueError("MPC requires providing tire stiffnesses in tire model")
The front and rear stiffness values of the tires on this chassis.
front_rear_stiffness
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def approx_max_speed(self): """This is the scientifically discovered maximum speed of this vehicle model""" return 95
This is the scientifically discovered maximum speed of this vehicle model
approx_max_speed
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def mass_and_inertia(self): """The mass and inertia values of this chassis.""" return ( self._client.getDynamicsInfo(self._bullet_id, 0)[0], self._client.getDynamicsInfo(self._bullet_id, 0)[2][2], )
The mass and inertia values of this chassis.
mass_and_inertia
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def controller_parameters(self): """The current controller parameters for this chassis.""" return self._controller_parameters
The current controller parameters for this chassis.
controller_parameters
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def max_steering_wheel(self): """Maximum steering output for the current gear ratio.""" return self._max_steering / self._steering_gear_ratio
Maximum steering output for the current gear ratio.
max_steering_wheel
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def wheel_radius(self): """The wheel radius of the wheels on the chassis.""" return self._wheel_radius
The wheel radius of the wheels on the chassis.
wheel_radius
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def front_rear_axle_CG_distance(self): """The axle offsets from the vehicle base.""" return (self._front_distant_CG, self._rear_distant_CG)
The axle offsets from the vehicle base.
front_rear_axle_CG_distance
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def front_track_width(self): """The track width between the front wheels.""" return self._front_track_width
The track width between the front wheels.
front_track_width
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def rear_track_width(self): """The track width between the back wheels.""" return self._rear_track_width
The track width between the back wheels.
rear_track_width
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def max_torque(self): """The maximum throttle torque.""" return self._max_torque
The maximum throttle torque.
max_torque
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def max_btorque(self): """The maximum break torque.""" return self._max_btorque
The maximum break torque.
max_btorque
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def steering_ratio(self): """The steering gear ratio""" return self._steering_gear_ratio
The steering gear ratio
steering_ratio
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def bullet_client(self): """The bullet physics simulator.""" return self._client
The bullet physics simulator.
bullet_client
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def control(self, throttle=0, brake=0, steering=0): """Apply throttle [0, 1], brake [0, 1], and steering [-1, 1] values for this time-step. """ self._last_control = (throttle, brake, steering) if isinstance(throttle, np.ndarray): assert all( 0 <= x <= 1 for x in throttle ), f"throttle ({throttle}) must be in [0, 1]" throttle_list = list(throttle * self._max_torque) else: assert 0 <= throttle <= 1, f"throttle ({throttle}) must be in [0, 1]" throttle_list = [throttle * self._max_torque] * 4 assert 0 <= brake <= 1, f"brake ({brake}) must be in [0, 1]" assert -1 <= steering <= 1, f"steering ({steering}) must be in [-1, 1]" # If we apply brake at low speed using reverse torque # the vehicle starts to roll back. we need to apply a condition # on brake such that, the reverse torque is only applied after # a threshold is passed for vehicle velocity. # Thus, brake is applied if: vehicle speed > 1/36 (m/s) if brake > 0 and self.longitudinal_lateral_speed[0] < 1 / 36: brake = 0 self._apply_steering(steering) # If the tire parameters yaml file exists, then the throttle and # brake forces are applied according to the requested tire model. # Otherwise, it uses bullet to calculate the reaction forces. if self._tire_model != None: self._lat_forces, self._lon_forces = self._tire_model.apply_tire_forces( self, self.bullet_client, [(1 / self._max_torque) * np.array(throttle_list), brake, steering], ) self._clear_step_cache() return self._apply_throttle(throttle_list) self._apply_brake(brake) self._clear_step_cache()
Apply throttle [0, 1], brake [0, 1], and steering [-1, 1] values for this time-step.
control
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def state_override( self, dt: float, force_pose: Pose, linear_velocity: Optional[np.ndarray] = None, angular_velocity: Optional[np.ndarray] = None, ): """Use with care! In essence, this is tinkering with the physics of the world, and may have unintended behavioral or performance consequences.""" self.set_pose(force_pose) if linear_velocity is not None or angular_velocity is not None: assert linear_velocity is not None assert angular_velocity is not None self._client.resetBaseVelocity( self._bullet_id, linearVelocity=linear_velocity, angularVelocity=angular_velocity, ) self._clear_step_cache()
Use with care! In essence, this is tinkering with the physics of the world, and may have unintended behavioral or performance consequences.
state_override
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def _set_road_friction(self, current_simulation_time): """Sets the road friction coefficient if fricition map exists and the vehicle is located in the defined regions in scenario file. """ pos = self.pose.point.as_shapely # A check to see if we are in a surface patch. for surface_patch in self._friction_map: if pos.within(surface_patch["zone"].to_geometry()) and ( surface_patch["begin_time"] < current_simulation_time < surface_patch["end_time"] ): self._update_tire_parameters(surface_patch["friction coefficient"]) return # If we are not in any surface patch then use the initial # tire parameters values. self._reset_tire_parameters()
Sets the road friction coefficient if fricition map exists and the vehicle is located in the defined regions in scenario file.
_set_road_friction
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def _update_tire_parameters(self, tire_model_parameters): """Updates the tire parameters if we are inside a surface patch defined in scenario file. If it is used with None argument, then it resets the tire paramters to their respective initial values. """ if self._tire_model is not None: if tire_model_parameters is None: tire_model_parameters = self._tire_parameters["road_friction"] self._tire_model.road_friction = tire_model_parameters return if tire_model_parameters is None: tire_model_parameters = ( self._road_wheel_frictions["wheel_friction"] * self._road_wheel_frictions["road_friction"] ) wheel_indices = [ self._joints[name].index for name in [ "front_left_wheel_joint", "front_right_wheel_joint", "rear_left_wheel_joint", "rear_right_wheel_joint", ] ] for wheel_id in wheel_indices: self._client.changeDynamics( self._bullet_id, wheel_id, lateralFriction=tire_model_parameters / self._road_wheel_frictions["road_friction"], ) self._clear_step_cache()
Updates the tire parameters if we are inside a surface patch defined in scenario file. If it is used with None argument, then it resets the tire paramters to their respective initial values.
_update_tire_parameters
python
huawei-noah/SMARTS
smarts/core/chassis.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/chassis.py
MIT
def from_spec(cls, map_spec: MapSpec): """Generate a road map from the given specification.""" scenario_dir = Path(map_spec.source) scenario_id = scenario_dir.stem map_path = scenario_dir / f"log_map_archive_{scenario_id}.json" if not map_path.exists(): logging.warning(f"Map not found: {map_path}") return None avm = ArgoverseStaticMap.from_json(map_path) assert avm.log_id == scenario_id, "Loaded map ID does not match expected ID" return cls(map_spec, avm)
Generate a road map from the given specification.
from_spec
python
huawei-noah/SMARTS
smarts/core/argoverse_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/argoverse_map.py
MIT
def source(self) -> str: """Path to the directory containing the map JSON file.""" return self._map_spec.source
Path to the directory containing the map JSON file.
source
python
huawei-noah/SMARTS
smarts/core/argoverse_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/argoverse_map.py
MIT
def composite_road(self) -> RoadMap.Road: """Return an abstract Road composed of one or more RoadMap.Road segments (including this one) that has been inferred to correspond to one continuous real-world road. May return same object as self.""" return self
Return an abstract Road composed of one or more RoadMap.Road segments (including this one) that has been inferred to correspond to one continuous real-world road. May return same object as self.
composite_road
python
huawei-noah/SMARTS
smarts/core/argoverse_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/argoverse_map.py
MIT
def is_composite(self) -> bool: """Returns True if this Road object was inferred and composed out of subordinate Road objects.""" return False
Returns True if this Road object was inferred and composed out of subordinate Road objects.
is_composite
python
huawei-noah/SMARTS
smarts/core/argoverse_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/argoverse_map.py
MIT
def update( self, lookahead: int, point: Point, filter_road_ids: tuple, llp, paths: List[List[Waypoint]], ): """Update the current cache if not already cached.""" if not self._match(lookahead, point, filter_road_ids): self.lookahead = lookahead self.point = point self.filter_road_ids = filter_road_ids self._starts = {} self._starts[llp.lp.lane.lane_id] = paths
Update the current cache if not already cached.
update
python
huawei-noah/SMARTS
smarts/core/argoverse_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/argoverse_map.py
MIT
def query( self, lookahead: int, point: Point, filter_road_ids: tuple, llp, ) -> Optional[List[List[Waypoint]]]: """Attempt to find previously cached waypoints""" if self._match(lookahead, point, filter_road_ids): hit = self._starts.get(llp.lp.lane.lane_id, None) if hit: # consider just returning all of them (not slicing)? return [path[: (lookahead + 1)] for path in hit] return None
Attempt to find previously cached waypoints
query
python
huawei-noah/SMARTS
smarts/core/argoverse_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/argoverse_map.py
MIT
def _waypoint_paths_along_route( self, point: Point, lookahead: int, route: Sequence[str] ) -> List[List[Waypoint]]: """finds the closest lane to vehicle's position that is on its route, then gets waypoint paths from all lanes in its road there.""" assert len(route) > 0, f"Expected at least 1 road in the route, got: {route}" closest_llp_on_each_route_road = [ self._lanepoints.closest_linked_lanepoint_on_road(point, road) for road in route ] closest_linked_lp = min( closest_llp_on_each_route_road, key=lambda l_lp: np.linalg.norm( vec_2d(l_lp.lp.pose.position) - vec_2d(point) ), ) closest_lane = closest_linked_lp.lp.lane waypoint_paths = [] for lane in closest_lane.road.lanes: waypoint_paths += lane._waypoint_paths_at(point, lookahead, route) return sorted(waypoint_paths, key=len, reverse=True)
finds the closest lane to vehicle's position that is on its route, then gets waypoint paths from all lanes in its road there.
_waypoint_paths_along_route
python
huawei-noah/SMARTS
smarts/core/argoverse_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/argoverse_map.py
MIT