From cea25354b15d6ad9c564ebe917d1d518e8e088f3 Mon Sep 17 00:00:00 2001 From: wutong88yuyu <2179751939@qq.com> Date: Thu, 18 Dec 2025 19:15:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=90=86=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E5=99=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Active-Lane-Keeping-Assistant/agent.py | 29 ++++++++++------------ 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/Active-Lane-Keeping-Assistant/agent.py b/src/Active-Lane-Keeping-Assistant/agent.py index 6c51f98c18..18a0706b7a 100644 --- a/src/Active-Lane-Keeping-Assistant/agent.py +++ b/src/Active-Lane-Keeping-Assistant/agent.py @@ -138,24 +138,21 @@ def get_actions(self, detection_surface_area:float, return steer, self.throttle @staticmethod - def _simple_controller(error:float) -> float: - """Hard Coded Controller - - Args: - error (float): Difference to the center of the detected lane. - - Returns: - float: Steering angle to use. + def _simple_controller(error: float) -> float: + """Hard Coded Controller - Optimized to use Class Constants """ - limit = 0.75 - tolerance = 0.1 + # 使用类中定义的常量,方便统一管理 + limit = Agent.SIMPLE_STEER_LIMIT + tolerance = Agent.SIMPLE_ERROR_TOLERANCE + if (abs(error) < tolerance): - steer = 0 - elif error > 0: - steer = -limit - else: - steer = limit - return steer + return 0.0 + + # 简化逻辑分支 + if error > 0: + return -limit + + return limit def _p_controller(self, error:float) -> float: """Proportional Controller