From 8eb8042a478a575983df5106971f6b0fc8d24dd5 Mon Sep 17 00:00:00 2001 From: misko Date: Mon, 29 Jan 2024 06:13:32 +0000 Subject: [PATCH] fix bounce by adding in random direction when cornered --- spf/grbl/grbl_interactive.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spf/grbl/grbl_interactive.py b/spf/grbl/grbl_interactive.py index c1a0faa3..96c7f289 100644 --- a/spf/grbl/grbl_interactive.py +++ b/spf/grbl/grbl_interactive.py @@ -297,11 +297,16 @@ def bounce(self, current_p, total_bounces=-1): to_points, new_direction = self.single_bounce( self.current_direction, current_p ) - logging.info(f"{str(self)},{str(to_points[0])},{str(to_points[-1])}") + logging.info( + f"{str(self)},{str(to_points[0])},{str(to_points[-1])},{str(new_direction)},{len(to_points)}" + ) assert len(to_points) > 0 yield from to_points current_p = to_points[-1] - self.current_direction = new_direction + if len(to_points) == 1: + self.current_direction = self.random_direction() + else: + self.current_direction = new_direction n_bounce += 1 logging.info("Exiting bounce")