Navigation: arrived 30 m from the end (banner, drive mode), navigating on past it (the reroute turns back); the next maneuver's lanes from 1 km or 45 s at the speed driven, in drive mode a cell under the maneuver over the map ("ahead" in the profile, shown only with something in it) with the next traffic signal; signals with no route: /api/road also routes 1.5 km straight on from the last fix and gives that way's signals, the nearest one in front shown. TODO: the CAN GNSS follow done (the LTE tracker a layer to switch on), any tracker point followable later
CI / check (push) Successful in 1m22s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-03 17:57:27 +01:00
1 parent ad975bcf62
commit a6158f4083
7 files changed
+110 -15

No files matched your search

+27 -1
View File
@@ -328,11 +328,37 @@ module Maptool
shape: points.map { |lon, lat| { lon: Float(lon), lat: Float(lat) } }, costing: "auto", shape_match: "map_snap",
filters: { attributes: %w[edge.names edge.road_class edge.speed_limit edge.surface], action: "include" })
edge = data["edges"]&.last or raise RouteError, "no road here"
{ name: edge["names"]&.first, road_class: edge["road_class"], speed_limit: speed_limit(edge["speed_limit"]), surface: edge["surface"] }.compact
{ name: edge["names"]&.first, road_class: edge["road_class"], speed_limit: speed_limit(edge["speed_limit"]), surface: edge["surface"],
signals: signals_ahead(valhalla_url, points) }.compact
rescue ArgumentError, TypeError
raise RouteError, "invalid coordinates"
end
AHEAD_KM = 1.5
# The traffic signals on the road ahead with no route: a route from the
# last fix, leaving in the direction driven, to AHEAD_KM straight on;
# [[lon, lat, km from the fix], ...], nil if that fails (it's extra).
# ponytail: "straight on" picks the way at a junction, a signal past a
# turn the driver then takes is missed until the next fix's lookup
def self.signals_ahead(valhalla_url, points)
(lon0, lat0), (lon, lat) = points.last(2).map { |p| p.map { |v| Float(v) } }
rad = Math::PI / 180
dx = (lon - lon0) * Math.cos(lat * rad)
dy = lat - lat0
return nil if dx.zero? && dy.zero?
heading = (Math.atan2(dx, dy) / rad) % 360
deg = AHEAD_KM / 111.32
to = { lon: lon + deg * Math.sin(heading * rad) / Math.cos(lat * rad), lat: lat + deg * Math.cos(heading * rad) }
data = valhalla(valhalla_url, "/route", locations: [{ lon: lon, lat: lat, heading: heading.round, heading_tolerance: 45 }, to],
costing: "auto", directions_type: "none")
along_route(valhalla_url, data.dig("trip", "legs"), "auto", {})&.dig(:signals)
rescue RouteError, Unavailable, Net::ReadTimeout, NoMethodError, TypeError, ArgumentError
nil
end
private_class_method :signals_ahead
ISOCHRONE_MAX_MINUTES = 240 # Valhalla's own default limit
# How far the vehicle gets from [lon, lat] in each of `minutes`: a