Skip to content

Scripted Bendy Ruler based Object Avoidance for Plane - #33955

Open
timtuxworth wants to merge 10 commits into
ArduPilot:masterfrom
timtuxworth:pr-scripted-oa
Open

timtuxworth wants to merge 10 commits into
ArduPilot:masterfrom
timtuxworth:pr-scripted-oa

Conversation

@timtuxworth

@timtuxworth timtuxworth commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add planedaa, a scripted Detect-Alert-Avoid (DAA) capability for Plane that avoids geofences and ADS-B traffic, together with the supporting library plumbing (AP_OAScripting, ADS-B/avoidance queries) and a SITL autotest suite. The feature is compiled out by default.

Here's a video of pDAA running in PteroSim at Munich's OlympiaPark - avoiding geofenced no-fly zones and a hovering multi-rotor. https://youtu.be/dV6-yDYsGgs?si=Ku1J4ftYeOpPi8Vl

Classification & Testing (check all that apply and add your own)

  • Checked by a human programmer
  • Non-functional change
  • No-binary change
  • Infrastructure change (e.g. unit tests, helper scripts)
  • Automated test(s) verify changes (e.g. unit test, autotest)
  • Tested manually, description below (e.g. SITL)
  • Tested on hardware
  • Logs attached
  • Logs available on request

Testing

  • Real World: the applet has had extensive field testing on real quadplanes over many flights, tuning the avoidance margins, loiter-to-altitude descent and trapped-failsafe against live behaviour — including a genuine in-flight encounter with DJI drones and a GA aircraft transmitting ADS-B that the vehicle avoided. Logs available on request.
  • Autotest: 43 new Plane.PlaneDAA* SITL tests, all passing. They cover fence avoidance and breach-escape, fence-label scoping, ADS-B drone and GA-aircraft avoidance, the conservative CPA gate (a converging contact engages, a diverging one is suppressed), the loiter-to-altitude descend commit, altitude-fence clamping, wind-scaled margins, trapped-failsafe no-false-fire, and disable-reverts-target. Traffic is injected as ADSB_VEHICLE messages.
    Where a test asserts new behaviour it was validated fail-on-neutralized (e.g. the descend test fails when DAA_AVD_ALT is set to cruise so no descent is possible).
  • Regression: Copter.DataFlashErase passes — confirming the shared-library changes do not alter non-Plane log volume, and that the FENC dev diagnostic stays disabled.
  • Build: clean SITL build of both ArduPlane and ArduCopter; the new params and methods are compiled only into ArduPlane (APM_BUILD_TYPE(ArduPlane)), verified absent from the Copter binary.
  • Scripting CI: luacheck and lua-language-server clean on the applet.

On exercising "the interesting cases" (comment from @tridge auto review on 2026-08-11): these are correctness/robustness fixes without a clean behavioural hook to assert in SITL. The obstacle-type classification doesn't change the avoidance the vehicle actually flies (that keys off the ADS-B emitter type), so it isn't independently observable in a flight test; and the vertical-separation fix only changes detection inside the internally-built look-ahead segment, so isolating it would be geometry- and timing-dependent and flaky. Rather than commit fragile tests, Claude has verified these by inspection — as with the loop-rate and _rsem fixes, which aren't SITL-observable either. The DAA suite stays green.

Description

What. planedaa is a Lua applet that gives Plane a Detect-Alert-Avoid capability for both static (geofence) and dynamic (ADS-B) hazards, without new C++ flight logic.

This code is based extensively on the prior work by @tridge Andrew Tridgell and others as part of Canberra UAV and the Outback Challenge in 2018. This work had also been progressed by @NDevDrone Nate Mailhot and @TeteJK Theresa de Jesus Krings in 2024/5 on #28903.

The code implements ASTM3442M-23 for "Well Clear" and "Near Miss" boundaries for crewed aircraft and different boundaries for UAV well clear and near miss based on ACAS sXu and real world testing. These values are all parameterized.

By default the code is only included in SITL and boards with > 2M flash like the CubeRed and Linux boards. It can be built for any 2M board using --enable-AP_OASCRIPTING

This code:

  • steers around inclusion/exclusion geofences with a bendy-ruler path, using margins that scale with wind (DAA_WIND_MARG) and default to the turn radius (WP_LOITER_RAD) so the standoff is one loiter circle;
  • flies a loiter-to-altitude descent (DAA_AVD_ALT) for GA aircraft to open a vertical gap;
  • avoids ADS-B traffic with a type-aware closest-point-of-approach (CPA) gate that ignores clearly-diverging traffic;
  • clamps to altitude fences (FENCE_ALT_MIN/MAX) with proactive level-off; and
  • provides a trapped-failsafe (DAA_TRAP_ACT) that fires on a sustained fence breach or aircraft near-miss.

How the code is layered (one subsystem per commit):

  1. AP_Avoidance — the DAA standoff params and the distance_to_aircraft/obstacle + emitter-classifier queries used by scripting.
  2. AC_Fence — signed distance_line_to_* fence queries for scripted avoidance.
  3. AC_Avoidance — AP_OAScripting, the singleton that exposes fence and ADS-B avoidance to Lua.
  4. Plane — QuadPlane holds the AP_OAScripting member.
  5. AP_Scripting — the planedaa applet, its bindings, and planedaa.md.
  6. waf — whitelist AP_OAScripting.h for the APM_BUILD_TYPE-in-header check.
  7. autotest — the PlaneDAA* test suite.

Why. ADS-B and geofence avoidance policy is easier to iterate and tune per-vehicle in Lua than in C++, and keeping it scripted lets operators adjust standoffs, actions and margins without a firmware rebuild. The C++ additions are minimal, generic library queries; all avoidance policy lives in the applet.

Using mostly Lua also allows the easier implementation of different mechanisms for avoidance and failsafes, and limits the flash space impact.

Parameters / migration.

  • New (ArduPlane only, gated APM_BUILD_TYPE(ArduPlane) — not present on other vehicles): AVD_WCLR_XY, AVD_WCLR_Z, AVD_NMAC_XY, AVD_NMAC_Z, AVD_UAV_XY, AVD_UAV_Z (well-clear / near-miss / UAV standoffs).
  • The applet adds its own DAA_* scripting parameters at load; these are documented in libraries/AP_Scripting/applets/planedaa.md.
  • No existing parameter changes value, storage, or default — nothing to migrate.

Scope note. The DAA standoff params and scripted-avoidance methods are gated so they compile only into ArduPlane, and only when --enable-AP_OASCRIPTING is used when compiling. The c++ code and bindings not compiled in by default. ArduCopter/Rover/etc. binaries and parameter tables are unaffected (verified by Copter.DataFlashErase).

This costs a few bytes of flash even when compiled out due to virtual methods required in AP_Vehicle. Trying to compile these out breaks a lot of other because they aren't well behaved consumers of AP_Vehicle, I don't think I can fix this here without extending the scope to a lot of other unrelated vehicles.

Depends on #34032 which has been split out. (Merged)


This contribution was AI-assisted: the applet, C++ library plumbing, and autotests were developed using ChatGPT and DeepSeek and iterated with Claude (Claude Code) under human direction and review, and validated in SITL and extensive field testing on real vehicles.

Comment thread ArduPlane/Plane.h Resolved
Comment thread libraries/AC_Avoidance/AC_Avoid.h Resolved
Comment thread libraries/AC_Avoidance/AP_OAScripting.h Resolved
Comment thread libraries/AC_Avoidance/AP_OAScripting.h Resolved
Comment thread libraries/AC_Fence/AC_Fence.cpp Resolved
Comment thread libraries/AP_Avoidance/AP_Avoidance.cpp Resolved
Comment thread libraries/AP_Avoidance/AP_Avoidance.cpp Resolved
Comment thread libraries/AP_Avoidance/AP_Avoidance.cpp Resolved
Comment thread libraries/AP_Scripting/docs/docs.lua Resolved
Comment thread libraries/AP_Scripting/docs/docs.lua Resolved
@tridge

tridge commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Deprecated - see below for the updated review.

Previous review (2026-08-10)

Automated review note — AI-generated (Claude), cross-checked by an independent second model against the live diff. Please sanity-check before acting.

Reviewed at head 874bb0fcda.

Verdict: REQUEST CHANGES

  • BUG — libraries/AP_Avoidance/AP_Avoidance.cpp:873 — Vertical separation handling. Flagged in the independent review of the new database reader path. Worth the author tracing directly — this is a 21-file, 320 kB diff adding an avoidance applet, and green CI does not exercise the interesting cases.

  • BUG — libraries/AC_Avoidance/AP_OAScripting.cpp:519 — _get_obstacle_type() path. Second defect found in the C++ side of the new scripting interface.

  • BUG — libraries/AP_Scripting/applets/planedaa.lua:2556 — avoid_obstacle() is sticky once entered. Once engaged the applet does not return cleanly, per the cold review.

  • BUG — libraries/AP_Scripting/applets/planedaa.lua:551 — Further defects at 551 and 2780.

  • ISSUE — libraries/AP_Avoidance/AP_Avoidance.cpp:848 — Both new database readers share a concern.

  • ISSUE — libraries/AP_Scripting/applets/planedaa.lua:2680 — Trap recovery type.

  • NOTE — Scope caveat on this entry. This PR got a cold independent review rather than a line-by-line pass from me — at 21 files and ~320 kB it is the largest in this batch. The findings above are real but the list should not be read as exhaustive.

Full report: https://uav.tridgell.net/DevCallReviews/2026_08_11/devcall_pr_reviews.html

@timtuxworth

timtuxworth commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Automated review note — AI-generated (Claude), cross-checked by an independent second model against the live diff. Please sanity-check before acting.

Reviewed at head 874bb0fcda.

Verdict: REQUEST CHANGES

* **BUG** — `libraries/AP_Avoidance/AP_Avoidance.cpp:873` — **Vertical separation handling.** Flagged in the independent review of the new database reader path. Worth the author tracing directly — this is a 21-file, 320 kB diff adding an avoidance applet, and green CI does not exercise the interesting cases.

* **BUG** — `libraries/AC_Avoidance/AP_OAScripting.cpp:519` — **`_get_obstacle_type()` path.** Second defect found in the C++ side of the new scripting interface.

* **BUG** — `libraries/AP_Scripting/applets/planedaa.lua:2556` — **`avoid_obstacle()` is sticky once entered.** Once engaged the applet does not return cleanly, per the cold review.

* **BUG** — `libraries/AP_Scripting/applets/planedaa.lua:551` — **Further defects at 551 and 2780.**

* **ISSUE** — `libraries/AP_Avoidance/AP_Avoidance.cpp:848` — **Both new database readers share a concern.**

* **ISSUE** — `libraries/AP_Scripting/applets/planedaa.lua:2680` — **Trap recovery type.**

* **NOTE** — **Scope caveat on this entry.** This PR got a cold independent review rather than a line-by-line pass from me — at 21 files and ~320 kB it is the largest in this batch. The findings above are real but the list should not be read as exhaustive.

Full report: https://uav.tridgell.net/DevCallReviews/2026_08_11/devcall_pr_reviews.html

I've now verified every finding against the actual code (the report itself carries no rationale beyond the locations, so my trace is the authority). Here's the triage — 4 are real, 1 is a real-but-known approximation, 1 is not a bug.

Confirmed bugs (clear fix)

  1. AP_OAScripting.cpp:519 — _get_obstacle_type() reads icao_code before it's set. ✅ REAL, high impact
    _get_obstacle_type(emitter, script_obstacle.icao_code) takes icao_code by value and reads it (icao_code <= 0x0BFFF … >= 0xB00000), but script_obstacle.icao_code isn't assigned until line 523, four
    lines later. It classifies on a stale/zero value — and 0 <= 0x0BFFF returns MAV_SYSID, so every obstacle (incl. GA aircraft) gets typed as a drone.
    Fix: hoist line 523 above 519, or just pass the value directly:
    script_obstacle.obstacle_type = static_cast<uint8_t>(_get_obstacle_type(avoid_obstacle->emitter_type, avoid_obstacle->src_id & 0xFFFFFF));

  2. planedaa.lua:551 + :2780 — update loop runs 10× too fast + divide-by-zero. ✅ REAL
    DAA_UPDATE_RATE is Hz (default 10). Line 551 computes refresh_rate = 1000/rate = 100 — that's a period in ms, misnamed "rate". Line 2780 then returns 1000 / refresh_rate = 10 ms → the loop runs at
    100 Hz, not 10 Hz. And DAA_UPDATE_RATE=0 → refresh_rate=inf → 1000/inf=0 ms → tight loop.
    Fix: return Protected_Wrapper, refresh_rate (it already is the ms period; rename to refresh_period_ms), and guard rate > 0 at 551/705.

  3. planedaa.lua:2556 — duplicate STATE.hovering (a copy-paste bug luacheck flagged and the code suppresses). ✅ REAL, needs your intent
    STATE = {monitoring=1, avoiding=2, loitering=3, loitering_avoiding=4, hovering=5, landing=6}. The "busy, don't re-decide" branch tests hovering or avoiding or hovering or landing — hovering twice,
    -- luacheck: ignore 542 hides it. The only STATE not handled anywhere in this chain is loitering_avoiding, so the second STATE.hovering was almost certainly meant to be STATE.loitering_avoiding.
    As-is, a loitering_avoiding state falls through to else → monitoring and gets reset every cycle. Confirm that's the intended state before I change it (it alters behavior).

  4. AP_Avoidance.cpp:848 + :905 — both new readers touch the obstacle DB without the lock. ✅ REAL (the "shared concern")
    distance_to_obstacle and distance_to_aircraft iterate _obstacles/_obstacle_count with no WITH_SEMAPHORE(_rsem) — the very lock the rest of the class uses (e.g. AP_Avoidance.cpp:269) to guard the DB
    against the MAVLink add/update path. These readers run on the scripting thread while MAVLink writes on another → data race.
    Fix: add WITH_SEMAPHORE(_rsem); at the top of both.

Real but not a crash

  1. AP_Avoidance.cpp:873 — vertical separation is a crude endpoint approximation.
    height_difference_m = MIN(|start.z−obs.z|, |end.z−obs.z|) gates on the endpoints, while the horizontal distance uses the closest point on the segment — decoupled on a climbing/descending leg. The
    z-frames are consistent (caller negates to down-positive, verified at find_aircraft:187; obstacle negated at :860), so no sign bug — but the code's own TODO at :862 admits "fairly simplistic… needs
    to deal with altitude." Recommend interpolating altitude at the horizontal-closest point (and cleaning the misleading _cm-named params at :556 that feed an _m function). Not urgent.

Not a bug

  1. planedaa.lua:2680 — trap recovery type. ⛔ no defect.
    (obstacle_avoiding ~= nil) and obstacle_is_dynamic(obstacle_avoiding.type) or false — .type is a valid field (set at :983/:1968), and the a and b or c idiom is safe here because
    obstacle_is_dynamic's false case coincides with the or false fallback. The only nuance is that trap_dynamic reflects the current obstacle at fire time, not necessarily the compromise cause from
    trap_s ago — which the comment already handles deliberately (breach-escape → treat as fence). I'd leave it.

Recommendation: fix #1, #2, #4 now (unambiguous, low-risk), confirm the intended state for #3, and defer #5 as a follow-up. I'd do them on scripted-oa (granular commits), bump to v048, rerun the DAA
suite, then regenerate + force-push pr-scripted-oa per the usual workflow.

@AP-Review

AP-Review commented Oct 20, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-10-20)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: REQUEST CHANGES

Reviewed at head 9e9a68782c.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/33955/18.html#pr33955

This review covers 9e9a687. That is the head your 20 Oct reply describes, rebased onto dc78bc5, and it was still the PR head at 15:45 UTC on 20 Oct. The last note here covered 68cbd95. All three review passes completed. Only the first pass and this note ran SITL; the other two used offline harnesses. CI was still queued at this head (79 of 80 check runs queued at 15:45 UTC on 20 Oct), so it is unconfirmed.

Thanks for the fixes. Last round's blocker is closed. With the live-mode guards (planedaa.lua:1435, planedaa.lua:1796), PlaneDAALoiterRespectsPilotTakeover and PlaneDAATrapRespectsPilotTakeover pass at head and fail with their guard removed. PlaneDAAAircraftModifiedTau fails with the tau decision disabled and still passes with only the first-fix fallback disabled, so it covers the right branch. The cold-cache terrain and populated-cache wind tests pass, all 46 PlaneDAA tests passed in one session, and header-check rebuilds pass at every commit in the new order. The wording fixes match the code.

Needs fixing before merge:

  1. The loiter handback can still undo a pilot or failsafe mode change. do_loitering() calls loiteralt.stop(false) (planedaa.lua:1417) before loiteralt.update() (planedaa.lua:1428), and update() is what notices the plane has left GUIDED. stop() restores the saved mode without checking the live one (daaltr.lua:277). So if the mode changes before the snapshot of the cycle where the loiter releases, the new DAA.avoid() guard passes (snapshot and live agree), and stop() puts AUTO back over the pilot's RTL. I ran this in SITL at this head with a review-only test. It uses your takeover test's setup, moves the contact away once the loiter starts, sets DAA_LTR_COOL_S=0, and sets RTL from the script just before stop(false). Both runs ended in AUTO with 'Loiter Done set mode: Auto'. With the default cooldown still pending, the same injection kept RTL. With update() called before stop(false), it also kept RTL. It is a one-cycle window per release, the handback side of last round's item, and the code is unchanged from 68cbd95, so it is new to this review. clear_avoidance() already calls update() first (planedaa.lua:1355); doing the same in do_loitering(), or checking for GUIDED in stop(), would close it.

Not blocking:

Not run: a real RC switch, GCS or failsafe timing for the guards and for item 1, hardware, a real carried or thrown launch, QuadPlane, AUTOLAND, go-arounds, a landing with a contact present, real ADS-B timing, other vehicles and the non-DAA Plane tests. Each SITL scenario here was run once or twice, so the runs show the behaviour exists, not how often it happens.

@timtuxworth

Copy link
Copy Markdown
Contributor Author

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Verdict: REQUEST CHANGES

Reviewed at head 9e9a68782c. Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/33955/18.html#pr33955

This review covers 9e9a687. That is the head your 20 Oct reply describes, rebased onto dc78bc5, and it was still the PR head at 15:45 UTC on 20 Oct. The last note here covered 68cbd95. All three review passes completed. Only the first pass and this note ran SITL; the other two used offline harnesses. CI was still queued at this head (79 of 80 check runs queued at 15:45 UTC on 20 Oct), so it is unconfirmed.

Thanks for the fixes. Last round's blocker is closed. With the live-mode guards (planedaa.lua:1435, planedaa.lua:1796), PlaneDAALoiterRespectsPilotTakeover and PlaneDAATrapRespectsPilotTakeover pass at head and fail with their guard removed. PlaneDAAAircraftModifiedTau fails with the tau decision disabled and still passes with only the first-fix fallback disabled, so it covers the right branch. The cold-cache terrain and populated-cache wind tests pass, all 46 PlaneDAA tests passed in one session, and header-check rebuilds pass at every commit in the new order. The wording fixes match the code.

Needs fixing before merge:

  1. The loiter handback can still undo a pilot or failsafe mode change. do_loitering() calls loiteralt.stop(false) (planedaa.lua:1417) before loiteralt.update() (planedaa.lua:1428), and update() is what notices the plane has left GUIDED. stop() restores the saved mode without checking the live one (daaltr.lua:277). So if the mode changes before the snapshot of the cycle where the loiter releases, the new DAA.avoid() guard passes (snapshot and live agree), and stop() puts AUTO back over the pilot's RTL. I ran this in SITL at this head with a review-only test. It uses your takeover test's setup, moves the contact away once the loiter starts, sets DAA_LTR_COOL_S=0, and sets RTL from the script just before stop(false). Both runs ended in AUTO with 'Loiter Done set mode: Auto'. With the default cooldown still pending, the same injection kept RTL. With update() called before stop(false), it also kept RTL. It is a one-cycle window per release, the handback side of last round's item, and the code is unchanged from 68cbd95, so it is new to this review. clear_avoidance() already calls update() first (planedaa.lua:1355); doing the same in do_loitering(), or checking for GUIDED in stop(), would close it.

Not blocking:

Not run: a real RC switch, GCS or failsafe timing for the guards and for item 1, hardware, a real carried or thrown launch, QuadPlane, AUTOLAND, go-arounds, a landing with a contact present, real ADS-B timing, other vehicles and the non-DAA Plane tests. Each SITL scenario here was run once or twice, so the runs show the behaviour exists, not how often it happens.

Addressed the blocking loiter-handback issue in 061e825. daaltr.stop() now checks the live mode before cooldown handling or restoring the saved mode. If the vehicle has left GUIDED, it relinquishes control, including during forced cleanup.

Added two SITL regression tests covering zero-cooldown release and forced cleanup with cooldown pending. Both pass with the fix and fail with it removed. Updated planedaa.md, including Known limitations.

Rebased onto master at 9c412ba and rebuilt with header checks enabled. The full DAA run had 47 passes and one post-test reboot timeout waiting for RC_CHANNELS; that test and both neighbours passed on retry without code changes.

The nonblocking findings remain outstanding, including the residual non-atomic mode-check/command window. These changes and tests were AI-assisted.

@AP-Review

AP-Review commented Oct 20, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-10-20)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 061e8255f4.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/33955/19.html#pr33955

This review covers 061e825, which was still the PR head at 20:40 UTC on 20 Oct. CI was still queued (78 of 79 check runs), so it is unconfirmed. All three review passes completed.

Thanks for the fix: the loiter handback blocker is closed. PlaneDAALoiterHandbackRespectsPilotTakeover, PlaneDAALoiterForcedStopRespectsPilotTakeover and last round's review-only probe pass in SITL at this head and fail with the new check at daaltr.lua:272 removed.

Should fix

  • planedaa.lua:1109 With DAA_TRAP_ACT set, one cycle with no position while a trap holds RTL during an aircraft loiter calls clear_avoidance(). Its loiteralt.update() (planedaa.lua:1355) treats the trap's RTL as a pilot change and drops the saved AUTO, so after the trap resumes GUIDED nothing returns the plane to AUTO. Skipping the loiter cleanup while trap_active fixed it in an offline probe. This is rare, because it needs a real position loss.

Low

  • daaltr.lua:218 start() reads the live mode only to save it, then switches to GUIDED at daaltr.lua:242, so a mode change during start()'s fence work is still overridden. The trap has the same gap (planedaa.lua:1793 to planedaa.lua:1702). Your Known limitations covers this. In SITL, comparing the live mode with the caller's just before the command closed it.
  • GUIDED retarget overwritten on release (still open), daaltr.lua:311.
  • GENERAL-contact margin masking (still open), daaobs.lua:373.
Minor (5)

Not run: SITL for the trap/dropout and retarget items, real RC, GCS or failsafe timing, the full PlaneDAA suite at this head, hardware, QuadPlane, AUTOLAND, go-arounds, landing with traffic, real ADS-B timing and other vehicles.

@timtuxworth

Copy link
Copy Markdown
Contributor Author

Added a home-to-fence pre-arm check in 202d00f. It uses auxiliary arming authorization, like arming-checks.lua, and prevents arming with:

pDAA: Fence too close to home for safe DAA

The check compares home’s clearance from enabled horizontal fences against the DAA buffer, including the current estimated wind allowance. It clears when clearance improves or DAA avoidance is disabled.

Documented the limitations: pre-arm wind estimates, fences enabled only after arming/takeoff, shared authorization slots, and the fact that static home clearance does not guarantee a safe RTL approach or VTOL transition.

The full 49-test DAA suite passed after rebasing onto master at 95e2ddb. Subsequent documentation and test-only changes added inclusion-circle and inclusion-polygon coverage; the expanded pre-arm test passed on the final submission tree. No flight logic changed in that follow-up.

Implementation, documentation and tests were AI-assisted.

@AP-Review

AP-Review commented Oct 22, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-10-22)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 202d00f514.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/33955/20.html#pr33955

Nothing blocks this at 202d00f, and CI is green (111 of 111 checks).

Since the last review you added the home-to-fence pre-arm check. It behaves as described in our probes and its SITL test passes, but none of the earlier open items changed.

