Skip to content

Commit 39294c4

Browse files
committed
ArduPlane: support target airspeed command from DDS
* Similar to MAV_CMD_GUIDED_CHANGE_SPEED Signed-off-by: Ryan Friedman <[email protected]>
1 parent a798be9 commit 39294c4

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

ArduPlane/AP_ExternalControl_Plane.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,34 @@ bool AP_ExternalControl_Plane::set_global_position(const Location& loc)
1919
return plane.set_target_location(loc);
2020
}
2121

22+
/*
23+
Sets the target airspeed.
24+
*/
25+
bool AP_ExternalControl_Plane::set_airspeed(const float airspeed)
26+
{
27+
#if AP_PLANE_OFFBOARD_GUIDED_SLEW_ENABLED
28+
// command is only valid in guided mode
29+
if (plane.control_mode != &plane.mode_guided) {
30+
return false;
31+
}
32+
33+
if (airspeed > plane.aparm.airspeed_max || airspeed < plane.aparm.airspeed_min) {
34+
return false;
35+
}
36+
plane.guided_state.target_airspeed_cm = airspeed * 100;
37+
plane.guided_state.target_airspeed_time_ms = AP_HAL::millis();
38+
39+
// Assume the user wanted /maximum acceleration, pick a large value as close enough
40+
plane.guided_state.target_airspeed_accel = 1000.0f;
41+
42+
// assign an acceleration direction
43+
if (plane.guided_state.target_airspeed_cm < plane.target_airspeed_cm) {
44+
plane.guided_state.target_airspeed_accel *= -1.0f;
45+
}
46+
return true;
47+
#else
48+
return false;
49+
#endif
50+
}
51+
2252
#endif // AP_EXTERNAL_CONTROL_ENABLED

ArduPlane/AP_ExternalControl_Plane.h

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ class AP_ExternalControl_Plane : public AP_ExternalControl {
1616
Sets the target global position for a loiter point.
1717
*/
1818
bool set_global_position(const Location& loc) override WARN_IF_UNUSED;
19+
20+
/*
21+
Sets the target airspeed.
22+
*/
23+
bool set_airspeed(const float airspeed) override WARN_IF_UNUSED;
24+
1925
};
2026

2127
#endif // AP_EXTERNAL_CONTROL_ENABLED

0 commit comments

Comments
 (0)