123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- #pragma once
- #include <inttypes.h>
- #include <AP_Common/AP_Common.h>
- #include <AP_Param/AP_Param.h>
- #include <AP_Math/AP_Math.h>
- #include <GCS_MAVLink/GCS.h>
- #include <AC_Fence/AC_PolyFence_loader.h>
- #include <AP_Common/Location.h>
- #define AC_FENCE_TYPE_ALT_MAX 1
- #define AC_FENCE_TYPE_CIRCLE 2
- #define AC_FENCE_TYPE_POLYGON 4
- #define AC_FENCE_ACTION_REPORT_ONLY 0
- #define AC_FENCE_ACTION_RTL_AND_LAND 1
- #define AC_FENCE_ACTION_ALWAYS_LAND 2
- #define AC_FENCE_ACTION_SMART_RTL 3
- #define AC_FENCE_ACTION_BRAKE 4
- #define AC_FENCE_ALT_MAX_DEFAULT 100.0f
- #define AC_FENCE_ALT_MIN_DEFAULT -10.0f
- #define AC_FENCE_CIRCLE_RADIUS_DEFAULT 300.0f
- #define AC_FENCE_ALT_MAX_BACKUP_DISTANCE 20.0f
- #define AC_FENCE_CIRCLE_RADIUS_BACKUP_DISTANCE 20.0f
- #define AC_FENCE_MARGIN_DEFAULT 2.0f
- #define AC_FENCE_GIVE_UP_DISTANCE 100.0f
- #define AC_FENCE_MANUAL_RECOVERY_TIME_MIN 10000
- class AC_Fence
- {
- public:
- AC_Fence();
-
- AC_Fence(const AC_Fence &other) = delete;
- AC_Fence &operator=(const AC_Fence&) = delete;
-
- void enable(bool value);
-
- bool enabled() const { return _enabled; }
-
- uint8_t get_enabled_fences() const;
-
- bool pre_arm_check(const char* &fail_msg) const;
-
-
-
-
- uint8_t check();
-
- bool check_destination_within_fence(const Location& loc);
-
- uint8_t get_breaches() const { return _breached_fences; }
-
- uint32_t get_breach_time() const { return _breach_time; }
-
- uint16_t get_breach_count() const { return _breach_count; }
-
-
- float get_breach_distance(uint8_t fence_type) const;
-
- uint8_t get_action() const { return _action.get(); }
-
- float get_safe_alt_max() const { return _alt_max - _margin; }
-
- float get_safe_alt_min() const { return _alt_min + _margin; }
-
- float get_radius() const { return _circle_radius.get(); }
-
- float get_margin() const { return _margin.get(); }
-
-
-
- void manual_recovery_start();
-
-
-
-
- bool is_polygon_valid() const { return _boundary_valid; }
-
-
- Vector2f* get_boundary_points(uint16_t& num_points) const;
-
- bool boundary_breached(const Vector2f& location, uint16_t num_points, const Vector2f* points) const;
-
- void handle_msg(GCS_MAVLINK &link, const mavlink_message_t &msg);
-
- uint32_t get_boundary_update_ms() const { return _boundary_update_ms; }
- static const struct AP_Param::GroupInfo var_info[];
-
- bool sys_status_present() const;
- bool sys_status_enabled() const;
- bool sys_status_failed() const;
-
- static AC_Fence *get_singleton() { return _singleton; }
- private:
- static AC_Fence *_singleton;
-
- bool check_fence_alt_max();
-
- bool check_fence_polygon();
-
- bool check_fence_circle();
-
- void record_breach(uint8_t fence_type);
-
- void clear_breach(uint8_t fence_type);
-
- bool pre_arm_check_polygon(const char* &fail_msg) const;
- bool pre_arm_check_circle(const char* &fail_msg) const;
- bool pre_arm_check_alt(const char* &fail_msg) const;
-
- bool load_polygon_from_eeprom();
-
- bool polygon_fence_is_breached();
-
- AP_Int8 _enabled;
- AP_Int8 _enabled_fences;
- AP_Int8 _action;
- AP_Float _alt_max;
- AP_Float _alt_min;
- AP_Float _circle_radius;
- AP_Float _margin;
- AP_Int8 _total;
-
- float _alt_max_backup;
- float _circle_radius_backup;
-
- float _alt_max_breach_distance;
- float _circle_breach_distance;
-
- float _home_distance;
- float _curr_alt;
-
- uint8_t _breached_fences;
- uint32_t _breach_time;
- uint16_t _breach_count;
- uint32_t _manual_recovery_start_ms;
-
- AC_PolyFence_loader _poly_loader;
- Vector2f *_boundary = nullptr;
- uint8_t _boundary_num_points = 0;
- bool _boundary_create_attempted = false;
- bool _boundary_valid = false;
- uint32_t _boundary_update_ms;
- };
- namespace AP {
- AC_Fence *fence();
- };
|