diff --git a/examples/tools/pybullet_trajectory_example.py b/examples/tools/pybullet_trajectory_example.py index a73471907d..a7d34b0126 100644 --- a/examples/tools/pybullet_trajectory_example.py +++ b/examples/tools/pybullet_trajectory_example.py @@ -81,12 +81,6 @@ def run(client, vehicle, plane_body_id, sliders, n_steps=1e6): vehicle, controller_state, dt_sec=TIMESTEP_SEC, - heading_gain=0.05, - lateral_gain=0.65, - velocity_gain=1.8, - traction_gain=2, - derivative_activation=False, - speed_reduction_activation=False, ) client.stepSimulation() diff --git a/smarts/core/smarts.py b/smarts/core/smarts.py index 041ebda933..e02de42aea 100644 --- a/smarts/core/smarts.py +++ b/smarts/core/smarts.py @@ -17,6 +17,8 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +from __future__ import annotations + import importlib.resources as pkg_resources import logging import os diff --git a/smarts/core/utils/resources.py b/smarts/core/utils/resources.py index e3da5f8316..20558fba0d 100644 --- a/smarts/core/utils/resources.py +++ b/smarts/core/utils/resources.py @@ -101,9 +101,13 @@ class VehicleDefinitions: data: Dict[str, Any] """The data associated with the vehicle definitions. This is generally vehicle type keys.""" - filepath: str + filepath: Union[str, Path] """The path to the vehicle definitions file.""" + def __post_init__(self): + if isinstance(self.filepath, Path): + object.__setattr__(self, "filepath", self.filepath.__str__()) + @lru_cache(maxsize=20) def load_vehicle_definition(self, vehicle_class: str): """Loads in a particular vehicle definition.""" diff --git a/smarts/core/utils/type_operations.py b/smarts/core/utils/type_operations.py index 979a5ea43f..68f5123d5f 100644 --- a/smarts/core/utils/type_operations.py +++ b/smarts/core/utils/type_operations.py @@ -190,13 +190,13 @@ def __init__(self, base_type: Type[T]) -> None: self._associated_groups: Dict[T, List[Type[T]]] = defaultdict(list) self._base_type = base_type - def clear_type(self, type_to_clear: Type[T]): + def clear_type(self, type_to_clear: Type[S]): """Clear all instances of the given type from this suite. This includes all sub-classes. This should be an sub-class of the type that this suite manages. Args: - type_to_clear (Type[T]): The type to clear. + type_to_clear (Type[S]): The type to clear. """ self._assert_is_managed(type_to_clear) t = self._associated_groups.get(type_to_clear) diff --git a/smarts/core/vehicle.py b/smarts/core/vehicle.py index 8abfc68085..2c8e9cabfc 100644 --- a/smarts/core/vehicle.py +++ b/smarts/core/vehicle.py @@ -53,7 +53,7 @@ from .vehicle_state import VEHICLE_CONFIGS, VehicleState if TYPE_CHECKING: - from smarts.core.plan import Mission + from smarts.core import plan from smarts.core.renderer_base import RendererBase from smarts.core.sensor_manager import SensorManager from smarts.core.smarts import SMARTS @@ -273,7 +273,7 @@ def valid(self) -> bool: @staticmethod def agent_vehicle_dims( - mission: "Mission", default: Optional[str] = None + mission: "plan.Mission", default: Optional[str] = None ) -> Dimensions: """Get the vehicle dimensions from the mission requirements. Args: diff --git a/smarts/core/vehicle_index.py b/smarts/core/vehicle_index.py index 94a8a99612..584a1d9d72 100644 --- a/smarts/core/vehicle_index.py +++ b/smarts/core/vehicle_index.py @@ -63,9 +63,9 @@ from .vehicle import Vehicle if TYPE_CHECKING: + from smarts.core import plan from smarts.core.agent_interface import AgentInterface from smarts.core.controllers.action_space_type import ActionSpaceType - from smarts.core.plan import Plan from smarts.core.renderer_base import RendererBase from smarts.core.smarts import SMARTS @@ -118,7 +118,9 @@ def __init__(self): self._controller_states = {} # Loaded from yaml file on scenario reset - self._vehicle_definitions: resources.VehicleDefinitions = {} + self._vehicle_definitions: resources.VehicleDefinitions = ( + resources.VehicleDefinitions({}, "") + ) @classmethod def identity(cls): @@ -395,7 +397,7 @@ def start_agent_observation( vehicle_id, agent_id, agent_interface: AgentInterface, - plan: Plan, + plan: "plan.Plan", boid=False, initialize_sensors=True, ): @@ -556,14 +558,14 @@ def stop_agent_observation(self, vehicle_id) -> Vehicle: @clear_cache def relinquish_agent_control( self, sim: SMARTS, vehicle_id: str, road_map: RoadMap - ) -> Tuple[VehicleState, List[str]]: + ) -> Tuple[VehicleState, Optional[RoadMap.Route]]: """Give control of the vehicle back to its original controller.""" self._log.debug(f"Relinquishing agent control v_id={vehicle_id}") v_id = _2id(vehicle_id) ss = sim.sensor_manager.sensor_state_for_actor_id(vehicle_id) - route = ss.get_plan(road_map).route + route = ss.get_plan(road_map).route if ss else None vehicle = self.stop_agent_observation(vehicle_id) # pytype: disable=attribute-error @@ -596,7 +598,11 @@ def relinquish_agent_control( @clear_cache def attach_sensors_to_vehicle( - self, sim: SMARTS, vehicle_id, agent_interface: AgentInterface, plan: Plan + self, + sim: SMARTS, + vehicle_id, + agent_interface: AgentInterface, + plan: "plan.Plan", ): """Attach sensors as per the agent interface requirements to the specified vehicle.""" vehicle_id = _2id(vehicle_id) @@ -639,6 +645,7 @@ def _switch_control_to_agent_recreate( ), f"Missing agent_interface for agent_id={agent_id}" vehicle = self._vehicles[vehicle_id] sensor_state = sim.sensor_manager.sensor_state_for_actor_id(vehicle.id) + assert sensor_state is not None controller_state = self._controller_states[vehicle_id] plan = sensor_state.get_plan(sim.road_map) @@ -652,7 +659,7 @@ def _switch_control_to_agent_recreate( agent_interface.action, vehicle_definition.get("type"), agent_interface.vehicle_class, - plan, + plan.mission, vehicle_definition.get("dynamics_model"), vehicle_definition.get("tire_params"), vehicle_definition.get("visual_model"), @@ -704,7 +711,7 @@ def _build_agent_vehicle( action: Optional[ActionSpaceType], vehicle_type: str, vehicle_class: str, - plan: Plan, + mission: plan.Mission, vehicle_dynamics_filepath: Optional[str], tire_filepath: str, visual_model_filepath: str, @@ -715,7 +722,6 @@ def _build_agent_vehicle( """Create a new vehicle and set up sensors and planning information as required by the ego agent. """ - mission = plan.mission chassis_dims = Vehicle.agent_vehicle_dims(mission, default=vehicle_type) start = mission.start @@ -781,7 +787,7 @@ def build_agent_vehicle( sim: SMARTS, agent_id, agent_interface: AgentInterface, - plan: Plan, + plan: "plan.Plan", trainable: bool, initial_speed: Optional[float] = None, boid: bool = False, @@ -798,7 +804,7 @@ def build_agent_vehicle( action=agent_interface.action, vehicle_type=vehicle_definition.get("type"), vehicle_class=agent_interface.vehicle_class, - plan=plan, + mission=plan.mission, vehicle_dynamics_filepath=vehicle_definition.get("dynamics_model"), tire_filepath=vehicle_definition.get("tire_params"), visual_model_filepath=vehicle_definition.get("visual_model"), diff --git a/smarts/p3d/renderer.py b/smarts/p3d/renderer.py index 3bf3171ddf..7eb0639897 100644 --- a/smarts/p3d/renderer.py +++ b/smarts/p3d/renderer.py @@ -491,7 +491,11 @@ def set_interest(self, interest_filter: re.Pattern, interest_color: Colors): self._interest_color = interest_color def create_vehicle_node( - self, glb_model: str, vid: str, color: Union[Colors, SceneColors], pose: Pose + self, + glb_model: Union[str, Path], + vid: str, + color: Union[Colors, SceneColors], + pose: Pose, ): """Create a vehicle node.""" if vid in self._vehicle_nodes: