Getting GPS Data every time a relay is auto switched

Good Morning,
I am trying to run a mission as to where I can flip a relay switch every 50 feet during my mission. I have a couple things that I would like to get done as a result of this. First, I would like to send a signal to an arduino board which will then perform some external coding that I have put on the board. Secondly, I would like pixhawk to report back the GPS coordinates every time that this relay signal is sent out. My questions are as follows:

  1. Is there a relay command that will cause the relay function to be set every 50 feet like there is on DO_SET_CAM_DIST?
  2. Is there possibly a way to see this information on the TLOGS after the flight has completed?
  3. Does anyone have any reccomendations on a way that I can succesfully implement this idea in the simplest way possible.

I am using a pixhawk orange cube with Rover 4.1 installed on the cube itself with a Here3+ GPS module. Thank you again for all of your help everyone!

You can probably replace the arduino by a lua script running on the CubeOrange.

Have you looked into that? It will be able to access and write the logs and read GPS coordinates.

I have never tried to write a lua script before. Do you have any advice on where to start doing research or finding examples of some lua scripts? Thank you

Here’s the documentation on Lua scripting for Ardupilot.

Here are the examples on GitHub. You’ll probably want to pay particular attention to this one.

I also published a video on the topic.

For GPS location information, here’s a short code snippet:

local instance = gps:primary_sensor()

local position = gps:location(instance)

local latitude  = position:lat()
local longitude = position:lng()
local altitude  = position:alt()

The location object also includes a handy get_distance() method that will return distance between itself and another location object (in meters). I’ve used it for distance based triggering similar to what you describe.

Perfect. I will do some digging into this and see what I can come up with. Thank you for your help

1 Like