2016-10-24 02:46:07 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2022-01-27 20:09:43 -04:00
|
|
|
#include "AP_Beacon_config.h"
|
|
|
|
|
|
|
|
#if AP_BEACON_ENABLED
|
|
|
|
|
2016-10-24 02:46:07 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
2019-04-12 05:37:14 -03:00
|
|
|
#include <AP_Common/Location.h>
|
2016-10-24 02:46:07 -03:00
|
|
|
|
|
|
|
class AP_Beacon_Backend;
|
|
|
|
|
|
|
|
#define AP_BEACON_MAX_BEACONS 4
|
|
|
|
#define AP_BEACON_TIMEOUT_MS 300
|
2017-06-08 03:57:24 -03:00
|
|
|
#define AP_BEACON_MINIMUM_FENCE_BEACONS 3
|
2016-10-24 02:46:07 -03:00
|
|
|
|
|
|
|
class AP_Beacon
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
friend class AP_Beacon_Backend;
|
|
|
|
|
2022-05-31 23:12:32 -03:00
|
|
|
AP_Beacon();
|
2016-10-24 02:46:07 -03:00
|
|
|
|
2019-05-22 03:01:49 -03:00
|
|
|
// get singleton instance
|
|
|
|
static AP_Beacon *get_singleton() { return _singleton; }
|
|
|
|
|
2016-10-24 02:46:07 -03:00
|
|
|
// external position backend types (used by _TYPE parameter)
|
2024-06-23 22:22:18 -03:00
|
|
|
enum class Type : uint8_t {
|
|
|
|
None = 0,
|
|
|
|
Pozyx = 1,
|
|
|
|
Marvelmind = 2,
|
|
|
|
Nooploop = 3,
|
|
|
|
#if AP_BEACON_SITL_ENABLED
|
|
|
|
SITL = 10
|
|
|
|
#endif
|
2016-10-24 02:46:07 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// The AP_BeaconState structure is filled in by the backend driver
|
|
|
|
struct BeaconState {
|
|
|
|
uint16_t id; // unique id of beacon
|
|
|
|
bool healthy; // true if beacon is healthy
|
|
|
|
float distance; // distance from vehicle to beacon (in meters)
|
|
|
|
uint32_t distance_update_ms; // system time of last update from this beacon
|
|
|
|
Vector3f position; // location of beacon as an offset from origin in NED in meters
|
|
|
|
};
|
|
|
|
|
|
|
|
// initialise any available position estimators
|
|
|
|
void init(void);
|
|
|
|
|
|
|
|
// return true if beacon feature is enabled
|
2020-11-08 21:27:27 -04:00
|
|
|
bool enabled(void) const;
|
2016-10-24 02:46:07 -03:00
|
|
|
|
|
|
|
// return true if sensor is basically healthy (we are receiving data)
|
2020-11-08 21:27:27 -04:00
|
|
|
bool healthy(void) const;
|
2016-10-24 02:46:07 -03:00
|
|
|
|
|
|
|
// update state of all beacons
|
|
|
|
void update(void);
|
|
|
|
|
2017-05-08 12:34:55 -03:00
|
|
|
// return origin of position estimate system in lat/lon
|
2016-10-24 02:46:07 -03:00
|
|
|
bool get_origin(Location &origin_loc) const;
|
|
|
|
|
2017-05-08 12:34:55 -03:00
|
|
|
// return vehicle position in NED from position estimate system's origin in meters
|
2016-10-24 02:46:07 -03:00
|
|
|
bool get_vehicle_position_ned(Vector3f& pos, float& accuracy_estimate) const;
|
|
|
|
|
|
|
|
// return the number of beacons
|
|
|
|
uint8_t count() const;
|
|
|
|
|
|
|
|
// methods to return beacon specific information
|
|
|
|
|
|
|
|
// return all beacon data
|
|
|
|
bool get_beacon_data(uint8_t beacon_instance, struct BeaconState& state) const;
|
|
|
|
|
|
|
|
// return individual beacon's id
|
|
|
|
uint8_t beacon_id(uint8_t beacon_instance) const;
|
|
|
|
|
|
|
|
// return beacon health
|
|
|
|
bool beacon_healthy(uint8_t beacon_instance) const;
|
|
|
|
|
|
|
|
// return distance to beacon in meters
|
|
|
|
float beacon_distance(uint8_t beacon_instance) const;
|
|
|
|
|
2017-05-08 12:34:55 -03:00
|
|
|
// return NED position of beacon in meters relative to the beacon systems origin
|
2016-10-24 02:46:07 -03:00
|
|
|
Vector3f beacon_position(uint8_t beacon_instance) const;
|
|
|
|
|
2017-05-08 12:34:55 -03:00
|
|
|
// return last update time from beacon in milliseconds
|
2016-10-24 02:46:07 -03:00
|
|
|
uint32_t beacon_last_update_ms(uint8_t beacon_instance) const;
|
|
|
|
|
2017-06-08 03:58:15 -03:00
|
|
|
// update fence boundary array
|
|
|
|
void update_boundary_points();
|
|
|
|
|
2017-06-08 03:57:24 -03:00
|
|
|
// return fence boundary array
|
|
|
|
const Vector2f* get_boundary_points(uint16_t& num_points) const;
|
|
|
|
|
2016-10-24 02:46:07 -03:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
2022-03-03 21:31:25 -04:00
|
|
|
// a method for vehicles to call to make onboard log messages:
|
|
|
|
void log();
|
|
|
|
|
2016-10-24 02:46:07 -03:00
|
|
|
private:
|
2016-12-09 13:33:25 -04:00
|
|
|
|
2019-05-22 03:01:49 -03:00
|
|
|
static AP_Beacon *_singleton;
|
|
|
|
|
2016-12-09 13:33:25 -04:00
|
|
|
// check if device is ready
|
|
|
|
bool device_ready(void) const;
|
|
|
|
|
2017-06-08 03:58:15 -03:00
|
|
|
// find next boundary point from an array of boundary points given the current index into that array
|
|
|
|
// returns true if a next point can be found
|
|
|
|
// current_index should be an index into the boundary_pts array
|
|
|
|
// start_angle is an angle (in radians), the search will sweep clockwise from this angle
|
|
|
|
// the index of the next point is returned in the next_index argument
|
|
|
|
// the angle to the next point is returned in the next_angle argument
|
|
|
|
static bool get_next_boundary_point(const Vector2f* boundary, uint8_t num_points, uint8_t current_index, float start_angle, uint8_t& next_index, float& next_angle);
|
|
|
|
|
2016-10-24 02:46:07 -03:00
|
|
|
// parameters
|
2024-06-23 22:22:18 -03:00
|
|
|
AP_Enum<Type> _type;
|
2016-10-24 02:46:07 -03:00
|
|
|
AP_Float origin_lat;
|
|
|
|
AP_Float origin_lon;
|
|
|
|
AP_Float origin_alt;
|
|
|
|
AP_Int16 orient_yaw;
|
|
|
|
|
|
|
|
// external references
|
|
|
|
AP_Beacon_Backend *_driver;
|
|
|
|
|
|
|
|
// last known position
|
|
|
|
Vector3f veh_pos_ned;
|
|
|
|
float veh_pos_accuracy;
|
|
|
|
uint32_t veh_pos_update_ms;
|
|
|
|
|
|
|
|
// individual beacon data
|
|
|
|
uint8_t num_beacons = 0;
|
|
|
|
BeaconState beacon_state[AP_BEACON_MAX_BEACONS];
|
2017-06-08 03:57:24 -03:00
|
|
|
|
|
|
|
// fence boundary
|
2017-06-08 03:58:15 -03:00
|
|
|
Vector2f boundary[AP_BEACON_MAX_BEACONS+1]; // array of boundary points (used for fence)
|
|
|
|
uint8_t boundary_num_points; // number of points in boundary
|
|
|
|
uint8_t boundary_num_beacons; // total number of beacon points consumed while building boundary
|
2016-10-24 02:46:07 -03:00
|
|
|
};
|
2019-05-22 03:01:49 -03:00
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_Beacon *beacon();
|
|
|
|
};
|
2022-01-27 20:09:43 -04:00
|
|
|
|
|
|
|
#endif // AP_BEACON_ENABLED
|