Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ sensors raises one alarm.
- `zones.ts` — sensitivity presets and `assess()`, the level decision with
hysteresis.
- `evaluator.ts` — reads the data model, keeps per-target levels, drives a sink.
- `land.ts` — the land on S-57 charts (`LNDARE`; any chart's `DEPARE` or
`DRGARE` water wins), read from the tiles a chart provider plugin offers
through the `chartTiles` PropertyValue (signalk-charts-provider-simple), in
process, so it works on secured servers. `landRuns` gives the stretches of
land along a course with charted water on either side, from cached tiles,
loading missing ones in the background. The evaluator judges a passage only
up to where land stops either course; land never raises a level.
- `targets.ts` — folds `targets.*` contexts (radar, camera; the server's
sensor-targets convention) into the evaluator's input: a target with
`sameAs` joins the context it names, the rest become objects of their own,
Expand Down Expand Up @@ -43,7 +50,8 @@ sensors raises one alarm.
- **Schema defaults are not applied at runtime.** `start()` receives `{}` for a
plugin that was never configured; always merge `DEFAULTS` under the config.
- **No install scripts.** The app store installs with `--ignore-scripts`; keep
runtime dependencies pure JS (today: `typebox` only).
runtime dependencies pure JS (today: `typebox`, and `@mapbox/vector-tile`
with `pbf` to read chart tiles).
- **ESM.** Relative imports carry the `.js` extension (nodenext module
resolution); the entry is `export default function (app)`.
- **Clear what you raise.** Every path that stops tracking a target (lost,
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Install **Collision Alerts** from the App Store. It starts by itself with the Co
- **Using SK Derived Data for CPA?** Turn its CPA calculation off, or every alarm comes twice.
- **Had the older `signalk-collision-alerts` plugin?** Uninstall it, or every alarm comes twice. Its settings don't carry over.
- **Have radar or a camera?** Also install **Target Fusion** from the App Store. A boat seen on both AIS and radar then raises one alarm, not two.
- **Have S-57 (ENC) charts?** Serve them with **Charts Provider Simple** 2.22 or later from the App Store. A boat that could reach you only across charted land, such as one behind a headland or an island, then raises nothing, within the limits under **Behind land** below. There is nothing to set up.

## Settings

Expand Down Expand Up @@ -53,6 +54,7 @@ The plugin tries to alarm only when it matters:
- **Between AIS reports.** Small boats report only every 30 s. In between, each boat is judged where it is by now, carried on along its course for up to a minute. A boat moving slower than 3 kn, judged by the Harbour limits, alarms only once a report puts it inside the alarm limits, or once its last report is 40 s old: it may be turning into its berth. A faster boat, judged by them at your berth with _Only for boats coming straight at you_, alarms on dead reckoning at once.
- **Busy waters.** At most 3 boats warn or alarm at once, the most urgent first. A warning that had to make room for a more urgent boat stays quiet for 2 minutes, unless it turns into an alarm or clears the limits and comes back.
- **No flicker.** An alarm stays on until the boat is clearly outside the limits again.
- **Behind land.** With S-57 (ENC) charts served by Charts Provider Simple 2.22 or later, a passage ends where a boat, or you, would reach charted land: at least 150 m of it along the course, with charted water right before and after, on the course and on the courses 3° to either side. The boat would have to go round. It raises only if it comes close enough before that, as one that first crosses your bow does, and is judged anew as soon as its course runs clear. A course once stopped by land is stopped at the same place again by 50 m of it, so one swinging across the tip of a headland does not switch the alarm on and off. This is kept through gaps of up to a minute in judging the boat. A course that only clips a point, land where any chart shows water or a chart could not be read, land next to waters no chart covers (such as unsurveyed areas) and land right where a boat or its closest approach is charted never count. Overview charts, which have no tiles at zoom 14, are not read. While the charts for a course load, no warning or alarm rises, for at most 10 s. Charts can be wrong or out of date: land only ever lowers a warning or alarm, never raises one.

The 3 kn is the advanced setting **Use the harbour distances when both boats are slower than X knots**. Set it to 0 to turn off the harbour, berth, stopped-boat and overtaking rules above, so every boat gets your chosen limits. Boats crossing your wake still stay quiet. The 3 boats are **No more than X boats raising alarms at the same time**.

Expand All @@ -62,4 +64,4 @@ A current mayara plugin leaves radar collision alarms to this plugin, so a boat

## For app developers

Each alarm is a notification at `notifications.navigation.closestApproach.<target id>` on your own vessel, raised through the server's Notifications API, or as a plain notification delta on servers that don't manage notifications. Its `data` holds `targetRef` (the target's context, such as `vessels.urn:mrn:imo:mmsi:244123456` or `targets.radar:…`), `source`, `sources` (when radar or a camera sees the target), `cpa` (m), `tcpa` (s), `range` (m), `targetCog` (rad, `null` when stopped), `targetSog` (m/s) and `cpaPositions`. Each target in range also gets `navigation.closestApproach` `{ distance, timeTo }`, which can be turned off. It is published when the target reports, when your course or speed changes, and otherwise at the first evaluation at least 10 s after the last, so a display that shows `timeTo` as received runs up to that long behind: 10 s at the default 2 s interval. Radar and camera targets are read from `targets.<type>:<id>` contexts. One whose `sameAs` names an AIS vessel joins it, and the alarm goes under the vessel's id. While the plugin runs, it emits the `collisionAlerts` PropertyValue `{ evaluatesTargets: true }`, and `{ evaluatesTargets: false }` when it stops, so sensor plugins can leave their alarms to it.
Each alarm is a notification at `notifications.navigation.closestApproach.<target id>` on your own vessel, raised through the server's Notifications API, or as a plain notification delta on servers that don't manage notifications. Its `data` holds `targetRef` (the target's context, such as `vessels.urn:mrn:imo:mmsi:244123456` or `targets.radar:…`), `source`, `sources` (when radar or a camera sees the target), `cpa` (m), `tcpa` (s), `range` (m), `targetCog` (rad, `null` when stopped), `targetSog` (m/s) and `cpaPositions`. Each target in range also gets `navigation.closestApproach` `{ distance, timeTo }`, which can be turned off. It is published when the target reports, when your course or speed changes, and otherwise at the first evaluation at least 10 s after the last, so a display that shows `timeTo` as received runs up to that long behind: 10 s at the default 2 s interval. Radar and camera targets are read from `targets.<type>:<id>` contexts. One whose `sameAs` names an AIS vessel joins it, and the alarm goes under the vessel's id. Land is read from the `chartTiles` PropertyValue, which a chart provider plugin such as Charts Provider Simple offers: `getTile(chartId, z, x, y)` for its charts' tiles, in-process, so it needs no token on a secured server. The S-57 charts are those the resources API lists with type `S-57`, and their land is their `LNDARE` layer. While the plugin runs, it emits the `collisionAlerts` PropertyValue `{ evaluatesTargets: true }`, and `{ evaluatesTargets: false }` when it stops, so sensor plugins can leave their alarms to it.
43 changes: 43 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"./docs/screenshots/cpa-alarm.png"
],
"recommends": [
"signalk-target-fusion"
"signalk-target-fusion",
"signalk-charts-provider-simple"
]
},
"files": [
Expand All @@ -44,6 +45,8 @@
"signalk": ">=2.31.0"
},
"dependencies": {
"@mapbox/vector-tile": "^3.0.0",
"pbf": "^5.1.2",
"typebox": "^1.3.34"
},
"devDependencies": {
Expand Down
11 changes: 11 additions & 0 deletions src/cpa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ export function computeCpa(own: Track, target: Track): CpaResult {
}
}

/** The distance (m) between two tracks `seconds` from now. */
export function separationAt(own: Track, target: Track, seconds: number): number {
const cosLat = Math.cos(own.position.latitude * DEG)
const dLon = wrapDegrees(target.position.longitude - own.position.longitude)
const rx = dLon * DEG * cosLat * EARTH_RADIUS
const ry = (target.position.latitude - own.position.latitude) * DEG * EARTH_RADIUS
const vx = target.sog * Math.sin(target.cog) - own.sog * Math.sin(own.cog)
const vy = target.sog * Math.cos(target.cog) - own.sog * Math.cos(own.cog)
return Math.hypot(rx + vx * seconds, ry + vy * seconds)
}

/** `rx`, `ry`: target relative to own ship (m); `vx`, `vy`: its relative velocity (m/s). */
function bowCrossing(
own: Track,
Expand Down
Loading
Loading