Navigation: rerouting off the route (30 m for 3 fixes, HDOP ≤ 5, every 15 s at most) from the position to the points not reached yet; lanes as SVG arrows, the ones to take bold; dashboard background see-through with a slider; the GNSS simulation starts at a random place in the offline countries, the map jumping there
CI / check (push) Successful in 22s
CI / deploy (push) Successful in 18s

This commit is contained in:
randy committed 2026-11-30 19:11:07 +01:00
1 parent fbccb2acc9
commit 5f4c7c6ee8
9 files changed
+176 -35

No files matched your search

+26 -7
View File
@@ -29,15 +29,22 @@ module Maptool
@mutex.synchronize { @thread&.alive? || false }
end
# Drives from [lon, lat] until stopped; each fix to the block:
RANDOM_START_TRIES = 20 # a random point at sea / off the routing tiles: another one
# Drives from [lon, lat] until stopped — or, with bboxes
# ([[west, south, east, north], ...], the offline countries) instead,
# from a random place in one of them; each fix to the block:
# { lat:, lon:, speed: m/s, satellites:, hdop: }.
def start(lon, lat, &on_fix)
def start(lon = nil, lat = nil, bboxes: nil, &on_fix)
stop
@error = nil
@mutex.synchronize do
@thread = Thread.new do
position = [Float(lon), Float(lat)]
loop { position = drive(position, &on_fix) }
position, route = bboxes ? random_start(bboxes) : [[Float(lon), Float(lat)], nil]
loop do
position = drive(position, route, &on_fix)
route = nil
end
rescue StandardError => e
@error = e.message
warn "gnss sim: #{e.message}"
@@ -50,9 +57,21 @@ module Maptool
thread&.kill&.join
end
# One random trip from position; returns where it ended.
def drive(position, &on_fix)
route = random_route(position)
# A random place in one of the bboxes with a route out of it: [position, route].
def random_start(bboxes)
RANDOM_START_TRIES.times do
west, south, east, north = bboxes.sample(random: @random)
position = [west + @random.rand * (east - west), south + @random.rand * (north - south)]
return [position, random_route(position)]
rescue Routing::RouteError
next
end
raise Routing::RouteError, "no road found at #{RANDOM_START_TRIES} random places in the offline countries"
end
# One random trip from position (route: already planned); returns where it ended.
def drive(position, route = nil, &on_fix)
route ||= random_route(position)
coords = route[:geometry][:coordinates]
km = [0.0]
coords.each_cons(2) { |a, b| km << km.last + self.class.meters(a, b) / 1000 }
+1
View File
@@ -254,6 +254,7 @@ module Maptool
properties: { kind: "route", costing: costing, distance_km: data["trip"]["summary"]["length"],
time_s: data["trip"]["summary"]["time"], countries: along[:countries],
speed_limits: along[:speed_limits], signals: along[:signals],
legs_km: legs.map { |leg| leg.dig("summary", "length") }, # to each via point, for rerouting
# lanes: Valhalla's [{directions:, valid:, active:}] bitmasks, at junctions that have them
maneuvers: legs.flat_map { |leg| leg["maneuvers"].map { |m| { text: m["instruction"], km: m["length"], lanes: m["lanes"] }.compact } } } }
rescue ArgumentError, TypeError