From f507d837f01aedd8e25e39c0ea1afceb882b52b5 Mon Sep 17 00:00:00 2001 From: Guillermo Date: Fri, 2 Dec 2022 13:27:16 +0100 Subject: [PATCH] Exposed Python agents' offset --- PythonAPI/carla/agents/navigation/basic_agent.py | 4 ++++ PythonAPI/carla/agents/navigation/controller.py | 8 ++++++++ PythonAPI/carla/agents/navigation/local_planner.py | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/PythonAPI/carla/agents/navigation/basic_agent.py b/PythonAPI/carla/agents/navigation/basic_agent.py index 1bed8cd37..093749d5a 100644 --- a/PythonAPI/carla/agents/navigation/basic_agent.py +++ b/PythonAPI/carla/agents/navigation/basic_agent.py @@ -229,6 +229,10 @@ class BasicAgent(object): """(De)activates the checks for stop signs""" self._ignore_vehicles = active + def set_offset(self, offset): + """Sets an offset for the vehicle""" + self._local_planner.set_offset(offset) + def lane_change(self, direction, same_lane_time=0, other_lane_time=0, lane_change_time=2): """ Changes the path so that the vehicle performs a lane change. diff --git a/PythonAPI/carla/agents/navigation/controller.py b/PythonAPI/carla/agents/navigation/controller.py index ac53d09f5..a87488c74 100644 --- a/PythonAPI/carla/agents/navigation/controller.py +++ b/PythonAPI/carla/agents/navigation/controller.py @@ -100,6 +100,10 @@ class VehiclePIDController(): """Changes the parameters of the PIDLateralController""" self._lat_controller.change_parameters(**args_lateral) + def set_offset(self, offset): + """Changes the offset""" + self._lat_controller.set_offset(offset) + class PIDLongitudinalController(): """ @@ -204,6 +208,10 @@ class PIDLateralController(): """ return self._pid_control(waypoint, self._vehicle.get_transform()) + def set_offset(self, offset): + """Changes the offset""" + self._offset = offset + def _pid_control(self, waypoint, vehicle_transform): """ Estimate the steering angle of the vehicle based on the PID equations diff --git a/PythonAPI/carla/agents/navigation/local_planner.py b/PythonAPI/carla/agents/navigation/local_planner.py index 67de7e781..e4f4b7fb7 100644 --- a/PythonAPI/carla/agents/navigation/local_planner.py +++ b/PythonAPI/carla/agents/navigation/local_planner.py @@ -216,6 +216,10 @@ class LocalPlanner(object): self._stop_waypoint_creation = stop_waypoint_creation + def set_offset(self, offset): + """Sets an offset for the vehicle""" + self._vehicle_controller.set_offset(offset) + def run_step(self, debug=False): """ Execute one step of local planning which involves running the longitudinal and lateral PID controllers to