Skip to content
Merged
4 changes: 2 additions & 2 deletions src/Active-Lane-Keeping-Assistant/agent.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import os
import matplotlib.pyplot as plt
import numpy as np
import os

class Agent():
"""Agent that outputs the desired behaviour given
Expand Down Expand Up @@ -128,7 +128,7 @@ def get_actions(self, detection_surface_area:float,
"""
if (self.check_surface_area(detection_surface_area)):
steer = 0
if len(self.errors) > 0:
if self.errors:
self.errors.append(self.errors[-1])
else:
self.errors.append(0)
Expand Down
5 changes: 4 additions & 1 deletion src/Active-Lane-Keeping-Assistant/lane.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Lane:
ROI_TOP = 260
ROI_LEFT = 200
ROI_RIGHT = 440
# === 新增 ===
MARGIN_RATIO = 1.0 / 12.0
# ===========
def __init__(self, height:int, width:int, save:bool=False,
save_folder:str=join('img', 'examples')) -> None:
"""Constructor
Expand All @@ -32,7 +35,7 @@ def __init__(self, height:int, width:int, save:bool=False,
self.save_folder = save_folder
self.img_height = height
self.img_width = width
self.margin = int((1/12) * self.img_width)
self.margin = int(self.MARGIN_RATIO * self.img_width)
self.DEGREE = 2

# Variables to store for lines
Expand Down
3 changes: 2 additions & 1 deletion src/Active-Lane-Keeping-Assistant/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def reset(self) -> tuple[float, float, np.ndarray, bool]:
self.collision_sensor = self.world.spawn_actor(blueprint,
carla.Transform(), attach_to=self.vehicle)
self.collision_detected = False
self.collision_sensor.listen(lambda e: {self._set_collision()})
# Remove redundant set brackets
self.collision_sensor.listen(lambda e: self._set_collision())
self.initialized = True

return 0.0, 0.0, np.zeros((self.image_height, self.image_width, 3)), False
Expand Down
Loading