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
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
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
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
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
muramura
3655c5066d
AP_Scripting: Change the maximum and minimum values of the type to named constants
2025-11-05 18:05:53 +11:00
Oleksiy Protas
979142b953
AP_Scripting: serial begin() automatic baud rate
...
If the baud rate is omitted or nil, use the HAL-derived value
which usually is taken from the corresponding parameter.
2025-10-20 23:05:47 +02:00
Andrew Tridgell
691e559db4
AP_Scripting: fixed a memory leak in socket recv()
...
we need to allocate the memory in the lua heap, otherwise a failure
leaks global memory
2025-10-14 12:56:41 +11:00
Iampete1
b9c177c363
AP_Scripting: check channel is valid before trying to send on it
2025-09-16 11:00:05 +01:00
Yuri Rage
e952d4b16b
AP_Scripting: add net-ntrip applet
...
Co-authored-by: Thomas Watson <twatson52@mac.com >
Co-authored-by: Thomas Watson <twatson52@mac.com >
2025-06-20 19:44:33 -05:00
Thomas Watson
55889f6db7
AP_Scripting: use luaL_checklstring for serial port writestring
...
Avoids potential null pointer dereferences if a port write method can't
handle a null pointer when doing a zero length write. Also provides a
nice type error if something that can't be converted to a string is
passed.
2025-05-18 11:58:54 +10:00
Peter Barker
42c1ad30c9
AP_Scripting: remove use of OwnPtr
colcon build/test / build-test (push) Waiting to run
Cygwin Build / build (push) Waiting to run
ESP32 Build / build (esp32buzz, 10) (push) Waiting to run
ESP32 Build / build (esp32s3empty, 10) (push) Waiting to run
Macos Build / build (CubeOrange) (push) Waiting to run
Macos Build / build (sitl) (push) Waiting to run
QURT Build / build (push) Waiting to run
test ccache / build (10, chibios) (push) Waiting to run
test chibios / build (CubeOrange-ODID, 10, chibios) (push) Waiting to run
test chibios / build (CubeOrange-PPP, 10, chibios) (push) Waiting to run
test chibios / build (CubeOrange-bootloader, 10, chibios) (push) Waiting to run
test chibios / build (CubeRed-EKF2, 10, chibios) (push) Waiting to run
test chibios / build (CubeRedPrimary-bootloader, 10, chibios) (push) Waiting to run
test chibios / build (MatekF405-Wing, 10, chibios) (push) Waiting to run
test chibios / build (Pixhawk6X-PPPGW, 10, chibios) (push) Waiting to run
test chibios / build (SOHW, 10, chibios) (push) Waiting to run
test chibios / build (build-options-defaults-test, 10, chibios) (push) Waiting to run
test chibios / build (configure-all, 10, chibios) (push) Waiting to run
test chibios / build (fmuv2-plane, 10, chibios) (push) Waiting to run
test chibios / build (fmuv3, 10, chibios) (push) Waiting to run
test chibios / build (fmuv3-bootloader, 10, chibios) (push) Waiting to run
test chibios / build (iofirmware, 10, chibios) (push) Waiting to run
test chibios / build (new-check, 10, chibios) (push) Waiting to run
test chibios / build (periph-build, 10, chibios) (push) Waiting to run
test chibios / build (revo-bootloader, 10, chibios) (push) Waiting to run
test chibios / build (revo-mini, 10, chibios) (push) Waiting to run
test chibios / build (signing, 10, chibios) (push) Waiting to run
test chibios / build (stm32f7, 10, chibios) (push) Waiting to run
test chibios / build (stm32h7, 10, chibios) (push) Waiting to run
test chibios / build (stm32h7-debug, 10, chibios) (push) Waiting to run
test dds / build (sitl) (push) Waiting to run
test dds / build (stm32h7) (push) Waiting to run
test Linux SBC / build (bbbmini, armhf) (push) Waiting to run
test Linux SBC / build (bebop, armhf) (push) Waiting to run
test Linux SBC / build (bhat, armhf) (push) Waiting to run
test Linux SBC / build (canzero, armhf) (push) Waiting to run
test Linux SBC / build (erlebrain2, armhf) (push) Waiting to run
test Linux SBC / build (linux, base) (push) Waiting to run
test Linux SBC / build (navigator, armhf-musl) (push) Waiting to run
test Linux SBC / build (navigator64, aarch64) (push) Waiting to run
test Linux SBC / build (navio, armhf) (push) Waiting to run
test Linux SBC / build (navio2, armhf) (push) Waiting to run
test Linux SBC / build (pxf, armhf) (push) Waiting to run
test Linux SBC / build (pxfmini, armhf) (push) Waiting to run
test replay / build (replay, base) (push) Waiting to run
test replay / build (replay, clang) (push) Waiting to run
test scripts / build (astyle-cleanliness) (push) Waiting to run
test scripts / build (check_autotest_options) (push) Waiting to run
test scripts / build (logger_metadata) (push) Waiting to run
test scripts / build (param_parse) (push) Waiting to run
test scripts / build (python-cleanliness) (push) Waiting to run
test scripts / build (validate_board_list) (push) Waiting to run
test blimp / build (base) (push) Waiting to run
test blimp / build (clang) (push) Waiting to run
test blimp / autotest (sitltest-blimp) (push) Blocked by required conditions
test copter / build (base) (push) Waiting to run
test copter / build (clang) (push) Waiting to run
test copter / autotest (sitltest-copter-tests1a) (push) Blocked by required conditions
test copter / autotest (sitltest-copter-tests1b) (push) Blocked by required conditions
test copter / autotest (sitltest-copter-tests1c) (push) Blocked by required conditions
test copter / autotest (sitltest-copter-tests1d) (push) Blocked by required conditions
test copter / autotest (sitltest-copter-tests1e) (push) Blocked by required conditions
test copter / autotest (sitltest-copter-tests2a) (push) Blocked by required conditions
test copter / autotest (sitltest-copter-tests2b) (push) Blocked by required conditions
test copter / build-gcc-heli (push) Waiting to run
test copter / autotest-heli (sitltest-heli) (push) Blocked by required conditions
test ap_periph / build-gcc-ap_periph (push) Waiting to run
test ap_periph / autotest-can (sitltest-can) (push) Blocked by required conditions
test plane / build (base) (push) Waiting to run
test plane / build (clang) (push) Waiting to run
test plane / autotest (sitltest-plane-tests1a) (push) Blocked by required conditions
test plane / autotest (sitltest-plane-tests1b) (push) Blocked by required conditions
test plane / autotest (sitltest-quadplane) (push) Blocked by required conditions
test rover / build (base) (push) Waiting to run
test rover / build (clang) (push) Waiting to run
test rover / autotest (sitltest-balancebot) (push) Blocked by required conditions
test rover / autotest (sitltest-rover) (push) Blocked by required conditions
test rover / autotest (sitltest-sailboat) (push) Blocked by required conditions
test sub / build (base) (push) Waiting to run
test sub / build (clang) (push) Waiting to run
test sub / autotest (sitltest-sub) (push) Blocked by required conditions
test tracker / build (base) (push) Waiting to run
test tracker / build (clang) (push) Waiting to run
test tracker / autotest (sitltest-tracker) (push) Blocked by required conditions
test unit tests and sitl building / build (sitl, base) (push) Waiting to run
test unit tests and sitl building / build (sitl, clang) (push) Waiting to run
test unit tests and sitl building / build (unit-tests, base) (push) Waiting to run
test unit tests and sitl building / build (unit-tests, clang) (push) Waiting to run
test scripting / test-scripting (push) Has been cancelled
2025-02-11 11:54:52 +11:00
Thomas Watson
c7f32c2fb4
AP_Scripting: mavlink: clearer error messages
2025-02-11 10:26:59 +11:00
Thomas Watson
55a0cbbd9a
AP_Scripting: mavlink: remove redundant Lua buffer usage
2025-02-11 10:26:59 +11:00
Thomas Watson
2b995b2087
AP_Scripting: mavlink: fix RX init locking
...
If there is an error, the semaphore will never be released. Fix by only
calling functions which could cause errors after it's released.
2025-02-11 10:26:59 +11:00
Andrew Tridgell
349ebde101
AP_Scripting: added support for FlexDebug message
...
allows lua to retrieve vendor specific data from CAN nodes
2024-11-05 17:03:23 +09:00
bugobliterator
2cc7277692
AP_Scripting: fix build with both GCS and Scripting enabled
2024-10-23 06:46:22 +09:00
Andrew Tridgell
6a16bce001
AP_Scripting: added bindings for IPv4 address/string
...
and make socket recv return the source address and port
2024-10-01 10:45:10 +10:00
Hayden Donald
52ba8e8513
AP_Scripting: Change serial depends HAL_GCS to AP_SERIALMANAGER
...
Serial bindings were dependant on HAL_GCS_ENABLED but this is not ideal, it should be dependant on AP_SERIALMANAGER_ENABLED so that serial can function without GCS
2024-07-31 08:27:34 +10:00
Thomas Watson
3a834e83c7
AP_Scripting: reference script environment directly
...
Referencing the original function to run is of questionable value and
the only user uses it to grab the script environent from the upvalues.
Instead, use a reference to the script environment table directly.
2024-07-30 10:33:56 +10:00
Thomas Watson
212256731f
AP_Scripting: improve object allocation efficiency
...
Make new_X return the new object instead of having to grab it to
configure it.
Saves ~1.3K.
2024-07-30 09:55:25 +10:00
Ian Burwell
6b4e11090c
AP_Scripting: Add BQ40Z shutdown example
...
This example intercepts PREFLIGHT_REBOOT_SHUTDOWN COMMAND_LONG's and if
param1==2, it shuts down the BQ40Z smart battery BMS. Otherwise it
passes through the COMMAND_LONG as a COMMAND_INT (this required updating
the gcs:run_command_int to return a MAV_RESULT rather than a bool).
2024-07-30 09:40:10 +10:00
Ian Burwell
9d34fa2a5e
AP_Scripting: Add I2C transfer bindings
...
This adds bindings for an I2CDevice's transfer() function, an example,
and removes the nil return hint from the get_device() docs as it never
actually returns nil.
2024-07-30 09:40:10 +10:00
Andrew Tridgell
7477c4e205
AP_Scripting: fixed remove call
...
need to use AP_Filesystem
2024-07-11 07:43:35 +10:00
Peter Barker
933aed5f91
AP_Scripting: add missing scheduler include
...
corrects compilation of cubeorange-periph-heavy
2024-07-09 07:40:03 +10:00
Peter Barker
e88d76d72d
AP_Scripting: rangefinder singleton requires AP_RANGEFINDER_ENABLED
...
.... or HAL_PERIPH_ENABLE_RANGEFINDER
2024-07-02 09:17:26 +10:00
Andrew Tridgell
38ca478178
AP_Scripting: added gcs:run_command_int() binding
2024-07-01 20:08:29 +10:00
Thomas Watson
a077e4a3ed
AP_Scripting: introduce serial device simulation support
...
Allows a script to simulate a device attached via any serial protocol.
The script can read and write data and have it handled according to the
protocol as if exchanged over a serial port. The script can then do
protocol translation, data filtering and validation,
hardware-in-the-loop simulation, experimentation, etc., especially in
combination with the scripting protocol which lets the script itself
handle an attached device and so interpose any communication.
2024-06-27 12:00:18 +10:00
Thomas Watson
c18f9f733e
AP_Scripting: add writestring for serial
...
Enables more efficient scripting.
2024-06-27 12:00:18 +10:00
Thomas Watson
d93aa15f2a
AP_Scripting: refactor serial readstring
...
Using `luaL_Buffer` avoids the need for any heap allocation in the
common case (count <= 512 bytes) and avoids stressing out the system
heap for large reads, instead using the script heap.
Zero net flash usage change.
2024-06-27 12:00:18 +10:00
Thomas Watson
e18449b1b8
AP_Scripting: use generic access userdata for serial ports
...
Adding another layer instead of just exposing UARTDriver bindings allows
substitution of the different functions for device simulation later.
Also take the opportunity to rework the docs a little.
2024-06-27 12:00:18 +10:00
Iampete1
cc99ebf872
AP_Scripting: allow logging lua boolean with uint8 format B
2024-06-25 11:01:10 +10:00
Iampete1
1c26c241f1
AP_Scripting: add uint64 userdata
2024-06-18 10:37:13 +10:00
Andrew Tridgell
a2459c6e61
AP_Scripting: use NEW_NOTHROW for new(std::nothrow)
2024-06-04 09:20:21 +10:00
Iampete1
95a5169439
AP_Scripting: CAN: get_device and get_device2 return nil if no driver is configure with the correct protocol
2024-05-07 09:48:10 +10:00
Iampete1
b7dd432409
AP_Scripting: allow loading moduels from ROMFS
2024-02-27 10:17:43 +11:00
Andrew Tridgell
f8097379cb
AP_Scripting: prevent a code path to abort() in scripting
...
if scripting can't find an error handler it can call abort(). We don't
ever want to do that in ArduPilot
2024-02-21 12:09:48 +11:00
Andrew Tridgell
7b36adf49d
AP_Scripting: prevent re-use of closed socket
...
this prevents a null pointer dereference after a close of a network
socket
2024-02-13 12:40:14 +11:00
Andrew Tridgell
efac52136b
AP_Scripting: fixed memory leak in sendfile()
...
this leaked the SocketAPM on each sendfile() call, we now rely on the
script calling close(). The net_webserver.lua is already using close()
correctly, this change just makes close able to find the socket
2024-01-08 13:01:02 +11:00
Andrew Tridgell
a841e9c109
AP_Scripting: don't throw an exception on out of sockets in accept()
...
normal lua sockets don't throw an exception on accept, it just returns
nil
2024-01-03 12:14:47 +11:00
Andrew Tridgell
213cdcef4b
AP_Scripting: use SocketAPM_native
2024-01-03 12:14:47 +11:00
Peter Mullen
a83ed6b730
AP_Scripting: Add LUA interface to access Range Finder state
2024-01-02 11:31:02 +11:00
Andrew Tridgell
75217ec1e6
AP_Scripting: added readstring for uarts
...
this is much more efficient than reading a byte at a time
2023-12-12 07:42:15 +11:00