-- Inspect parameter sets received via MAVLink, determine action based -- on whitelist. -- When this script runs and ENABLE is true ArduPilot will stop -- processing parameter-sets via the GCS library. Instead, this -- script becomes responsible for setting parameters, and it will -- only set parameters which are whitelisted. Setting ENABLE to -- false will allow ArduPilot to set parameters normally. -- Setting SCR_ENABLE to false while this script is running in the -- ENABLE state is... not advised. -- How To Use -- 1. copy this script to the autopilot's "scripts" directory -- 2. set SCR_ENABLE to 1 -- global definitions local MAV_SEVERITY = {EMERGENCY=0, ALERT=1, CRITICAL=2, ERROR=3, WARNING=4, NOTICE=5, INFO=6, DEBUG=7} local UPDATE_INTERVAL_MS = 10 -- update at about 100hz -- prefix for all text messages: local TEXT_PREFIX_STR = "param-set" -- -- parameter setup -- local PARAM_TABLE_KEY = 92 local PARAM_TABLE_PREFIX = "PARAM_SET_" assert(param:add_table(PARAM_TABLE_KEY, PARAM_TABLE_PREFIX, 7), 'could not add param table') -- add a parameter and bind it to a variable function bind_add_param(name, idx, default_value) assert(param:add_param(PARAM_TABLE_KEY, idx, name, default_value), string.format('could not add param %s', PARAM_TABLE_PREFIX .. name)) return Parameter(PARAM_TABLE_PREFIX .. name) end --[[ // @Param: PARAM_SET_ENABLE // @DisplayName: Param Set enable // @Description: Param Set enable // @Values: 0:Disabled,1:Enabled // @User: Standard --]] local PARAM_SET_ENABLE = bind_add_param("ENABLE", 1, 1) -- initialize MAVLink rx with buffer depth and number of rx message IDs to register mavlink:init(5, 1) -- register message id to receive local PARAM_SET_ID = 23 mavlink:register_rx_msgid(PARAM_SET_ID) -- support for sending mavlink messages: local MAV_PARAM_ERROR = { NO_ERROR = 0, DOES_NOT_EXIST = 1, VALUE_OUT_OF_RANGE = 2, PERMISSION_DENIED = 3, COMPONENT_NOT_FOUND = 4, READ_ONLY = 5 } -- mavlink message definition local param_error_msgid = 345 local messages = {} messages[param_error_msgid] = { -- PARAM_ERROR { "param_index", "