Skip to content

Commit

Permalink
fix: ensure the kart won't move after parking
Browse files Browse the repository at this point in the history
  • Loading branch information
HeadTriXz committed Jun 13, 2024
1 parent dd6a627 commit ec4a8ee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/lane_assist/lane_assist.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class LaneAssist:
speed_controller: ISpeedController
telemetry: TelemetryServer

__killed: bool = False
__path_follower: PathFollower
__stop_line_assist: StopLineAssist
__calibration: CalibrationData
Expand Down Expand Up @@ -152,10 +153,14 @@ def start(self, multithreading: bool = False) -> threading.Thread | None:

def stop(self) -> None:
"""Stop the lane assist."""
self.__killed = True
self.enabled = False

def toggle(self) -> None:
"""Toggle the lane assist."""
if self.__killed:
return

self.enabled = not self.enabled
self.__path_follower.reset()

Expand Down Expand Up @@ -185,12 +190,12 @@ def __follow_path(self, lines: list[Line], position: tuple[int, int], lane: int)
def __run(self) -> None:
"""Run the lane assist loop."""
try:
for gray_image in self.image_generator():
for image in self.image_generator():
if not self.enabled:
time.sleep(0.5)
continue

self.lane_assist_loop(gray_image)
self.lane_assist_loop(image)
time.sleep(0)
except StopIteration:
pass
3 changes: 0 additions & 3 deletions src/object_recognition/handlers/parking_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ def handle(self, predictions: Boxes) -> None:
manoeuvre = ParkingManoeuvre(self.__lidar, self.controller.lane_assist)
manoeuvre.park()

while True:
time.sleep(1)

def __any_within_distance(self, predictions: Boxes) -> bool:
"""Check if any parking space is within the distance threshold.
Expand Down
2 changes: 1 addition & 1 deletion src/utils/parking.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def park(self) -> None:
self.__straighten_wheels()

self.__wait_until(lambda: self.__is_centered(available_space))
self.__speed_controller.toggle()
self.__speed_controller.state = SpeedControllerState.STOPPED

def __angle_to_xy(self, angle: int) -> tuple[float, float]:
"""Convert an angle and distance to x, y coordinates.
Expand Down

0 comments on commit ec4a8ee

Please sign in to comment.