PX4 Firmware
PX4 Autopilot Software http://px4.io
|
#include <geofence.h>
Classes | |
struct | PolygonInfo |
Public Types | |
enum | { GF_ALT_MODE_WGS84 = 0, GF_ALT_MODE_AMSL = 1 } |
enum | { GF_SOURCE_GLOBALPOS = 0, GF_SOURCE_GPS = 1 } |
Public Member Functions | |
Geofence (Navigator *navigator) | |
Geofence (const Geofence &)=delete | |
Geofence & | operator= (const Geofence &)=delete |
~Geofence () | |
void | updateFence () |
update the geofence from dataman. More... | |
bool | check (const vehicle_global_position_s &global_position, const vehicle_gps_position_s &gps_position, const home_position_s home_pos, bool home_position_set) |
Return whether the system obeys the geofence. More... | |
bool | check (const struct mission_item_s &mission_item) |
Return whether a mission item obeys the geofence. More... | |
int | clearDm () |
bool | valid () |
int | loadFromFile (const char *filename) |
Load a single inclusion polygon, replacing any already existing polygons. More... | |
bool | isEmpty () |
int | getAltitudeMode () |
int | getSource () |
int | getGeofenceAction () |
bool | isHomeRequired () |
void | printStatus () |
print Geofence status to the console More... | |
Private Member Functions | |
void | _updateFence () |
implementation of updateFence(), but without locking More... | |
bool | checkPolygons (double lat, double lon, float altitude) |
Check if a point passes the Geofence test. More... | |
bool | checkAll (double lat, double lon, float altitude) |
Check if a point passes the Geofence test. More... | |
bool | checkAll (const vehicle_global_position_s &global_position) |
bool | checkAll (const vehicle_global_position_s &global_position, float baro_altitude_amsl) |
bool | insidePolygon (const PolygonInfo &polygon, double lat, double lon, float altitude) |
Check if a single point is within a polygon. More... | |
bool | insideCircle (const PolygonInfo &polygon, double lat, double lon, float altitude) |
Check if a single point is within a circle. More... | |
Private Attributes | |
Navigator * | _navigator {nullptr} |
hrt_abstime | _last_horizontal_range_warning {0} |
hrt_abstime | _last_vertical_range_warning {0} |
float | _altitude_min {0.0f} |
float | _altitude_max {0.0f} |
PolygonInfo * | _polygons {nullptr} |
int | _num_polygons {0} |
map_projection_reference_s | _projection_reference = {} |
reference to convert (lon, lat) to local [m] More... | |
DEFINE_PARAMETERS((ParamInt< px4::params::GF_ACTION >) _param_gf_action,(ParamInt< px4::params::GF_ALTMODE >) _param_gf_altmode,(ParamInt< px4::params::GF_SOURCE >) _param_gf_source,(ParamInt< px4::params::GF_COUNT >) _param_gf_count,(ParamFloat< px4::params::GF_MAX_HOR_DIST >) _param_gf_max_hor_dist,(ParamFloat< px4::params::GF_MAX_VER_DIST >) _param_gf_max_ver_dist) uORB int | _outside_counter {0} |
uint16_t | _update_counter {0} |
dataman update counter: if it does not match, we polygon data was updated More... | |
Definition at line 59 of file geofence.h.
anonymous enum |
Enumerator | |
---|---|
GF_ALT_MODE_WGS84 | |
GF_ALT_MODE_AMSL |
Definition at line 68 of file geofence.h.
anonymous enum |
Enumerator | |
---|---|
GF_SOURCE_GLOBALPOS | |
GF_SOURCE_GPS |
Definition at line 74 of file geofence.h.
Geofence::Geofence | ( | Navigator * | navigator | ) |
Definition at line 55 of file geofence.cpp.
References _updateFence().
|
delete |
Geofence::~Geofence | ( | ) |
Definition at line 64 of file geofence.cpp.
References _polygons.
|
private |
implementation of updateFence(), but without locking
Definition at line 86 of file geofence.cpp.
References _num_polygons, _polygons, _update_counter, vehicle_global_position_s::alt, checkAll(), Geofence::PolygonInfo::circle_radius, mission_fence_point_s::circle_radius, Geofence::PolygonInfo::dataman_index, DM_KEY_FENCE_POINTS, dm_read(), Geofence::PolygonInfo::fence_type, vehicle_global_position_s::lat, vehicle_global_position_s::lon, mission_fence_point_s::nav_cmd, NAV_CMD_FENCE_CIRCLE_EXCLUSION, NAV_CMD_FENCE_CIRCLE_INCLUSION, NAV_CMD_FENCE_POLYGON_VERTEX_EXCLUSION, NAV_CMD_FENCE_POLYGON_VERTEX_INCLUSION, NAV_CMD_FENCE_RETURN_POINT, mission_stats_entry_s::num_items, mission_stats_entry_s::update_counter, Geofence::PolygonInfo::vertex_count, and mission_fence_point_s::vertex_count.
Referenced by checkPolygons(), Geofence(), and updateFence().
bool Geofence::check | ( | const vehicle_global_position_s & | global_position, |
const vehicle_gps_position_s & | gps_position, | ||
const home_position_s | home_pos, | ||
bool | home_position_set | ||
) |
Return whether the system obeys the geofence.
Definition at line 190 of file geofence.cpp.
References vehicle_gps_position_s::alt, checkAll(), getAltitudeMode(), getSource(), GF_ALT_MODE_WGS84, GF_SOURCE_GLOBALPOS, vehicle_gps_position_s::lat, and vehicle_gps_position_s::lon.
Referenced by MissionFeasibilityChecker::checkGeofence(), and Navigator::run().
bool Geofence::check | ( | const struct mission_item_s & | mission_item | ) |
Return whether a mission item obeys the geofence.
Definition at line 216 of file geofence.cpp.
References mission_item_s::altitude, checkAll(), mission_item_s::lat, and mission_item_s::lon.
|
private |
Check if a point passes the Geofence test.
In addition to checkPolygons(), this takes all additional parameters into account.
Definition at line 221 of file geofence.cpp.
References _last_horizontal_range_warning, _last_vertical_range_warning, _navigator, _outside_counter, home_position_s::alt, checkPolygons(), FLT_EPSILON, GEOFENCE_RANGE_WARNING_LIMIT, get_distance_to_point_global_wgs84(), Navigator::get_home_position(), Navigator::get_mavlink_log_pub(), Navigator::home_position_valid(), hrt_absolute_time(), hrt_elapsed_time(), isHomeRequired(), home_position_s::lat, home_position_s::lon, and mavlink_log_critical.
Referenced by _updateFence(), and check().
|
private |
|
private |
|
private |
Check if a point passes the Geofence test.
This takes all polygons and minimum & maximum altitude into account
The check passes if: (inside(polygon_inclusion_1) || inside(polygon_inclusion_2) || ... ) && !inside(polygon_exclusion_1) && !inside(polygon_exclusion_2) && ... && (altitude within [min, max]) or: no polygon configured
Definition at line 281 of file geofence.cpp.
References _altitude_max, _altitude_min, _num_polygons, _polygons, _update_counter, _updateFence(), DM_KEY_FENCE_POINTS, dm_read(), dm_trylock(), dm_unlock(), insideCircle(), insidePolygon(), isEmpty(), NAV_CMD_FENCE_CIRCLE_EXCLUSION, NAV_CMD_FENCE_CIRCLE_INCLUSION, NAV_CMD_FENCE_POLYGON_VERTEX_INCLUSION, and mission_stats_entry_s::update_counter.
Referenced by checkAll().
int Geofence::clearDm | ( | ) |
Definition at line 562 of file geofence.cpp.
References dm_clear(), DM_KEY_FENCE_POINTS, and updateFence().
Referenced by loadFromFile().
|
inline |
Definition at line 127 of file geofence.h.
Referenced by check().
|
inline |
Definition at line 129 of file geofence.h.
References isHomeRequired(), and printStatus().
Referenced by isHomeRequired(), and Navigator::run().
|
inline |
Definition at line 128 of file geofence.h.
Referenced by check(), and Navigator::run().
|
private |
Check if a single point is within a circle.
polygon | must be a circle! |
Definition at line 399 of file geofence.cpp.
References _projection_reference, mission_fence_point_s::circle_radius, Geofence::PolygonInfo::dataman_index, DM_KEY_FENCE_POINTS, dm_read(), mission_fence_point_s::frame, mission_fence_point_s::lat, mission_fence_point_s::lon, map_projection_init(), map_projection_initialized(), map_projection_project(), NAV_FRAME_GLOBAL, NAV_FRAME_GLOBAL_INT, NAV_FRAME_GLOBAL_RELATIVE_ALT, and NAV_FRAME_GLOBAL_RELATIVE_ALT_INT.
Referenced by checkPolygons().
|
private |
Check if a single point is within a polygon.
Definition at line 357 of file geofence.cpp.
References Geofence::PolygonInfo::dataman_index, DM_KEY_FENCE_POINTS, dm_read(), mission_fence_point_s::frame, mission_fence_point_s::lat, mission_fence_point_s::lon, NAV_FRAME_GLOBAL, NAV_FRAME_GLOBAL_INT, NAV_FRAME_GLOBAL_RELATIVE_ALT, NAV_FRAME_GLOBAL_RELATIVE_ALT_INT, and Geofence::PolygonInfo::vertex_count.
Referenced by checkPolygons().
|
inline |
Definition at line 125 of file geofence.h.
References _num_polygons.
Referenced by checkPolygons().
bool Geofence::isHomeRequired | ( | ) |
Definition at line 569 of file geofence.cpp.
References FLT_EPSILON, and getGeofenceAction().
Referenced by checkAll(), MissionFeasibilityChecker::checkGeofence(), getGeofenceAction(), and Navigator::run().
int Geofence::loadFromFile | ( | const char * | filename | ) |
Load a single inclusion polygon, replacing any already existing polygons.
The file has one of the following formats:
Where the first line is min, max altitude in meters AMSL.
Definition at line 436 of file geofence.cpp.
References _altitude_max, _altitude_min, _navigator, mission_fence_point_s::alt, clearDm(), DM_KEY_FENCE_POINTS, DM_PERSIST_POWER_ON_RESET, dm_read(), dm_write(), mission_fence_point_s::frame, GEOFENCE_FILENAME, Navigator::get_mavlink_log_pub(), mission_fence_point_s::lat, mission_fence_point_s::lon, mavlink_log_critical, mavlink_log_info, mission_fence_point_s::nav_cmd, NAV_CMD_FENCE_POLYGON_VERTEX_INCLUSION, NAV_FRAME_GLOBAL, mission_stats_entry_s::num_items, updateFence(), and mission_fence_point_s::vertex_count.
Referenced by Navigator::load_fence_from_file(), and Navigator::run().
void Geofence::printStatus | ( | ) |
print Geofence status to the console
Definition at line 578 of file geofence.cpp.
References _num_polygons, _polygons, NAV_CMD_FENCE_CIRCLE_EXCLUSION, NAV_CMD_FENCE_CIRCLE_INCLUSION, NAV_CMD_FENCE_POLYGON_VERTEX_EXCLUSION, NAV_CMD_FENCE_POLYGON_VERTEX_INCLUSION, and Geofence::PolygonInfo::vertex_count.
Referenced by getGeofenceAction(), and Navigator::print_status().
void Geofence::updateFence | ( | ) |
update the geofence from dataman.
It's generally not necessary to call this as it will automatically update when the data is changed.
Definition at line 71 of file geofence.cpp.
References _updateFence(), DM_KEY_FENCE_POINTS, dm_lock(), and dm_unlock().
Referenced by clearDm(), and loadFromFile().
bool Geofence::valid | ( | ) |
Definition at line 430 of file geofence.cpp.
Referenced by MissionFeasibilityChecker::checkGeofence().
|
private |
Definition at line 145 of file geofence.h.
Referenced by checkPolygons(), and loadFromFile().
|
private |
Definition at line 144 of file geofence.h.
Referenced by checkPolygons(), and loadFromFile().
|
private |
Definition at line 141 of file geofence.h.
Referenced by checkAll().
|
private |
Definition at line 142 of file geofence.h.
Referenced by checkAll().
|
private |
Definition at line 139 of file geofence.h.
Referenced by checkAll(), and loadFromFile().
|
private |
Definition at line 156 of file geofence.h.
Referenced by _updateFence(), checkPolygons(), isEmpty(), and printStatus().
|
private |
Definition at line 171 of file geofence.h.
Referenced by checkAll().
|
private |
Definition at line 155 of file geofence.h.
Referenced by _updateFence(), checkPolygons(), printStatus(), and ~Geofence().
|
private |
reference to convert (lon, lat) to local [m]
Definition at line 158 of file geofence.h.
Referenced by insideCircle().
|
private |
dataman update counter: if it does not match, we polygon data was updated
Definition at line 172 of file geofence.h.
Referenced by _updateFence(), and checkPolygons().