mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 14:38:30 -04:00
AP_Proximity: add get_upward_distance
This allow support for upward facing proximity sensor received through a DISTANCE_SENSOR message. Also added SITL test
This commit is contained in:
parent
e7ba2420c1
commit
a47e215a8e
@ -385,3 +385,18 @@ float AP_Proximity::distance_min() const
|
|||||||
// get minimum distance from backend
|
// get minimum distance from backend
|
||||||
return drivers[primary_instance]->distance_min();
|
return drivers[primary_instance]->distance_min();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get distance in meters upwards, returns true on success
|
||||||
|
bool AP_Proximity::get_upward_distance(uint8_t instance, float &distance) const
|
||||||
|
{
|
||||||
|
if ((drivers[instance] == nullptr) || (_type[instance] == Proximity_Type_None)) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
@ -107,6 +107,14 @@ public:
|
|||||||
enum Proximity_Status status; // sensor status
|
enum Proximity_Status status; // sensor status
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// support for upwardward facing sensors
|
||||||
|
//
|
||||||
|
|
||||||
|
// get distance upwards in meters. returns true on success
|
||||||
|
bool get_upward_distance(uint8_t instance, float &distance) const;
|
||||||
|
bool get_upward_distance(float &distance) const;
|
||||||
|
|
||||||
// parameter list
|
// parameter list
|
||||||
static const struct AP_Param::GroupInfo var_info[];
|
static const struct AP_Param::GroupInfo var_info[];
|
||||||
|
|
||||||
|
@ -39,6 +39,9 @@ public:
|
|||||||
virtual float distance_max() const = 0;
|
virtual float distance_max() const = 0;
|
||||||
virtual float distance_min() const = 0;
|
virtual float distance_min() const = 0;
|
||||||
|
|
||||||
|
// get distance upwards in meters. returns true on success
|
||||||
|
virtual bool get_upward_distance(float &distance) const { return false; }
|
||||||
|
|
||||||
// handle mavlink DISTANCE_SENSOR messages
|
// handle mavlink DISTANCE_SENSOR messages
|
||||||
virtual void handle_msg(mavlink_message_t *msg) {}
|
virtual void handle_msg(mavlink_message_t *msg) {}
|
||||||
|
|
||||||
|
@ -43,6 +43,16 @@ void AP_Proximity_MAV::update(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get distance upwards in meters. returns true on success
|
||||||
|
bool AP_Proximity_MAV::get_upward_distance(float &distance) const
|
||||||
|
{
|
||||||
|
if ((_last_upward_update_ms != 0) && (AP_HAL::millis() - _last_upward_update_ms <= PROXIMITY_MAV_TIMEOUT_MS)) {
|
||||||
|
distance = _distance_upward;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// handle mavlink DISTANCE_SENSOR messages
|
// handle mavlink DISTANCE_SENSOR messages
|
||||||
void AP_Proximity_MAV::handle_msg(mavlink_message_t *msg)
|
void AP_Proximity_MAV::handle_msg(mavlink_message_t *msg)
|
||||||
{
|
{
|
||||||
@ -60,4 +70,10 @@ void AP_Proximity_MAV::handle_msg(mavlink_message_t *msg)
|
|||||||
_last_update_ms = AP_HAL::millis();
|
_last_update_ms = AP_HAL::millis();
|
||||||
update_boundary_for_sector(sector);
|
update_boundary_for_sector(sector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// store upward distance
|
||||||
|
if (packet.orientation == MAV_SENSOR_ROTATION_PITCH_90) {
|
||||||
|
_distance_upward = packet.current_distance / 100.0f;
|
||||||
|
_last_upward_update_ms = AP_HAL::millis();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,9 @@ public:
|
|||||||
float distance_max() const { return _distance_max; }
|
float distance_max() const { return _distance_max; }
|
||||||
float distance_min() const { return _distance_min; };
|
float distance_min() const { return _distance_min; };
|
||||||
|
|
||||||
|
// get distance upwards in meters. returns true on success
|
||||||
|
bool get_upward_distance(float &distance) const;
|
||||||
|
|
||||||
// handle mavlink DISTANCE_SENSOR messages
|
// handle mavlink DISTANCE_SENSOR messages
|
||||||
void handle_msg(mavlink_message_t *msg) override;
|
void handle_msg(mavlink_message_t *msg) override;
|
||||||
|
|
||||||
@ -27,7 +30,12 @@ private:
|
|||||||
// initialise sensor (returns true if sensor is succesfully initialised)
|
// initialise sensor (returns true if sensor is succesfully initialised)
|
||||||
bool initialise();
|
bool initialise();
|
||||||
|
|
||||||
|
// horizontal distance support
|
||||||
uint32_t _last_update_ms; // system time of last DISTANCE_SENSOR message received
|
uint32_t _last_update_ms; // system time of last DISTANCE_SENSOR message received
|
||||||
float _distance_max; // max range of sensor in meters
|
float _distance_max; // max range of sensor in meters
|
||||||
float _distance_min; // min range of sensor in meters
|
float _distance_min; // min range of sensor in meters
|
||||||
|
|
||||||
|
// upward distance support
|
||||||
|
uint32_t _last_upward_update_ms; // system time of last update distance
|
||||||
|
float _distance_upward; // upward distance in meters
|
||||||
};
|
};
|
||||||
|
@ -38,6 +38,10 @@ AP_Proximity_SITL::AP_Proximity_SITL(AP_Proximity &_frontend,
|
|||||||
if (fence_count == nullptr || ptype != AP_PARAM_INT8) {
|
if (fence_count == nullptr || ptype != AP_PARAM_INT8) {
|
||||||
AP_HAL::panic("Proximity_SITL: Failed to find FENCE_TOTAL");
|
AP_HAL::panic("Proximity_SITL: Failed to find FENCE_TOTAL");
|
||||||
}
|
}
|
||||||
|
fence_alt_max = (AP_Float *)AP_Param::find("FENCE_ALT_MAX", &ptype);
|
||||||
|
if (fence_alt_max == nullptr || ptype != AP_PARAM_FLOAT) {
|
||||||
|
AP_HAL::panic("Proximity_SITL: Failed to find FENCE_ALT_MAX");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the state of the sensor
|
// update the state of the sensor
|
||||||
@ -125,4 +129,12 @@ float AP_Proximity_SITL::distance_min() const
|
|||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get distance upwards in meters. returns true on success
|
||||||
|
bool AP_Proximity_SITL::get_upward_distance(float &distance) const
|
||||||
|
{
|
||||||
|
// return distance to fence altitude
|
||||||
|
distance = MAX(0.0f, fence_alt_max->get() - sitl->height_agl);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // CONFIG_HAL_BOARD
|
#endif // CONFIG_HAL_BOARD
|
||||||
|
@ -20,10 +20,14 @@ public:
|
|||||||
float distance_max() const;
|
float distance_max() const;
|
||||||
float distance_min() const;
|
float distance_min() const;
|
||||||
|
|
||||||
|
// get distance upwards in meters. returns true on success
|
||||||
|
bool get_upward_distance(float &distance) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SITL::SITL *sitl;
|
SITL::SITL *sitl;
|
||||||
Vector2l *fence;
|
Vector2l *fence;
|
||||||
AP_Int8 *fence_count;
|
AP_Int8 *fence_count;
|
||||||
|
AP_Float *fence_alt_max;
|
||||||
uint32_t last_load_ms;
|
uint32_t last_load_ms;
|
||||||
AC_PolyFence_loader fence_loader;
|
AC_PolyFence_loader fence_loader;
|
||||||
Location current_loc;
|
Location current_loc;
|
||||||
|
Loading…
Reference in New Issue
Block a user