Hi,
i am having trouble with one of my first LUA scripts.
I want to have my aircraft in Soar mode on my Waypoint mission with a desired and sometimes changing trim speed according to my planned mission.
Basically i want to get the last speed that was given by my Mission (“DO_SPEED_CHANGE”) and copy it to the “SOAR_CRSE_ARSPD” parameter.
I read in the help that the Mission command (“DO_SPEED_CHANGE”) should change the parameter “AIRSPEED_CRUISE”. (Mission Commands — Plane documentation)
I am currently using stable plane 4.4, so i guess this parameter is still the old one: “TRIM_ARSPD_CM”. (AP_Scripting: convert remaining uses of TRIM_ARSPD_CM to AIRSPEED_CRUISE · ArduPilot/ardupilot@00eeac0 · GitHub)
Unfortunately this parameter (“TRIM_ARSPD_CM”) is not changing during the mission. My LUA script reports this and i double checked with MP.
Is this functionality to update “TRIM_ARSPD_CM” deactivated with the Soaring mode? Or is there no LUA binding in 4.4? or was “TRIM_ARSPD_CM” not changed by the “DO_SPEED_CHANGE” command?
My next steps are:
- Test the current beta version
- Test without Soar enabled
- Hardcode the desired speed in the LUA script
but maybe somebody knows and can help me speed this up?
-Christian
According to the GCS messages i get, it looks to me that my script is working as i want it. Unfortunately the input variable (“TRIM_ARSPD_CM”) never changes during the mission.
Similar script that reads out AIRSPEED_CRUISE:
https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_Scripting/examples/plane-wind-fs.lua
Just FYI:
-- copy speed values from current mission "vehicle:set_desired_speed " to ardusoar parameter SOAR_CRSE_ARSPD
gcs:send_text(6, string.format('LUA: started ardusoar_planned_speed script'))
local SOAR_CRSE_ARSPD = Parameter() --creates a parameter object
SOAR_CRSE_ARSPD:init('SOAR_CRSE_ARSPD') --get the physical location in parameters memory area so no future name search is done
local soar_crse_arspd_parameter = SOAR_CRSE_ARSPD:get() --retrieve that parameters value and assign to "soar_crse_arspd_parameter"
local AIRSPEED_CRUISE = Parameter() --creates a parameter object
AIRSPEED_CRUISE:init('TRIM_ARSPD_CM') --get the physical location in parameters memory area so no future name search is done
local AIRSPEED_CRUISE_parameter = AIRSPEED_CRUISE:get() --retrieve that parameters value and assign to "AIRSPEED_CRUISE_parameter"
function update () -- periodic function that will be called
-- gcs:send_text(6, string.format('LUA: update()'))
flightmode = vehicle:get_mode()
-- gcs:send_text(6, string.format('LUA: flightmode = %i', flightmode))
if flightmode == 10 then --only do something if AUTO mode is active
-- gcs:send_text(6, string.format('LUA: AUTO detected'))
local soar_crse_arspd_parameter = SOAR_CRSE_ARSPD:get() --retrieve that parameters value and assign to "SOAR_CRSE_ARSPD"
local AIRSPEED_CRUISE_parameter = AIRSPEED_CRUISE:get() / 100 --retrieve that parameters value and assign to "SOAR_CRSE_ARSPD"
-- AIRSPEED_CRUISE_parameter = param:get('AIRSPEED_CRUISE')
if soar_crse_arspd_parameter then
gcs:send_text(6, string.format('LUA: soar_crse_arspd_parameter = %i', soar_crse_arspd_parameter))
if AIRSPEED_CRUISE_parameter then
gcs:send_text(6, string.format('LUA: AIRSPEED_CRUISE_parameter = %i', AIRSPEED_CRUISE_parameter))
if AIRSPEED_CRUISE_parameter ~= soar_crse_arspd_parameter then -- if update of soar cruise speed is needed
gcs:send_text(6, string.format('LUA: parameters are different'))
SOAR_CRSE_ARSPD:set(AIRSPEED_CRUISE_parameter)
gcs:send_text(6, string.format('LUA: set SOAR_CRSE_ARSPD to: %i', AIRSPEED_CRUISE_parameter))
end
end
end
end
return update, 1000 -- request "update" to be rerun again 1000 milliseconds (1 second) from now
end
return update, 1000 -- request "update" to be the first time 1000 milliseconds (1 second) after script is loaded