Should fix

  • planedaa.lua:1140 Trap plus position dropout during an aircraft loiter drops the saved AUTO (still open). Deferring the loiter cleanup at planedaa.lua:1386 while trap_active fixes it.
  • planedaa.lua:1140 Position-dropout revert order (still open, raised from minor). The validation probe loses the GUIDED destination with default settings: the failed revert still clears the saved target, so the avoidance carrot becomes the navigation target. Do the planedaa.lua:1153 refresh of the expected target from current_target_loc before clear_avoidance().

Low

  • planedaa.lua:1083 The new pre-arm text is exactly 42 characters, the size of AP_Arming's aux-auth buffer, so strncpy leaves it unterminated and each PreArm report reads past the heap block (ASan flags it in PlaneDAAHomeFencePreArm). Drop a character, e.g. "pDAA: Fence too close to home for DAA", and update arduplane.py:8661 to match.
  • GUIDED retarget overwritten on release (still open), daaltr.lua:311.
  • GENERAL-contact margin masking (still open), daaobs.lua:373.
Minor (6)

Not run: SITL for the trap/dropout, retarget and dropout-order items, the full PlaneDAA suite at this head, real RC/GCS/failsafe timing, hardware, QuadPlane, AUTOLAND and real ADS-B timing.

@timtuxworth

timtuxworth commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

When demoing at the conference, the Avoid vehicle avoided an unarmed, not-flying multirptor that was sitting on the ground waiting to launch. It should have ignored it as "parked". This was due to the difference between the GPS altitude of the multi rotor vs the avoid vehicle.

  • Increased the default AVD_GND_ALT from 3 m to 10 m to tolerate altitude-reference differences between nearby vehicles when filtering parked traffic.
  • Updated the parked-drone regression test to verify the new default and exercise an 8 m altitude offset.

Existing saved parameter values are not overwritten by the default change.

Validation: Plane SITL build succeeded, and all 49 DAA regression tests passed in one uninterrupted run after the rebase.

AI-assisted implementation and validation.

@AP-Review

AP-Review commented Nov 3, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-03)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 049b902f47.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/33955/21.html#pr33955

Nothing blocks this at 049b902; CI was still queued when this head was captured, so it is unconfirmed.

Since the last review the only change is the AVD_GND_ALT default (3 to 10 m) and its test, so nothing from the last round is fixed yet, and the new default brings one new issue.

Should fix

  • AP_Avoidance.cpp:185 The 10 m AVD_GND_ALT default makes is_parked() ignore a hovering drone too, not only a parked one: the test is altitude within 10 m of home plus low groundspeed, with no horizontal limit, and a hover reads 0 m/s. In SITL a 0 m/s UAV at home+8 m on the leg drew no reaction and the plane passed about 15 m from it horizontally and 16 m above; with 3 m it avoided. Either keep a lower default, or say in the AVD_GND_ALT/AVD_GND_SPD descriptions and planedaa.md:484 that hovering traffic in the band is ignored and add a hover control test.
  • planedaa.lua:1140 Trap plus position dropout during an aircraft loiter drops the saved AUTO (still open).
  • planedaa.lua:1140 Position-dropout revert order loses the GUIDED destination (still open).

Low

  • planedaa.lua:1083 Pre-arm text is exactly 42 characters, so it is left unterminated in AP_Arming's aux-auth buffer (still open); the test string is now at arduplane.py:8695.
  • daacore.lua:804 The side-commitment and slew smoothing can hold a course that its own probe now finds blocked: with defaults an offline probe keeps a heading with -147 m clearance for about 3 s and only reaches a clear one after 4.9 s. Re-probe the smoothed course and fall back to the resisted bearing when it is blocked.
Minor (9)

Not run: SITL for the trap/dropout, retarget, dropout-order and smoothing items, the full PlaneDAA suite at this head, real RC/GCS/failsafe timing, hardware, QuadPlane, AUTOLAND and real ADS-B timing.

Comment thread ArduPlane/Plane.h Resolved
@tridge

tridge commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

@IamPete1 I don't think we should move it up to AP_Vehicle for this PR just to avoid the scope creep and testing, but we may well move it up in future. No params (I think?) so it shouldn't be a hard move

@timtuxworth

Copy link
Copy Markdown
Contributor Author

Applied @peterbarker ’s suggestion: renamed the Plane AP_OAScripting member from aoscripting to oascripting and updated the nearby comment.

Rebased onto current master. Plane SITL build succeeded, and all 49 DAA regression tests passed in one uninterrupted run.

We just need your blessing @IamPete1 !

@timtuxworth

timtuxworth commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

I asked Codex about the mutable semaphore (originally added by Claude) - this is the assessment:

The semaphore already exists upstream. This PR adds mutable and makes its accessor const (line 190).
That lets read-only fence queries acquire the lock. Locking changes the semaphore’s bookkeeping, while leaving the fence data logically unchanged. C++ explicitly permits modifying a mutable member through a const object. Language reference.
The locking serves a real purpose:

I would keep it. It adds no additional semaphore allocation. The important constraint is that the low-level distance helpers rely on their caller holding the lock; tbefore DAA reads the fence data, it locks that data so another thread cannot replace or delete it mid-read. It unlocks the data when finished.

