GNSS simulation on its own diagnostics page (/sim.html: drive the trip's route or randomly, stop, simulated time, the position and the trip); along the route with a detour now and then (300–800 m off every 3–8 km, routed by Valhalla); simulated time 1–20× with the fixes carrying the simulation's clock, so a recorded trip keeps real speeds (PUT /api/sim/gnss); /api/can says simulated
This commit is contained in:
1 parent
7d72e9eb63
commit
0c809b3e2b
9 files changed
+265
-46
No files matched your search
+1
-1
@@ -174,7 +174,7 @@ class AppTest < Minitest::Test
|
||||
|
||||
def test_can_requires_login_and_is_off_without_a_config
|
||||
assert_equal 401, request.get("/api/can").status
|
||||
assert_equal({ "interfaces" => {}, "nodes" => {}, "signals" => {}, "frames" => [], "available" => false }, json_body(request.get("/api/can", **logged_in_env)))
|
||||
assert_equal({ "interfaces" => {}, "nodes" => {}, "signals" => {}, "frames" => [], "available" => false, "simulated" => false }, json_body(request.get("/api/can", **logged_in_env)))
|
||||
end
|
||||
|
||||
# MQTT messages land in the tracker / ITS-G5 parts of /api/live.
|
||||
|
||||
@@ -35,6 +35,51 @@ class GnssSimTest < Minitest::Test
|
||||
sim&.stop
|
||||
end
|
||||
|
||||
# Sped up: five times the ground per tick, the fixes' clock five times
|
||||
# faster — the speed they report (and a recorded track's) stays real.
|
||||
def test_speedup_covers_more_ground_on_a_faster_clock
|
||||
times = ->(speedup) do
|
||||
sim = FixedRoute.new("http://valhalla", sleep: ->(_s) {})
|
||||
sim.speedup = speedup
|
||||
fixes = []
|
||||
sim.drive([17.0, 48.0]) { |fix| fixes << fix }
|
||||
fixes
|
||||
end
|
||||
real, fast = times.(1), times.(5)
|
||||
assert_in_delta real.size / 5.0, fast.size, 2
|
||||
assert_in_delta real.last[:time] - real.first[:time], fast.last[:time] - fast.first[:time], 5 # the same simulated time
|
||||
assert_equal real.first[:speed], fast.first[:speed]
|
||||
sim = Maptool::GnssSim.new("http://valhalla")
|
||||
sim.speedup = 7
|
||||
assert_equal 1, sim.speedup # not one of SPEEDUPS
|
||||
end
|
||||
|
||||
# A long route gets detours: a stretch replaced by the router's way through
|
||||
# a point off to one side (here: straight there and back), the start and the
|
||||
# end kept, the limits in order; a detour with no way keeps the route.
|
||||
def test_a_route_gets_detours_off_to_the_side
|
||||
asked = []
|
||||
router = lambda do |_url, (a, via, b), _vehicle|
|
||||
asked << via
|
||||
raise Maptool::Routing::RouteError, "no way" if asked.size == 2
|
||||
|
||||
{ geometry: { coordinates: [a, via, b] }, properties: { speed_limits: [[0.0, 30]] } }
|
||||
end
|
||||
sim = Maptool::GnssSim.new("http://valhalla", random: Random.new(1), router: router)
|
||||
line = [[17.0, 48.0], [17.3, 48.0]] # ~22 km east
|
||||
route = sim.with_detours({ geometry: { coordinates: line }, properties: { speed_limits: [[0.0, 90]] } })
|
||||
coords = route[:geometry][:coordinates]
|
||||
assert_equal [line.first, line.last], [coords.first, coords.last]
|
||||
assert_operator asked.size, :>=, 2
|
||||
off = asked.map { |_lon, lat| (lat - 48.0).abs * 111_320 }
|
||||
assert(off.all? { |m| m.between?(250, 850) }, "#{off} m off the route")
|
||||
assert_includes coords, asked.first # the first detour driven through its point
|
||||
refute_includes coords, asked[1] # the second had no way: the route as it was
|
||||
starts = route[:properties][:speed_limits].map(&:first)
|
||||
assert_equal starts.sort, starts
|
||||
assert_includes route[:properties][:speed_limits].map(&:last), 30
|
||||
end
|
||||
|
||||
# No road at the first random place: another one, inside the bbox.
|
||||
class FirstPlaceAtSea < Maptool::GnssSim
|
||||
attr_reader :tried
|
||||
|
||||
Reference in new issue
Block a user