From a4109c6cf27b7f5a831c25050c72f1f0492922ce Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 Feb 2024 19:18:14 +1100 Subject: [PATCH] Plane: compile in AC_PrecLand for scripting --- ArduPlane/ArduPlane.cpp | 12 ++++++++++++ ArduPlane/Parameters.cpp | 8 +++++++- ArduPlane/Parameters.h | 4 ++++ ArduPlane/Plane.h | 9 +++++++++ ArduPlane/system.cpp | 4 ++++ ArduPlane/wscript | 2 ++ 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ArduPlane/ArduPlane.cpp b/ArduPlane/ArduPlane.cpp index 53e265b4fa..98a1dda017 100644 --- a/ArduPlane/ArduPlane.cpp +++ b/ArduPlane/ArduPlane.cpp @@ -135,6 +135,9 @@ const AP_Scheduler::Task Plane::scheduler_tasks[] = { #if AP_LANDINGGEAR_ENABLED SCHED_TASK(landing_gear_update, 5, 50, 159), #endif +#if AC_PRECLAND_ENABLED + SCHED_TASK(precland_update, 400, 50, 160), +#endif }; void Plane::get_scheduler_tasks(const AP_Scheduler::Task *&tasks, @@ -947,4 +950,13 @@ bool Plane::flight_option_enabled(FlightOptions flight_option) const return g2.flight_options & flight_option; } +#if AC_PRECLAND_ENABLED +void Plane::precland_update(void) +{ + // alt will be unused if we pass false through as the second parameter: + return g2.precland.update(rangefinder_state.height_estimate*100, + rangefinder_state.in_range && rangefinder_state.in_use); +} +#endif + AP_HAL_MAIN_CALLBACKS(&plane); diff --git a/ArduPlane/Parameters.cpp b/ArduPlane/Parameters.cpp index 53ad53307e..166b141c87 100644 --- a/ArduPlane/Parameters.cpp +++ b/ArduPlane/Parameters.cpp @@ -1242,7 +1242,13 @@ const AP_Param::GroupInfo ParametersG2::var_info[] = { // @Bitmask: 0:Roll,1:Pitch,2:Yaw // @User: Standard AP_GROUPINFO("AUTOTUNE_AXES", 34, ParametersG2, axis_bitmask, 7), - + +#if AC_PRECLAND_ENABLED + // @Group: PLND_ + // @Path: ../libraries/AC_PrecLand/AC_PrecLand.cpp + AP_SUBGROUPINFO(precland, "PLND_", 35, ParametersG2, AC_PrecLand), +#endif + AP_GROUPEND }; diff --git a/ArduPlane/Parameters.h b/ArduPlane/Parameters.h index dacc015496..ba89c45772 100644 --- a/ArduPlane/Parameters.h +++ b/ArduPlane/Parameters.h @@ -520,6 +520,10 @@ public: AP_LandingGear landing_gear; #endif +#if AC_PRECLAND_ENABLED + AC_PrecLand precland; +#endif + // crow flaps weighting AP_Int8 crow_flap_weight_outer; AP_Int8 crow_flap_weight_inner; diff --git a/ArduPlane/Plane.h b/ArduPlane/Plane.h index 3d08a2bca9..189189e9dc 100644 --- a/ArduPlane/Plane.h +++ b/ArduPlane/Plane.h @@ -87,6 +87,11 @@ #include "AP_ExternalControl_Plane.h" #endif +#include +#if AC_PRECLAND_ENABLED + # include +#endif + #include "GCS_Mavlink.h" #include "GCS_Plane.h" #include "quadplane.h" @@ -251,6 +256,10 @@ private: AP_Rally rally; #endif +#if AC_PRECLAND_ENABLED + void precland_update(void); +#endif + // returns a Location for a rally point or home; if // HAL_RALLY_ENABLED is false, just home. Location calc_best_rally_or_home_location(const Location ¤t_loc, float rtl_home_alt_amsl_cm) const; diff --git a/ArduPlane/system.cpp b/ArduPlane/system.cpp index 593dfb1c16..17d57395d9 100644 --- a/ArduPlane/system.cpp +++ b/ArduPlane/system.cpp @@ -132,6 +132,10 @@ void Plane::init_ardupilot() optflow.init(-1); } #endif + +#if AC_PRECLAND_ENABLED + g2.precland.init(scheduler.get_loop_rate_hz()); +#endif } //******************************************************************************** diff --git a/ArduPlane/wscript b/ArduPlane/wscript index 4dd670ccc3..32bbdb0a5a 100644 --- a/ArduPlane/wscript +++ b/ArduPlane/wscript @@ -29,6 +29,8 @@ def build(bld): 'AP_OSD', 'AC_AutoTune', 'AP_Follow', + 'AC_PrecLand', + 'AP_IRLock', ], )