Dynamic home position for plane out at sea

Hello everyone,
I’m trying to figure out how I can have a dynamic home position for my fixed-wing drone. I fly out in the ocean and BVLOS and the arming/home point is on a vessel. The vessel will move and I’d like to know the simplest way to keep updating the home position in case of an RTL. Does anyone have experience with MAV_CMD_DO_SET_HOME ? Can I pull the GPS position of the ground station laptop and feed this into Mission Planner? If so, what GPS systems are compatible? TY in advance.
All the best,
Novice pilot, Melissa

Mission Planner 1.3.38: Moving base question is a relevant discussion.

I know of several organisations who have implemented this type of feature a couple of different ways (Mavproxy, DroneKit, Missionplanner with IronPython). Not sure if any of the solutions is on the internet though

Thank you for the lead, I will have a google!
Best wishes
Melissa

hi Melissa

Perhaps the easiest way is with Missionplanner’s Ironpython as below.

A couple of years ago I developed some Ironpython scripting that runs inside Missionplanner, in order to get a plane to land automatically on a moving ship…(3 min video here https://www.youtube.com/watch?v=pMzLtfshx_w&feature=youtu.be ).

The GCS had a USB GPS connected to it, feeding the ships location into the script. Every second, it transmitted a new set of waypoints to the aircraft for the approach, which among other things, changed the mission’s first waypoint to reflect the changed position of the GCS. Some simplified code is below (it works in SITL for me).

Be aware that the ships ‘altitude’ relative to the ocean will vary over time as barometric pressure changes - if you are targettting a net on the ship, you need to account for such changes.

import clr
import MissionPlanner
clr.AddReference(“MAVLink”)
from System import Byte
import MAVLink

print ‘Start Script’
#you would need to find the ship’s lat. Python could get it from an NMEA feed from the ships GPS onboard
#or from a GPS attached to the ground control laptop by serial / USB. Somewhere, I have the code for reading
#an external GPS, and could dig it out if you want but it involves more imports above.

#but for this example, use hardcoded latlongs

shipLat = float( -27.4119) #Coominya, australia
shipLng = float(152.4671)
#shipLat = float(52.7647) #Loughboro, UK
#shipLng = float(-1.2315)
shipAlt = float(0)

while True:
#just to demonstrate, first display the current home location from the plane (which is stored as waypoint 0)
wpItem = MAV.getWP(0)
current_Home_Lat = wpItem.lat
current_Home_Lng = wpItem.lng
print "Current home location in plane " + str(current_Home_Lat) + ", " + str(current_Home_Lng)

# now, to simulate a moving ship by changing lat and lng each  time it loops... 
shipLat = shipLat + 0.01    
shipLng = shipLng + 0.01


#next line is the significant one
MAV.doCommand(MAVLink.MAV_CMD.DO_SET_HOME, 0, 0, 0, 0, shipLat, shipLng, shipAlt)
print 'should have reset home to lat:' + str(shipLat) + '  lng:' + str(shipLng)


Script.Sleep(5000)  #a timer function built into missionplanners scripting, but you could also use a native Python timer

ooops, the formatting messed up above, but you should get the picture…

Thank you Peter,
This is incredibly helpful. As we land on the ocean, and not the vessel, will this matter in terms of the script? (I guess not?)
Also, when you use this script, does it automatically change the location of home, on mission planner (so it is dynamically changing on the screen and you can see ‘H’ move around) or is it a background adjustment? I ran the script and a small box popped up and said the HP had been changed, but this was not reflected on screen. However, important to point out, the UAV was not armed nor flying- we’d just written the waypoints to the UAV. We can’t fly our UAV in the UK as the frequency is incorrect (for now).
All the best!!
Melissa