How to control relays with buttons already in use

Hi iampete,

Now with the dev versión I have problems with another script that worked fine with Rover 4.0.0

– This script switch on/off a relay with the arm/disarm status.

local gripperstatus = 0

function update() – this is the loop swhich periodically

–gcs:send_text(0, “switch relay”) – send the traditional message
servo.set_output_pwm(94, 1500) – set the servo assigned function 94 (servo9_function = 94)

if arming:is_armed() then
if (gripperstatus == 0) then
servo.set_output_pwm(94, 1100) – set the servo assigned function 94 (servo9_function = 94)
gcs:send_text(0, “TRITON desacoplado”) – send the traditional message
gripperstatus = 1
end
–gcs:send_text(0, “relay on”) – send the traditional message
relay:on(0)
end
if not arming:is_armed() then
if (gripperstatus == 1) then
servo.set_output_pwm(94, 1900) – set the servo assigned function 94 (servo9_function = 94)
gcs:send_text(0, “TRITON acoplado”) – send the traditional message
gripperstatus = 0
end
–gcs:send_text(0, “relay off”) – send the traditional message
relay:off(0)
end
return update, 1000 – reschedules the loop

end

return update() – run immediately before starting to reschedule

image

attemptto index a nil value (global ‘servo’)

Any ideas?

Thanks

Thank you very much.

There have been a few change to how servos work, take a look at this example

It Works!

Thank yoy again.

Hi iampete,

Now I have a problem uploading scripts files:
when I tried to upload (or download) a script, an error message appears

at the end, the script appear into the folder but it is empty…

I only can get put the scripts into the folder manually but I need to do that via telemetry!!

Also sometimes appear a error message in Mission Planner that may be related to this ( I am not sure)

This error message appear since I updated Mission Planner to the last versión to get the MAVftp option (because I can’t see it in the older versión I had installed)

After several trials…

Finally I got upload the script, but only if the size is smaller than 228…I don’t understand why…even changing the SCR_HEAP_SIZE parameter I can get it!

I have Pixhawk with Rover/beta/fmuv3 versión and Missionplanner 1.3.72 versión

Can you help me? I am really stuck here…

Thank you!

I would guess that is just no there on rover, the release is quite old now, try dev https://firmware.ardupilot.org/Rover/latest/fmuv3/

I can upload the script (big size script also) if I connect the pixwhak directly to the PC via USB but I have the problem if I try upload the script via telemetry (RPI + UAVcast)…

Any ideas?

ah, you need to use MAVLink 2 for the serial protocol

Thaks, but whre I must select the MAVLink2 serial protocol?

The serial port you have your telemetry connected to

I have connected the RPI via USB with the Pixhawk but I don’t know what serial port it is

So, you can download when mission planner is connected to the USB, but not when over UAVcast to the PI that is connected to the same USB? Sounds like you have a issue with UAVcast.

Yes, But it is extrange because I get download/upload litte scripts (smaller than 228) via telemetry, so it Works a Little…

I have connected a relay switch module to pixhawk (rover firmware 4.0.0) and I can change it with dedicated buttons of the Joystick…

The initial mapping between the Pixhawk outputs and the joystick buttons, did you do it with MP, scripting, QTCreator?