From ac0e125cce1aa47e3255e75ce28e9df14f426ae3 Mon Sep 17 00:00:00 2001 From: Tim Tuxworth Date: Mon, 24 Jun 2024 10:53:58 -0600 Subject: [PATCH] Various: Plane scripted follow checkpoint --- ArduPlane/ArduPlane.cpp | 9 ++++----- libraries/AP_Scripting/docs/docs.lua | 7 ++++++- .../AP_Scripting/generator/description/bindings.desc | 1 + libraries/AP_Vehicle/AP_Vehicle.h | 3 +++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ArduPlane/ArduPlane.cpp b/ArduPlane/ArduPlane.cpp index 758273d0f3a33..6fd1cf1f07ccc 100644 --- a/ArduPlane/ArduPlane.cpp +++ b/ArduPlane/ArduPlane.cpp @@ -865,6 +865,7 @@ bool Plane::update_target_location(const Location &old_loc, const Location &new_ */ if (!old_loc.same_loc_as(next_WP_loc) || old_loc.get_alt_frame() != new_loc.get_alt_frame()) { + gcs().send_text(MAV_SEVERITY_NOTICE, "location diff %d %d", old_loc.same_loc_as(next_WP_loc), old_loc.get_alt_frame() != new_loc.get_alt_frame()); return false; } next_WP_loc = new_loc; @@ -967,19 +968,17 @@ bool Plane::flight_option_enabled(FlightOptions flight_option) const // this implements the virtual function defined in AP_Vehicle for Plane to set the desired airspeed in m/s bool Plane::set_desired_airspeed(float airspeed_new) { - if (control_mode == &mode_guided || control_mode == &mode_auto) { + if (control_mode->is_guided_mode() || control_mode == &mode_auto) { plane.new_airspeed_cm = constrain_float(airspeed_new, aparm.airspeed_min, aparm.airspeed_max) * 100.0f; return true; } return false; } -#endif -#if AP_SCRIPTING_ENABLED -// Helper function to let scripting set the guided mode radius +// Helper function to let scripting set the guided mode radius this implements bool Plane::set_guided_radius_and_direction(float radius, bool direction_is_ccw) { - if (control_mode->mode_number() == Mode::GUIDED) { + if (control_mode->is_guided_mode()) { plane.mode_guided.set_radius_and_direction(radius, direction_is_ccw); return true; } diff --git a/libraries/AP_Scripting/docs/docs.lua b/libraries/AP_Scripting/docs/docs.lua index f47e5d11301a6..b214b581c4524 100644 --- a/libraries/AP_Scripting/docs/docs.lua +++ b/libraries/AP_Scripting/docs/docs.lua @@ -2427,10 +2427,15 @@ function vehicle:nav_scripting_enable(param1) end ---@return boolean -- success function vehicle:set_desired_speed(param1) end +-- desc sets autopilot desired airspeed (Plane) +---@param airspeed_new number -- new airspeed in m/s +---@return boolean +function vehicle:set_desired_airspeed(airspeed_new) end + -- desc set the guided mode radious and direction used for the final loiter at the target ---@return boolean ---@param radius float ----@param direction_is_ccw boolean +---@param direction_is_ccw boolean function vehicle:set_guided_radius_and_direction() end -- desc diff --git a/libraries/AP_Scripting/generator/description/bindings.desc b/libraries/AP_Scripting/generator/description/bindings.desc index 6cc5610b06f7a..bbc98bffb45c2 100644 --- a/libraries/AP_Scripting/generator/description/bindings.desc +++ b/libraries/AP_Scripting/generator/description/bindings.desc @@ -339,6 +339,7 @@ singleton AP_Vehicle method set_target_throttle_rate_rpy void float -100 100 flo singleton AP_Vehicle method set_rudder_offset void float'skip_check boolean singleton AP_Vehicle method set_desired_turn_rate_and_speed boolean float'skip_check float'skip_check singleton AP_Vehicle method set_desired_speed boolean float'skip_check +singleton AP_Vehicle method set_desired_airspeed boolean float'skip_check singleton AP_Vehicle method set_guided_radius_and_direction boolean float'skip_check boolean singleton AP_Vehicle method nav_scripting_enable boolean uint8_t'skip_check singleton AP_Vehicle method set_velocity_match boolean Vector2f diff --git a/libraries/AP_Vehicle/AP_Vehicle.h b/libraries/AP_Vehicle/AP_Vehicle.h index a5f61f3da92e3..6b3fd12f07eb9 100644 --- a/libraries/AP_Vehicle/AP_Vehicle.h +++ b/libraries/AP_Vehicle/AP_Vehicle.h @@ -210,6 +210,9 @@ class AP_Vehicle : public AP_HAL::HAL::Callbacks { // set auto mode speed in meters/sec (for use by scripting with Copter/Rover) virtual bool set_desired_speed(float speed) { return false; } + // set auto mode airspeed in meters/sec (for use by scripting with Plane) + virtual bool set_desired_airspeed(float airspeed_new) { return false; } + // support for NAV_SCRIPT_TIME mission command virtual bool nav_script_time(uint16_t &id, uint8_t &cmd, float &arg1, float &arg2, int16_t &arg3, int16_t &arg4) { return false; } virtual void nav_script_time_done(uint16_t id) {}