Skip to content

Commit

Permalink
No unnecessary inheritance from object and empty class brackets & other
Browse files Browse the repository at this point in the history
Removed empty variables and whitespaces
formatting
  • Loading branch information
Daraan committed Sep 9, 2024
1 parent 0664c4d commit bb2566d
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 39 deletions.
18 changes: 9 additions & 9 deletions PythonAPI/carla/agents/navigation/basic_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -353,7 +353,7 @@ def get_route_polygon():
return None

return Polygon(route_bb)

if self._ignore_vehicles:
return ObstacleDetectionResult(False, None, -1)

Expand Down
1 change: 0 additions & 1 deletion PythonAPI/carla/agents/navigation/behavior_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions PythonAPI/carla/agents/navigation/behavior_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions PythonAPI/carla/agents/navigation/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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.
"""
Expand Down
37 changes: 20 additions & 17 deletions PythonAPI/carla/agents/navigation/global_route_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions PythonAPI/carla/agents/navigation/local_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions PythonAPI/carla/agents/tools/hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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])])
4 changes: 2 additions & 2 deletions PythonAPI/carla/agents/tools/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
Expand All @@ -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
"""
Expand Down

0 comments on commit bb2566d

Please sign in to comment.