In this section
- SatNav Orient17a V9215 Browser render · gridatlas / tools/satnav/orient17a-v9215-browser.py lines 1–112
- SatNav Orient17a V9216 Browser render · gridatlas / tools/satnav/orient17a-v9216-browser.py lines 1–138
- Orient17a Heading Filter transform · gridatlas / tools/satnav/orientation/orient17a-heading-filter.mjs lines 1–39
- Orient17a Navigation transform · gridatlas / tools/satnav/orientation/orient17a-navigation.mjs lines 1–47
- Orient17a Navigation Test test · gridatlas / tools/satnav/orientation/orient17a-navigation.test.mjs lines 1–13
- Orient17a Reference Wmm transform · gridatlas / tools/satnav/orientation/orient17a-reference-wmm.mjs lines 1–31
- Orient17a Reference transform · gridatlas / tools/satnav/orientation/orient17a-reference.mjs lines 1–5
- Orient17a V9211 Heading transform · gridatlas / tools/satnav/orientation/orient17a-v9211-heading.mjs lines 1–61
- Orient17a V9211 Heading Test test · gridatlas / tools/satnav/orientation/orient17a-v9211-heading.test.mjs lines 1–16
- Orient17a V9212 Heading transform · gridatlas / tools/satnav/orientation/orient17a-v9212-heading.mjs lines 1–62
- Orient17a V9212 Navigation transform · gridatlas / tools/satnav/orientation/orient17a-v9212-navigation.mjs lines 1–50
- Orient17a V9212 Test test · gridatlas / tools/satnav/orientation/orient17a-v9212.test.mjs lines 1–20
- Orient17a V9214 Compass Test test · gridatlas / tools/satnav/orientation/orient17a-v9214-compass.test.mjs lines 1–20
- Orient17a V9214 Event Clock transform · gridatlas / tools/satnav/orientation/orient17a-v9214-event-clock.mjs lines 1–16
SatNav Orient17a V9215 Browser
A Python module in the tools folder of GridAtlas that emits heading (`emit_heading`).
rendergridatlas / tools/satnav/orient17a-v9215-browser.py · lines 1–112 of 112 · Not reached from any entry point (candidate for review) · pattern emit_heading (shared by 5 files)
- What it does
- Defines emit_heading. Uses libraries os, pathlib, runpy, playwright.sync_api. Side effects: changes the web page (DOM); reads or writes files.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- What it achieves
- V9.215 composed application acceptance: simulated acquisition, not device evidence.
- Why it matters
- No other file in the estate was found to import it.
- Application
- gridatlas · tools/satnav · Python module
- Uses
- os, pathlib, runpy, playwright.sync_api
- Used by
- none found
- Produces
- none declared
- Defines here
- emit_heading
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/orient17a-v9215-browser.py:1-112 · blob d7363b85d167ee85a6bec7f107b2e0c15271b87f · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom, filesystem · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: unreached_review
"""V9.215 composed application acceptance: simulated acquisition, not device evidence."""
import os
from pathlib import Path
from runpy import run_path
from playwright.sync_api import expect,sync_playwright
gps=run_path(str(Path(__file__).with_name('compact-browser.py')))['GPS_SPY']
start=[-.12,51.5]
target=[-.12,51.501]
site='http://127.0.0.1:8873/atlas/v/202612040126/'
with sync_playwright() as p:
browser=getattr(p,os.environ['ORIENT_BROWSER']).launch()
for width,height in [(390,844),(844,390),(1366,768),(1920,1080)]:
with browser.new_context(viewport={'width':width,'height':height},has_touch=True) as ctx:
ctx.add_init_script(gps)
ctx.add_init_script("""Object.defineProperty(window,'DeviceOrientationEvent',{configurable:true,value:class extends Event{static async requestPermission(){return 'granted';}}});""")
page=ctx.new_page()
page.goto(site,wait_until='domcontentloaded',timeout=90000)
page.wait_for_function("()=>document.querySelector('#satnav-compact')?.satnavSurvey?.getMap()?.getLayer('l-sat')&&document.querySelector('#satnav-walk-mode')&&document.querySelector('#field-compass-toggle')",timeout=120000)
if not page.locator('#satnav-compact').is_visible(): page.locator('#satnav-toggle').tap()
page.evaluate("pts=>document.querySelector('#satnav-compact').satnavSurvey.replacePlan(pts)",[start,target])
mode=page.locator('#satnav-walk-mode')
button=page.locator('#satnav-walk-start')
for val in ('walking','driving','mapped'):
mode.select_option(val)
expect(button).to_be_disabled()
mode.select_option('direct')
button.tap()
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",start)
card=page.locator('#orient17a-direction')
arrow=page.locator('#orient17a-arrow')
expect(card).to_be_visible()
expect(card).to_contain_text('Direction uncertain')
expect(card).to_contain_text('straight line')
expect(arrow).to_be_hidden()
page.locator('#field-compass-toggle').tap()
expect(page.locator('#field-compass-toggle')).to_have_attribute('aria-pressed','true')
page.wait_for_timeout(100)
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",start)
page.evaluate("""()=>{const e=new Event('deviceorientation');Object.defineProperties(e,{webkitCompassHeading:{value:90},webkitCompassAccuracy:{value:3},beta:{value:0},gamma:{value:0}});window.dispatchEvent(e);}""")
expect(arrow).to_be_visible()
# Empty events must not erase a valid reading or refresh its age.
for _ in range(3):
page.evaluate("()=>window.dispatchEvent(new Event('deviceorientation'))")
expect(arrow).to_be_visible()
page.wait_for_timeout(100)
page.wait_for_timeout(2850)
page.evaluate("()=>window.dispatchEvent(new Event('deviceorientation'))")
expect(arrow).to_be_hidden()
def emit_heading(heading, accuracy=3, beta=0):
page.evaluate("""args=>{const e=new Event('deviceorientation');Object.defineProperties(e,{webkitCompassHeading:{value:args[0]},webkitCompassAccuracy:{value:args[1]},beta:{value:args[2]},gamma:{value:0}});window.dispatchEvent(e);}""",[heading,accuracy,beta])
for heading in (0,45,90,135,180,225,270,315):
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",start)
page.wait_for_timeout(30)
emit_heading(heading,0)
expect(arrow).to_be_hidden()
page.wait_for_timeout(30)
emit_heading(heading)
expect(arrow).to_be_visible()
actual=page.evaluate("""()=>Number(document.querySelector('#orient17a-arrow').style.transform.match(/rotate\(([-.\d]+)deg\)/)[1])""")
assert abs((actual+heading+180)%360-180)<5,(heading,actual)
page.wait_for_timeout(30)
emit_heading(0,3,100)
expect(arrow).to_be_hidden()
page.wait_for_timeout(30)
emit_heading(0)
expect(arrow).to_be_visible()
# Map rotation is not handset rotation.
before=arrow.get_attribute('style')
page.evaluate("()=>document.querySelector('#satnav-compact').satnavSurvey.getMap().jumpTo({bearing:90})")
expect(arrow).to_be_visible()
assert arrow.get_attribute('style')==before
page.evaluate("()=>document.querySelector('#satnav-compact').satnavSurvey.getMap().jumpTo({bearing:0})")
page.evaluate("p=>window.__lineGpsTest.emit(p,75)",start)
expect(arrow).to_be_hidden()
page.wait_for_timeout(30)
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",start)
emit_heading(0)
expect(arrow).to_be_visible()
page.wait_for_timeout(3200)
expect(arrow).to_be_hidden()
guide=page.locator('#satnav-walk-guidance')
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",target)
expect(guide).not_to_contain_text('Near last pin')
page.wait_for_timeout(1100)
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",target)
expect(guide).not_to_contain_text('Near last pin')
page.wait_for_timeout(1100)
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",target)
expect(guide).to_contain_text('Near last pin')
# A visited intermediate pin survives a simulated page visibility suspension.
mid=[-.12,51.5005]
page.evaluate("pts=>document.querySelector('#satnav-compact').satnavSurvey.replacePlan(pts)",[start,mid,target])
page.wait_for_timeout(40)
for i in range(3):
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",mid)
if i<2: page.wait_for_timeout(1100)
expect(guide).to_contain_text('Waypoint 2 of 2')
page.evaluate("""()=>{Object.defineProperty(document,'hidden',{configurable:true,value:true});document.dispatchEvent(new Event('visibilitychange'));}""")
page.evaluate("""()=>{delete document.hidden;document.dispatchEvent(new Event('visibilitychange'));}""")
page.wait_for_timeout(40)
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",mid)
expect(guide).to_contain_text('Waypoint 2 of 2')
assert page.evaluate("window.__lineGpsTest.records.starts")==[1]
page.locator('#satnav-toggle').tap()
expect(card).to_be_visible()
page.locator('#satnav-toggle').tap()
page.locator('#satnav-walk-stop').tap()
expect(card).to_be_hidden()
assert page.evaluate("window.__lineGpsTest.records.stops")==[1]
page.screenshot(path=f"orient17a-v9215-{os.environ['ORIENT_BROWSER']}-{width}x{height}.png")
print('V9.215 composed acquisition checkpoint PASS',os.environ['ORIENT_BROWSER'],width,height,flush=True)
browser.close()SatNav Orient17a V9216 Browser
A Python module in the tools folder of GridAtlas that emits heading (`emit_heading`).
rendergridatlas / tools/satnav/orient17a-v9216-browser.py · lines 1–138 of 138 · Not reached from any entry point (candidate for review) · pattern emit_heading (shared by 5 files)
- What it does
- Defines emit_heading. Uses libraries os, pathlib, runpy, playwright.sync_api. Side effects: changes the web page (DOM); reads or writes files.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- What it achieves
- V9.216 composed application acceptance: simulated acquisition, not device evidence.
- Why it matters
- No other file in the estate was found to import it.
- Application
- gridatlas · tools/satnav · Python module
- Uses
- os, pathlib, runpy, playwright.sync_api
- Used by
- none found
- Produces
- none declared
- Defines here
- emit_heading
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/orient17a-v9216-browser.py:1-138 · blob 9380af86cd0d544f2cac41e071263ad8fa3b6e1a · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom, filesystem · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: unreached_review
"""V9.216 composed application acceptance: simulated acquisition, not device evidence."""
import os
from pathlib import Path
from runpy import run_path
from playwright.sync_api import expect,sync_playwright
gps=run_path(str(Path(__file__).with_name('compact-browser.py')))['GPS_SPY']
start=[-.12,51.5]
target=[-.12,51.501]
site='http://127.0.0.1:8873/atlas/v/202612040127/'
with sync_playwright() as p:
browser=getattr(p,os.environ['ORIENT_BROWSER']).launch()
for width,height in [(390,844),(844,390),(1366,768),(1920,1080)]:
with browser.new_context(viewport={'width':width,'height':height},has_touch=True) as ctx:
ctx.add_init_script(gps)
ctx.add_init_script("""Object.defineProperty(window,'DeviceOrientationEvent',{configurable:true,value:class extends Event{static async requestPermission(){return 'granted';}}});""")
page=ctx.new_page()
page.goto(site,wait_until='domcontentloaded',timeout=90000)
page.wait_for_function("()=>document.querySelector('#satnav-compact')?.satnavSurvey?.getMap()?.getLayer('l-sat')&&document.querySelector('#satnav-walk-mode')&&document.querySelector('#field-compass-toggle')",timeout=120000)
if not page.locator('#satnav-compact').is_visible(): page.locator('#satnav-toggle').tap()
page.evaluate("pts=>document.querySelector('#satnav-compact').satnavSurvey.replacePlan(pts)",[start,target])
mode=page.locator('#satnav-walk-mode')
button=page.locator('#satnav-walk-start')
for val in ('walking','driving','mapped'):
mode.select_option(val)
expect(button).to_be_disabled()
mode.select_option('direct')
button.tap()
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",start)
card=page.locator('#orient17a-direction')
arrow=page.locator('#orient17a-arrow')
expect(card).to_be_visible()
expect(card).to_contain_text('Direction uncertain')
expect(card).to_contain_text('straight line')
expect(arrow).to_be_hidden()
page.locator('#field-compass-toggle').tap()
expect(page.locator('#field-compass-toggle')).to_have_attribute('aria-pressed','true')
page.wait_for_timeout(100)
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",start)
# Capture the original event and synchronously observe the application.
# The independent reference evaluation uses the same input but does not
# mutate the application's clock, filter, or acquisition state.
diagnostic = page.evaluate("""async()=>{
const root=new URL('../../../',location.href);
const {eligibleObservation,createReference}=await import(new URL('tools/satnav/orientation/orient17a-v9212-heading.mjs',root));
const {geometry,relativeGuidance}=await import(new URL('tools/satnav/orientation/orient17a-v9212-navigation.mjs',root));
const panel=document.querySelector('#satnav-compact');
const e=new Event('deviceorientation');
Object.defineProperties(e,{webkitCompassHeading:{value:90},webkitCompassAccuracy:{value:3},beta:{value:0},gamma:{value:0}});
const before=Date.now(),origin=performance.timeOrigin,stamp=e.timeStamp;
const frame=window.screen.orientation?.angle??window.orientation??0;
window.dispatchEvent(e);
const after=Date.now(),epoch=stamp>1e12?stamp:origin+stamp;
const fix=panel.satnavSurvey.getFix(),target=panel.satnavOrientationTarget;
const observation=eligibleObservation(e,frame,Math.floor(epoch));
const reference=createReference().resolve(observation,fix,after);
const metrics=geometry(fix,target,after);
return {before,after,origin,stamp,epoch,frame,clockDeltaMs:epoch-before,
fix,target,observation,reference,metrics,independentGuide:relativeGuidance(metrics,reference,after),
app:{reading:document.querySelector('#field-compass-reading').textContent,
reason:document.querySelector('#orient17a-reason').textContent,
arrowHidden:document.querySelector('#orient17a-arrow').hasAttribute('hidden'),
cardHidden:document.querySelector('#orient17a-direction').hidden,
visibility:document.visibilityState,secureContext:window.isSecureContext}};
}""")
print('ORIENT17A first acquisition diagnostic:',diagnostic,flush=True)
expect(arrow).to_be_visible()
# Empty events must not erase a valid reading or refresh its age.
for _ in range(3):
page.evaluate("()=>window.dispatchEvent(new Event('deviceorientation'))")
expect(arrow).to_be_visible()
page.wait_for_timeout(100)
page.wait_for_timeout(2850)
page.evaluate("()=>window.dispatchEvent(new Event('deviceorientation'))")
expect(arrow).to_be_hidden()
def emit_heading(heading, accuracy=3, beta=0):
page.evaluate("""args=>{const e=new Event('deviceorientation');Object.defineProperties(e,{webkitCompassHeading:{value:args[0]},webkitCompassAccuracy:{value:args[1]},beta:{value:args[2]},gamma:{value:0}});window.dispatchEvent(e);}""",[heading,accuracy,beta])
for heading in (0,45,90,135,180,225,270,315):
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",start)
page.wait_for_timeout(30)
emit_heading(heading,0)
expect(arrow).to_be_hidden()
page.wait_for_timeout(30)
emit_heading(heading)
expect(arrow).to_be_visible()
actual=page.evaluate("""()=>Number(document.querySelector('#orient17a-arrow').style.transform.match(/rotate\(([-.\d]+)deg\)/)[1])""")
assert abs((actual+heading+180)%360-180)<5,(heading,actual)
page.wait_for_timeout(30)
emit_heading(0,3,100)
expect(arrow).to_be_hidden()
page.wait_for_timeout(30)
emit_heading(0)
expect(arrow).to_be_visible()
# Map rotation is not handset rotation.
before=arrow.get_attribute('style')
page.evaluate("()=>document.querySelector('#satnav-compact').satnavSurvey.getMap().jumpTo({bearing:90})")
expect(arrow).to_be_visible()
assert arrow.get_attribute('style')==before
page.evaluate("()=>document.querySelector('#satnav-compact').satnavSurvey.getMap().jumpTo({bearing:0})")
page.evaluate("p=>window.__lineGpsTest.emit(p,75)",start)
expect(arrow).to_be_hidden()
page.wait_for_timeout(30)
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",start)
emit_heading(0)
expect(arrow).to_be_visible()
page.wait_for_timeout(3200)
expect(arrow).to_be_hidden()
guide=page.locator('#satnav-walk-guidance')
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",target)
expect(guide).not_to_contain_text('Near last pin')
page.wait_for_timeout(1100)
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",target)
expect(guide).not_to_contain_text('Near last pin')
page.wait_for_timeout(1100)
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",target)
expect(guide).to_contain_text('Near last pin')
# A visited intermediate pin survives a simulated page visibility suspension.
mid=[-.12,51.5005]
page.evaluate("pts=>document.querySelector('#satnav-compact').satnavSurvey.replacePlan(pts)",[start,mid,target])
page.wait_for_timeout(40)
for i in range(3):
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",mid)
if i<2: page.wait_for_timeout(1100)
expect(guide).to_contain_text('Waypoint 2 of 2')
page.evaluate("""()=>{Object.defineProperty(document,'hidden',{configurable:true,value:true});document.dispatchEvent(new Event('visibilitychange'));}""")
page.evaluate("""()=>{delete document.hidden;document.dispatchEvent(new Event('visibilitychange'));}""")
page.wait_for_timeout(40)
page.evaluate("p=>window.__lineGpsTest.emit(p,3)",mid)
expect(guide).to_contain_text('Waypoint 2 of 2')
assert page.evaluate("window.__lineGpsTest.records.starts")==[1]
page.locator('#satnav-toggle').tap()
expect(card).to_be_visible()
page.locator('#satnav-toggle').tap()
page.locator('#satnav-walk-stop').tap()
expect(card).to_be_hidden()
assert page.evaluate("window.__lineGpsTest.records.stops")==[1]
page.screenshot(path=f"orient17a-v9216-{os.environ['ORIENT_BROWSER']}-{width}x{height}.png")
print('V9.216 composed acquisition checkpoint PASS',os.environ['ORIENT_BROWSER'],width,height,flush=True)
browser.close()Orient17a Heading Filter
A JavaScript module in the orientation folder of GridAtlas. It creates heading filter (`createHeadingFilter`) and is built from the norm step (`norm`) and the delta step (`delta`).
transformgridatlas / tools/satnav/orientation/orient17a-heading-filter.mjs · lines 1–39 of 39 · Not reached from any entry point (candidate for review) · pattern createHeadingFilter (shared by 3 files)
- What it does
- It calculates its inputs. Defines 6 functions or classes, including norm, delta, createHeadingFilter, reset, inflate.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- Downstream impact
- Used directly by 1 file: Orient17a V9214 Compass Test (gridatlas).
- What it achieves
- Heading filter with persistence-confirmed jumps and decaying accuracy inflation.
- Why it matters
- Checked by Orient17a V9214 Compass Test.
- Application
- gridatlas · tools/satnav/orientation · JavaScript module
- Uses
- none found
- Used by
- imported by Orient17a V9214 Compass Test (import)
- Produces
- createHeadingFilter
- Defines here
- norm, delta, createHeadingFilter, reset, inflate, push
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/orientation/orient17a-heading-filter.mjs:1-39 · blob ab70689f6f40587a97c2cc049b17dcb3779ad70f · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: unreached_review
// SPDX-License-Identifier: Apache-2.0
// Heading filter with persistence-confirmed jumps and decaying accuracy inflation.
const norm=d=>((d%360)+360)%360;
const delta=(a,b)=>norm(a-b+180)-180;
export function createHeadingFilter({tauMs=300,jumpDeg=60,confirmMs=250,confirmDeg=25}={}){
let value=null,last=-Infinity,pending=null,output=null,snap=null;
function reset(){value=null;last=-Infinity;pending=null;output=null;snap=null;}
function inflate(o,t){
if(!snap)return 0;
const x=snap.jump*Math.exp(-(t-snap.t)/tauMs);
if(x<0.01){snap=null;return 0;}
return x;
}
function push(o){
if(!o||!Number.isFinite(o.timestampMs)){reset();return null;}
const t=o.timestampMs;
if(t<=last)return t===last?output:null;
if(value&&(t-last>3000||value.frame!==o.frame||value.provenance!==o.provenance))reset();
const dt=t-last;last=t;
if(!value){value=o;return output=o;}
const d=delta(o.degrees,value.degrees);
if(pending||Math.abs(d)>=jumpDeg){
if(pending&&Math.abs(delta(o.degrees,pending.first.degrees))>confirmDeg){pending=null;}
if(!pending&&Math.abs(d)>=jumpDeg)pending={first:o,t0:t};
if(pending){
if(t-pending.t0>=confirmMs){
const jump=Math.abs(d);pending=null;value=o;snap={jump,t};
return output={...o,accuracyDeg:o.accuracyDeg+jump};
}
return output=null;
}
}
pending=null;
const degrees=norm(value.degrees+(1-Math.exp(-dt/tauMs))*d);
value={...o,degrees};
return output={...value,accuracyDeg:o.accuracyDeg+Math.abs(delta(o.degrees,degrees))+inflate(o,t)};
}
return {push,reset};
}Orient17a Navigation
A JavaScript module in the orientation folder of GridAtlas that creates arrival (`createArrival`) and calculates planar distances and angles.
transformgridatlas / tools/satnav/orientation/orient17a-navigation.mjs · lines 1–47 of 47 · Not reached from any entry point (candidate for review) · pattern relativeGuidance (shared by 2 files)
- What it does
- It calculates its inputs. Defines 7 functions or classes, including geometry, point, vector, createArrival, reset.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'navigation'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- Downstream impact
- Used directly by 6 files: Orient17a Continuity Ordered (gridatlas); Orient17a Ordered (gridatlas); Orient17a Navigation Test (gridatlas); Wmm2025 Test (gridatlas); and 2 more.
- What it achieves
- It creates arrival (`createArrival`) and is built from the geometry step (`geometry`) and the point step (`point`). ORIENT-17A safe spherical geometry (GridAtlas radius), proximity and reference boundary.
- Why it matters
- Imported by 4 files, including Orient17a Continuity Ordered, Orient17a Ordered and Orient17a Continuity Direct. Checked by 2 tests, including Orient17a Navigation Test.
- Application
- gridatlas · tools/satnav/orientation · JavaScript module
- Uses
- none found
- Used by
- imported by Orient17a Continuity Ordered (import), imported by Orient17a Ordered (import), imported by Orient17a Navigation Test (import), imported by Wmm2025 Test (import), imported by Orient17a Continuity Direct (import), imported by Orient17a Direct (import), mentioned in Standalone (comment link)
- Produces
- geometry, createArrival, relativeGuidance
- Defines here
- geometry, point, vector, createArrival, reset, observe, relativeGuidance
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/orientation/orient17a-navigation.mjs:1-47 · blob e18a58cd70527b4198c21fa7a6c64c8a5b4bdb04 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: unreached_review
// SPDX-License-Identifier: Apache-2.0
// ORIENT-17A safe spherical geometry (GridAtlas radius), proximity and reference boundary.
export function geometry(fix,target,now=Date.now()){
const point=p=>Array.isArray(p)&&p.length===2&&p.every(Number.isFinite)&&Math.abs(p[0])<=180&&Math.abs(p[1])<=90;
const pos=[fix?.longitude,fix?.latitude];
if(!point(pos)||!point(target)||!Number.isFinite(now)||!Number.isFinite(fix?.timestampMs)||fix.timestampMs>now||now-fix.timestampMs>10000||!Number.isFinite(fix.accuracyM)||fix.accuracyM<=0||fix.accuracyM>30)return {distanceM:null,bearingDeg:null,reason:"GPS uncertain"};
const rad=Math.PI/180,R=6378137;
const vector=([x,y])=>[Math.cos(y*rad)*Math.cos(x*rad),Math.cos(y*rad)*Math.sin(x*rad),Math.sin(y*rad)];
const a=vector(pos),b=vector(target),dot=a.reduce((s,v,i)=>s+v*b[i],0);
const cross=[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]];
const central=Math.atan2(Math.hypot(...cross),dot),distanceM=R*central;
const base={distanceM,bearingDeg:null,accuracyM:fix.accuracyM};
if(distanceM<=fix.accuracyM)return {...base,reason:"Within GPS uncertainty"};
if(Math.abs(pos[1])===90||Math.PI-central<=Math.max(1e-10,fix.accuracyM/R))return {...base,reason:"Bearing singular"};
const x=pos[0]*rad,y=pos[1]*rad;
const east=-Math.sin(x)*b[0]+Math.cos(x)*b[1];
const north=-Math.sin(y)*Math.cos(x)*b[0]-Math.sin(y)*Math.sin(x)*b[1]+Math.cos(y)*b[2];
if(Math.hypot(east,north)<1e-12)return {...base,reason:"Bearing singular"};
return {...base,bearingDeg:(Math.atan2(east,north)/rad+360)%360,reason:null};
}
export function createArrival({radiusM=15,maxGapMs=2500,minSpanMs=2000}={}){
let samples=[],last=-Infinity,identity=null;
function reset(){samples=[];last=-Infinity;identity=null;}
function observe({fix,metrics,key,now=Date.now(),eligible=true}){
if(key!==identity){reset();identity=key;}
if(!eligible||!Number.isFinite(fix?.timestampMs)||!Number.isFinite(now)||fix.timestampMs>now||now-fix.timestampMs>10000||!Number.isFinite(fix.accuracyM)||fix.accuracyM<=0||!Number.isFinite(metrics?.distanceM)||metrics.distanceM<0||metrics.distanceM+fix.accuracyM>radiusM){samples=[];return false;}
const t=fix.timestampMs;
if(t<last){samples=[];return false;}
if(t===last)return samples.length>=3&&samples.at(-1)-samples[0]>=minSpanMs;
if(t-last>maxGapMs)samples=[];
last=t;samples.push(t);samples=samples.filter(x=>t-x<=maxGapMs+minSpanMs);
return samples.length>=3&&t-samples[0]>=minSpanMs;
}
return {observe,reset};
}
export function relativeGuidance(metrics,heading,now=Date.now()){
const result={distanceM:metrics?.distanceM??null,relativeDeg:null,label:"Direction uncertain"};
if(!Number.isFinite(metrics?.bearingDeg)||!Number.isFinite(metrics?.accuracyM)||!Number.isFinite(metrics?.distanceM)||metrics.distanceM<=metrics.accuracyM)return {...result,reason:metrics?.reason??"Bearing unavailable"};
if(heading?.reference!=="true"||!Number.isFinite(heading.degrees)||heading.degrees<0||heading.degrees>=360||!Number.isFinite(heading.accuracyDeg)||heading.accuracyDeg<0||heading.accuracyDeg>25||!Number.isFinite(heading.timestampMs)||heading.timestampMs>now||now-heading.timestampMs>3000||heading.disturbed===true)return {...result,reason:"Heading reference, accuracy or freshness unverified"};
const uncertainty=Math.asin(Math.min(1,metrics.accuracyM/metrics.distanceM))*180/Math.PI+heading.accuracyDeg;
if(uncertainty>45)return {...result,reason:"Combined bearing uncertainty"};
const r=((metrics.bearingDeg-heading.degrees+540)%360)-180;
const label=Math.abs(r)<=22.5?"Ahead":Math.abs(r)>=157.5?"Behind":r>0?"Right":"Left";
return {...result,relativeDeg:r,label,uncertaintyDeg:uncertainty,reason:null};
}Orient17a Navigation Test
A test in the orientation folder of GridAtlas that checks Orient17a Navigation.
testgridatlas / tools/satnav/orientation/orient17a-navigation.test.mjs · lines 1–13 of 13 · Not reached from any entry point (candidate for review)
- What it does
- It tests its inputs. Defines tests.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'navigation'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- What it achieves
- Defines `tests`.
- Why it matters
- Guards the behaviour of Orient17a Navigation.
- Application
- gridatlas · tools/satnav/orientation · test
- Uses
- Orient17a Navigation (import)
- Used by
- none found
- Produces
- tests
- Defines here
- tests
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/orientation/orient17a-navigation.test.mjs:1-13 · blob 900c9349631f6a116092594aa4a5a0422cd528f3 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: unreached_review
import {geometry,createArrival,relativeGuidance} from './orient17a-navigation.mjs';
function tests(geometry,createArrival,relativeGuidance){
let count=0; const assert=(ok,msg)=>{if(!ok)throw Error(msg);count++};
const n=100000,f=(t=0,a=3,x=0,y=0)=>({longitude:x,latitude:y,accuracyM:a,timestampMs:n+t});
const m=geometry(f(),[0,0.001],n);assert(Math.abs(m.distanceM-111.31949)<.0001,"distance");assert(m.bearingDeg===0,"north");
for(let i=0;i<8;i++){const h=i*45;assert(relativeGuidance(m,{reference:"true",degrees:h,accuracyDeg:2,timestampMs:n},n).relativeDeg===((540-h)%360)-180,"heading "+i);}
assert(geometry(f(),[180,0],n).bearingDeg===null,"antipode");assert(geometry(f(0,3,180),[-180,0],n).bearingDeg===null,"dateline alias");assert(geometry(f(0,3,0,90),[1,89],n).bearingDeg===null,"pole");assert(geometry(f(0,0),[0,1],n).distanceM===null,"zero accuracy");assert(geometry(f(),[0,0.00001],n).bearingDeg===null,"within GPS error");
const h={reference:"true",degrees:0,accuracyDeg:2,timestampMs:n};
for(const v of [{...h,reference:"magnetic"},{...h,accuracyDeg:null},{...h,timestampMs:n-3001},{...h,timestampMs:n+1},{...h,disturbed:true}])assert(relativeGuidance(m,v,n).relativeDeg===null,"uncertainty");
let a=createArrival();const o=(t,key="a",accuracyM=3,eligible=true)=>a.observe({fix:f(t,accuracyM),metrics:{distanceM:2},key,now:n+t,eligible});
assert(!o(0),"one");assert(!o(0),"duplicate");assert(!o(1000),"two");assert(o(2000),"three");assert(!o(2100,"b"),"target reset");assert(!o(3100,"b",0),"bad accuracy");assert(!o(4100,"b"),"reset after bad");assert(!o(7101,"b"),"gap");assert(!o(8101,"b"),"two after gap");assert(o(9101,"b"),"three after gap");assert(!o(9200,"b",3,false),"suspend");assert(!o(9300,"b"),"resume");a.reset();assert(!o(94 … [line shortened here: 425 characters; full line on GitHub]
}
console.log('ORIENT17A core checks',tests(geometry,createArrival,relativeGuidance));Orient17a Reference Wmm
A JavaScript module in the orientation folder of GridAtlas. It is built from the true heading from observation helper (`trueHeadingFromObservation`).
transformgridatlas / tools/satnav/orientation/orient17a-reference-wmm.mjs · lines 1–31 of 31 · Not reached from any entry point (candidate for review) · pattern trueHeadingFromObservation (shared by 2 files)
- What it does
- It calculates its inputs. Defines trueHeadingFromObservation.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- Downstream impact
- Used directly by 1 file: Wmm2025 Test (gridatlas).
- What it achieves
- ORIENT-17A integration boundary: magnetic observation -> true heading.
- Why it matters
- Checked by Wmm2025 Test.
- Application
- gridatlas · tools/satnav/orientation · JavaScript module
- Uses
- Wmm2025 (import)
- Used by
- imported by Wmm2025 Test (import)
- Produces
- ACCEPTED_PROVENANCE, trueHeadingFromObservation
- Defines here
- trueHeadingFromObservation
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/orientation/orient17a-reference-wmm.mjs:1-31 · blob 20d8ea3acf3b240f2edf7db13115145da4f0db3e · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: unreached_review
// SPDX-License-Identifier: Apache-2.0
// ORIENT-17A integration boundary: magnetic observation -> true heading.
// Proposed V9.211 boundary by Claude (support branch engineering/claude-orient17a-wmm)
// for review by the ORIENT-17A integration agent. Same signature as the pinned
// V9.210 stub orient17a-reference.mjs (left untouched); a new composition swaps the import.
//
// Rules kept from the stub: never substitute zero declination, never relabel
// generic absolute orientation. Only WebKit's webkitCompassHeading, which
// WebKit documents as relative to magnetic north, is corrected. Chromium's
// deviceorientationabsolute ("unverified-absolute") stays rejected until a
// field check establishes its reference on the device in use.
import { magneticToTrue } from './wmm2025.mjs';
export const ACCEPTED_PROVENANCE = Object.freeze(['webkit-magnetic']);
export function trueHeadingFromObservation(observation, fix, now = Date.now()) {
if (!observation || observation.reference !== 'magnetic') return null;
if (!ACCEPTED_PROVENANCE.includes(observation.provenance)) return null;
if (!Number.isFinite(observation.timestampMs) || observation.timestampMs > now) return null;
if (!Number.isFinite(fix?.latitude) || !Number.isFinite(fix?.longitude)) return null;
// Declination changes by roughly 0.01 degree per km across Great Britain,
// so fix accuracy and age are gated by relativeGuidance(), not here.
const altitudeKm = Number.isFinite(fix.altitudeM) ? fix.altitudeM / 1000
: Number.isFinite(fix.altitude) ? fix.altitude / 1000 : 0;
const { heading } = magneticToTrue(observation, {
latitude: fix.latitude,
longitude: fix.longitude,
altitudeKm: Math.min(850, Math.max(-1, altitudeKm)),
}, { when: observation.timestampMs });
return heading;
}Orient17a Reference
A JavaScript module in the orientation folder of GridAtlas. It is built from the true heading from observation helper (`trueHeadingFromObservation`).
transformgridatlas / tools/satnav/orientation/orient17a-reference.mjs · lines 1–5 of 5 · Not reached from any entry point (candidate for review) · pattern trueHeadingFromObservation (shared by 2 files)
- What it does
- It calculates its inputs. Defines trueHeadingFromObservation.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- What it achieves
- ORIENT-17A integration boundary. Pending independently validated WMM2025 evaluator.
- Why it matters
- No other file in the estate was found to import it.
- Application
- gridatlas · tools/satnav/orientation · JavaScript module
- Uses
- none found
- Used by
- none found
- Produces
- trueHeadingFromObservation
- Defines here
- trueHeadingFromObservation
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/orientation/orient17a-reference.mjs:1-5 · blob c15df29b7602eddc1326a8848185dcb99320c86c · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: unreached_review
// ORIENT-17A integration boundary. Pending independently validated WMM2025 evaluator.
// Do not substitute zero declination or relabel generic absolute orientation.
export function trueHeadingFromObservation(observation,fix,now=Date.now()) {
return null;
}Orient17a V9211 Heading
A JavaScript module in the orientation folder of GridAtlas that creates heading filter (`createHeadingFilter`) and reference (`createReference`). It creates heading filter (`createHeadingFilter`) and creates reference (`createReference`).
transformgridatlas / tools/satnav/orientation/orient17a-v9211-heading.mjs · lines 1–61 of 61 · Not reached from any entry point (candidate for review) · pattern eligibleObservation (shared by 2 files)
- What it does
- It calculates its inputs. Defines 10 functions or classes, including norm, delta, eligibleObservation, createHeadingFilter, reset.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- Downstream impact
- Used directly by 1 file: Orient17a V9211 Heading Test (gridatlas).
- What it achieves
- Strict V9.211 acquisition boundary. No GPS-course substitution.
- Why it matters
- Checked by Orient17a V9211 Heading Test.
- Application
- gridatlas · tools/satnav/orientation · JavaScript module
- Uses
- Wmm2025 (import), Heading (import)
- Used by
- imported by Orient17a V9211 Heading Test (import), mentioned in Standalone (comment link)
- Produces
- eligibleObservation, createHeadingFilter, createReference, stableLabel
- Defines here
- norm, delta, eligibleObservation, createHeadingFilter, reset, push, createReference, reset, resolve, stableLabel
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/orientation/orient17a-v9211-heading.mjs:1-61 · blob f9091c44f08b7b840e6c7510b0aec067cb90eeae · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: duplicate_candidate
// SPDX-License-Identifier: Apache-2.0
// Strict V9.211 acquisition boundary. No GPS-course substitution.
import {magneticToTrue} from './wmm2025.mjs';
import {deviceHeading} from './heading.mjs';
const norm=d=>((d%360)+360)%360;
const delta=(a,b)=>norm(a-b+180)-180;
export function eligibleObservation(event,frame,t){
if(!Number.isFinite(event.beta)||!Number.isFinite(event.gamma)||Math.abs(event.beta)>=90||Math.abs(event.gamma)>90)return null;
if(typeof event.webkitCompassHeading!=='number'||!Number.isFinite(event.webkitCompassAccuracy)||event.webkitCompassAccuracy<0||event.webkitCompassAccuracy>25)return null;
const o=deviceHeading(event,frame);
return o?.reference==='magnetic'?{...o,accuracyDeg:event.webkitCompassAccuracy,timestampMs:t,frame,provenance:'webkit-magnetic'}:null;
}
export function createHeadingFilter(){
let value=null,last=-Infinity,pending=null,output=null;
function reset(){value=null;last=-Infinity;pending=null;output=null;}
function push(o){
if(!o||!Number.isFinite(o.timestampMs)){reset();return null;}
const t=o.timestampMs;
if(t<=last)return t===last?output:null;
if(value&&(t-last>3000||value.frame!==o.frame||value.provenance!==o.provenance))reset();
const dt=t-last;last=t;
if(!value){value=o;return output=o;}
const d=delta(o.degrees,value.degrees);
if(Math.abs(d)>=60){
if(!pending||Math.abs(delta(o.degrees,pending.degrees))>25||t-pending.timestampMs>1000){pending=o;return output=null;}
pending=null;value=o;return output=o;
}
pending=null;
const degrees=norm(value.degrees+(1-Math.exp(-dt/300))*d);
value={...o,degrees};
return output={...value,accuracyDeg:o.accuracyDeg+Math.abs(delta(o.degrees,degrees))};
}
return {push,reset};
}
export function createReference(){
let key=null,result=null;
function reset(){key=null;result=null;}
function resolve(o,f,now=Date.now()){
if(!o||o.reference!=='magnetic'||o.provenance!=='webkit-magnetic'||!Number.isFinite(o.timestampMs)||o.timestampMs>now||now-o.timestampMs>3000||
!Number.isFinite(f?.latitude)||Math.abs(f.latitude)>90||!Number.isFinite(f.longitude)||Math.abs(f.longitude)>180||
!Number.isFinite(f.timestampMs)||f.timestampMs>now||now-f.timestampMs>10000||!Number.isFinite(f.accuracyM)||f.accuracyM<=0||f.accuracyM>30||
!Number.isFinite(o.accuracyDeg)||o.accuracyDeg<0||o.accuracyDeg>25||o.disturbed===true){reset();return null;}
const altitude=f.altitudeM??f.altitude,assumed=altitude==null;
if(!assumed&&(!Number.isFinite(altitude)||altitude<-1000||altitude>850000)){reset();return null;}
const altitudeKm=assumed?0:altitude/1000;
const k=JSON.stringify([o.timestampMs,o.degrees,o.accuracyDeg,f.latitude,f.longitude,altitudeKm,assumed]);
if(k===key)return result;
const {heading,declination}=magneticToTrue(o,{latitude:f.latitude,longitude:f.longitude,altitudeKm},{when:o.timestampMs});
result=heading&&declination?.zone==='normal'?{...heading,source:{...heading.source,altitudeAssumed:assumed}}:null;
key=k;return result;
}
return {resolve,reset};
}
export function stableLabel(g,previous){
if(!Number.isFinite(g.relativeDeg))return g.label;
const r=g.relativeDeg,a=Math.abs(r);
if(previous==='Ahead'&&a<=27.5)return 'Ahead';
if(previous==='Behind'&&a>=152.5)return 'Behind';
if((previous==='Left'&&r<0||previous==='Right'&&r>0)&&a>17.5&&a<162.5)return previous;
return g.label;
}Orient17a V9211 Heading Test
A test in the orientation folder of GridAtlas that checks Orient17a V9211 Heading.
testgridatlas / tools/satnav/orientation/orient17a-v9211-heading.test.mjs · lines 1–16 of 16 · Not reached from any entry point (candidate for review)
- What it does
- It tests its inputs. Defines obs. Uses libraries node:test, node:assert/strict.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- What it achieves
- Defines `obs`.
- Why it matters
- Guards the behaviour of Orient17a V9211 Heading.
- Application
- gridatlas · tools/satnav/orientation · test
- Uses
- Orient17a V9211 Heading (import), node:test, node:assert/strict
- Used by
- none found
- Produces
- obs
- Defines here
- obs
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/orientation/orient17a-v9211-heading.test.mjs:1-16 · blob a6319642fbe546143cf996b54a64d914f4ce45d5 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: unreached_review
import test from 'node:test';
import assert from 'node:assert/strict';
import {eligibleObservation,createReference,createHeadingFilter} from './orient17a-v9211-heading.mjs';
const now=Date.UTC(2026,11,4),fix={latitude:0,longitude:120,accuracyM:3,timestampMs:now};
const obs=(degrees,t=now)=>({reference:'magnetic',provenance:'webkit-magnetic',frame:0,degrees,accuracyDeg:3,timestampMs:t});
test('reference and altitude gates',()=>{
const r=createReference();assert.ok(r.resolve(obs(0),fix,now));assert.equal(r.resolve(obs(0),fix,now).source.altitudeAssumed,true);
for(const f of [{...fix,altitudeM:851000},{...fix,altitudeM:NaN},{...fix,longitude:181},{...fix,accuracyM:31},{...fix,timestampMs:now-10001}])assert.equal(r.resolve(obs(0),f,now),null);
assert.equal(r.resolve({...obs(0),reference:'true'},fix,now),null);
assert.equal(r.resolve(obs(0,now-3001),fix,now),null);
});
test('pose and circular reversal',()=>{
const e={beta:0,gamma:0,webkitCompassHeading:0,webkitCompassAccuracy:3};
assert.ok(eligibleObservation(e,0,now));assert.equal(eligibleObservation({...e,beta:100},0,now),null);assert.equal(eligibleObservation({...e,beta:null},0,now),null);
const s=createHeadingFilter();assert.equal(s.push(obs(359)).degrees,359);assert.ok(s.push(obs(1,now+100)).degrees>359);assert.equal(s.push(obs(180,now+200)),null);assert.equal(s.push(obs(180,now+200)),null);assert.equal(s.push(obs(180,now+300)).degrees,180);
});Orient17a V9212 Heading
A JavaScript module in the orientation folder of GridAtlas that creates heading filter (`createHeadingFilter`) and reference (`createReference`). It creates heading filter (`createHeadingFilter`) and creates reference (`createReference`).
transformgridatlas / tools/satnav/orientation/orient17a-v9212-heading.mjs · lines 1–62 of 62 · Not reached from any entry point (candidate for review) · pattern eligibleObservation (shared by 2 files)
- What it does
- It calculates its inputs. Defines 10 functions or classes, including norm, delta, eligibleObservation, createHeadingFilter, reset.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- Downstream impact
- Used directly by 1 file: Orient17a V9212 Test (gridatlas).
- What it achieves
- Strict V9.211 acquisition boundary. No GPS-course substitution.
- Why it matters
- Checked by Orient17a V9212 Test.
- Application
- gridatlas · tools/satnav/orientation · JavaScript module
- Uses
- Wmm2025 (import), Heading (import)
- Used by
- imported by Orient17a V9212 Test (import)
- Produces
- eligibleObservation, createHeadingFilter, createReference, stableLabel
- Defines here
- norm, delta, eligibleObservation, createHeadingFilter, reset, push, createReference, reset, resolve, stableLabel
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/orientation/orient17a-v9212-heading.mjs:1-62 · blob 265af1405ed7f635c67b2cd8b6b20ac1f4b1536a · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: unreached_review
// SPDX-License-Identifier: Apache-2.0
// Strict V9.211 acquisition boundary. No GPS-course substitution.
import {magneticToTrue} from './wmm2025.mjs';
import {deviceHeading} from './heading.mjs';
const norm=d=>((d%360)+360)%360;
const delta=(a,b)=>norm(a-b+180)-180;
export function eligibleObservation(event,frame,t){
if(!Number.isFinite(event.beta)||!Number.isFinite(event.gamma)||Math.abs(event.beta)>=90||Math.abs(event.gamma)>90)return null;
if(typeof event.webkitCompassHeading!=='number'||!Number.isFinite(event.webkitCompassAccuracy)||event.webkitCompassAccuracy<=0||event.webkitCompassAccuracy>25)return null;
const o=deviceHeading(event,frame);
return o?.reference==='magnetic'?{...o,accuracyDeg:event.webkitCompassAccuracy,timestampMs:t,frame,provenance:'webkit-magnetic'}:null;
}
export function createHeadingFilter(){
let value=null,last=-Infinity,pending=null,output=null;
function reset(){value=null;last=-Infinity;pending=null;output=null;}
function push(o){
if(!o||!Number.isFinite(o.timestampMs)){reset();return null;}
const t=o.timestampMs;
if(t<=last)return t===last?output:null;
if(value&&(t-last>3000||value.frame!==o.frame||value.provenance!==o.provenance))reset();
const dt=t-last;last=t;
if(!value){value=o;return output=o;}
const d=delta(o.degrees,value.degrees);
if(Math.abs(d)>=60){
if(!pending||Math.abs(delta(o.degrees,pending.degrees))>25||t-pending.timestampMs>1000){pending=o;return output=null;}
pending=null;value=o;return output=o;
}
pending=null;
const degrees=norm(value.degrees+(1-Math.exp(-dt/300))*d);
value={...o,degrees};
return output={...value,accuracyDeg:o.accuracyDeg+Math.abs(delta(o.degrees,degrees))};
}
return {push,reset};
}
export function createReference(){
let key=null,result=null;
function reset(){key=null;result=null;}
function resolve(o,f,now=Date.now()){
if(!o||o.reference!=='magnetic'||o.provenance!=='webkit-magnetic'||!Number.isFinite(o.timestampMs)||o.timestampMs>now||now-o.timestampMs>3000||
!Number.isFinite(f?.latitude)||Math.abs(f.latitude)>90||!Number.isFinite(f.longitude)||Math.abs(f.longitude)>180||
!Number.isFinite(f.timestampMs)||f.timestampMs>now||now-f.timestampMs>10000||!Number.isFinite(f.accuracyM)||f.accuracyM<=0||f.accuracyM>30||
!Number.isFinite(o.accuracyDeg)||o.accuracyDeg<=0||o.accuracyDeg>25||o.disturbed===true){reset();return null;}
const altitude=f.altitudeM??f.altitude,accuracy=f.altitudeAccuracyM;
if(altitude!=null&&(!Number.isFinite(altitude)||altitude<-1000||altitude>850000)){reset();return null;}
const assumed=altitude==null||!Number.isFinite(accuracy)||accuracy<=0||accuracy>500;
const altitudeKm=assumed?0:altitude/1000;
const k=JSON.stringify([o.timestampMs,o.degrees,o.accuracyDeg,f.latitude,f.longitude,altitudeKm,assumed]);
if(k===key)return result;
const {heading,declination}=magneticToTrue(o,{latitude:f.latitude,longitude:f.longitude,altitudeKm},{when:o.timestampMs});
result=heading&&declination?.zone==='normal'?{...heading,source:{...heading.source,altitudeAssumed:assumed}}:null;
key=k;return result;
}
return {resolve,reset};
}
export function stableLabel(g,previous){
if(!Number.isFinite(g.relativeDeg))return g.label;
const r=g.relativeDeg,a=Math.abs(r);
if(previous==='Ahead'&&a<=27.5)return 'Ahead';
if(previous==='Behind'&&a>=152.5)return 'Behind';
if((previous==='Left'&&r<0||previous==='Right'&&r>0)&&a>17.5&&a<162.5)return previous;
return g.label;
}Orient17a V9212 Navigation
A JavaScript module in the orientation folder of GridAtlas that creates arrival (`createArrival`) and calculates planar distances and angles.
transformgridatlas / tools/satnav/orientation/orient17a-v9212-navigation.mjs · lines 1–50 of 50 · Not reached from any entry point (candidate for review) · pattern relativeGuidance (shared by 2 files)
- What it does
- It calculates its inputs. Defines 7 functions or classes, including geometry, point, vector, createArrival, reset.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'navigation'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- Downstream impact
- Used directly by 3 files: Orient17a V9212 Ordered (gridatlas); Orient17a V9212 Test (gridatlas); Orient17a V9212 Direct (gridatlas).
- What it achieves
- It creates arrival (`createArrival`) and is built from the geometry step (`geometry`) and the point step (`point`). ORIENT-17A safe spherical geometry (GridAtlas radius), proximity and reference boundary.
- Why it matters
- Imported by Orient17a V9212 Ordered and Orient17a V9212 Direct. Checked by Orient17a V9212 Test.
- Application
- gridatlas · tools/satnav/orientation · JavaScript module
- Uses
- none found
- Used by
- imported by Orient17a V9212 Ordered (import), imported by Orient17a V9212 Test (import), imported by Orient17a V9212 Direct (import)
- Produces
- geometry, createArrival, relativeGuidance
- Defines here
- geometry, point, vector, createArrival, reset, observe, relativeGuidance
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/orientation/orient17a-v9212-navigation.mjs:1-50 · blob 0a897653a7f96c45d732886f0b48093aedb05b67 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: duplicate_candidate
// SPDX-License-Identifier: Apache-2.0
// ORIENT-17A safe spherical geometry (GridAtlas radius), proximity and reference boundary.
export function geometry(fix,target,now=Date.now()){
const point=p=>Array.isArray(p)&&p.length===2&&p.every(Number.isFinite)&&Math.abs(p[0])<=180&&Math.abs(p[1])<=90;
const pos=[fix?.longitude,fix?.latitude];
if(!point(pos)||!point(target)||!Number.isFinite(now)||!Number.isFinite(fix?.timestampMs)||fix.timestampMs>now||now-fix.timestampMs>10000||!Number.isFinite(fix.accuracyM)||fix.accuracyM<=0||fix.accuracyM>30)return {distanceM:null,bearingDeg:null,reason:"GPS uncertain"};
const rad=Math.PI/180,R=6378137;
const vector=([x,y])=>[Math.cos(y*rad)*Math.cos(x*rad),Math.cos(y*rad)*Math.sin(x*rad),Math.sin(y*rad)];
const a=vector(pos),b=vector(target),dot=a.reduce((s,v,i)=>s+v*b[i],0);
const cross=[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]];
const central=Math.atan2(Math.hypot(...cross),dot),distanceM=R*central;
const base={distanceM,bearingDeg:null,accuracyM:fix.accuracyM};
if(distanceM<=fix.accuracyM)return {...base,reason:"Within GPS uncertainty"};
if(Math.abs(pos[1])===90||Math.PI-central<=Math.max(1e-10,fix.accuracyM/R))return {...base,reason:"Bearing singular"};
const x=pos[0]*rad,y=pos[1]*rad;
const east=-Math.sin(x)*b[0]+Math.cos(x)*b[1];
const north=-Math.sin(y)*Math.cos(x)*b[0]-Math.sin(y)*Math.sin(x)*b[1]+Math.cos(y)*b[2];
if(Math.hypot(east,north)<1e-12)return {...base,reason:"Bearing singular"};
return {...base,bearingDeg:(Math.atan2(east,north)/rad+360)%360,reason:null};
}
export function createArrival({radiusM=15,maxGapMs=2500,minSpanMs=2000}={}){
let samples=[],last=-Infinity,identity=null;
function reset(){samples=[];last=-Infinity;identity=null;}
function observe({fix,metrics,key,now=Date.now(),eligible=true}){
if(key!==identity){reset();identity=key;}
if(!eligible||!Number.isFinite(fix?.timestampMs)||!Number.isFinite(now)||fix.timestampMs>now||now-fix.timestampMs>10000||!Number.isFinite(fix.accuracyM)||fix.accuracyM<=0||!Number.isFinite(metrics?.distanceM)||metrics.distanceM<0||metrics.distanceM+fix.accuracyM>radiusM){samples=[];return false;}
const t=fix.timestampMs;
if(t<last){samples=[];return false;}
if(t===last)return samples.length>=3&&samples.at(-1)-samples[0]>=minSpanMs;
if(t-last>maxGapMs)samples=[];
last=t;
// Keep the first fix of the uninterrupted run and the latest two. A legal
// 2500 ms cadence must not lose its first fix; memory remains bounded.
samples.push(t);if(samples.length>3)samples.splice(1,1);
return samples.length>=3&&t-samples[0]>=minSpanMs;
}
return {observe,reset};
}
export function relativeGuidance(metrics,heading,now=Date.now()){
const result={distanceM:metrics?.distanceM??null,relativeDeg:null,label:"Direction uncertain"};
if(!Number.isFinite(metrics?.bearingDeg)||!Number.isFinite(metrics?.accuracyM)||!Number.isFinite(metrics?.distanceM)||metrics.distanceM<=metrics.accuracyM)return {...result,reason:metrics?.reason??"Bearing unavailable"};
if(heading?.reference!=="true"||!Number.isFinite(heading.degrees)||heading.degrees<0||heading.degrees>=360||!Number.isFinite(heading.accuracyDeg)||heading.accuracyDeg<0||heading.accuracyDeg>25||!Number.isFinite(heading.timestampMs)||heading.timestampMs>now||now-heading.timestampMs>3000||heading.disturbed===true)return {...result,reason:"Heading reference, accuracy or freshness unverified"};
const uncertainty=Math.asin(Math.min(1,metrics.accuracyM/metrics.distanceM))*180/Math.PI+heading.accuracyDeg;
if(uncertainty>45)return {...result,reason:"Combined bearing uncertainty"};
const r=((metrics.bearingDeg-heading.degrees+540)%360)-180;
const label=Math.abs(r)<=22.5?"Ahead":Math.abs(r)>=157.5?"Behind":r>0?"Right":"Left";
return {...result,relativeDeg:r,label,uncertaintyDeg:uncertainty,reason:null};
}Orient17a V9212 Test
A test in the orientation folder of GridAtlas that checks Orient17a V9212 Navigation and Orient17a V9212 Heading.
testgridatlas / tools/satnav/orientation/orient17a-v9212.test.mjs · lines 1–20 of 20 · Not reached from any entry point (candidate for review)
- What it does
- It tests its inputs. Uses libraries node:test, node:assert/strict.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- What it achieves
- No statement of purpose was found in the file, a README line naming it, or its name.
- Why it matters
- Guards the behaviour of Orient17a V9212 Navigation and Orient17a V9212 Heading.
- Application
- gridatlas · tools/satnav/orientation · test
- Uses
- Orient17a V9212 Navigation (import), Orient17a V9212 Heading (import), node:test, node:assert/strict
- Used by
- none found
- Produces
- none declared
- Defines here
- none
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/orientation/orient17a-v9212.test.mjs:1-20 · blob 6fb47030bd1c527492d9aae9ba163ea913d3dc08 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: unknown · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: unreached_review
import test from 'node:test';
import assert from 'node:assert/strict';
import {createArrival} from './orient17a-v9212-navigation.mjs';
import {eligibleObservation,createReference} from './orient17a-v9212-heading.mjs';
const t=Date.UTC(2026,11,4),fix={latitude:0,longitude:120,accuracyM:3,timestampMs:t};
test('arrival across all allowed cadences, no duplicate or gap bypass',()=>{
for(const gap of [1000,2000,2250,2251,2300,2500,2501]){
const a=createArrival(),seen=[];for(let i=0;i<3;i++){const now=t+i*gap;seen.push(a.observe({fix:{...fix,timestampMs:now},metrics:{distanceM:2},key:'x',now}));}
assert.deepEqual(seen,[false,false,gap<=2500],String(gap));
}
const a=createArrival();for(let i=0;i<=20;i++){const now=t+i*100;assert.equal(a.observe({fix:{...fix,timestampMs:now},metrics:{distanceM:2},key:'x',now}),i===20);}
const b=createArrival();for(let i=0;i<10;i++)assert.equal(b.observe({fix,metrics:{distanceM:2},key:'x',now:t}),false);
});
test('zero heading accuracy rejected and altitude quality explicit',()=>{
const event={beta:0,gamma:0,webkitCompassHeading:0,webkitCompassAccuracy:0};assert.equal(eligibleObservation(event,0,t),null);
const obs=eligibleObservation({...event,webkitCompassAccuracy:3},0,t);assert.ok(obs);
const r=createReference();for(const acc of [null,0,501,NaN])assert.equal(r.resolve(obs,{...fix,altitudeM:100,altitudeAccuracyM:acc},t).source.altitudeAssumed,true);
assert.equal(r.resolve(obs,{...fix,altitudeM:100,altitudeAccuracyM:10},t).source.altitudeAssumed,false);
assert.equal(r.resolve(obs,{...fix,altitudeM:NaN},t),null);
});Orient17a V9214 Compass Test
A test in the orientation folder of GridAtlas that checks Orient17a V9214 Event Clock and Orient17a Heading Filter.
testgridatlas / tools/satnav/orientation/orient17a-v9214-compass.test.mjs · lines 1–20 of 20 · Not reached from any entry point (candidate for review)
- What it does
- It tests its inputs. Defines obs. Uses libraries node:assert/strict.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'compass'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- What it achieves
- Defines `obs`.
- Why it matters
- Guards the behaviour of Orient17a V9214 Event Clock and Orient17a Heading Filter.
- Application
- gridatlas · tools/satnav/orientation · test
- Uses
- Orient17a V9214 Event Clock (import), Orient17a Heading Filter (import), node:assert/strict
- Used by
- none found
- Produces
- obs
- Defines here
- obs
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/orientation/orient17a-v9214-compass.test.mjs:1-20 · blob 6b306d17ec04f1adefc62a17e8e280a31dd3b988 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: unreached_review
import assert from 'node:assert/strict';
import {createEventClock} from './orient17a-v9214-event-clock.mjs';
import {createHeadingFilter} from './orient17a-heading-filter.mjs';
let now=1800000000000,base=now-500,checks=0;
const c=createEventClock({now:()=>now,origin:()=>base});c.reset();
for(let i=0;i<1000;i++){
now+=17;
for(const f of [0,.125,.5,.875]){
c.reset();assert.equal(c.stamp({timeStamp:now-base+f}),now);checks++;
assert.equal(c.stamp({timeStamp:now-base+f}),null);checks++;
assert.equal(c.stamp({timeStamp:now-base+1}),null);checks++;
assert.equal(c.stamp({timeStamp:now-base-3001}),null);checks++;
}
}
c.reset();assert.equal(c.stamp({timeStamp:now+.75}),now);checks++;
now-=10;assert.equal(c.stamp({timeStamp:now}),null);checks++;
c.reset();assert.equal(c.stamp({timeStamp:now}),now);checks++;
console.log(checks,'clock assertions PASS');
const obs=(degrees,timestampMs)=>({degrees,timestampMs,accuracyDeg:5,frame:0,provenance:'p'});
const f=createHeadingFilter();f.push(obs(0,1000));assert.equal(f.push(obs(180,1017)),null);assert.equal(f.push(obs(180,1034)),null);assert.equal(f.push(obs(180,1266)),null);let r=f.push(obs(180,1267));assert.equal(r.degrees,180);assert.ok(r.accuracyDeg>100);r=f.push(obs(180,2267));assert.ok(r.accuracyDeg<25);f.reset();f.push(obs(359,3000));assert.ok(f.push(obs(1,3017)).degrees>=359);console.log('h … [line shortened here: 440 characters; full line on GitHub]Orient17a V9214 Event Clock
A JavaScript module in the orientation folder of GridAtlas that normalises event epoch to the integer wall-clock domain used by the GPS/reference gates. It creates event clock (`createEventClock`).
transformgridatlas / tools/satnav/orientation/orient17a-v9214-event-clock.mjs · lines 1–16 of 16 · Not reached from any entry point (candidate for review) · pattern stamp (shared by 31 files)
- What it does
- It calculates its inputs. Defines createEventClock, reset, stamp.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
- Downstream impact
- Used directly by 1 file: Orient17a V9214 Compass Test (gridatlas).
- What it achieves
- Defines `createEventClock`, `reset` and `stamp`.
- Why it matters
- Checked by Orient17a V9214 Compass Test.
- Application
- gridatlas · tools/satnav/orientation · JavaScript module
- Uses
- none found
- Used by
- imported by Orient17a V9214 Compass Test (import)
- Produces
- createEventClock
- Defines here
- createEventClock, reset, stamp
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/satnav/orientation/orient17a-v9214-event-clock.mjs:1-16 · blob 40dafb8239241c20cf94f5aa46b3eed2a43ac030 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: unreached_review
// SPDX-License-Identifier: Apache-2.0
// Normalise event epoch to the integer wall-clock domain used by the GPS/reference gates.
export function createEventClock({now=Date.now,origin=()=>performance.timeOrigin}={}){
let last=-Infinity,started=-Infinity;
function reset(){started=now();last=-Infinity;}
function stamp(event){
const n=now(),raw=event?.timeStamp;
if(!Number.isFinite(n)||!Number.isFinite(raw)||raw<0)return null;
const epoch=raw>1e12?raw:origin()+raw;
if(!Number.isFinite(epoch)||epoch>=n+1)return null;
const t=Math.floor(epoch);
if(t<started||t<=last||n-t>3000)return null;
last=t;return t;
}
return {stamp,reset};
}