From bb2566d5f0d6f4be3bd6458576ea13435bab1a65 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 9 Sep 2024 10:20:41 +0200 Subject: [PATCH] No unnecessary inheritance from object and empty class brackets & other Removed empty variables and whitespaces formatting --- .../carla/agents/navigation/basic_agent.py | 18 ++++----- .../carla/agents/navigation/behavior_agent.py | 1 - .../carla/agents/navigation/behavior_types.py | 6 +-- .../carla/agents/navigation/controller.py | 6 +-- .../agents/navigation/global_route_planner.py | 37 ++++++++++--------- .../carla/agents/navigation/local_planner.py | 4 +- PythonAPI/carla/agents/tools/hints.py | 4 +- PythonAPI/carla/agents/tools/misc.py | 4 +- 8 files changed, 41 insertions(+), 39 deletions(-) diff --git a/PythonAPI/carla/agents/navigation/basic_agent.py b/PythonAPI/carla/agents/navigation/basic_agent.py index 2f8e6c18c6..9f34fef796 100644 --- a/PythonAPI/carla/agents/navigation/basic_agent.py +++ b/PythonAPI/carla/agents/navigation/basic_agent.py @@ -20,7 +20,7 @@ from agents.tools.hints import ObstacleDetectionResult, TrafficLightDetectionResult -class BasicAgent(object): +class BasicAgent: """ BasicAgent implements an agent that navigates the scene. This agent respects traffic lights and other vehicles, but ignores stop signs. @@ -138,14 +138,14 @@ def get_local_planner(self): def get_global_planner(self): """Get method for protected member local planner""" return self._global_planner - + def set_destination(self, end_location, start_location=None, clean_queue=True): # type: (carla.Location, carla.Location | None, bool) -> None """ This method creates a list of waypoints between a starting and ending location, based on the route returned by the global router, and adds it to the local planner. - If no starting location is passed and `clean_queue` is True, the vehicle local planner's - target location is chosen, which corresponds (by default), to a location about 5 meters + If no starting location is passed and `clean_queue` is True, the vehicle local planner's + target location is chosen, which corresponds (by default), to a location about 5 meters in front of the vehicle. If `clean_queue` is False the newly planned route will be appended to the current route. @@ -156,19 +156,19 @@ def set_destination(self, end_location, start_location=None, clean_queue=True): if not start_location: if clean_queue and self._local_planner.target_waypoint: # Plan from the waypoint in front of the vehicle onwards - start_location = self._local_planner.target_waypoint.transform.location + start_location = self._local_planner.target_waypoint.transform.location elif not clean_queue and self._local_planner._waypoints_queue: # Append to the current plan start_location = self._local_planner._waypoints_queue[-1][0].transform.location else: # no target_waypoint or _waypoints_queue empty, use vehicle location - start_location = self._vehicle.get_location() + start_location = self._vehicle.get_location() start_waypoint = self._map.get_waypoint(start_location) end_waypoint = self._map.get_waypoint(end_location) - + route_trace = self.trace_route(start_waypoint, end_waypoint) self._local_planner.set_global_plan(route_trace, clean_queue=clean_queue) - + def set_global_plan(self, plan, stop_waypoint_creation=True, clean_queue=True): """ Adds a specific plan to the agent. @@ -353,7 +353,7 @@ def get_route_polygon(): return None return Polygon(route_bb) - + if self._ignore_vehicles: return ObstacleDetectionResult(False, None, -1) diff --git a/PythonAPI/carla/agents/navigation/behavior_agent.py b/PythonAPI/carla/agents/navigation/behavior_agent.py index 6ca680595a..f4cc1bf279 100644 --- a/PythonAPI/carla/agents/navigation/behavior_agent.py +++ b/PythonAPI/carla/agents/navigation/behavior_agent.py @@ -8,7 +8,6 @@ waypoints and avoiding other vehicles. The agent also responds to traffic lights, traffic signs, and has different possible configurations. """ -import random import numpy as np import carla from agents.navigation.basic_agent import BasicAgent diff --git a/PythonAPI/carla/agents/navigation/behavior_types.py b/PythonAPI/carla/agents/navigation/behavior_types.py index 3008f9f73b..9eb81dd21e 100644 --- a/PythonAPI/carla/agents/navigation/behavior_types.py +++ b/PythonAPI/carla/agents/navigation/behavior_types.py @@ -4,7 +4,7 @@ """ This module contains the different parameters sets for each behavior. """ -class Cautious(object): +class Cautious: """Class for Cautious agent.""" max_speed = 40 speed_lim_dist = 6 @@ -15,7 +15,7 @@ class Cautious(object): tailgate_counter = 0 -class Normal(object): +class Normal: """Class for Normal agent.""" max_speed = 50 speed_lim_dist = 3 @@ -26,7 +26,7 @@ class Normal(object): tailgate_counter = 0 -class Aggressive(object): +class Aggressive: """Class for Aggressive agent.""" max_speed = 70 speed_lim_dist = 1 diff --git a/PythonAPI/carla/agents/navigation/controller.py b/PythonAPI/carla/agents/navigation/controller.py index 45bf373ad2..0b23d8571e 100644 --- a/PythonAPI/carla/agents/navigation/controller.py +++ b/PythonAPI/carla/agents/navigation/controller.py @@ -12,7 +12,7 @@ from agents.tools.misc import get_speed -class VehiclePIDController(): +class VehiclePIDController: """ VehiclePIDController is the combination of two PID controllers (lateral and longitudinal) to perform the @@ -105,7 +105,7 @@ def set_offset(self, offset): self._lat_controller.set_offset(offset) -class PIDLongitudinalController(): +class PIDLongitudinalController: """ PIDLongitudinalController implements longitudinal control using a PID. """ @@ -171,7 +171,7 @@ def change_parameters(self, K_P, K_I, K_D, dt): self._dt = dt -class PIDLateralController(): +class PIDLateralController: """ PIDLateralController implements lateral control using a PID. """ diff --git a/PythonAPI/carla/agents/navigation/global_route_planner.py b/PythonAPI/carla/agents/navigation/global_route_planner.py index 17545f40a4..47310b84c1 100644 --- a/PythonAPI/carla/agents/navigation/global_route_planner.py +++ b/PythonAPI/carla/agents/navigation/global_route_planner.py @@ -26,28 +26,31 @@ from typing_extensions import NotRequired else: from typing_extensions import TypedDict, NotRequired - - TopologyDict = TypedDict('TopologyDict', {'entry': carla.Waypoint, - 'exit': carla.Waypoint, - 'entryxyz': tuple[float, float, float], - 'exitxyz': tuple[float, float, float], - 'path': list[carla.Waypoint]}) - - EdgeDict = TypedDict('EdgeDict', + + TopologyDict = TypedDict('TopologyDict', + { + 'entry': carla.Waypoint, + 'exit': carla.Waypoint, + 'entryxyz': tuple[float, float, float], + 'exitxyz': tuple[float, float, float], + 'path': list[carla.Waypoint] + }) + + EdgeDict = TypedDict('EdgeDict', { 'length': int, 'path': list[carla.Waypoint], - 'entry_waypoint': carla.Waypoint, - 'exit_waypoint': carla.Waypoint, - 'entry_vector': np.ndarray, - 'exit_vector': np.ndarray, - 'net_vector': list[float], - 'intersection': bool, - 'type': RoadOption, + 'entry_waypoint': carla.Waypoint, + 'exit_waypoint': carla.Waypoint, + 'entry_vector': np.ndarray, + 'exit_vector': np.ndarray, + 'net_vector': list[float], + 'intersection': bool, + 'type': RoadOption, 'change_waypoint': NotRequired[carla.Waypoint] }) -class GlobalRoutePlanner(object): +class GlobalRoutePlanner: """ This class provides a very high level route plan. """ @@ -353,7 +356,7 @@ def _successive_last_intersection_edge(self, index, route): for node1, node2 in [(route[i], route[i + 1]) for i in range(index, len(route) - 1)]: candidate_edge = self._graph.edges[node1, node2] # type: EdgeDict if node1 == route[index]: - last_intersection_edge = candidate_edge + last_intersection_edge = candidate_edge if candidate_edge['type'] == RoadOption.LANEFOLLOW and candidate_edge['intersection']: last_intersection_edge = candidate_edge last_node = node2 diff --git a/PythonAPI/carla/agents/navigation/local_planner.py b/PythonAPI/carla/agents/navigation/local_planner.py index 717e6aefae..25833cecf5 100644 --- a/PythonAPI/carla/agents/navigation/local_planner.py +++ b/PythonAPI/carla/agents/navigation/local_planner.py @@ -28,7 +28,7 @@ class RoadOption(IntEnum): CHANGELANERIGHT = 6 -class LocalPlanner(object): +class LocalPlanner: """ LocalPlanner implements the basic behavior of following a trajectory of waypoints that is generated on-the-fly. @@ -287,7 +287,7 @@ def get_incoming_waypoint_and_direction(self, steps=3): try: wpt, direction = self._waypoints_queue[-1] return wpt, direction - except IndexError as i: + except IndexError: return None, RoadOption.VOID def get_plan(self): diff --git a/PythonAPI/carla/agents/tools/hints.py b/PythonAPI/carla/agents/tools/hints.py index 475d93d3dd..6a6bf520e6 100644 --- a/PythonAPI/carla/agents/tools/hints.py +++ b/PythonAPI/carla/agents/tools/hints.py @@ -18,7 +18,7 @@ class ObstacleDetectionResult(NamedTuple): obstacle_was_found : bool obstacle : Union[Actor, None] - distance : float + distance : float # distance : Union[float, Literal[-1]] # Python 3.8+ only class TrafficLightDetectionResult(NamedTuple): @@ -30,5 +30,5 @@ class TrafficLightDetectionResult(NamedTuple): ObstacleDetectionResult = NamedTuple('ObstacleDetectionResult', [('obstacle_was_found', bool), ('obstacle', Union[Actor, None]), ('distance', Union[float, Literal[-1]])]) else: ObstacleDetectionResult = NamedTuple('ObstacleDetectionResult', [('obstacle_was_found', bool), ('obstacle', Union[Actor, None]), ('distance', float)]) - + TrafficLightDetectionResult = NamedTuple('TrafficLightDetectionResult', [('traffic_light_was_found', bool), ('traffic_light', Union[TrafficLight, None])]) diff --git a/PythonAPI/carla/agents/tools/misc.py b/PythonAPI/carla/agents/tools/misc.py index cc59363c8f..9400e15175 100644 --- a/PythonAPI/carla/agents/tools/misc.py +++ b/PythonAPI/carla/agents/tools/misc.py @@ -142,7 +142,7 @@ def vector(location_1, location_2): Returns the unit vector from location_1 to location_2 :param location_1, location_2: carla.Location objects - + .. note:: Alternatively you can use: `(location_2 - location_1).make_unit_vector()` @@ -159,7 +159,7 @@ def compute_distance(location_1, location_2): Euclidean distance between 3D points :param location_1, location_2: 3D points - + .. deprecated:: 0.9.13 Use `location_1.distance(location_2)` instead """