I have not tried to run a lua script on the Cube before so please let me know if I have missed a step. I am trying to limit the output on the servo channels assigned to the elevon left and right when using the elevator. This is the code I thought would work but I am getting a control map error in MP.
My code I would like to get working:
( I added in a few extra text strings to see if it would push through the messages)
local scripting_rc_1 = rc:find_channel_for_option(300)
local scripting_rc_2 = rc:find_channel_for_option(301)
function update()
pwm1 = rc:get_pwm(1)
pwm2 = rc:get_pwm(2)
pwm3 = rc:get_pwm(3)
pwm4 = rc:get_pwm(4)
gcs:send_text(0, “RCIN 1:” … tostring(pwm1) … " 2:" … tostring(pwm2)… " 3:" … tostring(pwm3)… " 4:" … tostring(pwm4))
– Define input and output channels
local channel1 = 1
local channel2 = 2
local channel4 = 4
– Define input value ranges
local range1 = {1100, 1500}
local range2 = {1501, 1900}
– Read input values
local input1 = pmw1
local input2 = pmw2
– Process channel 1 input
if input1 >= range1[1] and input1 <= range1[2] then
– Input value is in range, output on channel 1
servo.set_output_pwm(78, input1)
elseif input1 >= range2[1] and input1 <= range2[2] then
– Input value is in range, output on channel 4
local output4 = input1 – Output value on channel 4 is the same as input value
servo.set_output_pwm(78, 1500)
servo.set_output_pwm(77, output4)
end
– Process channel 2 input
if input2 >= range1[1] and input2 <= range1[2] then
– Input value is in range, output on channels 1 and 4
local output1 = input2 – Output value on channel 1 is the same as input value
local output4 = input2 – Output value on channel 4 is the same as input value
servo.set_output_pwm(78, output1)
servo.set_output_pwm(77, output4)
elseif input2 >= range2[1] and input2 <= range2[2] then
– Input value is in range, output fixed value on channels 1 and 4
servo.set_output_pwm(78, 1500 )
servo.set_output_pwm(77, 1500)
return update, 1000 – reschedules the loop
end
return update()