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

Class VehiclePIDController

agents/navigation/controller.py:15–88  ·  view source on GitHub ↗

VehiclePIDController is the combination of two PID controllers (lateral and longitudinal) to perform the low level control a vehicle from client side

Source from the content-addressed store, hash-verified

13
14
15class VehiclePIDController():
16 """
17 VehiclePIDController is the combination of two PID controllers
18 (lateral and longitudinal) to perform the
19 low level control a vehicle from client side
20 """
21
22
23 def __init__(self, vehicle, args_lateral, args_longitudinal, max_throttle=0.75, max_brake=0.3, max_steering=0.8):
24 """
25 Constructor method.
26
27 :param vehicle: actor to apply to local planner logic onto
28 :param args_lateral: dictionary of arguments to set the lateral PID controller
29 using the following semantics:
30 K_P -- Proportional term
31 K_D -- Differential term
32 K_I -- Integral term
33 :param args_longitudinal: dictionary of arguments to set the longitudinal
34 PID controller using the following semantics:
35 K_P -- Proportional term
36 K_D -- Differential term
37 K_I -- Integral term
38 """
39
40 self.max_brake = max_brake
41 self.max_throt = max_throttle
42 self.max_steer = max_steering
43
44 self._vehicle = vehicle
45 self._world = self._vehicle.get_world()
46 self.past_steering = self._vehicle.get_control().steer
47 self._lon_controller = PIDLongitudinalController(self._vehicle, **args_longitudinal)
48 self._lat_controller = PIDLateralController(self._vehicle, **args_lateral)
49
50 def run_step(self, target_speed, waypoint):
51 """
52 Execute one step of control invoking both lateral and longitudinal
53 PID controllers to reach a target waypoint
54 at a given target_speed.
55
56 :param target_speed: desired vehicle speed
57 :param waypoint: target location encoded as a waypoint
58 :return: distance (in meters) to the waypoint
59 """
60
61 acceleration = self._lon_controller.run_step(target_speed)
62 current_steering = self._lat_controller.run_step(waypoint)
63 control = carla.VehicleControl()
64 if acceleration >= 0.0:
65 control.throttle = min(acceleration, self.max_throt)
66 control.brake = 0.0
67 else:
68 control.throttle = 0.0
69 control.brake = min(abs(acceleration), self.max_brake)
70
71 # Steering regulation: changes cannot happen abruptly, can't steer too much.
72

Callers 2

run_stepMethod · 0.90
_init_controllerMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected