1358 Commits

Author SHA1 Message Date
Peter Barker
88029b0673 AP_Scripting: replace HTML <table> with markdown tables 2026-02-04 21:51:36 +11:00
Peter Barker
7ceb7c31c7 global: fix whitespace issues in markdown files
global: fix MD007 unordered list indentation in markdown files

Normalize unordered list indentation to use 2-space multiples:
- Top-level list items start at column 0
- Nested list items use 2 additional spaces per level

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

global: fix MD009 trailing whitespace in markdown files

Remove trailing whitespace from all affected markdown files.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

global: fix MD010 hard tabs in markdown files

Replace hard tab characters with 4 spaces.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

global: fix MD012 multiple consecutive blank lines in markdown

Collapse multiple consecutive blank lines to single blank lines
across all markdown files (excluding vendored code).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

global: fix MD007 list indentation base level in markdown

Shift list indentation left by 2 spaces so top-level list items
start at column 0 instead of column 2.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tools/scripts: fix MD022 blank lines around headings in markdown

Ensure headings are surrounded by blank lines as required by
markdownlint MD022 rule.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tools/scripts: fix MD032 blank lines around lists in markdown

Ensure lists are surrounded by blank lines as required by
markdownlint MD032 rule.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tools/scripts: fix MD031 blank lines around code blocks in markdown

Ensure fenced code blocks are surrounded by blank lines as required
by markdownlint MD031 rule.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tools/scripts: fix MD047 files should end with single newline

Ensure all markdown files end with exactly one newline character
as required by markdownlint MD047 rule.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tools/scripts: fix MD023 headings must start at beginning of line

Remove leading whitespace from heading lines as required by
markdownlint MD023 rule.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tools/scripts: fix MD007 remaining list indentation in markdown

Fix unordered list indentation to use correct spacing as required
by markdownlint MD007 rule.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tools/scripts: fix MD030 spaces after list markers in markdown

Reduce multiple spaces after list markers to single space as
required by markdownlint MD030 rule.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tools/scripts: fix MD022 blank lines around setext headings

Ensure setext-style headings (underlined with === or ---) are
surrounded by blank lines as required by markdownlint MD022 rule.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tools/scripts: fix MD018 missing space after hash in headings

Add space after hash marks in atx-style headings as required by
markdownlint MD018 rule.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tools/scripts: fix MD019 multiple spaces after hash in headings

Reduce multiple spaces after hash marks to single space in
atx-style headings as required by markdownlint MD019 rule.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tools/scripts: fix MD012 multiple consecutive blank lines in markdown

Remove multiple consecutive blank lines and ensure files end with
exactly one newline as required by markdownlint MD012 rule.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tools/scripts: fix MD023 headings with leading whitespace

Remove leading whitespace from setext-style heading text lines
as required by markdownlint MD023 rule.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tools/scripts: fix MD022 blank line after heading in markdown

Add missing blank line after heading as required by markdownlint
MD022 rule.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tools/scripts: fix MD009 trailing non-breaking space in markdown

Remove trailing non-breaking space (U+00A0) as required by
markdownlint MD009 rule.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tools/scripts: fix MD012 remaining multiple blank lines in markdown

Remove leading blank lines and whitespace-only lines that create
multiple consecutive blank lines.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 11:37:38 +11:00
Thomas Watson
b996debd67 AP_Scripting: avoid leaking script on engine error during load
If Lua raises an error we won't ever link the new_script into the list
and won't find it to remove it and free its components later. The
components do ultimately get freed by the destruction of the heap, and
there's no way to access them after, but we'd rather it be empty and
know nothing is dangling.

This should be replaced by storing the components as Lua objects and
letting Lua's GC take care of them. That way the code could be made much
less fragile.

Also removes a chance of a leak in run_next_script.
2026-01-22 21:09:09 -06:00
Thomas Watson
b0d93f0e16 AP_Scripting: simplify Lua abort handler
This should never be called so there's not much to be gained from a
panic message. If it is, the call should be identifiable by the internal
error line number.
2026-01-22 21:09:09 -06:00
Thomas Watson
79e591f947 AP_Scripting: remove Lua panic handler
Nominally cannot be called as we do not call error-raising Lua functions
outside of protected mode. In the event a panic happens somehow anyway,
Lua calls `lua_abort` which we already handle safely.
2026-01-22 21:09:09 -06:00
Thomas Watson
67860f11c0 AP_Scripting: run scripting engine in protected mode
Lua calls our registered panic function if a Lua error is raised outside
of any protected mode set up by `lua_pcall` and friends. As scripts
themselves are run in protected mode, such an error will only originate
from our engine code.

The current code handles panics, but does so incorrectly by neglecting
to free the error message buffer during a panic exit. As the underlying
heap is eventually destroyed and recreated, that static buffer pointer
is to a heap that no longer exists. If the new state raises an error it
will try to free that pointer, causing heap corruption and sadness.

Fix this issue and avoid similar ones by refactoring to run the main
part of the scripting engine in Lua protected mode. This creates exactly
one exit path from the scripting engine and avoids the need for fragile
panic handling infrastructure that duplicates what is built into Lua.
Quoth the Lua manual, "The panic function, as its name implies, is a
mechanism of last resort. Programs should avoid it."

This is unlikely to be triggerable in flight as the main engine loop
does not appear to use the Lua API in a way which can trigger errors.
But the possibility can't be fully excluded. It is, however, possible to
trigger beforehand using a perfectly wrong heap size that causes a
memory error during initialization.

Note that due to the error message buffer being freed properly now, an
error message originating from the engine will not cause a pre-arm
failure. This could be improved in the future.
2026-01-22 21:09:09 -06:00
Randy Mackay
71cf8dcb5c AP_Scripting: arming-checks update for copter RTL parms 2026-01-23 11:51:54 +11:00
Randy Mackay
71dee9460d AP_Scripting: config_profiles example uses new RTL params 2026-01-23 11:51:54 +11:00
Randy Mackay
8ede7673ba AP_Scripting: param-set example uses new RTL params 2026-01-23 11:51:54 +11:00
Thomas Watson
56005f8ca8 AP_Scripting: fix minor bug in repl applet
If `writechar` failed because the serial buffer was full, then `tx_buf`
could be nil and appending to it would fail. Fix by letting
`writestring` handle the work in this rare case.

Also bump the version to signify the fix.
2026-01-18 14:56:58 -06:00
Thomas Watson
7e777b6371 AP_Scripting: fix CRSF leaks and nullptr dereferences
There are several bogus error messages and checks that are removed.

This should probably be refactored to use ap_objects and avoid
reallocation of the underlying bits.
2026-01-07 08:56:01 -06:00
Peter Barker
abf75c1831 AP_Scripting: improve definition of AP_SCRIPTING_BINDING_MOTORS_ENABLED 2026-01-06 10:37:48 +00:00
Peter Barker
8ea793aca7 AP_Scripting: correct compilation when !AP_SCRIPTING_BINDING_VEHICLE_ENABLED
Fixes:

../../libraries/AP_Scripting/lua_bindings.cpp: In function 'int lua_AP_Vehicle_set_target_velocity_NED(lua_State*)':
../../libraries/AP_Scripting/lua_bindings.cpp:1240:23: error: 'check_AP_Vehicle' was not declared in this scope; did you mean 'check_AC_Fence'?
 1240 |     AP_Vehicle * ud = check_AP_Vehicle(L);
      |                       ^~~~~~~~~~~~~~~~
      |                       check_AC_Fence
compilation terminated due to -Wfatal-errors.
2026-01-06 10:37:48 +00:00
Aadarsh Agarwal
d20814809e AP_Scripting: fix 'received' typo in RockBlock applet 2026-01-03 13:55:07 +09:00
robot-to-society
3e7867ebd0 AP_Scripting: Add experimental Lua example for S.Bus-style serial output 2025-12-31 09:45:04 +09:00
deepak61296
ed2c34310c AP_Scripting: remove viewpro lua driver
C++ driver now handles ViewPro gimbals, lua version no longer needed
2025-12-26 08:17:45 +09:00
Thomas Watson
2fccf2c1be AP_Scripting: remove old setjmp workarounds
No longer necessary; verified with a debugger. These were also never
applied to Cortex-M4.
2025-12-25 07:07:08 +11:00
Thomas Watson
83ee6fc583 AP_Scripting: use ap_setjmp
It properly saves and restores the floating point registers.
2025-12-25 07:07:08 +11:00
Andy Piper
9562c98f84 AP_Scripting: allow vehicles to yaw to target
docs for set_target_velocity_NED()
add set_target_angle_and_rate_and_throttle() for precise vehicle control
manual binding for set_target_velocity_NED() to allow optional boolean
update docs for attitude control
2025-12-17 16:31:37 +00:00
Andy Piper
a14116f64a AP_Scripting: add get_throttle_in() to scripting 2025-12-17 16:31:37 +00:00
Leonard Hall
f71edcdb15 AP_Scripting: : NEU to NED renaming - Parameter Name Change 2025-12-17 08:03:10 +09:00
Andy Piper
bd08004972 AP_Scripting: update crsf-calibrate.md install instructions 2025-12-16 13:32:00 +00:00
Andy Piper
9e54d43b16 AP_Scripting: refactor crsf-calibrate.lua to use new crsf_helper.lua module 2025-12-16 13:32:00 +00:00
Andy Piper
1ed72ce4be AP_Scripting: crsf_helper module for easily creating lua CRSF menus 2025-12-16 13:32:00 +00:00
Gregor Kikelj
ebe4fc2074 AP_Scripting: Sync 2MB flash limit with docs
https://ardupilot.org/copter/docs/common-lua-scripts.html

The docs reference 2MB limit, discord discussion suggested 2MB is the real limit.
2025-12-16 11:49:13 +11:00
Thomas Watson
1f09f80043 AP_Scripting: only print out one state memory usage
Now that startup RAM usage is not dependent on the number of bindings,
there is little need to specifically measure that phase. This combines
~700 bytes used by the string setup into the initial state usage. But
that number should very rarely change.
2025-12-16 11:13:16 +11:00
Thomas Watson
a550087eee AP_Scripting: generator: dynamically create userdata metatables
The `luaL_testudata` and `luaL_checkudata` functions correctly treat the
absence of a metatable for the type to check as the type not matching,
so there is no need to have the type's metatable in memory until an
object using it exists. Therefore we can defer the metatable's creation
until the first time an object of that type is created.

Saves some 4500 bytes of Lua heap RAM, at least if no such objects are
created. The created metatables are shared between all scripts, so there
is no increase in the total RAM usage if all objects are used. However,
there is some increased risk of heap fragmentation and unexpected
out-of-memory errors on rarely used code paths.

It would be nice to construct the object in the new utility function,
but it's not possible in C++ to take the address of a constructor.
Instead passing in a lambda is ugly, hardly any more efficient, and
screws up constructors which take parameters.

Also optimizes by using the generated userdata creators where possible,
and convincing the compiler to omit unnecessary checks.
2025-12-16 11:13:16 +11:00
Thomas Watson
00a2b76779 AP_Scripting: generator: dynamically create ap_object metatables
The `luaL_testudata` and `luaL_checkudata` functions correctly treat the
absence of a metatable for the type to check as the type not matching,
so there is no need to have the type's metatable in memory until an
object using it exists. Therefore we can defer the metatable's creation
until the first time an object of that type is created.

