Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing and modernisation of Agent code #8072

Merged
merged 65 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
4952c74
added cpp client build docs (#7942)
MattRoweEAIF Jul 11, 2024
5c2d297
fixed IMU units (#7960)
MattRoweEAIF Jul 17, 2024
32f97ea
Merge branch 'dev' of https://github.com/carla-simulator/carla into dev
Blyron Jul 19, 2024
29fbcce
Update README.md with new TinyURL links (#7988)
MattRoweEAIF Jul 25, 2024
eeb507e
Added inverse transform (#7999)
glopezdiest Jul 31, 2024
e83b79b
Merge branch 'dev' of https://github.com/carla-simulator/carla into dev
Blyron Jul 31, 2024
f2695a1
Aaron/fixwheelchair (#8001)
Blyron Jul 31, 2024
1ef3f55
Docs/unit updates (#8007)
MattRoweEAIF Jul 31, 2024
fd44ea0
Add a `*.pyi` file for auto-completion & hints.
Minokori Dec 16, 2023
951fcc4
Fixes and missing Iterators
Daraan Feb 15, 2024
be8735f
Fixed Actor.parent
Daraan Feb 19, 2024
bc6e7cd
Fixed missing return types
Daraan Feb 29, 2024
251b293
Updated changelog
Daraan Feb 29, 2024
7b2c1db
Added DSVEventArray iterator
Daraan Feb 29, 2024
f275e47
Added missing type for Labelled Point
Daraan Feb 29, 2024
4c1104d
Fixed spelling misstakes
Daraan Feb 29, 2024
755c0d8
Removed wrong unit indication
Daraan Mar 14, 2024
232cb8c
Added missing -> World to load_world
Daraan Mar 14, 2024
a0cff71
Added missing return value to reload_world
Daraan Mar 14, 2024
de33210
FIX: __init__ methods do not return
Daraan Mar 14, 2024
0197e0a
FIX: added ApplyTransform, fixed ApplyTorque
Daraan Apr 2, 2024
1d4450b
Filled in missing information and types.
Daraan Apr 3, 2024
4c086ad
ActorList.filter actually returns ActorList
Daraan Apr 3, 2024
caac503
Fixed CityObjectLabels
Daraan Apr 12, 2024
df1eb25
Disambiguated get_waypoint signature
Daraan Apr 12, 2024
e765559
Added undocumented variables
Daraan Apr 12, 2024
ddb5834
Corrected Sensor.is_listening
Daraan Jun 14, 2024
2935897
Added type hints for `values` attribute on enums
Daraan Jul 23, 2024
8df99c0
Fix intendation shadowing methods
Daraan Jul 24, 2024
19b892f
Fix missing @property
Daraan Jul 24, 2024
a089c3b
Formatted some docstring to be shorter
Daraan Jul 24, 2024
d9c217e
Added stubs for HUD drawing
Daraan Jul 24, 2024
41e595c
Corrected and more precise type-hints
Daraan Jul 24, 2024
f797e15
Improved get_waypoint disambiguation
Daraan Jul 24, 2024
b061f9e
Fix spelling mistakes
Daraan Jul 24, 2024
a959577
Better usage of Enum if typing.Self is availiable
Daraan Jul 29, 2024
453ceca
Fix: Enum values were tuples. Added Flag or Int to Enums
Daraan Jul 29, 2024
da80757
Fixes for wrong stubs
Daraan Jul 29, 2024
ca81e35
Added self parameter to property signatures
Daraan Jul 29, 2024
77856f4
Various fixes
Daraan Jul 29, 2024
798c9e1
Added setters for VehicleControl
Daraan Jul 29, 2024
26dc386
Improved get_waypoints and Literal type hints
Daraan Jul 29, 2024
58e0374
Corrected [try_]spawn_actor keyword name
Daraan Aug 1, 2024
aec0b26
Added Transform.inverse_transform and corrected signature
Daraan Aug 1, 2024
2b465bc
Improved Callable and callbacks signature
Daraan Aug 8, 2024
7633334
Corrections and additions
Daraan Aug 15, 2024
334740a
Fixed Vector arithmetic
Daraan Aug 23, 2024
c097d7a
added digital twins video (#8090)
MattRoweEAIF Aug 29, 2024
00df447
Merge branch 'dev' of https://github.com/carla-simulator/carla into dev
Blyron Sep 2, 2024
279351a
Typing for GlobalRoutePlanner
Daraan Aug 23, 2024
1d42020
0.9.13+ modernisation of code
Daraan Aug 23, 2024
555ab73
made function static
Daraan Aug 27, 2024
9879cbd
Updated changelog
Daraan Sep 6, 2024
0664c4d
fixed spelling mistakes
Daraan Sep 9, 2024
bb2566d
No unnecessary inheritance from object and empty class brackets & other
Daraan Sep 9, 2024
9e94feb
navigation information is now loaded when changing maps
AreopagX Feb 29, 2024
4d09f0a
Porting the changes done to UE5 to fix the recording leak to UE4
jorge-kabuto Sep 12, 2024
c733936
Fixed typo in CityScapes palette (#8137)
sergiopaniego Sep 13, 2024
92a6e71
Correcting makefile typo to avoid override warning for target "downlo…
Ylmdrin Sep 20, 2024
4feeb77
Merge branch 'dev' of https://github.com/carla-simulator/carla into dev
Blyron Sep 25, 2024
f7ed6c2
fix typo in title (#8225)
MattRoweEAIF Sep 30, 2024
88cab6e
Merge branch 'dev' into agent-modernisation
Daraan Oct 5, 2024
2a2cc5f
added unreal coord system, fixed v2x (#8251)
MattRoweEAIF Oct 7, 2024
4a6f61e
Merge branch 'dev' into agent-modernisation
glopezdiest Oct 18, 2024
07a23e0
Merge remote-tracking branch 'origin/ue4-dev' into agent-modernisation
Daraan Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Added V2X sensors for cooperative awareness message and custom user-defined messages to support vehicle-to-vehicle communication
* Added named tuples for BasicAgent.py's detection result to allow for type-hints and better semantics.
* Added type-hint support for the PythonAPI
* Added type-hints to GlobalRoutePlanner and use carla.Vector3D code instead of pre 0.9.13 numpy code.


## CARLA 0.9.15
Expand Down
37 changes: 19 additions & 18 deletions PythonAPI/carla/agents/navigation/basic_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
This module implements an agent that roams around a track following random
waypoints and avoiding other vehicles. The agent also responds to traffic lights.
It can also make use of the global route planner to follow a specifed route
It can also make use of the global route planner to follow a specified route
"""

import carla
Expand All @@ -15,13 +15,12 @@
from agents.navigation.local_planner import LocalPlanner, RoadOption
from agents.navigation.global_route_planner import GlobalRoutePlanner
from agents.tools.misc import (get_speed, is_within_distance,
get_trafficlight_trigger_location,
compute_distance)
get_trafficlight_trigger_location)

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 All @@ -31,7 +30,7 @@ class BasicAgent(object):

def __init__(self, vehicle, target_speed=20, opt_dict={}, map_inst=None, grp_inst=None):
"""
Initialization the agent paramters, the local and the global planner.
Initialization the agent parameters, the local and the global planner.

:param vehicle: actor to apply to agent logic onto
:param target_speed: speed (in Km/h) at which the vehicle will move
Expand Down Expand Up @@ -102,7 +101,7 @@ def __init__(self, vehicle, target_speed=20, opt_dict={}, map_inst=None, grp_ins

# Get the static elements of the scene
self._lights_list = self._world.get_actors().filter("*traffic_light*")
self._lights_map = {} # Dictionary mapping a traffic light to a wp corrspoing to its trigger volume location
self._lights_map = {} # Dictionary mapping a traffic light to a wp corresponding to its trigger volume location

def add_emergency_stop(self, control):
"""
Expand Down Expand Up @@ -139,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 @@ -157,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 @@ -325,7 +324,7 @@ def _vehicle_obstacle_detected(self, vehicle_list=None, max_distance=None, up_an
"""
Method to check if there is a vehicle in front of the agent blocking its path.

:param vehicle_list (list of carla.Vehicle): list contatining vehicle objects.
:param vehicle_list (list of carla.Vehicle): list containing vehicle objects.
If None, all vehicle in the scene are used
:param max_distance: max freespace to check for obstacles.
If None, the base threshold value is used
Expand Down Expand Up @@ -354,7 +353,7 @@ def get_route_polygon():
return None

return Polygon(route_bb)

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

Expand Down Expand Up @@ -404,7 +403,7 @@ def get_route_polygon():
target_polygon = Polygon(target_list)

if route_polygon.intersects(target_polygon):
return ObstacleDetectionResult(True, target_vehicle, compute_distance(target_vehicle.get_location(), ego_location))
return ObstacleDetectionResult(True, target_vehicle, target_vehicle.get_location().distance(ego_location))

# Simplified approach, using only the plan waypoints (similar to TM)
else:
Expand All @@ -425,13 +424,15 @@ def get_route_polygon():
)

if is_within_distance(target_rear_transform, ego_front_transform, max_distance, [low_angle_th, up_angle_th]):
return ObstacleDetectionResult(True, target_vehicle, compute_distance(target_transform.location, ego_transform.location))
return ObstacleDetectionResult(True, target_vehicle, target_transform.location.distance(ego_transform.location))

return ObstacleDetectionResult(False, None, -1)

def _generate_lane_change_path(self, waypoint, direction='left', distance_same_lane=10,
@staticmethod
def _generate_lane_change_path(waypoint, direction='left', distance_same_lane=10,
distance_other_lane=25, lane_change_distance=25,
check=True, lane_changes=1, step_distance=2):
# type: (carla.Waypoint, str, float, float, float, bool, int, float) -> list[tuple[carla.Waypoint, RoadOption]]
"""
This methods generates a path that results in a lane change.
Use the different distances to fine-tune the maneuver.
Expand Down
3 changes: 1 addition & 2 deletions PythonAPI/carla/agents/navigation/behavior_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
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
from agents.navigation.local_planner import RoadOption
from agents.navigation.behavior_types import Cautious, Aggressive, Normal

from agents.tools.misc import get_speed, positive, is_within_distance, compute_distance
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functions were unused

from agents.tools.misc import get_speed, positive

class BehaviorAgent(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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
This module implements an agent that roams around a track following random
waypoints and avoiding other vehicles. The agent also responds to traffic lights.
It can also make use of the global route planner to follow a specifed route
It can also make use of the global route planner to follow a specified route
"""

import carla
Expand Down
8 changes: 4 additions & 4 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 Expand Up @@ -199,7 +199,7 @@ def __init__(self, vehicle, offset=0, K_P=1.0, K_I=0.0, K_D=0.0, dt=0.03):
def run_step(self, waypoint):
"""
Execute one step of lateral control to steer
the vehicle towards a certain waypoin.
the vehicle towards a certain waypoint.

:param waypoint: target waypoint
:return: steering control in the range [-1, 1] where:
Expand Down
Loading