Hi,
I started to adopt your lua script for an rc submarine because I use SBUS on the FrSky Tx / RFD Txmod and RFD900 modem which, in contrast to PPM, provides no means to set specific failsafe positions to individual rc channels as discussed here (RFD900 / TXMOD and SBUS - #7 by xfacta).
I managed to establish SBUS transmission and it works flawless. The lua script detects the loss of valid rc input (TX switch off) and sets ground_steering to defined PWM 1700; switiching the TX back on terminates the failsafe. All good up to here!
I´m asking on advice on how to extend the lua script to cover 16 rc channels on ardurover 4.4. A brief template to work with would be great. Of note, rc channels besides throttle and steering are just PWM passthrough and dont carry a nominator. Current script looks like this:
– start LUA script and send start message to GCS
gcs:send_text(5, ‘LUA: Failsave script started’)
– initialize all used variables
local groundsteering_channel = SRV_Channels:find_channel(26)
local lost_signal_time = 0
local current_time = 0
local time_difference = 0
local RC1 = rc:get_channel(1)
– function update that does all the failsave action
function update()
-- check if the RC has a valid input
if rc:has_valid_input() then
-- if valid signal: do nothing except set the variable to zero
-- this variable saves the last time the rc input was not valid
lost_signal_time = 0
else
-- if the input is not valid = no signal from RC
if lost_signal_time == 0 then
-- save the first time when no signal was comming in
lost_signal_time = millis()
end
-- get current time
current_time = millis()
-- calculate the time differrence from initial lost contact to now
time_difference = current_time - lost_signal_time
if time_difference >= 1500 then
-- if this time difference is bigger than 1.5 seconds go into failsave condition
gcs:send_text(5, 'LUA: NOT a valid rc input. set failsave position')
-- Set the groundsteering channel to a fixed pwm. This is with servo function 26 Example 2) -> works
SRV_Channels:set_output_pwm_chan_timeout(groundsteering_channel, 1700, 300)
end
end
-- Repeat function every 200ms. This is more frequent than the timeout -> As long as rc input is invalid, the pwm outputs should stay in FS position.
return update, 200
end
– start function update
return update()