Resume auto mission after battery failsafe

I’ve taken a bit of a break from ArduPilot. It’s time to update my firmware and get back to work.

One of the things I’ve done during my hiatus was buy an old DJI Mavic 2 Pro and test out a variety of mission planning apps. I thought it might be worthwhile to take a look at how mapping missions are accomplished on that platform.

Given the limited flight time of some of this older DJI equipment, it wasn’t surprising to find that most of the mission planning apps make it easy to RTH for a battery swap - and resume the mission where it left off.

With ArduPilot, I’ve avoided this by calibrating my current sensor so that I know my missions will complete within the margins I’ve established. This has meant planning multiple missions for larger areas.

What I’d ideally like is to do is plan a single large mission, and be able to easily do battery swaps as necessary - similar to how it’s done with my DJI equipment.

There are a few forum posts about this - but I’m not sure they’re up to date with the latest firmware and Mission Planner updates - and what’s described is a little inelegant.

So before I start testing my options, I thought I’d make this post and gain the benefit from other’s experiences.

Many Thanks!

Hi @jstroup1986,

It’s on the to-do list but it’s been there since 2014 I’m afraid.

I’ve seen many mapping and spraying drones feature this, but they achieve this in a different way. They have a backup battery for the flight controller and the GPS. The flight controller won’t power off when users are changing their batteries, so the mission can continue after the battery has been replaced.

1 Like

Hello @rmackay9 -

It was interesting to me to see that while a DJI drone supporting waypoints can fly autonomously, it is typically done while the mission planning software is running on the flight controller. This application is handling telemetry reporting - and keeping track of waypoint passage.

So when the copter lands for a battery swap, the mission planning software knows the last waypoint traversed.

After the battery swap and powering up, the mission planning software typically offers the option to resume the mission. Taking the option to resume, the mission from the point of the last traversed waypoint is uploaded to the copter before takeoff.

To my knowledge, with ArduPilot the ground control computers running either Mission Planner or Qgroundcontrol isn’t keeping track of waypoints. (Although there is a MavLink message announcing waypoint passage.) So to resume a mission, ArduPilot firmware would need to have a way to “check-off” each waypoint traversed, and retain that between re-boots.

Without the ability to resume missions, much of the ArduPilot drone development I’ve observed is based on increasing flight time. My own is a case in point. But if long missions could be conducted by easily breaking them up into segments, the development focus could broaden out to more areas.

If any of the DEVs decide to take this on - I’d be happy to participate from the users perspective.

@XinChengGe - thank you for making this point - I hadn’t considered agricultural spraying missions.

Maintaining power to the flight controller between battery swaps is certainly an option.

By copy to @Christian_Mauch - have you ever considered a version of the MAUCH BEC’s that might allow attaching a small battery that would maintain power to the Power1 and Power2 ports? Maybe something like this already exists. Your input would be greatly appreciated.

This should be relatively easy, as most flight controllers have dual power input support. Maybe we should find a way to reset the battery monitor count after replacing the batteries. Additionally, we could use some new features about RTL, not only triggering RTL at the specified voltage or mAh but also based on the distance and RTL speed. This will make autonomous missions much easier.

1 Like

And Yes, all DJI Pro version drones do support mission functions, but it’s not autonomous. The RC is always needed. I think DJI is now strictly limited by Chinese law, and the government won’t allow them to have such features.

Yes - resetting the mAh so that the battery failsafe can be used again would be essential.

No doubt - taking the time to do a proper analysis and design would be well worth the effort.

I’m wondering if a new flight mode might help - something that extends the function of Auto flight mode. Lots of options to consider.

I’m glad to know I’m not the only one who things this new functionality is worth considering.

@jstroup1986 @XinChengGem,

AP does support resetting the battery failsafe now using MAVLink and MP may have implemented this although I have never tested it.

There’s an item on the to-do list somewhere to make the battery failsafe smarter so that it estimates whether it has enough power to reach home (instead of just triggering at a given voltage or remaining capacity). Someone brought that up again a couple of days ago. There is also a Lua script somewhere written by @iampete that does this.


Wow…That is just great. I’m always excited to talk to you guys, as we can discover some features that we hadn’t noticed before

1 Like

Thanks @rmackay9 - this is helpful information.

I’ve been mulling over the idea of resuming an auto mission.

I suspect there are lots of ways to approach resuming a mission after a failsafe/RTH. (The pilot may elect to abort the mission and either RTH or land somewhere else - yet still want to continue again after a flight controller re-boot.)

When the flight controller reboots, whatever mission was loaded is still loaded. The missing bit of information is what was the last waypoint. If this were recorded on the flight controller, then the needed element is some sort of “RESUME” flight mode - where the mission begins at the last waypoint - rather than the first waypoint.

If the flight controller is re-booted due to a battery swap - the battery data will be re-set automatically. So the “Battery_Reset” function is only necessary if the flight controller stays powered up.

In my opinion, keeping the flight controller powered up during a battery swap is a can of worms.

We do already support mission resume, you set a distance that should be repeated with a special waypoint see:

This does require that the flight controller stay powered, you can change flight battery and do a battery reset to get it back to 100%.

Thank you @iampete - I remember reading this wiki article now - it’s been a while.

