MCPcopy Create free account
hub / github.com/OpenDriveLab/DriveAdapter / BasicAgent

Class BasicAgent

agents/navigation/basic_agent.py:17–128  ·  view source on GitHub ↗

BasicAgent implements a basic agent that navigates scenes to reach a given target destination. This agent respects traffic lights and other vehicles.

Source from the content-addressed store, hash-verified

15from agents.navigation.global_route_planner_dao import GlobalRoutePlannerDAO
16
17class BasicAgent(Agent):
18 """
19 BasicAgent implements a basic agent that navigates scenes to reach a given
20 target destination. This agent respects traffic lights and other vehicles.
21 """
22
23 def __init__(self, vehicle, target_speed=20):
24 """
25
26 :param vehicle: actor to apply to local planner logic onto
27 """
28 super(BasicAgent, self).__init__(vehicle)
29
30 self._proximity_tlight_threshold = 5.0 # meters
31 self._proximity_vehicle_threshold = 10.0 # meters
32 self._state = AgentState.NAVIGATING
33 args_lateral_dict = {
34 'K_P': 1,
35 'K_D': 0.4,
36 'K_I': 0,
37 'dt': 1.0/20.0}
38 self._local_planner = LocalPlanner(
39 self._vehicle, opt_dict={'target_speed' : target_speed,
40 'lateral_control_dict':args_lateral_dict})
41 self._hop_resolution = 2.0
42 self._path_seperation_hop = 2
43 self._path_seperation_threshold = 0.5
44 self._target_speed = target_speed
45 self._grp = None
46
47 def set_destination(self, location):
48 """
49 This method creates a list of waypoints from agent's position to destination location
50 based on the route returned by the global router
51 """
52
53 start_waypoint = self._map.get_waypoint(self._vehicle.get_location())
54 end_waypoint = self._map.get_waypoint(
55 carla.Location(location[0], location[1], location[2]))
56
57 route_trace = self._trace_route(start_waypoint, end_waypoint)
58
59 self._local_planner.set_global_plan(route_trace)
60
61 def _trace_route(self, start_waypoint, end_waypoint):
62 """
63 This method sets up a global router and returns the optimal route
64 from start_waypoint to end_waypoint
65 """
66
67 # Setting up global router
68 if self._grp is None:
69 dao = GlobalRoutePlannerDAO(self._vehicle.get_world().get_map(), self._hop_resolution)
70 grp = GlobalRoutePlanner(dao)
71 grp.setup()
72 self._grp = grp
73
74 # Obtain route plan

Callers 3

run_stepMethod · 0.90
run_stepMethod · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected