2016-08-15 03:17:15 -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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "AP_Proximity.h"
|
2019-11-13 07:10:53 -04:00
|
|
|
#include "AP_Proximity_LightWareSF40C_v09.h"
|
2017-07-07 13:04:55 -03:00
|
|
|
#include "AP_Proximity_RPLidarA2.h"
|
2017-02-03 00:36:03 -04:00
|
|
|
#include "AP_Proximity_TeraRangerTower.h"
|
2018-06-15 06:08:01 -03:00
|
|
|
#include "AP_Proximity_TeraRangerTowerEvo.h"
|
2017-02-09 07:30:04 -04:00
|
|
|
#include "AP_Proximity_RangeFinder.h"
|
2016-12-23 02:03:21 -04:00
|
|
|
#include "AP_Proximity_MAV.h"
|
2019-11-13 04:46:29 -04:00
|
|
|
#include "AP_Proximity_LightWareSF40C.h"
|
2016-11-14 00:48:38 -04:00
|
|
|
#include "AP_Proximity_SITL.h"
|
2018-12-04 01:54:20 -04:00
|
|
|
#include "AP_Proximity_MorseSITL.h"
|
2019-07-10 19:15:58 -03:00
|
|
|
#include "AP_Proximity_AirSimSITL.h"
|
2019-05-12 23:53:50 -03:00
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
2016-08-15 03:17:15 -03:00
|
|
|
|
|
|
|
extern const AP_HAL::HAL &hal;
|
|
|
|
|
|
|
|
// table of user settable parameters
|
|
|
|
const AP_Param::GroupInfo AP_Proximity::var_info[] = {
|
|
|
|
// 0 is reserved for possible addition of an ENABLED parameter
|
|
|
|
|
|
|
|
// @Param: _TYPE
|
|
|
|
// @DisplayName: Proximity type
|
|
|
|
// @Description: What type of proximity sensor is connected
|
2019-11-13 04:46:29 -04:00
|
|
|
// @Values: 0:None,7:LightwareSF40c,1:LightWareSF40C-legacy,2:MAVLink,3:TeraRangerTower,4:RangeFinder,5:RPLidarA2,6:TeraRangerTowerEvo,10:SITL,11:MorseSITL,12:AirSimSITL
|
2017-05-12 10:36:35 -03:00
|
|
|
// @RebootRequired: True
|
2016-08-15 03:17:15 -03:00
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_TYPE", 1, AP_Proximity, _type[0], 0),
|
|
|
|
|
|
|
|
// @Param: _ORIENT
|
|
|
|
// @DisplayName: Proximity sensor orientation
|
|
|
|
// @Description: Proximity sensor orientation
|
|
|
|
// @Values: 0:Default,1:Upside Down
|
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_ORIENT", 2, AP_Proximity, _orientation[0], 0),
|
|
|
|
|
|
|
|
// @Param: _YAW_CORR
|
|
|
|
// @DisplayName: Proximity sensor yaw correction
|
|
|
|
// @Description: Proximity sensor yaw correction
|
2017-05-02 10:47:15 -03:00
|
|
|
// @Units: deg
|
2016-08-15 03:17:15 -03:00
|
|
|
// @Range: -180 180
|
|
|
|
// @User: Standard
|
2019-05-20 02:54:33 -03:00
|
|
|
AP_GROUPINFO("_YAW_CORR", 3, AP_Proximity, _yaw_correction[0], 0),
|
2016-08-15 03:17:15 -03:00
|
|
|
|
2016-11-15 03:27:34 -04:00
|
|
|
// @Param: _IGN_ANG1
|
|
|
|
// @DisplayName: Proximity sensor ignore angle 1
|
|
|
|
// @Description: Proximity sensor ignore angle 1
|
2017-05-02 10:47:15 -03:00
|
|
|
// @Units: deg
|
2016-11-15 03:27:34 -04:00
|
|
|
// @Range: 0 360
|
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_IGN_ANG1", 4, AP_Proximity, _ignore_angle_deg[0], 0),
|
|
|
|
|
|
|
|
// @Param: _IGN_WID1
|
|
|
|
// @DisplayName: Proximity sensor ignore width 1
|
|
|
|
// @Description: Proximity sensor ignore width 1
|
2017-05-02 10:47:15 -03:00
|
|
|
// @Units: deg
|
2016-11-15 03:27:34 -04:00
|
|
|
// @Range: 0 45
|
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_IGN_WID1", 5, AP_Proximity, _ignore_width_deg[0], 0),
|
|
|
|
|
|
|
|
// @Param: _IGN_ANG2
|
|
|
|
// @DisplayName: Proximity sensor ignore angle 2
|
|
|
|
// @Description: Proximity sensor ignore angle 2
|
2017-05-02 10:47:15 -03:00
|
|
|
// @Units: deg
|
2016-11-15 03:27:34 -04:00
|
|
|
// @Range: 0 360
|
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_IGN_ANG2", 6, AP_Proximity, _ignore_angle_deg[1], 0),
|
|
|
|
|
2017-03-01 01:58:26 -04:00
|
|
|
// @Param: _IGN_WID2
|
2016-11-15 03:27:34 -04:00
|
|
|
// @DisplayName: Proximity sensor ignore width 2
|
|
|
|
// @Description: Proximity sensor ignore width 2
|
2017-05-02 10:47:15 -03:00
|
|
|
// @Units: deg
|
2016-11-15 03:27:34 -04:00
|
|
|
// @Range: 0 45
|
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_IGN_WID2", 7, AP_Proximity, _ignore_width_deg[1], 0),
|
|
|
|
|
|
|
|
// @Param: _IGN_ANG3
|
|
|
|
// @DisplayName: Proximity sensor ignore angle 3
|
|
|
|
// @Description: Proximity sensor ignore angle 3
|
2017-05-02 10:47:15 -03:00
|
|
|
// @Units: deg
|
2016-11-15 03:27:34 -04:00
|
|
|
// @Range: 0 360
|
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_IGN_ANG3", 8, AP_Proximity, _ignore_angle_deg[2], 0),
|
|
|
|
|
|
|
|
// @Param: _IGN_WID3
|
|
|
|
// @DisplayName: Proximity sensor ignore width 3
|
|
|
|
// @Description: Proximity sensor ignore width 3
|
2017-05-02 10:47:15 -03:00
|
|
|
// @Units: deg
|
2016-11-15 03:27:34 -04:00
|
|
|
// @Range: 0 45
|
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_IGN_WID3", 9, AP_Proximity, _ignore_width_deg[2], 0),
|
|
|
|
|
|
|
|
// @Param: _IGN_ANG4
|
|
|
|
// @DisplayName: Proximity sensor ignore angle 4
|
|
|
|
// @Description: Proximity sensor ignore angle 4
|
2017-05-02 10:47:15 -03:00
|
|
|
// @Units: deg
|
2016-11-15 03:27:34 -04:00
|
|
|
// @Range: 0 360
|
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_IGN_ANG4", 10, AP_Proximity, _ignore_angle_deg[3], 0),
|
|
|
|
|
|
|
|
// @Param: _IGN_WID4
|
|
|
|
// @DisplayName: Proximity sensor ignore width 4
|
|
|
|
// @Description: Proximity sensor ignore width 4
|
2017-05-02 10:47:15 -03:00
|
|
|
// @Units: deg
|
2016-11-15 03:27:34 -04:00
|
|
|
// @Range: 0 45
|
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_IGN_WID4", 11, AP_Proximity, _ignore_width_deg[3], 0),
|
|
|
|
|
|
|
|
// @Param: _IGN_ANG5
|
|
|
|
// @DisplayName: Proximity sensor ignore angle 5
|
|
|
|
// @Description: Proximity sensor ignore angle 5
|
2017-05-02 10:47:15 -03:00
|
|
|
// @Units: deg
|
2016-11-15 03:27:34 -04:00
|
|
|
// @Range: 0 360
|
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_IGN_ANG5", 12, AP_Proximity, _ignore_angle_deg[4], 0),
|
|
|
|
|
|
|
|
// @Param: _IGN_WID5
|
|
|
|
// @DisplayName: Proximity sensor ignore width 5
|
|
|
|
// @Description: Proximity sensor ignore width 5
|
2017-05-02 10:47:15 -03:00
|
|
|
// @Units: deg
|
2016-11-15 03:27:34 -04:00
|
|
|
// @Range: 0 45
|
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_IGN_WID5", 13, AP_Proximity, _ignore_width_deg[4], 0),
|
|
|
|
|
|
|
|
// @Param: _IGN_ANG6
|
|
|
|
// @DisplayName: Proximity sensor ignore angle 6
|
|
|
|
// @Description: Proximity sensor ignore angle 6
|
2017-05-02 10:47:15 -03:00
|
|
|
// @Units: deg
|
2016-11-15 03:27:34 -04:00
|
|
|
// @Range: 0 360
|
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_IGN_ANG6", 14, AP_Proximity, _ignore_angle_deg[5], 0),
|
|
|
|
|
|
|
|
// @Param: _IGN_WID6
|
|
|
|
// @DisplayName: Proximity sensor ignore width 6
|
|
|
|
// @Description: Proximity sensor ignore width 6
|
2017-05-02 10:47:15 -03:00
|
|
|
// @Units: deg
|
2016-11-15 03:27:34 -04:00
|
|
|
// @Range: 0 45
|
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_IGN_WID6", 15, AP_Proximity, _ignore_width_deg[5], 0),
|
|
|
|
|
2016-08-15 03:17:15 -03:00
|
|
|
#if PROXIMITY_MAX_INSTANCES > 1
|
|
|
|
// @Param: 2_TYPE
|
|
|
|
// @DisplayName: Second Proximity type
|
|
|
|
// @Description: What type of proximity sensor is connected
|
2019-11-13 04:46:29 -04:00
|
|
|
// @Values: 0:None,7:LightwareSF40c,1:LightWareSF40C-legacy,2:MAVLink,3:TeraRangerTower,4:RangeFinder,5:RPLidarA2,6:TeraRangerTowerEvo,10:SITL,11:MorseSITL,12:AirSimSITL
|
2016-08-15 03:17:15 -03:00
|
|
|
// @User: Advanced
|
2017-05-12 10:36:35 -03:00
|
|
|
// @RebootRequired: True
|
2016-11-15 03:27:34 -04:00
|
|
|
AP_GROUPINFO("2_TYPE", 16, AP_Proximity, _type[1], 0),
|
2016-08-15 03:17:15 -03:00
|
|
|
|
2017-01-05 14:07:14 -04:00
|
|
|
// @Param: 2_ORIENT
|
2016-08-15 03:17:15 -03:00
|
|
|
// @DisplayName: Second Proximity sensor orientation
|
|
|
|
// @Description: Second Proximity sensor orientation
|
|
|
|
// @Values: 0:Default,1:Upside Down
|
|
|
|
// @User: Standard
|
2016-11-15 03:27:34 -04:00
|
|
|
AP_GROUPINFO("2_ORIENT", 17, AP_Proximity, _orientation[1], 0),
|
2016-08-15 03:17:15 -03:00
|
|
|
|
2017-01-05 14:07:14 -04:00
|
|
|
// @Param: 2_YAW_CORR
|
2016-08-15 03:17:15 -03:00
|
|
|
// @DisplayName: Second Proximity sensor yaw correction
|
|
|
|
// @Description: Second Proximity sensor yaw correction
|
2017-05-02 10:47:15 -03:00
|
|
|
// @Units: deg
|
2016-08-15 03:17:15 -03:00
|
|
|
// @Range: -180 180
|
|
|
|
// @User: Standard
|
2019-05-20 02:54:33 -03:00
|
|
|
AP_GROUPINFO("2_YAW_CORR", 18, AP_Proximity, _yaw_correction[1], 0),
|
2016-08-15 03:17:15 -03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
AP_GROUPEND
|
|
|
|
};
|
|
|
|
|
2019-09-27 05:06:44 -03:00
|
|
|
AP_Proximity::AP_Proximity()
|
2016-08-15 03:17:15 -03:00
|
|
|
{
|
|
|
|
AP_Param::setup_object_defaults(this, var_info);
|
2018-05-09 04:45:43 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
|
|
|
if (_singleton != nullptr) {
|
|
|
|
AP_HAL::panic("AP_Proximity must be singleton");
|
|
|
|
}
|
|
|
|
#endif // CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
|
|
|
_singleton = this;
|
2016-08-15 03:17:15 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// initialise the Proximity class. We do detection of attached sensors here
|
|
|
|
// we don't allow for hot-plugging of sensors (i.e. reboot required)
|
|
|
|
void AP_Proximity::init(void)
|
|
|
|
{
|
|
|
|
if (num_instances != 0) {
|
|
|
|
// init called a 2nd time?
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (uint8_t i=0; i<PROXIMITY_MAX_INSTANCES; i++) {
|
|
|
|
detect_instance(i);
|
2016-10-30 02:24:21 -03:00
|
|
|
if (drivers[i] != nullptr) {
|
2016-08-15 03:17:15 -03:00
|
|
|
// we loaded a driver for this instance, so it must be
|
|
|
|
// present (although it may not be healthy)
|
|
|
|
num_instances = i+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialise status
|
2019-09-27 05:58:52 -03:00
|
|
|
state[i].status = Status::NotConnected;
|
2016-08-15 03:17:15 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update Proximity state for all instances. This should be called at a high rate by the main loop
|
|
|
|
void AP_Proximity::update(void)
|
|
|
|
{
|
|
|
|
for (uint8_t i=0; i<num_instances; i++) {
|
2019-09-27 05:48:49 -03:00
|
|
|
if (!valid_instance(i)) {
|
|
|
|
continue;
|
2016-08-15 03:17:15 -03:00
|
|
|
}
|
2019-09-27 05:48:49 -03:00
|
|
|
drivers[i]->update();
|
2016-08-15 03:17:15 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// work out primary instance - first sensor returning good data
|
|
|
|
for (int8_t i=num_instances-1; i>=0; i--) {
|
2019-09-27 05:58:52 -03:00
|
|
|
if (drivers[i] != nullptr && (state[i].status == Status::Good)) {
|
2016-08-15 03:17:15 -03:00
|
|
|
primary_instance = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return sensor orientation
|
|
|
|
uint8_t AP_Proximity::get_orientation(uint8_t instance) const
|
|
|
|
{
|
2019-09-27 05:48:49 -03:00
|
|
|
if (!valid_instance(instance)) {
|
2016-08-15 03:17:15 -03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _orientation[instance].get();
|
|
|
|
}
|
|
|
|
|
|
|
|
// return sensor yaw correction
|
|
|
|
int16_t AP_Proximity::get_yaw_correction(uint8_t instance) const
|
|
|
|
{
|
2019-09-27 05:48:49 -03:00
|
|
|
if (!valid_instance(instance)) {
|
2016-08-15 03:17:15 -03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _yaw_correction[instance].get();
|
|
|
|
}
|
|
|
|
|
|
|
|
// return sensor health
|
2019-09-27 05:58:52 -03:00
|
|
|
AP_Proximity::Status AP_Proximity::get_status(uint8_t instance) const
|
2016-08-15 03:17:15 -03:00
|
|
|
{
|
|
|
|
// sanity check instance number
|
2019-09-27 05:48:49 -03:00
|
|
|
if (!valid_instance(instance)) {
|
2019-09-27 05:58:52 -03:00
|
|
|
return Status::NotConnected;
|
2016-08-15 03:17:15 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
return state[instance].status;
|
|
|
|
}
|
|
|
|
|
2019-09-27 05:58:52 -03:00
|
|
|
AP_Proximity::Status AP_Proximity::get_status() const
|
2016-08-15 03:17:15 -03:00
|
|
|
{
|
|
|
|
return get_status(primary_instance);
|
|
|
|
}
|
|
|
|
|
2017-01-09 23:09:18 -04:00
|
|
|
// handle mavlink DISTANCE_SENSOR messages
|
2019-04-30 07:22:49 -03:00
|
|
|
void AP_Proximity::handle_msg(const mavlink_message_t &msg)
|
2017-01-09 23:09:18 -04:00
|
|
|
{
|
|
|
|
for (uint8_t i=0; i<num_instances; i++) {
|
2019-09-27 05:43:39 -03:00
|
|
|
if (valid_instance(i)) {
|
2017-01-09 23:09:18 -04:00
|
|
|
drivers[i]->handle_msg(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-15 03:17:15 -03:00
|
|
|
// detect if an instance of a proximity sensor is connected.
|
|
|
|
void AP_Proximity::detect_instance(uint8_t instance)
|
|
|
|
{
|
2019-09-27 05:43:39 -03:00
|
|
|
switch (get_type(instance)) {
|
|
|
|
case Type::None:
|
|
|
|
return;
|
2019-11-13 07:10:53 -04:00
|
|
|
case Type::SF40C_v09:
|
|
|
|
if (AP_Proximity_LightWareSF40C_v09::detect()) {
|
2016-08-15 03:17:15 -03:00
|
|
|
state[instance].instance = instance;
|
2019-11-13 07:10:53 -04:00
|
|
|
drivers[instance] = new AP_Proximity_LightWareSF40C_v09(*this, state[instance]);
|
2016-08-15 03:17:15 -03:00
|
|
|
return;
|
|
|
|
}
|
2019-09-27 05:43:39 -03:00
|
|
|
break;
|
|
|
|
case Type::RPLidarA2:
|
2019-09-27 05:06:44 -03:00
|
|
|
if (AP_Proximity_RPLidarA2::detect()) {
|
2017-07-07 13:04:55 -03:00
|
|
|
state[instance].instance = instance;
|
2019-09-27 05:06:44 -03:00
|
|
|
drivers[instance] = new AP_Proximity_RPLidarA2(*this, state[instance]);
|
2017-07-07 13:04:55 -03:00
|
|
|
return;
|
|
|
|
}
|
2019-09-27 05:43:39 -03:00
|
|
|
break;
|
|
|
|
case Type::MAV:
|
2016-12-23 02:03:21 -04:00
|
|
|
state[instance].instance = instance;
|
|
|
|
drivers[instance] = new AP_Proximity_MAV(*this, state[instance]);
|
|
|
|
return;
|
2019-09-27 05:43:39 -03:00
|
|
|
|
|
|
|
case Type::TRTOWER:
|
2019-09-27 05:06:44 -03:00
|
|
|
if (AP_Proximity_TeraRangerTower::detect()) {
|
2017-02-03 00:36:03 -04:00
|
|
|
state[instance].instance = instance;
|
2019-09-27 05:06:44 -03:00
|
|
|
drivers[instance] = new AP_Proximity_TeraRangerTower(*this, state[instance]);
|
2017-02-03 00:36:03 -04:00
|
|
|
return;
|
|
|
|
}
|
2019-09-27 05:43:39 -03:00
|
|
|
break;
|
|
|
|
case Type::TRTOWEREVO:
|
2019-09-27 05:06:44 -03:00
|
|
|
if (AP_Proximity_TeraRangerTowerEvo::detect()) {
|
2018-06-15 06:08:01 -03:00
|
|
|
state[instance].instance = instance;
|
2019-09-27 05:06:44 -03:00
|
|
|
drivers[instance] = new AP_Proximity_TeraRangerTowerEvo(*this, state[instance]);
|
2018-06-15 06:08:01 -03:00
|
|
|
return;
|
|
|
|
}
|
2019-09-27 05:43:39 -03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Type::RangeFinder:
|
2017-02-09 07:30:04 -04:00
|
|
|
state[instance].instance = instance;
|
|
|
|
drivers[instance] = new AP_Proximity_RangeFinder(*this, state[instance]);
|
|
|
|
return;
|
2019-09-27 05:43:39 -03:00
|
|
|
|
2019-11-13 04:46:29 -04:00
|
|
|
case Type::SF40C:
|
|
|
|
if (AP_Proximity_LightWareSF40C::detect()) {
|
|
|
|
state[instance].instance = instance;
|
|
|
|
drivers[instance] = new AP_Proximity_LightWareSF40C(*this, state[instance]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-11-14 00:48:38 -04:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
2019-09-27 05:43:39 -03:00
|
|
|
case Type::SITL:
|
2016-11-14 00:48:38 -04:00
|
|
|
state[instance].instance = instance;
|
|
|
|
drivers[instance] = new AP_Proximity_SITL(*this, state[instance]);
|
|
|
|
return;
|
2019-09-27 05:43:39 -03:00
|
|
|
|
|
|
|
case Type::MorseSITL:
|
2018-12-04 01:54:20 -04:00
|
|
|
state[instance].instance = instance;
|
|
|
|
drivers[instance] = new AP_Proximity_MorseSITL(*this, state[instance]);
|
|
|
|
return;
|
2019-09-27 05:43:39 -03:00
|
|
|
|
|
|
|
case Type::AirSimSITL:
|
2019-07-10 19:15:58 -03:00
|
|
|
state[instance].instance = instance;
|
|
|
|
drivers[instance] = new AP_Proximity_AirSimSITL(*this, state[instance]);
|
|
|
|
return;
|
2016-11-14 00:48:38 -04:00
|
|
|
#endif
|
2019-09-27 05:43:39 -03:00
|
|
|
}
|
2016-08-15 03:17:15 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// get distance in meters in a particular direction in degrees (0 is forward, clockwise)
|
|
|
|
// returns true on successful read and places distance in distance
|
|
|
|
bool AP_Proximity::get_horizontal_distance(uint8_t instance, float angle_deg, float &distance) const
|
|
|
|
{
|
2019-09-27 05:43:39 -03:00
|
|
|
if (!valid_instance(instance)) {
|
2016-08-15 03:17:15 -03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// get distance from backend
|
|
|
|
return drivers[instance]->get_horizontal_distance(angle_deg, distance);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get distance in meters in a particular direction in degrees (0 is forward, clockwise)
|
|
|
|
// returns true on successful read and places distance in distance
|
|
|
|
bool AP_Proximity::get_horizontal_distance(float angle_deg, float &distance) const
|
|
|
|
{
|
|
|
|
return get_horizontal_distance(primary_instance, angle_deg, distance);
|
|
|
|
}
|
2016-11-15 03:15:46 -04:00
|
|
|
|
2017-04-12 06:00:41 -03:00
|
|
|
// get distances in 8 directions. used for sending distances to ground station
|
|
|
|
bool AP_Proximity::get_horizontal_distances(Proximity_Distance_Array &prx_dist_array) const
|
|
|
|
{
|
2019-09-27 05:43:39 -03:00
|
|
|
if (!valid_instance(primary_instance)) {
|
2017-04-12 06:00:41 -03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// get distances from backend
|
|
|
|
return drivers[primary_instance]->get_horizontal_distances(prx_dist_array);
|
|
|
|
}
|
|
|
|
|
2016-11-15 03:29:35 -04:00
|
|
|
// get boundary points around vehicle for use by avoidance
|
|
|
|
// returns nullptr and sets num_points to zero if no boundary can be returned
|
|
|
|
const Vector2f* AP_Proximity::get_boundary_points(uint8_t instance, uint16_t& num_points) const
|
|
|
|
{
|
2019-09-27 05:43:39 -03:00
|
|
|
if (!valid_instance(instance)) {
|
2016-11-15 03:29:35 -04:00
|
|
|
num_points = 0;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
// get boundary from backend
|
2017-01-16 03:35:59 -04:00
|
|
|
return drivers[instance]->get_boundary_points(num_points);
|
2016-11-15 03:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const Vector2f* AP_Proximity::get_boundary_points(uint16_t& num_points) const
|
|
|
|
{
|
|
|
|
return get_boundary_points(primary_instance, num_points);
|
|
|
|
}
|
|
|
|
|
2016-11-15 03:15:46 -04:00
|
|
|
// get distance and angle to closest object (used for pre-arm check)
|
|
|
|
// returns true on success, false if no valid readings
|
|
|
|
bool AP_Proximity::get_closest_object(float& angle_deg, float &distance) const
|
|
|
|
{
|
2019-09-27 05:43:39 -03:00
|
|
|
if (!valid_instance(primary_instance)) {
|
2016-11-15 03:15:46 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// get closest object from backend
|
|
|
|
return drivers[primary_instance]->get_closest_object(angle_deg, distance);
|
2016-12-16 23:42:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// get number of objects, used for non-GPS avoidance
|
|
|
|
uint8_t AP_Proximity::get_object_count() const
|
|
|
|
{
|
2019-09-27 05:43:39 -03:00
|
|
|
if (!valid_instance(primary_instance)) {
|
2016-12-16 23:42:13 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// get count from backend
|
|
|
|
return drivers[primary_instance]->get_object_count();
|
|
|
|
}
|
|
|
|
|
|
|
|
// get an object's angle and distance, used for non-GPS avoidance
|
|
|
|
// returns false if no angle or distance could be returned for some reason
|
|
|
|
bool AP_Proximity::get_object_angle_and_distance(uint8_t object_number, float& angle_deg, float &distance) const
|
|
|
|
{
|
2019-09-27 05:43:39 -03:00
|
|
|
if (!valid_instance(primary_instance)) {
|
2016-12-16 23:42:13 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// get angle and distance from backend
|
|
|
|
return drivers[primary_instance]->get_object_angle_and_distance(object_number, angle_deg, distance);
|
2016-11-15 03:15:46 -04:00
|
|
|
}
|
2016-11-25 01:01:21 -04:00
|
|
|
|
|
|
|
// get maximum and minimum distances (in meters) of primary sensor
|
|
|
|
float AP_Proximity::distance_max() const
|
|
|
|
{
|
2019-09-27 05:43:39 -03:00
|
|
|
if (!valid_instance(primary_instance)) {
|
2016-11-25 01:01:21 -04:00
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
// get maximum distance from backend
|
|
|
|
return drivers[primary_instance]->distance_max();
|
|
|
|
}
|
|
|
|
float AP_Proximity::distance_min() const
|
|
|
|
{
|
2019-09-27 05:43:39 -03:00
|
|
|
if (!valid_instance(primary_instance)) {
|
2016-11-25 01:01:21 -04:00
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
// get minimum distance from backend
|
|
|
|
return drivers[primary_instance]->distance_min();
|
|
|
|
}
|
2017-01-16 02:58:14 -04:00
|
|
|
|
|
|
|
// get distance in meters upwards, returns true on success
|
|
|
|
bool AP_Proximity::get_upward_distance(uint8_t instance, float &distance) const
|
|
|
|
{
|
2019-09-27 05:43:39 -03:00
|
|
|
if (!valid_instance(instance)) {
|
2017-01-16 02:58:14 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// get upward distance from backend
|
|
|
|
return drivers[instance]->get_upward_distance(distance);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AP_Proximity::get_upward_distance(float &distance) const
|
|
|
|
{
|
|
|
|
return get_upward_distance(primary_instance, distance);
|
|
|
|
}
|
2018-05-09 04:45:43 -03:00
|
|
|
|
2019-09-27 05:43:39 -03:00
|
|
|
AP_Proximity::Type AP_Proximity::get_type(uint8_t instance) const
|
2018-05-09 04:45:43 -03:00
|
|
|
{
|
|
|
|
if (instance < PROXIMITY_MAX_INSTANCES) {
|
2019-09-27 05:43:39 -03:00
|
|
|
return (Type)((uint8_t)_type[instance]);
|
2018-05-09 04:45:43 -03:00
|
|
|
}
|
2019-09-27 05:43:39 -03:00
|
|
|
return Type::None;
|
2018-05-09 04:45:43 -03:00
|
|
|
}
|
|
|
|
|
2018-06-25 06:50:47 -03:00
|
|
|
bool AP_Proximity::sensor_present() const
|
|
|
|
{
|
2019-09-27 05:58:52 -03:00
|
|
|
return get_status() != Status::NotConnected;
|
2018-06-25 06:50:47 -03:00
|
|
|
}
|
|
|
|
bool AP_Proximity::sensor_enabled() const
|
|
|
|
{
|
2019-09-27 05:43:39 -03:00
|
|
|
return get_type(primary_instance) != Type::None;
|
2018-06-25 06:50:47 -03:00
|
|
|
}
|
|
|
|
bool AP_Proximity::sensor_failed() const
|
|
|
|
{
|
2019-09-27 05:58:52 -03:00
|
|
|
return get_status() != Status::Good;
|
2018-06-25 06:50:47 -03:00
|
|
|
}
|
|
|
|
|
2018-05-09 04:45:43 -03:00
|
|
|
AP_Proximity *AP_Proximity::_singleton;
|
2019-05-22 03:02:11 -03:00
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
|
|
|
|
AP_Proximity *proximity()
|
|
|
|
{
|
|
|
|
return AP_Proximity::get_singleton();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|