LocalPlanner implements the basic behavior of following a trajectory of waypoints that is generated on-the-fly. The low-level motion of the vehicle is computed by using two PID controllers, one is used for the lateral control and the other for the longitudinal control (cruise speed).
| 28 | |
| 29 | |
| 30 | class LocalPlanner(object): |
| 31 | """ |
| 32 | LocalPlanner implements the basic behavior of following a trajectory of waypoints that is generated on-the-fly. |
| 33 | The low-level motion of the vehicle is computed by using two PID controllers, one is used for the lateral control |
| 34 | and the other for the longitudinal control (cruise speed). |
| 35 | |
| 36 | When multiple paths are available (intersections) this local planner makes a random choice. |
| 37 | """ |
| 38 | |
| 39 | # minimum distance to target waypoint as a percentage (e.g. within 90% of |
| 40 | # total distance) |
| 41 | MIN_DISTANCE_PERCENTAGE = 0.9 |
| 42 | |
| 43 | def __init__(self, vehicle, opt_dict=None): |
| 44 | """ |
| 45 | :param vehicle: actor to apply to local planner logic onto |
| 46 | :param opt_dict: dictionary of arguments with the following semantics: |
| 47 | dt -- time difference between physics control in seconds. This is typically fixed from server side |
| 48 | using the arguments -benchmark -fps=F . In this case dt = 1/F |
| 49 | |
| 50 | target_speed -- desired cruise speed in Km/h |
| 51 | |
| 52 | sampling_radius -- search radius for next waypoints in seconds: e.g. 0.5 seconds ahead |
| 53 | |
| 54 | lateral_control_dict -- dictionary of arguments to setup the lateral PID controller |
| 55 | {'K_P':, 'K_D':, 'K_I':, 'dt'} |
| 56 | |
| 57 | longitudinal_control_dict -- dictionary of arguments to setup the longitudinal PID controller |
| 58 | {'K_P':, 'K_D':, 'K_I':, 'dt'} |
| 59 | """ |
| 60 | self._vehicle = vehicle |
| 61 | self._map = self._vehicle.get_world().get_map() |
| 62 | |
| 63 | self._dt = None |
| 64 | self._target_speed = None |
| 65 | self._sampling_radius = None |
| 66 | self._min_distance = None |
| 67 | self._current_waypoint = None |
| 68 | self._target_road_option = None |
| 69 | self._next_waypoints = None |
| 70 | self.target_waypoint = None |
| 71 | self._vehicle_controller = None |
| 72 | self._global_plan = None |
| 73 | # queue with tuples of (waypoint, RoadOption) |
| 74 | self._waypoints_queue = deque(maxlen=20000) |
| 75 | self._buffer_size = 5 |
| 76 | self._waypoint_buffer = deque(maxlen=self._buffer_size) |
| 77 | |
| 78 | # initializing controller |
| 79 | self._init_controller(opt_dict) |
| 80 | |
| 81 | def __del__(self): |
| 82 | if self._vehicle: |
| 83 | self._vehicle.destroy() |
| 84 | print("Destroying ego-vehicle!") |
| 85 | |
| 86 | def reset_vehicle(self): |
| 87 | self._vehicle = None |
no outgoing calls
no test coverage detected