@AP-Review

AP-Review commented Nov 10, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-10)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 5597c9acac.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/33955/22.html#pr33955

Nothing blocks this at 5597c9a; CI was still queued when this head was captured, so it is unconfirmed.

Since the last review the head was rebased and the Plane member renamed to oascripting, as suggested; the PR's other changes are identical, so the earlier items are not fixed yet. I re-ran all 49 PlaneDAA tests at this head, and they passed.

Should fix

  • AP_Avoidance.cpp:185 Hover exclusion from the 10 m AVD_GND_ALT default, undocumented in the AVD_GND_ALT/AVD_GND_SPD descriptions and planedaa.md:484 (still open).
  • planedaa.lua:1140 Trap plus position dropout during an aircraft loiter drops the saved AUTO (still open).
  • planedaa.lua:1140 Position-dropout revert order loses the GUIDED destination (still open).

Low

Minor (10)

Not run: SITL for the trap/dropout, dropout-order, retarget and smoothing items (offline Lua probes only), CI, hardware, QuadPlane, AUTOLAND and real RC/GCS/failsafe and ADS-B timing.

@AP-Review

AP-Review commented Nov 11, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-11)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 23dd2112fe.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/33955/23.html#pr33955

Nothing blocks this at 23dd211. CI is still mostly queued; the one red job, check-merge-commits, is a markdownlint install failure that every PR is hitting today.

Since the last review the PR was rebased onto master's scripting-guard rename and gained the PlaneDAABindingGuards test. The applet and library code is unchanged, so the earlier items are not fixed yet. All 50 PlaneDAA tests pass at this head, and the new guard test also passes with AP_OASCRIPTING disabled. One new minor item is below.

Should fix

  • AP_Avoidance.cpp:185 Hover exclusion from the 10 m AVD_GND_ALT default (still open).
  • planedaa.lua:1140 Trap plus position dropout during an aircraft loiter drops the saved AUTO (still open).
  • planedaa.lua:1140 Position-dropout revert order loses the GUIDED destination (still open).

Low

Minor (11)

Not run: SITL for the dropout, trap, retarget, smoothing and loiter-radius items (offline Lua probes only), finished CI, hardware, QuadPlane, AUTOLAND and real RC/GCS/failsafe and ADS-B timing.

@timtuxworth

Copy link
Copy Markdown
Contributor Author

Rebased onto master and updated scripted DAA for the Lua/external-binding split introduced by #35078:

  • Use AP_SCRIPTING_LUA_ENABLED for scripted DAA enablement.
  • Keep Plane’s crosstrack APIs under AP_EXTERNAL_BINDING_ENABLED.
  • Add a regression test covering Lua bindings with OAScripting enabled and disabled.

Validation passed: all 50 DAA regressions, plus the binding test with OAScripting disabled. Plane builds successfully with Lua both with and without OAScripting.

The additional Lua-disabled build exposed an existing native custom-controller dependency problem. That fix is submitted separately in #35118.

The current check-merge-commits CI failure occurred while installing markdownlint-cli2, before the branch checks ran; it needs a rerun.

@timtuxworth

Copy link
Copy Markdown
Contributor Author

As at 2026-11-12

Global Size Summary (Total Flash delta in bytes)

Built from 23dd211 rebased onto aea9a1b

Board Periph tracker blimp bootloader copter heli iofw plane rover sub
DrotekP3Pro _ _ _ * _ _ _ _ _ _
Durandal _ +24 +24 _ +24 +24 _ +52 +24 +24
Hitec-Airspeed * _ _ _ _ _ _ _ _ _
KakuteF7 _ * * _ * * _ * * *
MambaH743v4 _ +24 +24 _ +12 +12 _ +44 +24 +24
MatekF405-CAN _ _ _ * _ _ _ _ _ _
MatekF405 _ * * _ * * _ * * *
MatekH743-bdshot _ +24 +24 _ +24 +24 _ +52 +24 +24
Pixhawk1-1M _ * * _ * * _ * * *
disco _ +60 +56 _ +120 +102 _ +13358 +56 +56
f103-GPS * _ _ _ _ _ _ _ _ _

@IamPete1 IamPete1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still some outstanding AI review comments.

Comment thread libraries/AC_Avoidance/AP_OAScripting.h Resolved
Comment thread libraries/AC_Avoidance/AP_OAScripting.h Outdated
FENCE_CIRCLE_EXCLUSION = 5,
FENCE_POLYGON_INCLUSION = 6,
FENCE_POLYGON_EXCLUSION = 7,
FENCE_LUA = 8,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean? Its not clear to me that its used anywhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not currently used. It's a placeholder for future integration with @tridge 's Lua fences.

AI-assisted development, review fixes and automated validation under human direction.
AI-assisted development, review fixes and automated validation under human direction.
AI-assisted development, review fixes and automated validation under human direction.
Comment thread libraries/AC_Fence/AC_Fence.cpp Resolved
@timtuxworth

