Skip to content

Commit

Permalink
AP_Scripting: make 2-position switch easier for quicktune
Browse files Browse the repository at this point in the history
this allows for low/high instead of low/mid for quicktune with a 2
position switch such as with a herelink transmitter
  • Loading branch information
tridge committed Oct 18, 2023
1 parent 63805a0 commit ff73702
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
25 changes: 21 additions & 4 deletions libraries/AP_Scripting/applets/VTOL-quicktune.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function bind_add_param(name, idx, default_value)
end

-- setup quicktune specific parameters
assert(param:add_table(PARAM_TABLE_KEY, PARAM_TABLE_PREFIX, 13), 'could not add param table')
assert(param:add_table(PARAM_TABLE_KEY, PARAM_TABLE_PREFIX, 14), 'could not add param table')

--[[
// @Param: QUIK_ENABLE
Expand Down Expand Up @@ -158,6 +158,17 @@ local QUIK_RC_FUNC = bind_add_param('RC_FUNC', 12, 300)
--]]
local QUIK_MAX_REDUCE = bind_add_param('MAX_REDUCE', 13, 20)

--[[
// @Param: QUIK_OPTIONS
// @DisplayName: Quicktune options
// @Description: Additional options. When the Two Position Switch option is enabled then a high switch position will start the tune, low will disable the tune. you should also set a QUIK_AUTO_SAVE time so that you will be able to save the tune.
// @Bitmask: 0:UseTwoPositionSwitch
// @User: Standard
--]]
local QUIK_OPTIONS = bind_add_param('OPTIONS', 14, 0)

local OPTIONS_TWO_POSITION = (1<<0)

local INS_GYRO_FILTER = bind_param("INS_GYRO_FILTER")

local RCMAP_ROLL = bind_param("RCMAP_ROLL")
Expand Down Expand Up @@ -490,7 +501,13 @@ function update()
if not sw_pos then
return
end
if sw_pos == 1 and (not arming:is_armed() or not vehicle:get_likely_flying()) and get_time() > last_warning + 5 then
local sw_pos_tune = 1
local sw_pos_save = 2
if (QUIK_OPTIONS:get() & OPTIONS_TWO_POSITION) ~= 0 then
sw_pos_tune = 2
sw_pos_save = -1
end
if sw_pos == sw_pos_tune and (not arming:is_armed() or not vehicle:get_likely_flying()) and get_time() > last_warning + 5 then
gcs:send_text(MAV_SEVERITY_EMERGENCY, string.format("Tuning: Must be flying to tune"))
last_warning = get_time()
return
Expand All @@ -506,15 +523,15 @@ function update()
reset_axes_done()
return
end
if sw_pos == 2 then
if sw_pos == sw_pos_save then
-- save all params
if need_restore then
need_restore = false
save_all_params()
gcs:send_text(MAV_SEVERITY_NOTICE, string.format("Tuning: saved"))
end
end
if sw_pos ~= 1 then
if sw_pos ~= sw_pos_tune then
return
end

Expand Down
16 changes: 16 additions & 0 deletions libraries/AP_Scripting/applets/VTOL-quicktune.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,19 @@ values. Parameters will also be reverted if you disarm before saving.

If the pilot gives roll, pitch or yaw input while tuning then the tune
is paused until 4 seconds after the pilot input stops.

# Using a Two Position Switch

Some transitters only have 2 position switches, with no 3 position
switches available. To support quicktune with a 2 position switch
please set the following:

- set QUIK_OPTIONS to 1 to indicate the use of a 2 position switch
- set QUIK_AUTO_SAVE to 10 to automatically save the tune 10 seconds after tuning is done

with these two options the tuning will start when the switch gives a
PWM value of over 1800. Ten seconds after tuning is complete the tune
will automatically save.



0 comments on commit ff73702

Please sign in to comment.