-
Notifications
You must be signed in to change notification settings - Fork 18.6k
ArduPlane: Factor out guided airspeed cmd logic from GCS_MAVLinkPlane to ModeGuided #29862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ArduPlane: Factor out guided airspeed cmd logic from GCS_MAVLinkPlane to ModeGuided #29862
Conversation
Ryanf55
commented
Apr 22, 2025
•
edited
Loading
edited
- Precursor to Add airspeed control to AP_DDS for plane in GUIDED #29829 to reduce code duplication
f17fca7
to
a092f85
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing things this way.
ArduPlane/mode_guided.cpp
Outdated
// same airspeed any further, if we are already doing it. | ||
float new_target_airspeed_cm = airspeed * 100; | ||
if ( is_equal(new_target_airspeed_cm,plane.guided_state.target_airspeed_cm)) { | ||
return MAV_RESULT_ACCEPTED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exits early without setting acceleration and timestamp. I think you might have mentioned this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, do you want a functional change in this refactor too? I'd prefer to solve that in a separate PR with a test that verifies it's working.
d573339
to
4f0f013
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What testing has this had?
ArduPlane/GCS_MAVLink_Plane.cpp
Outdated
// the user wanted /maximum acceleration, pick a large value as close enough | ||
plane.guided_state.target_airspeed_accel = 1000.0f; | ||
if (plane.mode_guided.handle_change_airspeed(packet.param2, packet.param3)) { | ||
return MAV_RESULT_ACCEPTED; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
Try this python script. I played around with changing speed, sending the same command multiple times, and putting a really slow acceleration (0.25). You can also try airspeeds of 9 and 31 which are rejected. Run this against default SITL, with an added UDP output on 14551. #!/usr/bin/env python3
from pymavlink import mavutil
# Connect to the vehicle
master = mavutil.mavlink_connection('udp:127.0.0.1:14551') # Change if needed
# Wait for heartbeat
master.wait_heartbeat()
print(f"Connected to system {master.target_system}, component {master.target_component}")
# Define constants
MAV_CMD_GUIDED_CHANGE_SPEED = 43000
SPEED_TYPE_AIRSPEED = 0
TARGET_SPEED = 24.0 # m/s
INSTANT_ACCEL = 0.0 # 0 = change speed instantly
# Send command
master.mav.command_long_send(
master.target_system,
master.target_component,
MAV_CMD_GUIDED_CHANGE_SPEED,
0, # confirmation
SPEED_TYPE_AIRSPEED, # param1: speed type
TARGET_SPEED, # param2: target speed (m/s)
INSTANT_ACCEL, # param3: acceleration (0 = instant)
0, 0, 0, 0 # param4-7: empty
)
print(f"MAV_CMD_GUIDED_CHANGE_SPEED sent: airspeed {TARGET_SPEED} m/s")
import time
start_time = time.time()
timeout = 5 # seconds
while time.time() - start_time < timeout:
msg = master.recv_match(type='COMMAND_ACK', blocking=True, timeout=1)
if msg and msg.command == MAV_CMD_GUIDED_CHANGE_SPEED:
result = mavutil.mavlink.enums['MAV_RESULT'][msg.result].name
print(f"Received ACK: {result}")
break
else:
print("Timed out waiting for COMMAND_ACK")
|
99d9102
to
deffaf6
Compare
An autotest would be more useful. And yes, chatgpt can generate those with a little more prompting :-) |
* Precursor to ArduPilot#29829 Signed-off-by: Ryan Friedman <[email protected]> Co-authored-by: Peter Barker <[email protected]>
3df4d96
to
c82247d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like code has been moved.
Just need to know it's been tested in its current form.
Retested, LGTM on c82247d
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM