AP_Scripting: add fast param bindings and example
This commit is contained in:
parent
9dae370356
commit
1f7d796845
@ -1,6 +1,19 @@
|
||||
-- This script is a test of param set and get
|
||||
local count = 0
|
||||
|
||||
-- for fast param acess it is better to get a param object,
|
||||
-- this saves the code searching for the param by name every time
|
||||
local VM_I_Count = Parameter()
|
||||
if not VM_I_Count:init('SCR_VM_I_COUNT') then
|
||||
gcs:send_text(6, 'get SCR_VM_I_COUNT failed')
|
||||
end
|
||||
|
||||
-- returns null if param cant be found
|
||||
local fake_param = Parameter()
|
||||
if not fake_param:init('FAKE_PARAM') then
|
||||
gcs:send_text(6, 'get FAKE_PARAM failed')
|
||||
end
|
||||
|
||||
function update() -- this is the loop which periodically runs
|
||||
|
||||
-- get and print all the scripting parameters
|
||||
@ -40,6 +53,18 @@ function update() -- this is the loop which periodically runs
|
||||
end
|
||||
|
||||
|
||||
-- increment the VM I count by one using direct accsess method
|
||||
local VM_count = VM_I_Count:get()
|
||||
if VM_count then
|
||||
gcs:send_text(6, string.format('LUA: SCR_VM_I_COUNT: %i',VM_count))
|
||||
if not VM_I_Count:set( VM_count + 1) then
|
||||
gcs:send_text(6, string.format('LUA: failed to set SCR_VM_I_COUNT'))
|
||||
end
|
||||
else
|
||||
gcs:send_text(6, 'LUA: read SCR_VM_I_COUNT failed')
|
||||
end
|
||||
|
||||
|
||||
count = count + 1;
|
||||
|
||||
-- self terminate after 30 loops
|
||||
|
@ -248,6 +248,13 @@ singleton AP_Param method get boolean string float'Null
|
||||
singleton AP_Param method set boolean string float -FLT_MAX FLT_MAX
|
||||
singleton AP_Param method set_and_save boolean string float -FLT_MAX FLT_MAX
|
||||
|
||||
include AP_Scripting/AP_Scripting_helpers.h
|
||||
userdata Parameter method init boolean string
|
||||
userdata Parameter method get boolean float'Null
|
||||
userdata Parameter method set boolean float -FLT_MAX FLT_MAX
|
||||
userdata Parameter method set_and_save boolean float -FLT_MAX FLT_MAX
|
||||
|
||||
|
||||
include AP_Mission/AP_Mission.h
|
||||
singleton AP_Mission alias mission
|
||||
singleton AP_Mission scheduler-semaphore
|
||||
|
Loading…
Reference in New Issue
Block a user