The resume in this wiki is very close - but not quite exactly - like what I think would be helpful to have in ArduPilot.

As I understand it - the wiki is simply referring to the normal ability to leave an AUTO mission by changing flight modes, Then when re-enabling AUTO flight mode, the vehicle returns navigating to the same waypoint it was last navigating towards.

The “rewind” function enabled by the DO_SET_RESUME_REPEAT_DIST parameter is something required for fixed wing aircraft - that don’t have a copter’s ability to navigate directly to a point.

In the non-ArduPilot mapping mission software I’ve evaluated, the “resume” function returns the vehicle to last waypoint that was passed. The function in ArduPilot works differently - it causes the vehicle to navigate to the same waypoint it was navigating towards when the AUTO mission was interrupted.

When taking actions based on time or distance, the ability to return to the last traversed waypoint is important.

Besides this difference - the ability to reboot the flight controller during a battery swap is a feature that makes all the difference for many cases. In fact, it may be dangerous to approach a vehicle when still powered up and active.

No doubt, with the functionality that presently exists, an approximation of the “resume” function I think would helpful to include in ArduPilot can be accomplished. In fact, I plan to give it a try as soon as I figure out the best way to enable constant power to the flight controller.

I realize that the goal of ArduPilot isn’t to meet specific commercial needs. However I’m confident that there’s be a great deal more ArduPilot adoption if swapping batteries was supported as it is on many off-the-shelf drone products.


Not quite. You can also set the repeat distance to zero, which would allow a copter to resume the exact point on the mission leg where it stopped. The reason you need some larger distance is for plane where you need to not only reach the point but line up with the leg.

I would argue that the distance based functionality is more powerful, the last waypoint could be 1m or 1km away, if you just passed it then you don’t get the overlap you wanted, if it was a long way then you overlap much too much and waste flight time.

If its not clear, you can disarm. It will still resume are the correct point when you arm and takeoff on the new battery (provided you have not set the parameter to reset the mission on disarm). This is just the same as when you approach your powered up vehicle to take out the battery normally.

This doesn’t have to be any clever system. You can just stick the flight controller on USB while you switch battery’s. Or have a small USB power bank on the vehicle all the time. This is also allows much faster turn arounds, no need to wait for GPS lock and the EKF to converge.

It would be great functionality to have but as with many things its not so easy as it might seem. For example we now support storing missions on the SD card. So if we stash away a waypoint number to resume at we need to check that the mission is the same and were not going to head to a random point on a totally different mission because the user has swapped SD cards.

1 Like

Hi @iampete, as Randy mentioned above, you’ve already got the smart battery failsafe in the Lua script, but I can’t find it in the GitHub repo. Could you please tell us where we can find it?

Thank you @iampete for taking the time to read and digest - and respond to - my comments. I appreciate it.

It’s occurred to me that the mapping specific apps I’ve used with my commercial camera drones have the advantage of being written for a single task. ArduPilot, serving many purposes, is way more complicated.

I don’t know the history of the division of ArduPilot into individual programs for Copter, Plane, Rover, Sub, etc. - but I’m guessing that the issue is the same. It’s simply impossible for a single application to do everything well.

I don’t know what percentage of ArduPilot instances are used for mapping or agricultural missions - where similar functional needs exist. Maybe the functionality can be accomplished with a Mission Planner plug-in instead of mods to the firmware. If nothing less - I’d just like to help keeping the issues alive among the DEVs. If a goal of ArduPilot is widening it’s user base - better mapping support may be a way to achieve it.

Thinking through the power situation, I’m wondering if the “constant” power might be from an on-board battery connected to the carrier board’s Power-2 connector. I think this might be cleaner than using the flight controller’s USB connector.

Lastly, if I understand present functionality correctly, there’s still the issue of returning to the proper waypoint. As I understand it, current functionality is that the vehicle navigates back to the same waypoint it was when the mission was interrupted.

Mapping requires retuning to the last waypoint - not the next.

I think you may understand why - but for the sake of others reading this thread that are unfamiliar - there may be considerable distance between waypoints on a long mapping leg. Photos may be taken at distance or time intervals. The only way to ensure complete coverage is to return to the last waypoint. Going to the “next” waypoint will likely cause a gap in coverage.

This actually brings up a new problem of duplicate coverage. Returning to the last waypoint will cause all the actions (photos) be performed - which may be a repeat for some - if the mission was interrupted between waypoints separated by some distance.

There are multiple ways to address this - and no need to discuss it here. But I should say that the mapping apps I’ve used on commercial camera-drones all appear to address this - and photos are not duplicated when a battery failsafe triggers a RTH between waypoints.

Once again - thank you for your time and attention. I’ll report back when I try the “constant power” resume function.

That particular script is not public. The idea is similar to the plane one which is here: ardupilot/libraries/AP_Scripting/examples/plane-wind-fs.lua at master · ArduPilot/ardupilot · GitHub

Sorry if I have not been clear. The DO_SET_RESUME_REPEAT_DIST lets you return to the exact location where the mission was interrupted. Not the waypoint before or after, the exact location. If you want to re-cover some of the mission again to make sure there is some over lap, set the repeat distance larger than 0.