AP_Scripting: Support UART drivers #13207
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This was something I said I'd take on awhile ago, and then didn't get to for a bit. This allows a script to access a UART driver and read/write from it. There are some future enhancements to make this be more then just a byte by byte read/write, but the basic functionality does work.
uint32_t
's are also less frustrating to use in scripts now, more details below.To do this the generator has gained the new concept of an
ap_object
. This is just a name I've assigned to a userdata which ArduPilot actually manages the memory for. (Userdatas are typically garbage collected by Lua, in this case all we are doing is storing a pointer back to the actual object which already exsists in ArduPilot. Normally you would use a light userdata for this, but I wanted to have a metatable which required the full userdata).ap_object
s support pretty much everything a normaluserdata
/singleton
supports, except they can not be a nil punned argument anywhere.Another change included with this is that the
uint32_t
as arguments was frustrating me as overly strict. For example the call ofbegin
on a serial port requires auint32_t
to indicate the baud rate. The way master current works is you actually have to do:This is primarily frustrating as it is basically just a cast hint, but being a dynamic language you tend to forget about the casting until you need it, at which point the program then stops. This is also unfortunate as it serves to allocate a new object that we then promptly use once and forget about, which increases memory pressure. I've changed the generator so that anywhere we want a
uint32_t
as an argument we will automatically cast it into auint32_t
without any allocations. This is a small quality of life improvement, but should make the boxed numerics a lot less frustrating to deal with. I haven't gone back and tested any of the other scripts, but it is on my to do list.Finally it's probably fairly obvious but I added a new serial protocol of 28 for scripting use of a serial port.
This was tested using a green cube, on Telem 2 with both a FTDI cable and a loopback cable plugged in.