2014-04-06 21:35:40 -03:00
|
|
|
/// @file AP_Rally.h
|
|
|
|
/// @brief Handles rally point storage, retrieval and lookup
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The AP_Rally library:
|
|
|
|
*
|
|
|
|
* Initial implementation: Michael Day, September 2013
|
|
|
|
* Moved to AP_Rally lib: Andrew Chapman April 2014
|
|
|
|
*
|
|
|
|
* - responsible for managing a list of rally points
|
|
|
|
* - reads and writes the rally points to storage
|
|
|
|
* - provides access to the rally points, including logic to find the nearest one
|
|
|
|
*
|
|
|
|
*/
|
2016-02-17 21:25:43 -04:00
|
|
|
#pragma once
|
2014-04-06 21:35:40 -03:00
|
|
|
|
2015-08-11 03:28:45 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
2019-02-18 05:33:09 -04:00
|
|
|
#include <AP_Common/Location.h>
|
2015-08-11 03:28:45 -03:00
|
|
|
#include <AP_Param/AP_Param.h>
|
2014-04-06 21:35:40 -03:00
|
|
|
|
2014-08-13 01:43:28 -03:00
|
|
|
#define AP_RALLY_WP_SIZE 15 // eeprom size of rally points
|
2014-04-19 02:44:25 -03:00
|
|
|
|
|
|
|
struct PACKED RallyLocation {
|
|
|
|
int32_t lat; //Latitude * 10^7
|
|
|
|
int32_t lng; //Longitude * 10^7
|
2014-08-14 09:10:21 -03:00
|
|
|
int16_t alt; //transit altitude (and loiter altitude) in meters (absolute);
|
2014-04-19 02:44:25 -03:00
|
|
|
int16_t break_alt; //when autolanding, break out of loiter at this alt (meters)
|
|
|
|
uint16_t land_dir; //when the time comes to auto-land, try to land in this direction (centidegrees)
|
|
|
|
uint8_t flags; //bit 0 = seek favorable winds when choosing a landing poi
|
|
|
|
//bit 1 = do auto land after arriving
|
|
|
|
//all other bits are for future use.
|
|
|
|
};
|
|
|
|
|
2014-04-06 21:35:40 -03:00
|
|
|
/// @class AP_Rally
|
|
|
|
/// @brief Object managing Rally Points
|
|
|
|
class AP_Rally {
|
|
|
|
public:
|
2019-02-18 05:33:09 -04:00
|
|
|
AP_Rally();
|
2017-08-29 20:19:58 -03:00
|
|
|
|
|
|
|
/* Do not allow copies */
|
|
|
|
AP_Rally(const AP_Rally &other) = delete;
|
|
|
|
AP_Rally &operator=(const AP_Rally&) = delete;
|
2014-04-06 21:35:40 -03:00
|
|
|
|
|
|
|
// data handling
|
|
|
|
bool get_rally_point_with_index(uint8_t i, RallyLocation &ret) const;
|
|
|
|
bool set_rally_point_with_index(uint8_t i, const RallyLocation &rallyLoc);
|
|
|
|
uint8_t get_rally_total() const { return _rally_point_total_count; }
|
2014-08-13 01:43:28 -03:00
|
|
|
uint8_t get_rally_max(void) const { return _storage.size() / AP_RALLY_WP_SIZE; }
|
2014-04-06 21:35:40 -03:00
|
|
|
|
2014-04-21 18:30:06 -03:00
|
|
|
float get_rally_limit_km() const { return _rally_limit_km; }
|
2017-08-29 20:19:58 -03:00
|
|
|
|
2014-04-21 18:30:06 -03:00
|
|
|
Location rally_location_to_location(const RallyLocation &ret) const;
|
|
|
|
|
2014-04-06 21:35:40 -03:00
|
|
|
// logic handling
|
|
|
|
Location calc_best_rally_or_home_location(const Location ¤t_loc, float rtl_home_alt) const;
|
|
|
|
bool find_nearest_rally_point(const Location &myloc, RallyLocation &ret) const;
|
|
|
|
|
2014-08-06 03:35:43 -03:00
|
|
|
// last time rally points changed
|
|
|
|
uint32_t last_change_time_ms(void) const { return _last_change_time_ms; }
|
|
|
|
|
2014-04-06 21:35:40 -03:00
|
|
|
// parameter block
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
2018-12-25 01:17:15 -04:00
|
|
|
// get singleton instance
|
|
|
|
static AP_Rally *get_singleton() { return _singleton; }
|
|
|
|
|
|
|
|
|
2014-04-06 21:35:40 -03:00
|
|
|
private:
|
2018-12-25 01:17:15 -04:00
|
|
|
static AP_Rally *_singleton;
|
|
|
|
|
2016-07-19 19:40:22 -03:00
|
|
|
virtual bool is_valid(const Location &rally_point) const { return true; }
|
|
|
|
|
2014-08-13 01:43:28 -03:00
|
|
|
static StorageAccess _storage;
|
|
|
|
|
2014-04-06 21:35:40 -03:00
|
|
|
// parameters
|
|
|
|
AP_Int8 _rally_point_total_count;
|
|
|
|
AP_Float _rally_limit_km;
|
2015-08-04 08:12:53 -03:00
|
|
|
AP_Int8 _rally_incl_home;
|
2014-08-06 03:35:43 -03:00
|
|
|
|
2019-02-18 05:33:09 -04:00
|
|
|
uint32_t _last_change_time_ms = 0xFFFFFFFF;
|
2014-04-06 21:35:40 -03:00
|
|
|
};
|
2018-12-25 01:17:15 -04:00
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_Rally *rally();
|
|
|
|
};
|