Storing WAYPOINT files onboard a drone

That’s exactly what I did…

It’s also possible to write a simpler selector script using this method. The script could just cycle through the various takeoff waypoints whenever a switch or button is pressed (and be disabled while armed).

1 Like

That’s a great approach @Yuri_Rage . Do you have experience writing these LUA scripts for this or is this just an example that you’re proposing?

Yes, I have a bit of experience with ArduPilot Lua scripts.

3 Likes

Hey everyone,

I’ve decided to go the LUA script way to create this solution. I’m starting by experimenting with SITL and the mission-load.lua file from the ArduPilot repo, and it didn’t take me long to get it to work and upload the mission fine.

I’m now moving onto implementing the mission-selector.lua script. If I’m understanding the code / documentation correctly, then this script only allows for selecting between 3 different missions, as the AUX_FUNCTION switch is limited to 3 positions (low, medium, high).

Is there any way to create a script like this mission-selector , but so that I can have it select between an “unlimited” number of missions (e.g. 10, 20 or 30 + different missions) ? Do you have an idea for how to go about doing this? (I’m going to work on implementing and testing this in SITL over the course of this weekend before moving to a real drone).

Given your Lua script experience, maybe you have some ideas @Yuri_Rage ?

You could just use a two position switch and iterate through all stored missions (increment by one on each toggle of the switch). I suggested such a method to Willy but he claimed it wasn’t his desire for some reason.

In our application I’d need this to be done somehow remotely via MAVLink commands, so switches and manually doing this isn’t a viable solution in our use case unfortunately.

We’re using a tool called MAVSDK in our Android app though, which allows us to use almost all MAVLink commands and send them to the drone. Ideally the workflow would look something like this: the user connects with the drone via our Android app, Android app sends some MAVLink command based on which mission the user wants to fly, and that MAVLink command then triggers a Lua script to upload the corresponding mission.

Any ideas for how we could achieve this?

I think maybe you could leverage the script time feature for this. Send a mission with a single waypoint containing a script time command with the index of the stored mission you want to execute. When auto is initiated, the script time command would trigger a script to load the waypoints from storage.

Alternatively, create a custom (scripted) parameter to store the mission index. Have the script poll for changes to that parameter and load the corresponding mission.

1 Like

May be a bit jank but you could also send RC PWM values via MAVLink and continue with how the current Lua script works. Since you can pretty much send the exact PWM you want (1, 2, 99, 3000, etc.) - you can just send the PWM value that correlates to the the mission you want.

1 Like

@manavgandhi17 This is quite a cool idea, although it’d require having a spare channel configured for this.

We are not using an RC for our setup. The drone flies in AUTO modes for 99% of the time, and then the 1 or 2% of the time were manual control is needed the pilot can do this via a joystick configured on Mission Planner via MAVLink. The details of this type of this type of setup are described here.

Can we still use the MAVLink commands to send PWM values to the autopilot without having them linked to a real switch on an RC?

@Yuri_Rage If I’m understanding this correctly, then what you are suggesting is numbering each of the missio files that are preloaded onto the autopilot storage, and then either A) uploading a mission via our app which triggers the loading of the correct preloaded mission already on the autopilot or B) writing a value to a scripted parameter which tells the autopilot which one of the preloaded missions it should upload and use.

Did I understand your idea correctly?

That’s exactly what I’m suggesting. You could just name the stored files something like:

0.waypoints
1.waypoints
2.waypoints
…
1 Like

In that case, that sounds like a great idea!

Which of the two approaches you suggested do you think would work better?

Changing a single parameter is probably easier. I’m not sure either approach is “better.”

1 Like

All makes sense, thank you!