I needed a script to use a DJI Remote controller w/Arduplane as it has no ability to create mixes, etc. in the Tx.
This is a test file (need to finish putting in all the desired modes).
It seems to work (the gcs words are appearing in MP) but are there any glaring errors? Is the update time too short/long? Feedback would be very welcome. (TIA)
– script to use two channels to change mode in Arduplane –
– using channels 6 and 7 for mode selection (DJI Remote Controller –
local chan6Pwm = rc:find_channel_for_option(300) – input for the use of onboard lua scripting
local chan7Pwm = rc:find_channel_for_option(301)
function update()
pwm6 = rc:get_pwm(6)
pwm7 = rc:get_pwm(7)
if (pwm6 < 1300) then -- sw 6 up
if (pwm7 < 1300) then -- sw 6 up sw 7 up
vehicle:set_mode(0)
gcs:send_text(0, "Manual mode")
return update, 100 -- reschedules the loop
elseif (pwm7 > 1300 and pwm7 < 1700) then -- sw 6 up sw 7 mid
vehicle:set_mode(2)
gcs:send_text(0, "Stabilize mode")
return update, 100 -- reschedules the loop
else -- sw 6 up sw 7 down
vehicle:set_mode(10)
gcs:send_text(0, "Waypoint mode")
return update, 100 -- reschedules the loop
end -- end if sw 6 up
elseif (pwm6 > 1300 and pwm6< 1700) then -- sw 6 mid
if (pwm7 < 1300) then -- sw 6 mid sw 7 up
vehicle:set_mode(5)
gcs:send_text(0, "FBWA mode")
return update, 100 -- reschedules the loop
elseif (pwm7 > 1300 and pwm7 < 1700) then -- sw 6 mid sw 7 mid
vehicle:set_mode(8)
gcs:send_text(0, "Autotune mode")
return update, 100 -- reschedules the loop
else -- sw 6 mid sw 7 down
vehicle:set_mode(12)
gcs:send_text(0, "Loiter mode")
return update, 100 -- reschedules the loop
end -- end if sw 6 mid
elseif (pwm6 > 1700) then -- sw 6 down
if (pwm7 < 1300) then -- sw 6 down sw 7 up
-- vehicle:set_mode(5)
gcs:send_text(0, "6dn 7 dn mode")
return update, 100 -- reschedules the loop
elseif (pwm7 > 1300 and pwm7 < 1700) then -- sw 6 down sw 7 mid
-- vehicle:set_mode(8)
gcs:send_text(0, "6 dn 7mid mode")
return update, 100 -- reschedules the loop
else -- sw 6 down sw 7 down
vehicle:set_mode(11)
gcs:send_text(0, "RTL mode")
return update, 100 -- reschedules the loop
end -- if sw 6 is down
end -- end if block
end – func update()
return update()