Path: blob/master/libraries/AC_Avoidance/AP_OABendyRuler.h
4182 views
#pragma once12#include "AC_Avoidance_config.h"34#if AP_OAPATHPLANNER_BENDYRULER_ENABLED56#include <AP_Common/AP_Common.h>7#include <AP_Common/Location.h>8#include <AP_Math/AP_Math.h>9#include <AP_Logger/AP_Logger_config.h>1011/*12* BendyRuler avoidance algorithm for avoiding the polygon and circular fence and dynamic objects detected by the proximity sensor13*/14class AP_OABendyRuler {15public:16AP_OABendyRuler();1718CLASS_NO_COPY(AP_OABendyRuler); /* Do not allow copies */1920// send configuration info stored in front end parameters21void set_config(float margin_max) { _margin_max = MAX(margin_max, 0.0f); }2223enum class OABendyType {24OA_BENDY_DISABLED = 0,25OA_BENDY_HORIZONTAL = 1,26OA_BENDY_VERTICAL = 2,27};2829// run background task to find best path30// returns true and updates origin_new and destination_new if a best path has been found. returns false if OA is not required31// bendy_type is set to the type of BendyRuler used32bool update(const Location& current_loc, const Location& destination, const Vector2f &ground_speed_vec, Location &origin_new, Location &destination_new, OABendyType &bendy_type, bool proximity_only);3334static const struct AP_Param::GroupInfo var_info[];3536private:3738// return type of BendyRuler in use39OABendyType get_type() const;4041// search for path in XY direction42bool search_xy_path(const Location& current_loc, const Location& destination, float ground_course_deg, Location &destination_new, float lookahead_step_1_dist, float lookahead_step_2_dist, float bearing_to_dest, float distance_to_dest, bool proximity_only);4344// search for path in the Vertical directions45bool search_vertical_path(const Location ¤t_loc, const Location &destination, Location &destination_new, float lookahead_step1_dist, float lookahead_step2_dist, float bearing_to_dest, float distance_to_dest, bool proximity_only);4647// calculate minimum distance between a path and any obstacle48float calc_avoidance_margin(const Location &start, const Location &end, bool proximity_only) const;4950// determine if BendyRuler should accept the new bearing or try and resist it. Returns true if bearing is not changed51bool resist_bearing_change(const Location &destination, const Location ¤t_loc, bool active, float bearing_test, float lookahead_step1_dist, float margin, Location &prev_dest, float &prev_bearing, float &final_bearing, float &final_margin, bool proximity_only) const;5253// calculate minimum distance between a path and the circular fence (centered on home)54// on success returns true and updates margin55bool calc_margin_from_circular_fence(const Location &start, const Location &end, float &margin) const;5657// calculate minimum distance between a path and the altitude fence58// on success returns true and updates margin59bool calc_margin_from_alt_fence(const Location &start, const Location &end, float &margin) const;6061// calculate minimum distance between a path and all inclusion and exclusion polygons62// on success returns true and updates margin63bool calc_margin_from_inclusion_and_exclusion_polygons(const Location &start, const Location &end, float &margin) const;6465// calculate minimum distance between a path and all inclusion and exclusion circles66// on success returns true and updates margin67bool calc_margin_from_inclusion_and_exclusion_circles(const Location &start, const Location &end, float &margin) const;6869// calculate minimum distance between a path and proximity sensor obstacles70// on success returns true and updates margin71bool calc_margin_from_object_database(const Location &start, const Location &end, float &margin) const;7273// Logging function74#if HAL_LOGGING_ENABLED75void Write_OABendyRuler(const uint8_t type, const bool active, const float target_yaw, const float target_pitch, const bool resist_chg, const float margin, const Location &final_dest, const Location &oa_dest) const;76#else77void Write_OABendyRuler(const uint8_t type, const bool active, const float target_yaw, const float target_pitch, const bool resist_chg, const float margin, const Location &final_dest, const Location &oa_dest) const {}78#endif7980// OA common parameters81float _margin_max; // object avoidance will ignore objects more than this many meters from vehicle8283// BendyRuler parameters84AP_Float _lookahead; // object avoidance will look this many meters ahead of vehicle85AP_Float _bendy_ratio; // object avoidance will avoid major directional change if change in margin ratio is less than this param86AP_Int16 _bendy_angle; // object avoidance will try avoiding change in direction over this much angle87AP_Int8 _bendy_type; // Type of BendyRuler to run8889// internal variables used by background thread90float _current_lookahead; // distance (in meters) ahead of the vehicle we are looking for obstacles91float _bearing_prev; // stored bearing in degrees92Location _destination_prev; // previous destination, to check if there has been a change in destination93};9495#endif // AP_OAPATHPLANNER_BENDYRULER_ENABLED969798