Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/Active-Lane-Keeping-Assistant/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,35 @@ def save_error_fig(self, path:str, id:str) -> None:
file_name = os.path.join(path, f'{id}_error.jpg')
plt.savefig(file_name)

def get_actions(self, detection_surface_area:float,
def get_actions(self, detection_surface_area:float,
error:float) -> tuple[float, float]:

# 默认基础油门
dynamic_throttle = self.throttle

if (self.check_surface_area(detection_surface_area)):
# Case 1: 没找到车道线 (安全模式)
steer = 0
# [Planning] Safety: 丢失视野时,强制降速以策安全
dynamic_throttle = 0.2

if self.errors:
self.errors.append(self.errors[-1])
else:
self.errors.append(0)
else:
# Case 2: 正常行驶
self.errors.append(error)
steer = self.func(error=error)
return steer, self.throttle

# [Planning] 核心修改:基于曲率的纵向速度规划 (Longitudinal Speed Planning)
# 注意:这不是 ACC (自适应巡航),而是弯道速度控制。
# 策略:方向盘转角越大 -> 弯越急 -> 速度越慢
# 公式:基础油门 - (转角绝对值 * 系数)
# 优化:系数调整为 0.8,确保弯道减速肉眼可见
dynamic_throttle = max(0.2, self.throttle - abs(steer) * 0.8)

return steer, dynamic_throttle

@staticmethod
def _simple_controller(error: float) -> float:
Expand Down
Loading