Saves some 1500 bytes of Lua heap RAM, at least if no such objects are
created. The created metatables are shared between all scripts, so there
is no increase in the total RAM usage if all objects are used. However,
there is some increased risk of heap fragmentation and unexpected
out-of-memory errors on rarely used code paths.
2025-12-16 11:13:16 +11:00
Andrew Tridgell
9456449a44 AP_Scripting: removed zero field in plane_precland.lua
always zero
2025-12-16 08:19:11 +11:00
Thomas Watson
b6a31f28b0 AP_Scripting: logger: do proper uint64_t coercion
Allows all non-negative numbery things to be logged as type `Q`, instead
of just the `uint64_t` userdata.
2025-12-15 14:05:49 -06:00
Thomas Watson
28898bf348 AP_Scripting: logger: use existing check functions
Reduces size but changes error messages somewhat.
2025-12-15 14:05:49 -06:00
Thomas Watson
b380b3f120 AP_Scripting: logger: fix spelling and format 2025-12-15 14:05:49 -06:00
Thomas Watson
be6ffb5f61 AP_Scripting: logger: use snprintf for more efficient prepend
Contrary to the comment there is no scope issue.
2025-12-15 14:05:49 -06:00
Thomas Watson
005a7afd30 AP_Scripting: logger: use appropriate types and names
Avoids shenanigans with strings long enough to wrap a uint8_t.
2025-12-15 14:05:49 -06:00
Thomas Watson
be52b644ea AP_Scripting: logger: clean up error handling returns
It is more efficient to have them.
2025-12-15 14:05:49 -06:00
Thomas Watson
a684486cb0 AP_Scripting: logger: use stack buffer
malloc is kinda slow and we were failing to free the memory in tandem
with its original allocated size, causing Lua to believe we still had
the bytes allocated. This created misleading stats and unnecessary GC
pressure, but no actual leak.

Fix by using a stack buffer half the buffer size we use in other
functions but still big enough for the maximum possible log message.

Co-authored-by: jschall <mr.challinger@gmail.com>
2025-12-15 14:05:49 -06:00
Thomas Watson
628ed68a21 AP_Scripting: factor non-templated definitions out of generated code
In some far future we may use a real templating language, but this makes
that code easier to edit today.
2025-12-10 14:39:14 -06:00
Thomas Watson
7a48bd363e AP_Scripting: mavlink: avoid crash on reinit with bigger size
The different size won't cause the `accept_msg_ids` array to be
reallocated, but it will still be zeroed up to its new size. If that's
bigger than the old one, then the heap gets corrupted, and mayhem and
destruction ensues.

Fix by only initializing the related data immediately on successful
allocation.
2025-12-09 00:58:33 +00:00
Thomas Watson
6dcd0889ca AP_Scripting: unify handling of legacy dot vs. colon calls
Push a dummy element on a dot call to make the stack look like the
generated bindings, which always expect the colon call (that pushes self
as the first argument) and the intended usage pattern.

Folds in `arg_offset = 1`. Note that none of these routines care about
the first argument as they were fine being called without it.
2025-12-09 00:56:31 +00:00
Thomas Watson
fbf146fc35 AP_Scripting: fix spelling mistake in error message 2025-12-04 21:12:30 -06:00
Thomas Watson
3b93ae972b AP_Scripting: fix binding generator spelling mistakes 2025-12-04 21:12:30 -06:00
Andy Piper
83e2647b5e AP_Scripting: add access to more fence methods 2025-12-03 19:18:19 +00:00
Andrew Tridgell
92d6c292ca AP_Scripting: dynamic mixer example for X8 co-rotating frame 2025-12-02 11:16:21 +11:00
Peter Barker
27781c8f18 AP_Scripting: add a pair of warnings about using RC set_override method
had an instance where a script was using this override and didn't failsafe as expected
2025-11-28 18:26:08 +11:00
neo-0007
16a79f5554 AP_Scripting: add example script to test target location
Script to test location for all 7 modes of mount using the
AP_Scripting_Backend.

Signed-off-by: neo-0007 <hrishikeshgohain123@gmail.com>
2025-11-27 10:14:20 +11:00
Andrew Tridgell
150c0e0879 AP_Scripting: add arm error for no battery tag
if the user neglects to connect the battery tag give a clear error
message
2025-11-27 07:32:09 +11:00
Andy Piper
7ede7dc715 AP_Scripting: clean-up semaphore access for CRSF 2025-11-19 19:01:11 +11:00
Andy Piper
94bc8d86e3 AP_Scripting: add CRSF peek_menu_event() and pop_menu_event()
add CRSF send_response() method
2025-11-19 19:01:11 +11:00
Peter Barker
93f45acb45 AP_Scripting: rename airspeed methods on AHRS to include EAS or TAS
mixing these up has caused confusion in the past.

"estimate" could also be confused as to mean "synthetic", when it will often come from a sensor.
2025-11-17 18:46:52 -06:00
Stephen Dade
d256a73ee7 AP_Scripting: Add Rockblock 9704 Lua script 2025-11-17 19:18:42 +11:00