commit b739d9a411badb9f76fce084b7158757fb339506
parent 64789d1fe98bee96f69e0d9a4df56aa8c6b1ab45
Author: Daniel Barlow <dan@telent.net>
Date: Mon, 30 Jun 2025 18:19:20 +0100
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
Diffstat:
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git 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 []