diff --git a/ArduPlane/ArduPlane.cpp b/ArduPlane/ArduPlane.cpp index 8a727950df..09c9e59bbf 100644 --- a/ArduPlane/ArduPlane.cpp +++ b/ArduPlane/ArduPlane.cpp @@ -699,4 +699,42 @@ void Plane::publish_osd_info() } #endif +// set target location (for use by scripting) +bool Plane::set_target_location(const Location& target_loc) +{ + if (plane.control_mode != &plane.mode_guided) { + // only accept position updates when in GUIDED mode + return false; + } + plane.guided_WP_loc = target_loc; + // add home alt if needed + if (plane.guided_WP_loc.relative_alt) { + plane.guided_WP_loc.alt += plane.home.alt; + plane.guided_WP_loc.relative_alt = 0; + } + plane.set_guided_WP(); + return true; +} + +// set target location (for use by scripting) +bool Plane::get_target_location(Location& target_loc) +{ + switch (control_mode->mode_number()) { + case Mode::Number::RTL: + case Mode::Number::AVOID_ADSB: + case Mode::Number::GUIDED: + case Mode::Number::AUTO: + case Mode::Number::LOITER: + case Mode::Number::QLOITER: + case Mode::Number::QLAND: + case Mode::Number::QRTL: + target_loc = next_WP_loc; + return true; + break; + default: + break; + } + return false; +} + AP_HAL_MAIN_CALLBACKS(&plane); diff --git a/ArduPlane/Plane.h b/ArduPlane/Plane.h index aa4620d67c..d3d2d9adbc 100644 --- a/ArduPlane/Plane.h +++ b/ArduPlane/Plane.h @@ -1040,6 +1040,8 @@ private: public: void failsafe_check(void); + bool set_target_location(const Location& target_loc) override; + bool get_target_location(Location& target_loc) override; }; extern Plane plane;