Skip to content

Add airspeed control to AP_DDS for plane in GUIDED #29829

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Ryanf55
Copy link
Collaborator

@Ryanf55 Ryanf55 commented Apr 20, 2025

Purpose

I want to control plane's airspeed from DDS while in GUIDED mode, similar to MAV_CMD_GUIDED_CHANGE_SPEED.

Description

We already have low level velocity control in the DDS interface, currently implemented on copter. We can use the same topic for airspeed commands, assuming the linear Y and Z components are NaN, and it's in the body frame obeying the ROS REP-103 FLU convention. I assume that ROS users will want airspeed control in plane rather than local GPS speed control.

The guided code was pulled from GCS_Mavlink_Plane::handle_command_int_guided_slew_commands where it handled MAV_CMD_GUIDED_CHANGE_SPEED:

case MAV_CMD_GUIDED_CHANGE_SPEED: {
// command is only valid in guided mode
if (plane.control_mode != &plane.mode_guided) {
return MAV_RESULT_FAILED;
}
// only airspeed commands are supported right now...
if (int(packet.param1) != SPEED_TYPE_AIRSPEED) { // since SPEED_TYPE is int in range 0-1 and packet.param1 is a *float* this works.
return MAV_RESULT_DENIED;
}
// reject airspeeds that are outside of the tuning envelope
if (packet.param2 > plane.aparm.airspeed_max || packet.param2 < plane.aparm.airspeed_min) {
return MAV_RESULT_DENIED;
}
// no need to process any new packet/s with the
// same airspeed any further, if we are already doing it.
float new_target_airspeed_cm = packet.param2 * 100;
if ( is_equal(new_target_airspeed_cm,plane.guided_state.target_airspeed_cm)) {
return MAV_RESULT_ACCEPTED;
}
plane.guided_state.target_airspeed_cm = new_target_airspeed_cm;
plane.guided_state.target_airspeed_time_ms = AP_HAL::millis();
if (is_zero(packet.param3)) {
// the user wanted /maximum acceleration, pick a large value as close enough
plane.guided_state.target_airspeed_accel = 1000.0f;
} else {
plane.guided_state.target_airspeed_accel = fabsf(packet.param3);
}
// assign an acceleration direction
if (plane.guided_state.target_airspeed_cm < plane.target_airspeed_cm) {
plane.guided_state.target_airspeed_accel *= -1.0f;
}
return MAV_RESULT_ACCEPTED;
}

Example Command

header:
  stamp:
    sec: 0
    nanosec: 0
  frame_id: base_link
twist:
  linear:
    x: 30.0
    y: .nan
    z: .nan
  angular:
    x: 0.0
    y: 0.0
    z: 0.0

Tests Performed

colcon build --packages-up-to ardupilot_sitl
source install/setup.bash
ros2 launch ardupilot_sitl sitl_dds_udp.launch.py command:=arduplane model:=plane defaults:=$(ros2 pkg prefix --share ardupilot_sitl)/config/models/plane.parm

In another terminal, take off and get the vehicle into GUIDED so it's ready to accept airspeed commands

mavproxy.py --master :14551
mode takeoff
arm throttle
# wait till at altitude
mode guided

In another terminal, send the airspeed command to 26 m/s.

source install/setup.bash
ros2 topic pub /ap/cmd_vel geometry_msgs/msg/TwistStamped "{header: {stamp: now, frame_id: base_link}, twist: {linear: {x: 26.0, y: .nan, z: .nan}}}" --once

Observe the plane speed up from 23 to 26 m/s in mavproxy's console.
image

Now, slow it down to 15 m/S.

ros2 topic pub /ap/cmd_vel geometry_msgs/msg/TwistStamped "{header: {stamp: now, frame_id: base_link}, twist: {linear: {x: 15.0, y: .nan, z: .nan}}}" --once

Observe it slow down.

YOu can also try with 9 to see it's rejected (too slow) and 31 (too fast), or in another mode like FBWB to see it's rejected.

@Ryanf55 Ryanf55 added this to DDS/ROS2 Apr 20, 2025
@Ryanf55 Ryanf55 force-pushed the dds-plane-airspeed-guided branch from 980de3d to d51f9d8 Compare April 20, 2025 04:08
@Ryanf55 Ryanf55 requested a review from srmainwaring April 20, 2025 04:11
@Ryanf55 Ryanf55 force-pushed the dds-plane-airspeed-guided branch 2 times, most recently from 39294c4 to 7aed7ea Compare April 20, 2025 04:52
@MatthewFehl365
Copy link

It would be nice if support for climb rate control was also added! otherwise great feature.

@Ryanf55 Ryanf55 changed the title Add airspeed control to AP_DDS for plane Add airspeed control to AP_DDS for plane in GUIDED Apr 22, 2025
Ryanf55 added a commit to Ryanf55/ardupilot that referenced this pull request Apr 22, 2025
Ryanf55 added a commit to Ryanf55/ardupilot that referenced this pull request Apr 22, 2025
Ryanf55 added a commit to Ryanf55/ardupilot that referenced this pull request Apr 23, 2025
* Precursor to ArduPilot#29829

Signed-off-by: Ryan Friedman <[email protected]>
Co-authored-by: Peter Barker <[email protected]>
Ryanf55 added a commit to Ryanf55/ardupilot that referenced this pull request Apr 23, 2025
* Precursor to ArduPilot#29829

Signed-off-by: Ryan Friedman <[email protected]>
Co-authored-by: Peter Barker <[email protected]>
Ryanf55 added a commit to Ryanf55/ardupilot that referenced this pull request Apr 23, 2025
* Precursor to ArduPilot#29829

Signed-off-by: Ryan Friedman <[email protected]>
Co-authored-by: Peter Barker <[email protected]>
peterbarker added a commit that referenced this pull request Apr 29, 2025
* Precursor to #29829

Signed-off-by: Ryan Friedman <[email protected]>
Co-authored-by: Peter Barker <[email protected]>
@peterbarker
Copy link
Contributor

Time for a rebase

Ryanf55 added 3 commits May 8, 2025 20:53
* Similar to MAV_CMD_GUIDED_CHANGE_SPEED

Signed-off-by: Ryan Friedman <[email protected]>
* Similar to MAV_CMD_GUIDED_CHANGE_SPEED

Signed-off-by: Ryan Friedman <[email protected]>
* Similar to MAV_CMD_GUIDED_CHANGE_SPEED

Signed-off-by: Ryan Friedman <[email protected]>
@Ryanf55 Ryanf55 force-pushed the dds-plane-airspeed-guided branch from 7aed7ea to f43e694 Compare May 9, 2025 02:58
@Ryanf55
Copy link
Collaborator Author

Ryanf55 commented May 9, 2025

Time for a rebase

Done, retestested with the same test cases. Ready for final review.

@Ryanf55 Ryanf55 requested a review from peterbarker May 9, 2025 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

5 participants