From b739d9a411badb9f76fce084b7158757fb339506 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Mon, 30 Jun 2025 18:19:20 +0100 Subject: [PATCH] experiment: smooth orientation a bit remember three most recent orientation values and pick the middle one but clamped between the values of the least and most recent --- pkgs/maps/main.fnl | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl index c8e79c8..67a6e76 100644 --- a/pkgs/maps/main.fnl +++ b/pkgs/maps/main.fnl @@ -86,6 +86,7 @@ label.readout { :lon 0 :zoom 17 :course 0 ; direction of travel + :courses [0 0 0] :orientation-target 0 ; map rotation angle from north :orientation-actual 0 ; map rotation angle from north :tiles {} @@ -446,6 +447,11 @@ label.readout { })))) +(fn clamp [a b c] + (if (< b a) a + (> b c) c + b)) + (fn read-gnss [socket] (each [l #(socket:read "l")] ; (print "gnss" l) @@ -463,9 +469,14 @@ label.readout { ) { : speed-knots } (update-app-state { :speed (* speed-knots knot-in-m-s) })) - (if message.bearing-true - (update-app-state { :course message.bearing-true })) - ))) + (when message.bearing-true + (let [c1 message.bearing-true + c2 (. app-state.courses 1) + c3 (. app-state.courses 2)] + (update-app-state + { :course (clamp c1 c2 c3) + :courses [c1 c2 c3] + })))))) true) (fn collect-profile []