From 6b921e2c253d1dc8559ba23b4820a67351be8096 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 15 Jun 2025 17:49:46 +0100 Subject: [PATCH] clamp minimum turn speed if there's less than ten degrees between target and actual, snap to target. Otherwise we only approach the target asymptotically and never reach it --- pkgs/maps/main.fnl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl index e6fe4de..ab83346 100644 --- a/pkgs/maps/main.fnl +++ b/pkgs/maps/main.fnl @@ -301,6 +301,11 @@ label.readout { (expect= (hhmmss (+ 45 (* 60 12) (* 60 60 3))) "3:12:45") +(fn turn-smoothly [from to] + (if (< (math.abs (- from to)) 10) to + (+ from (* 0.05 (- to from))))) + + (fn update-app-state [new-vals] (let [old-state (merge {} app-state) @@ -320,10 +325,7 @@ label.readout { (when (not (= app-state.orientation-target app-state.orientation-actual)) (set app-state.orientation-actual - (+ app-state.orientation-actual - (* 0.05 (- app-state.orientation-target app-state.orientation-actual)))) - ) - + (turn-smoothly app-state.orientation-actual app-state.orientation-target))) (each [name widget (pairs state-widgets)] (case name :speed (widget:set_label