ardupilot icon indicating copy to clipboard operation
ardupilot copied to clipboard

AP_Scripting: Add set_options and get_options to the Lua SERIAL class

Open muramura opened this issue 3 weeks ago • 4 comments

This PR adds set_options() and get_options() to the Lua SERIAL class.

set_options() allows Lua scripts to configure advanced UART hardware behavior, such as signal inversion, half-duplex mode, pull-up/down resistors, and DMA usage. get_options() has been added to allow scripts to retrieve the currently applied UART option bitmask.

Documentation has been updated to describe each bit in the option mask and to note that multiple options may be combined using the bitwise OR operator (|).

THIS message tag is ### options 1, or 3は、set to get value. Screenshot from 2025-12-06 13-18-24

muramura avatar Dec 06 '25 05:12 muramura

Are there use cases where these options need to be dynamically set?

tpwrules avatar Dec 06 '25 16:12 tpwrules

@tpwrules and @IamPete1 san When outputting SBUS frames from a UART using a Lua script, the signal needs to be inverted because SBUS uses an inverted serial protocol.

In this video, the SBUS frames are regenerated in Lua and then transmitted back to the flight controller.

Before: Transmitter -> SBUS Receiver -> RC Main System

After: Transmitter -> SBUS Receiver -> Flight Controller (Lua regenerates SBUS) -> RC Main System

https://youtu.be/ceosbnV8bbQ?si=SJkr0lyjNPHJeKMJ

muramura avatar Dec 07 '25 00:12 muramura

You should be able to set inversion in the SERIALn_OPTIONS and not have to do that in the Lua script.

tpwrules avatar Dec 07 '25 01:12 tpwrules

@tpwrules san If the argument is that “we don’t need to configure it in Lua because it can be configured in MP/GCS,” then logically the existing Lua methods for setting baud rate and flow control would also be unnecessary.

As you understand, our intention is the opposite: since communication-related settings are already configurable in Lua scripts, it is more consistent and user-friendly to allow this setting in Lua as well, instead of forcing users to configure some parts in MP/GCS and others in scripts.

To maintain consistency and avoid user confusion, I believe all UART communication settings should be configured in the same place. If baud rate and flow control are already configured in Lua, but the inversion configuration must be done through MP/GCS, the workflow becomes inconsistent and more complex.

So I think communication settings should be unified in Lua when possible.

muramura avatar Dec 07 '25 02:12 muramura