diff --git a/TODO.adoc b/TODO.adoc
index d9e68c0..3e3c4fb 100644
--- a/TODO.adoc
+++ b/TODO.adoc
@@ -212,17 +212,27 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho
** [ ] Speed limits that aren't on the edge: `maxspeed:conditional` (time, wet), variable
signs, `zone:maxspeed` defaults per country (Valhalla leaves untagged roads empty — show
the country's default by road class?), the vehicle's own limits (a camper > 3.5 t: 80/100)
-** [ ] Rerouting when off the route (> 50 m for a while): a new route from the position to the
- remaining points
+** [x] Rerouting (after Ferrostar's split of deviation detection and recalculation): off the
+ route = over 30 m from its line for 3 fixes in a row (fixes with HDOP > 5 don't count), then
+ the route panel routes from the position to the points not reached yet (via points passed
+ by km along the route, `legs_km`), at most every 15 s and only moving
+*** [ ] Step advance like Ferrostar's DistanceEntryExit (30 m to the step's end, 5 m past it)
+ instead of "the first maneuver ahead by km"; arrival at 30 m
** [ ] Turn-by-turn: the next maneuver big (arrow, distance, street), voice
(`speechSynthesis`), the route ahead highlighted / the driven part greyed
-** [ ] Lanes as proper arrows (SVG per direction bit, not Unicode) and only the lanes Valhalla
- marks for the maneuver; through-lanes guidance before motorway exits
+** [x] Lanes as SVG arrows, one per direction bit, the lanes to take (Valhalla's `active`) blue
+ with that direction bold
+*** [ ] Lane guidance before motorway exits (lanes several maneuvers ahead), bigger on the
+ driving screen
** [ ] Traffic signals with no route: around the position (Valhalla `locate` or the offline
PBF), and only for the direction driven (`traffic_signals:direction`)
** [ ] The "Navigate" follow mode for the CAN GNSS position (today the MQTT tracker and the
browser's GNSS control), the dashboard as part of the driving-mode UI
** [ ] `locate()` scans the whole route each fix — a window around the last hit on long routes
+** [ ] A native Android app on Ferrostar (rerouting, Valhalla speed limits, TTS built in) over
+ our Valhalla (`format: osrm`) — only if navigation is wanted on a phone outside the car; the
+ car's 16" display is the Pi's browser either way. Ferrostar's web components are beta: no
+ rerouting or annotations on the web, bundler + WASM, its own map element
** [x] GNSS simulation for trying it without the car (`lib/maptool/gnss_sim.rb`, Dashboard
settings → "Simulate driving from the map center", `POST/DELETE /api/sim/gnss`): random
trips over our Valhalla (2–8 km each, one after another) at 90 % of the road's limit, a fix
diff --git a/app.rb b/app.rb
index 9920415..ecd2b91 100644
--- a/app.rb
+++ b/app.rb
@@ -1259,7 +1259,8 @@ module Maptool
end
# The GNSS simulation: POST {"start": [lon, lat]} drives randomly from
- # there, DELETE stops it, GET says whether it's on (and why it stopped).
+ # there, POST {} from a random place in the offline countries, DELETE
+ # stops it, GET says whether it's on (and why it stopped).
get "/api/sim/gnss" do
require_login!
json running: GNSS_SIM.running?, error: GNSS_SIM.error
@@ -1268,10 +1269,16 @@ module Maptool
post "/api/sim/gnss" do
require_login!
lon, lat = JSON.parse(request.body.read)["start"]
- halt 400, json(error: "start must be [lon, lat]") unless lon.is_a?(Numeric) && lat.is_a?(Numeric)
+ if lon.nil?
+ codes = (PmtilesBuilder.offline_meta(DATA_DIR) || {}).fetch("sources", []).map { |source| source["code"] }
+ bboxes = codes.filter_map { |code| PmtilesBuilder.country_bbox(code) }
+ halt 422, json(error: "no offline countries to start in") if bboxes.empty?
+ elsif !lon.is_a?(Numeric) || !lat.is_a?(Numeric)
+ halt 400, json(error: "start must be [lon, lat]")
+ end
CAN_STORE.override_prefix = "gnss."
- GNSS_SIM.start(lon, lat) do |fix|
+ GNSS_SIM.start(lon, lat, bboxes: bboxes) do |fix|
CAN_STORE.put(fix.transform_keys { |key| "gnss.#{key}" })
App.gnss_update(fix)
end
diff --git a/lib/maptool/gnss_sim.rb b/lib/maptool/gnss_sim.rb
index fc53263..52b2257 100644
--- a/lib/maptool/gnss_sim.rb
+++ b/lib/maptool/gnss_sim.rb
@@ -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 }
diff --git a/lib/maptool/routing.rb b/lib/maptool/routing.rb
index 55c25c7..d5a320f 100644
--- a/lib/maptool/routing.rb
+++ b/lib/maptool/routing.rb
@@ -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
diff --git a/public/css/style.css b/public/css/style.css
index 5038394..64c42c4 100644
--- a/public/css/style.css
+++ b/public/css/style.css
@@ -3293,10 +3293,13 @@ html.night .maplibregl-marker {
z-index: 3;
padding: 8px;
border-radius: 12px;
- background: #fff;
- box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
+ background: rgb(255 255 255 / var(--dash-alpha, 0.45));
+ backdrop-filter: blur(2px);
+ box-shadow: 0 1px 6px rgb(0 0 0 / calc(var(--dash-alpha, 0.45) * 0.5));
text-align: center;
pointer-events: none;
+ /* readable over the map whatever the background */
+ text-shadow: 0 0 3px #fff, 0 0 3px #fff;
}
.dash-incl {
@@ -3307,7 +3310,8 @@ html.night .maplibregl-marker {
}
.dash-incl text { text-anchor: middle; dominant-baseline: middle; fill: #222; }
-.dash-face { fill: #f6f6f4; stroke: #bbb; stroke-width: 2; }
+.dash-face { fill: rgb(246 246 244 / var(--dash-alpha, 0.45)); stroke: #999; stroke-width: 2; }
+.dash-incl text { paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.dash-ring line { stroke: #555; stroke-width: 2; }
.dash-ring text { font-size: 14px; font-weight: 600; }
.dash-ring .dash-n { fill: #c62828; }
@@ -3343,7 +3347,11 @@ html.night .maplibregl-marker {
radial-gradient(circle at 50% 83%, #43a047 2.5px, transparent 3px), #222;
}
.dash-lanes { display: flex; gap: 3px; }
-.dash-lanes span { min-width: 22px; padding: 1px 3px; border-radius: 4px; background: #eee; color: #999; text-align: center; font-size: 16px; }
-.dash-lanes .dash-lane--go { background: #1d6fdc; color: #fff; }
.dash-card--over { box-shadow: 0 0 0 4px #d32f2f, 0 1px 6px rgba(0, 0, 0, 0.25); }
.dash-card--over .dash-speed span { color: #d32f2f; }
+.dash-lanes svg.dash-lane { width: 26px; height: 34px; border-radius: 4px; background: #eee; }
+.dash-lane__arrow { fill: none; stroke: #aaa; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
+.dash-lane--go { background: #1d6fdc !important; }
+.dash-lane--go .dash-lane__arrow { stroke: #cfe0f7; }
+.dash-lane--go .dash-lane__take { stroke: #fff; stroke-width: 3; }
+.dash-offroute { color: #c62828; font-weight: 600; }
diff --git a/public/js/dashboard.js b/public/js/dashboard.js
index 75e7258..f5928b1 100644
--- a/public/js/dashboard.js
+++ b/public/js/dashboard.js
@@ -1,5 +1,5 @@
import { isLoggedIn } from "/js/auth.js";
-import { onRouteChanged } from "/js/panels.js";
+import { onRouteChanged, requestReroute } from "/js/panels.js";
// The car's dashboard over the map, off the CAN signals (GET /api/can,
// names from data/can.json): one inclinometer — compass ring around a rear
@@ -9,7 +9,7 @@ import { onRouteChanged } from "/js/panels.js";
// Heading: driving, the GNSS course (from consecutive fixes); standing
// still, the compass (imu.heading, once the node sends it) — else the
// last course stays, dimmed.
-const SIGNALS = { pitch: "imu.pitch", roll: "imu.roll", heading: "imu.heading", speed: "gnss.speed", lat: "gnss.lat", lon: "gnss.lon" };
+const SIGNALS = { pitch: "imu.pitch", roll: "imu.roll", heading: "imu.heading", speed: "gnss.speed", lat: "gnss.lat", lon: "gnss.lon", hdop: "gnss.hdop" };
const MOVING_MS = 1.5; // m/s: above this the GNSS course counts
const COURSE_MIN_M = 5; // fixes closer than this: too noisy for a course
const POLL_MS = 500;
@@ -20,11 +20,19 @@ const STORE_KEY = "maptool.dashboard";
// while on it (its speed_limits / signals / maneuvers from /api/route),
// else the limit of the road being driven (POST /api/road, map-matched).
const OVER_KMH = 3; // over the limit by more than this: warning
-const ON_ROUTE_M = 50; // farther from the route line: off it
+// Off the route → rerouting, after Ferrostar's split: deviation detected
+// (farther than ON_ROUTE_M for OFF_ROUTE_FIXES fixes in a row, fixes with an
+// HDOP over MAX_HDOP don't count), then a new route from the position to
+// the points not reached yet — at most every REROUTE_EVERY_MS, only moving.
+const ON_ROUTE_M = 30; // farther from the route line: off it
+const OFF_ROUTE_FIXES = 3;
+const MAX_HDOP = 5; // ~ over 10 m off at the NEO-6M's few m UERE
+const REROUTE_EVERY_MS = 15000;
const ROAD_EVERY_MS = 4000; // /api/road at most this often, only while moving
const TRACE_STEP_M = 10; // fixes kept for /api/road at least this far apart
const LANES_AHEAD_M = 1000; // the next maneuver's lanes from this close
const DEFAULT_WIDGETS = { inclinometer: true, speed: true, navigation: true };
+const DEFAULT_OPACITY = 0.45; // the card's background, the map shows through
const load = () => {
try { const saved = JSON.parse(localStorage.getItem(STORE_KEY)) || {}; return { ...saved, widgets: { ...DEFAULT_WIDGETS, ...saved.widgets } }; }
@@ -35,9 +43,23 @@ const RAD = Math.PI / 180;
// meters between two [lon, lat] (equirectangular: fine at these distances)
const meters = ([lon1, lat1], [lon2, lat2]) => Math.hypot((lon2 - lon1) * Math.cos(((lat1 + lat2) / 2) * RAD), lat2 - lat1) * 111320;
const distance = (m) => (m >= 1000 ? `${(m / 1000).toFixed(1)} km` : `${Math.round(m / 10) * 10} m`);
-// Valhalla's lane direction bits → arrows
-const LANE_ARROWS = [[2, "↑"], [16, "↖"], [8, "←"], [4, "↙"], [32, "↗"], [64, "→"], [128, "↘"], [256, "↶"], [512, "⇤"], [1024, "⇥"]];
-const laneArrows = (bits) => LANE_ARROWS.filter(([bit]) => bits & bit).map(([, arrow]) => arrow).join("") || "↑";
+// Valhalla's lane direction bits → the arrow's angle (° from straight on)
+const LANE_ANGLES = { 2: 0, 16: -45, 8: -90, 4: -135, 32: 45, 64: 90, 128: 135, 512: -25, 1024: 25 };
+const LANE_REVERSE = 256;
+// One lane as an SVG: an arrow per direction it allows; `active` (the
+// directions to take, a bitmask too) drawn bold.
+function laneSvg({ directions, active = 0 }) {
+ const arrow = (bit) => {
+ const bold = active & bit ? " dash-lane__take" : "";
+ if (bit === LANE_REVERSE) return `