Geofence: Add vehicle sync and plan types#2807
Conversation
Automated PR Review (Claude)0. SummaryVerdict: MINOR SUGGESTIONS Minor items to consider: 1.1, 1.2, 1.3, 4.1, 6.1, 6.2 This PR adds the foundational types, MAVLink conversion helpers, vehicle-level fence upload/fetch/clear, autopilot capability tracking, parameter request helpers, and a comprehensive 1. Correctness & Implementation Bugs1.1 1.2 1.3 2. AGENTS.md Adherence — ✅3. Security — ✅4. Performance4.1 5. UI / UX — ✅6. Code Quality & Style6.1 6.2 7. Commit Hygiene — ✅8. Tests — ✅9. Documentation — ✅10. Nitpicks / Optional10.1 10.2 10.3 Generated by Claude. This is advisory; a human reviewer must still approve. |
fba258a to
8ff9d6b
Compare
|
/review |
Automated PR Re-review 2 (Claude)Comparing Previous findings status
New findings0. SummaryVerdict: MINOR SUGGESTIONS Minor items to consider: 6.1, 6.2 (carried over nits) This re-review covers the incremental changes since the first review. The author addressed all four substantive findings (1.1–1.3, 4.1) — 1. Correctness & Implementation Bugs — ✅2. AGENTS.md Adherence — ✅3. Security — ✅4. Performance — ✅5. UI / UX — ✅6. Code Quality & Style — ✅No new findings beyond the two carried-over nits (6.1 and 6.2) noted in the status table above. 7. Commit Hygiene — ✅8. Tests — ✅9. Documentation — ✅10. Nitpicks / Optional — ✅No new nits beyond 10.3 carried over above. Generated by Claude. This is advisory; a human reviewer must still approve. |
8ff9d6b to
eed1509
Compare
Adds the runtime types backing the new geofencing flow: FenceLatLng, FencePolygon (with inclusion flag and vertex list), FenceCircle, BreachReturnPoint, and the Cockpit-level GeoFencePlan, plus the instanceOfGeoFencePlan guard that inspects only the outer discriminator + version so deeper validation stays at the call site that knows the schema.
On vehicle bring-up, send MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES and cache the bitmask received via the AUTOPILOT_VERSION message. Exposes a `capabilities()` accessor and a new `onCapabilities` signal so consumers can react when the bitmask first arrives. Failures are logged at warn level and gracefully fall back to "optimistic" capability reporting (consumers default to enabling features when no AUTOPILOT_VERSION has been seen yet).
Adds two helpers that turn the existing PARAM_REQUEST_READ / PARAM_VALUE round-trip into something callers can actually \`await\`: - \`requestParameter(name)\`: fires a single PARAM_REQUEST_READ for the given parameter id; the reply still bubbles up through \`onParameter\` for code that wants to keep listening passively. - \`requestParameterValue(name, timeoutMs)\`: subscribes a one-shot listener that resolves with the value as soon as the matching PARAM_VALUE arrives (or undefined on timeout). Both the listener and the timeout handle are cleared as soon as the promise settles to avoid stray callbacks. Signed-off-by: Arturo Manzoli <arturomanzoli@gmail.com>
Wires geofence support into the existing MAVLink mission micro-service: - geofence-conversion.ts: pure helpers that translate between a Cockpit GeoFencePlan and a flat list of MissionItemInt[]. Polygons are emitted vertex-per-item with a shared param1=vertex_count; circles use param1 for the radius; the optional breach return point goes last as a MAV_FRAME_GLOBAL_RELATIVE_ALT item. The reverse path detects bad/incomplete polygon item streams from the autopilot and surfaces a descriptive error. - vehicle.ts: extracts _fetchMissionItems / _uploadMissionItems from the mission code so fence and mission paths share the handshake, then layers uploadFence / fetchFence / clearFence on top using MAV_MISSION_TYPE_FENCE. uploadFence also calls _ensureArduPilotPolygonFenceTypeBit to set the Polygon bit (4) of FENCE_TYPE on ArduPilot — without it the autopilot silently ignores the uploaded polygons/circles. Other FENCE_TYPE bits are preserved. Signed-off-by: Arturo Manzoli <arturomanzoli@gmail.com>
Surfaces the new MAVLink capability and fence APIs through the existing main-vehicle Pinia store so consumers don't need to reach into the underlying MAVLinkVehicle instance: - \`capabilities\` ref + \`onCapabilities\` subscription, kept in sync as AUTOPILOT_VERSION arrives. - \`uploadFence\` / \`fetchFence\` / \`clearFence\` proxy actions, mirroring the existing mission helpers (and emitting the same "Geofence deleted from vehicle" snackbar on clear). - \`requestParameter\` proxy so other stores (notably the upcoming geo-fence store) can pull individual parameter values without duplicating the MAVLink boilerplate. Signed-off-by: Arturo Manzoli <arturomanzoli@gmail.com>
Framework-agnostic geofence geometry extracted so it stays unit-testable and reusable outside the store: WGS84 metric offsetting for default shape sizing, turf-backed point-in-polygon and haversine distance, plan/vertex deep-clone helpers, and detectMissionBreaches, which flags waypoints that fall outside every inclusion shape or inside any exclusion shape. Also houses the shared placement constants (default/max polygon half-side and circle radius) consumed by both the store and the editor draft.
Pinia store that owns the persisted editor-side geofencing state and vehicle sync, delegating pure geometry to libs/geo-fence and transient draw/interaction state to the useGeoFenceEditorDraft composable: - Reactive polygons, circles and breach-return point with `cockpit-draft-fence` (in-progress) and `cockpit-vehicle-fence` (last uploaded) persistence so the user doesn't lose work across reloads. - Vehicle sync: `uploadToVehicle` (auto-enables FENCE_ENABLE and FENCE_AUTOENABLE on ArduPilot once the upload completes), `downloadFromVehicle`, `clearOnVehicle`, plus `setFenceEnabled` / `setFenceAutoEnable` that write the parameters through the vehicle. - `FENCE_ENABLE` polling watch (10s) tied to ArduPilot + a loaded plan so the Map widget toggle reflects autopilot-side flips (e.g. takeoff-time activation) the autopilot doesn't broadcast. - Capability gate via `isFenceSupported` (`MISSION_FENCE` bit) and a `detectMissionBreaches` wrapper that picks the editor plan (or the last uploaded plan as fallback) so the UI can warn before mission upload.
Bail from _ensureArduPilotPolygonFenceTypeBit when the FENCE_TYPE read returns undefined (timeout) instead of assuming 0 and writing bit 4 alone, which would wipe the user's AltMax/AltMin/Circle bits. Logically belongs folded into "lib: vehicle-mavlink: add fence upload, fetch and clear" (0008163); kept separate because folding it would rewrite the stacked base and force a rebuild of the bluerobotics#2808/bluerobotics#2809 [drop] chains — do that explicitly, not autonomously.
Move emptyGeoFencePlan into libs/geo-fence and reuse it for the cockpit-draft-fence default and the MAVLink conversion re-export so the empty-plan literal is defined once. Addresses nit 10.3 from the local all-threshold review; logically folds into the geo-fence libs commit on a stack reshape.
eed1509 to
dbefadd
Compare
|
/review |
Automated PR Re-review 3 (Claude)Comparing The incremental diff includes all PR files because the branch was rebased since the last review. Re-checking is based on the full Previous findings status
New findings0. SummaryVerdict: READY TO MERGE This PR adds geofence plan types, MAVLink geofence conversion helpers, fence upload/fetch/clear over the mission micro-service, autopilot capability tracking, generic parameter-request helpers, and a 1. Correctness & Implementation Bugs — ✅2. AGENTS.md Adherence — ✅3. Security — ✅4. Performance — ✅5. UI / UX — ✅6. Code Quality & Style — ✅7. Commit Hygiene7.1 8. Tests — ✅9. Documentation — ✅10. Nitpicks / Optional — ✅Generated by Claude. This is advisory; a human reviewer must still approve. |
|
@rafaellehmkuhl This one is ready to review |
.cfpand MAVLink.planenvelopes and their type guards.GeoFencePlanand theMissionItemIntarray format.AUTOPILOT_VERSIONon the MAVLink vehicle.uploadFence,fetchFence,clearFence,requestParameter) on the main-vehicle store.geoFencePinia store: editor draft state, persistence undercockpit-keys, vehicle sync, visibility-gatedFENCE_ENABLEenforcement polling, and mission-vs-fence breach detection.First of three sequential PRs splitting #2671 — the follow-ups land on top of this one:
geofence-planning-editor— Mission/GeoFence sidebar switch, polygon and circle drawing, inclusion/exclusion tagging, breach return point, parameter panel, vehicle send/fetch/clear,.cfp/.planimport-export, and the pre-upload breach check.geofence-map-overlay— live fence overlay and enforcement toggle on the Map widget.