ArduCopter: add MAV_CMD_DO_ORBIT support in Guided mode#32434
ArduCopter: add MAV_CMD_DO_ORBIT support in Guided mode#32434researcher3 wants to merge 1 commit intoArduPilot:masterfrom
Conversation
peterbarker
left a comment
There was a problem hiding this comment.
Nice!
Can you outline why you chose to add to guided mode rather than forcing the vehicle into circle mode, please? I'm not saying what you did was wrong.
peterbarker
left a comment
There was a problem hiding this comment.
I think we also need to support param4 - otherwise we're dangerously not compliant with the spec.
It may also be that @lthall would like us to use the arc-waypoint infrastructure for this. I suggest waiting for Leonard to chime in before making adjustments to the guided mode implementation here
|
Re using the new Arc method, it's a reasonable idea but it's too much scope creep. If we were going to move to use Arcs we would do that in Circle mode or Auto mode first I suspect. So let's stick with the direction this PR is taking |
ba8f6eb to
82c8082
Compare
Yes I tend to agree. When I come along later I can work through it all. |
Thanks for the question. I did consider switching to Circle mode. However, Circle mode relies on persistent parameters such as CIRCLE_RADIUS and CIRCLE_RATE, while MAV_CMD_DO_ORBIT provides its own parameters (radius, velocity, center point, etc.). Implementing it via Circle mode would likely require temporarily overriding parameters or adapting that mode’s behaviour, which felt less clean. Keeping it in Guided mode also avoids a forced mode transition and allows the vehicle to remain under companion/GCS command control. Another difference I noticed is that MAV_CMD_DO_ORBIT explicitly defines the orbit center as part of the command (lat/lon/alt), while Circle mode implicitly uses the vehicle's position at the time the mode is entered as the center of the circle. |
Implemented - param4 now sets the number of turns (0 = orbit forever). |
peterbarker
left a comment
There was a problem hiding this comment.
The concept behind the guards is to not use up flash space on boards which can't spare it.
For reference, this new feature takes up 1168 bytes of Pixhawk1-1M's 1976 bytes remaining!
|
Implemented param3 (yaw behaviour) fully, covering all five ORBIT_YAW_BEHAVIOUR values from the MAVLink spec (face center, hold initial heading, uncontrolled, tangent to circle, RC controlled, unchanged). Additionally fixed two yaw-related bugs discovered during manual SITL testing: (1) after orbit completion the vehicle now correctly maintains the requested yaw behaviour instead of always snapping to face center, and (2) during the approach to the orbit edge the vehicle now looks in the direction of travel rather than holding its previous heading. Also fixed a separate bug where the vehicle would fly back toward its start position and descend after completing the requested number of turns — replaced pos_control_start() with hold_position() which correctly stops the vehicle in place. |
|
Found and fixed the root cause of the 2x speed bug. orbit_run() was calling update_ms() twice per loop — once before the turn-count check (without parameters) and once after (with 0.0f). Since each update_ms() call advances _angle_rad and ramps _angular_vel_rads, two calls per loop resulted in exactly double the requested speed, which matches the observed behaviour (1.0 m/s requested → 2.0 m/s measured, consistently across all speeds). Fixed by removing the redundant first call. |
05e747c to
9ba6018
Compare
Sends ORBIT_EXECUTION_STATUS (MAVLink ArduPilot#360) when requested via MAV_CMD_SET_MESSAGE_INTERVAL during an active guided orbit. Provides current orbit radius, center coordinates (lat/lon in degE7, altitude relative to home in meters) and coordinate frame MAV_FRAME_GLOBAL_RELATIVE_ALT. Altitude is converted from EKF-origin-absolute to ABOVE_HOME to correctly match the reported coordinate frame. Guarded by AC_COPTER_MODEGUIDED_ORBIT_ENABLED. Autotest extended to request the message and validate radius and center coordinates. Companion PR to ArduPilot#32434 (MAV_CMD_DO_ORBIT implementation).
|
Tested on hardware (Pixhawk 4 with custom firmware build). MAV_CMD_DO_ORBIT returns MAV_RESULT_ACCEPTED. Flight test with full drone pending. |
peterbarker
left a comment
There was a problem hiding this comment.
Make sure the code builds without AC_COPTER_MODEGUIDED_ORBIT_ENABLED
|
@researcher3 we've merged What's your intention with this PR? |
Thank you for merging ORBIT_EXECUTION_STATUS into the XML! |
Yes, I agree this could be merged once the minor requests I've made have been addressed (need Randy's approval for merge, however)
The submodule reference now points to a commit which includes I was unable to find a PR which adds support for that message. I'm guessing it's pretty straight forward, so if you can present some patches on top of this one in a PR then it should be straight-forward to review. |
The follow-up PR with ORBIT_EXECUTION_STATUS sending support is already |
Sends ORBIT_EXECUTION_STATUS (MAVLink ArduPilot#360) when requested via MAV_CMD_SET_MESSAGE_INTERVAL during an active guided orbit. Provides current orbit radius, center coordinates (lat/lon in degE7, altitude relative to home in meters) and coordinate frame MAV_FRAME_GLOBAL_RELATIVE_ALT. Altitude is converted from EKF-origin-absolute to ABOVE_HOME to correctly match the reported coordinate frame. Guarded by AC_COPTER_MODEGUIDED_ORBIT_ENABLED. Autotest extended to request the message and validate radius and center coordinates. Companion PR to ArduPilot#32434 (MAV_CMD_DO_ORBIT implementation).
Sends ORBIT_EXECUTION_STATUS (MAVLink ArduPilot#360) when requested via MAV_CMD_SET_MESSAGE_INTERVAL during an active guided orbit. Provides current orbit radius, center coordinates (lat/lon in degE7, altitude relative to home in meters) and coordinate frame MAV_FRAME_GLOBAL_RELATIVE_ALT. Altitude is converted from EKF-origin-absolute to ABOVE_HOME to correctly match the reported coordinate frame. Guarded by AC_COPTER_MODEGUIDED_ORBIT_ENABLED. Autotest extended to request the message and validate radius and center coordinates. Companion PR to ArduPilot#32434 (MAV_CMD_DO_ORBIT implementation).
8545226 to
e95bb7e
Compare
e95bb7e to
a9aa9f6
Compare
|
|
Wiki PR submitted: ArduPilot/ardupilot_wiki#7628 |
|
Neat PR - I'm happy to see something like this going in. For our use case, we want to do orbits with precise radius. Being 3 meters off from the orbit location can lead to a crash (because our orbit radius is ~5m typically), and may also will result in the poor sensor data from our payload because the distance we want to use it around the target is not what is actually flown. Why do we not try to follow the exact path? |
a9aa9f6 to
371f42a
Compare
The 3m thing is all about how you get to the edge, not the radius at which you circle.... Are you suggesting that for your purposes 3m is insane and it should always fly to the circle edge in a straight line, not circle out onto the edge? |
Implements MAV_CMD_DO_ORBIT (command 34) in ArduCopter Guided mode. Parameters: - param1: radius in meters (positive=CW, negative=CCW) - param2: tangential speed in m/s (0=default) - param3: yaw behaviour (ORBIT_YAW_BEHAVIOUR enum, all 5 values supported) - param4: number of turns (0=forever, NaN=preserve existing) - x/y: center latitude/longitude - z: altitude in meters Implementation: - New SubMode::Orbit in ModeGuided - circle_start(), orbit_run(), orbit_apply_yaw_behaviour() in mode_guided.cpp - handle_MAV_CMD_DO_ORBIT() in GCS_MAVLink_Copter.cpp - MAV_CMD_DO_ORBIT in command_long_stores_location() in GCS_Common.cpp - AC_COPTER_MODEGUIDED_ORBIT_ENABLED flash guard (default: MODE_GUIDED_ENABLED && HAL_PROGRAM_SIZE_LIMIT_KB>1024) - AP_MAVLINK_MAV_CMD_DO_ORBIT_ENABLED in GCS_config.h, build_options.py, extract_features.py and test_build_options.py - Autotest DO_ORBIT in arducopter.py Fixes: - Double speed bug: removed duplicate update_ms() call in orbit_run() - Post-orbit hold: use hold_position() instead of pos_control_start() - Yaw consistency during approach, orbiting and after completion - Cross-platform compile: use copter.ahrs.get_yaw_rad() Addresses ArduPilot#15098
371f42a to
dfc263c
Compare
|
I reduced the approach threshold from 3m to 0.1m — the vehicle now flies to within 0.1m of the exact orbit edge before beginning the orbit. This ensures more precise orbit positioning for small-radius use cases with RTK-equipped vehicles, while still avoiding unnecessary micro-corrections at floating-point scale. |
|
As a first-time contributor I'm not fully familiar with the merge process — is there anything still needed from my side to move this forward, or is it purely waiting for the next Dev Call? |
|
Hi @researcher3, we just need a dev to review it.. probably me mostly.. |
Summary
Implements MAV_CMD_DO_ORBIT (command 34) as an immediate command executable while the vehicle is in Guided mode. The vehicle flies to the edge of the specified circle and then orbits the given GPS coordinate. Addresses #15098.
Testing (more checks increases chance of being merged)
Description
Changes:
Behaviour:
Known limitations / Future work
DO_ORBIT_SITL.bin.log