GNSS course worked out server-side (App.gnss_update, for the CAN node and the simulation, which send none): following in 3D turns heading-up behind the position again
This commit is contained in:
1 parent
f65eb98d18
commit
8680cdbee7
4 files changed
+62
-6
No files matched your search
@@ -384,6 +384,31 @@ module Maptool
|
||||
|
||||
GNSS_LATEST = {}
|
||||
GNSS_LATEST_MUTEX = Mutex.new
|
||||
COURSE_MIN_M = 5 # fixes closer than this: too noisy for a course
|
||||
COURSE_MIN_SPEED = 1.5 # m/s: slower, the last course stays
|
||||
|
||||
# Where every GNSS fix lands (the node over CAN, the simulation): into
|
||||
# GNSS_LATEST, with the course over ground (track, °) worked out from
|
||||
# the fix COURSE_MIN_M back when the receiver sends none — following
|
||||
# heading-up from behind (followPosition, gnss.js) turns by it.
|
||||
def self.gnss_update(gnss, at: Time.now.to_f)
|
||||
GNSS_LATEST_MUTEX.synchronize do
|
||||
GNSS_LATEST.merge!(gnss)
|
||||
next unless gnss.key?(:lat) || gnss.key?(:lon)
|
||||
|
||||
GNSS_LATEST[:received_at] = at
|
||||
next if gnss.key?(:track)
|
||||
|
||||
position = GNSS_LATEST.values_at(:lon, :lat)
|
||||
from = GNSS_LATEST[:course_from]
|
||||
if from.nil? || (GNSS_LATEST[:speed] || 0) < COURSE_MIN_SPEED
|
||||
GNSS_LATEST[:course_from] = position
|
||||
elsif GnssSim.meters(from, position) >= COURSE_MIN_M
|
||||
GNSS_LATEST[:track] = GnssSim.bearing(from, position).round(1)
|
||||
GNSS_LATEST[:course_from] = position
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Native CAN (lib/maptool/can.rb), on when data/can.json exists: one
|
||||
# reader thread per interface. Signals named gnss.<field> (lat, lon,
|
||||
@@ -410,10 +435,7 @@ module Maptool
|
||||
gnss = values.filter_map { |name, value| [name.delete_prefix("gnss.").to_sym, value] if name.start_with?("gnss.") }.to_h
|
||||
next if gnss.empty? || GNSS_SIM.running?
|
||||
|
||||
GNSS_LATEST_MUTEX.synchronize do
|
||||
GNSS_LATEST.merge!(gnss)
|
||||
GNSS_LATEST[:received_at] = Time.now.to_f if gnss.key?(:lat) || gnss.key?(:lon)
|
||||
end
|
||||
App.gnss_update(gnss)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1251,7 +1273,7 @@ module Maptool
|
||||
CAN_STORE.override_prefix = "gnss."
|
||||
GNSS_SIM.start(lon, lat) do |fix|
|
||||
CAN_STORE.put(fix.transform_keys { |key| "gnss.#{key}" })
|
||||
GNSS_LATEST_MUTEX.synchronize { GNSS_LATEST.merge!(fix, received_at: Time.now.to_f) }
|
||||
App.gnss_update(fix)
|
||||
end
|
||||
json running: true
|
||||
rescue JSON::ParserError
|
||||
@@ -1281,7 +1303,7 @@ module Maptool
|
||||
GNSS_LATEST_MUTEX.synchronize do
|
||||
received_at = GNSS_LATEST[:received_at]
|
||||
fresh = received_at && (Time.now.to_f - received_at) < GNSS_STALE_AFTER
|
||||
json(fresh ? GNSS_LATEST.merge(available: true) : { available: false })
|
||||
json(fresh ? GNSS_LATEST.except(:course_from).merge(available: true) : { available: false })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user