Skip to content

examples: add ArduPilot mission example using mission_raw - #833

Open
vishwagw wants to merge 2 commits into
mavlink:mainfrom
vishwagw:examples-mission-ardupilot
Open

vishwagw wants to merge 2 commits into
mavlink:mainfrom
vishwagw:examples-mission-ardupilot

Conversation

@vishwagw

Copy link
Copy Markdown
Contributor

Why mission.py fails on ArduPilot

The upload error in #819 (MissionError: INVALID_ARGUMENT, with ArduPilot answering
MISSION_ACK = INVALID_PARAM1) comes from the RTL item that
set_return_to_launch_after_mission(True) appends. It is sent with
param1..4 = NaN. ArduPilot's AP_Mission::sanity_check_params() only allows NaN in
param4 for a few NAV commands, and it rejects NaN params on NAV_RETURN_TO_LAUNCH with
MAV_MISSION_INVALID_PARAM1.

This is fixed on the C++ side in mavlink/MAVSDK#3213 (in v4.2.0). This repo still pins
mavsdk_server v4.0.5, so mission.py still fails with the published mavsdk-grpc.
Even with that fixed, the high-level mission plugin's output can't be flown by ArduCopter
from the ground:

  • ArduPilot reserves mission item 0 for home (AP_MISSION_FIRST_REAL_COMMAND = 1), so
    the first waypoint is overwritten.
  • ArduCopter won't enter AUTO while landed unless the first real item is a NAV_TAKEOFF
    (Auto: Missing Takeoff Cmd). The VehicleAction.TAKEOFF item is also sent with NaN
    param1, which ArduPilot rejects too.

What this PR adds

examples/mission_ardupilot.py builds the mission with mission_raw:
home at seq 0, NAV_TAKEOFF, three waypoints offset from home (so it works wherever the
vehicle/SITL is), and NAV_RETURN_TO_LAUNCH. Unused params are 0 instead of NaN. Then it
arms, runs mission_raw.start_mission() and exits after landing. The docstring explains the
three ArduPilot requirements so users of the high-level API know why it differs.
mission.py gets a one-line pointer to it.

Testing

  • Reproduced the Mission example does not work on ArduPilot #819 error with the unchanged examples/mission.py (mavsdk-grpc 4.0.5).
    The RTL item is uploaded as cmd=20 params=[nan, nan, nan, nan] and rejected with
    INVALID_PARAM1.
  • mission_ardupilot.py uploads 6 items that are all accepted, then arms and switches to AUTO.
  • Ran against ArduCopter SITL (sim_vehicle.py -v ArduCopter): <describe result: takeoff, 3 waypoints, RTL, land>
  • ruff format --check / ruff check --select=ASYNC,RUF006,E,F pass.

> ⚠️ Before opening the PR, run it on real ArduCopter SITL and fill in the SITL testing line
> above (or delete it). My checks used a pymavlink stand-in for ArduPilot plus the ArduPilot
> source; I couldn't build SITL here.

---

Add a comment indicating the target platform for the example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant