/
Sangak
/
ardupilot
Обзор
Документация
Войти
/
Sangak
/
ardupilot
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
libraries/AP_Scripting/examples/copter-circle-speed.lua
41 строка
2 KB
Peter Barker
AP_Scripting: examples: copter-circle-speed.lua: parameterise groundspeed
19 апр 2026, 03:36
19 апр 2026, 03:36
6dd6c4e
Код
Авторство
О чём код?
-- Maintain a constant ground speed while flying in Circle mode even if the pilot adjusts the radius -- -- CAUTION: This script only works for Copter -- this script waits for the vehicle to be armed and in circle mode and then -- updates the target rate around the circle (in degrees / sec) to maintain the desired ground speed -- create and initialise parameters local PARAM_TABLE_KEY = 95 assert(param:add_table(PARAM_TABLE_KEY, "CSPD_", 1), 'could not add param table') assert(param:add_param(PARAM_TABLE_KEY, 1, 'SPEED', 6), 'could not add CSPD_SPEED param') -- ground speed in circle mode (m/s) local circle_ground_speed = Parameter("CSPD_SPEED") function update() -- this is the loop which periodically runs -- must be armed, flying and in circle mode if (not arming:is_armed()) or (not vehicle:get_likely_flying()) or (vehicle:get_mode() ~= 7) then return update, 1000 -- reschedules the loop, 1hz end -- get circle radius local radius = vehicle:get_circle_radius() if not radius then gcs:send_text(0, "speed-circle.lua: failed to get circle radius") return update, 1000 end -- set the rate to give the desired ground speed at the current radius local new_rate = 360 * (circle_ground_speed:get() / (radius*math.pi*2)) new_rate = math.max(new_rate, -90) new_rate = math.min(new_rate, 90) if not vehicle:set_circle_rate(new_rate) then gcs:send_text(0, "speed-circle.lua: failed to set rate") else gcs:send_text(0, string.format("speed-circle.lua: radius:%f new_rate=%f", radius, new_rate)) end return update, 100 -- reschedules the loop, 10hz end return update()