timtuxworth commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for your reviews @IamPete1 and @rmackay9 . Updated at 10e3362019, rebased onto master a995235cda:

  • Removed the extra spacing in the four PR-added AC_Fence.cpp conditions, as Randy suggested.
  • Renamed MAV_SYSID to UNCREWED_AIRCRAFT throughout the C++/Lua code, documentation and test terminology. It covers both MAVLink traffic and ADS-B UAV contacts. Its numeric value remains 1.
  • Added the clarification that FENCE_LUA is a placeholder for future Lua/KML fence integration.
  • Updated script versions to planedaa.lua 4.8.0-120 and daaobs.lua 4.8.0-011.

Plane SITL builds successfully. All 50 DAA regressions passed in one uninterrupted run.

Regarding the three outstanding “Should fix” findings, my intention remains to defer these from the current revision, rather than claim they are resolved:

  • Hover exclusion: retaining the 10 m default is a deliberate trade-off to tolerate the altitude-reference differences observed between nearby vehicles. The altitude/groundspeed heuristic can also exclude a hovering or slowly moving aircraft within that band; it does not positively establish that a contact is on the ground. This limitation remains open.
  • Trap plus position dropout during an aircraft loiter: the saved AUTO mode can be lost during cleanup while the trap holds another mode. This remains an unresolved recovery edge case when trapped while loitering to avoid a crewed aircraft, the result will be it will continue to loiter rather than returning to AUTO, which IMO is a "safe" option.
  • Position-dropout revert order: cleanup can discard the saved GUIDED destination after an unsuccessful restore. This also remains unresolved and deferred. The result would be to fly to the last avoidance target and circle there.

The latter two need targeted fault-injection coverage and a reviewed recovery change. Passing the existing regression suite does not demonstrate that these cases are handled correctly.

I would prefer to address these in a follow-up rather than expand this naming/compatibility revision. They should remain recorded as open findings, not marked fixed.

Implementation and validation were AI-assisted.

AI-assisted development, review fixes and automated validation under human direction.
AI-assisted development, review fixes and automated validation under human direction.
AI-assisted development, review fixes and automated validation under human direction.
AI-assisted development, review fixes and automated validation under human direction.
AI-assisted development, review fixes and automated validation under human direction.
AI-assisted development, review fixes and automated validation under human direction.
AI-assisted development, review fixes and automated validation under human direction.
@timtuxworth

Copy link
Copy Markdown
Contributor Author

There are still some outstanding AI review comments.

See above, but specifically:

my intention remains to defer these from the current revision, rather than claim they are resolved:

  • Hover exclusion: retaining the 10 m default is a deliberate trade-off to tolerate the altitude-reference differences observed between nearby vehicles. The altitude/groundspeed heuristic can also exclude a hovering or slowly moving aircraft within that band; it does not positively establish that a contact is on the ground. This limitation remains open.
  • Trap plus position dropout during an aircraft loiter: the saved AUTO mode can be lost during cleanup while the trap holds another mode. This remains an unresolved recovery edge case.
  • Position-dropout revert order: cleanup can discard the saved GUIDED destination after an unsuccessful restore. This also remains unresolved and deferred.

The latter two need targeted fault-injection coverage and a reviewed recovery change. Passing the existing regression suite does not demonstrate that these cases are handled correctly.

I would prefer to address these in a follow-up rather than expand this naming/compatibility revision. They should remain recorded as open findings, not marked fixed.

@AP-Review

Copy link
Copy Markdown

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head e2730887d4.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/33955/24.html#pr33955

Nothing blocks this at e273088. CI is still running: 91 of 112 checks have passed and none has failed so far.

Since the last review, MAV_SYSID has been renamed to UNCREWED_AIRCRAFT throughout (value still 1), the AC_Fence spacing has been fixed and FENCE_LUA is marked as a placeholder. All 50 PlaneDAA tests pass at this head. The code behind the earlier items is unchanged, and you have deferred the three Should-fix items to a follow-up.

Should fix

  • AP_Avoidance.cpp:185 Hover exclusion (still open). You have accepted the 10 m default as a trade-off. The AVD_GND_ALT/AVD_GND_SPD descriptions and planedaa.md:484 still say a matching contact is parked or taxiing, not flying. One sentence saying that a drone hovering or moving slowly within AVD_GND_ALT of home is also excluded would close this.
  • planedaa.lua:1140 Trap plus position dropout during an aircraft loiter drops the saved AUTO (still open). While it is deferred, add it to Known limitations.
  • planedaa.lua:1140 Position-dropout revert order loses the GUIDED destination (still open). This also happens with the default DAA_TRAP_ACT=0, so give it its own Known limitations entry, not one framed as trap-only.

Low

Minor (12)

Not run: SITL reproductions of the dropout, trap, retarget, smoothing and loiter-radius items (offline Lua and extracted C++ probes only), finished CI, hardware, QuadPlane, AUTOLAND and real RC/GCS/failsafe and ADS-B timing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status
Status: No status

Development

Successfully merging this pull request may close these issues.

9 participants