mirror of https://github.com/ArduPilot/ardupilot
AP_InertialSensor: make PX4 healthy call _get_sample()
this prevents a false positive during times like arming where we are not reading the sensors
This commit is contained in:
parent
2af69b7131
commit
f10a4b04ae
|
@ -140,7 +140,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual uint16_t error_count(void) const { return 0; }
|
virtual uint16_t error_count(void) const { return 0; }
|
||||||
virtual bool healthy(void) const { return true; }
|
virtual bool healthy(void) { return true; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ void AP_InertialSensor_HIL::set_gyro(const Vector3f &gyro)
|
||||||
/**
|
/**
|
||||||
try to detect bad accel/gyro sensors
|
try to detect bad accel/gyro sensors
|
||||||
*/
|
*/
|
||||||
bool AP_InertialSensor_HIL::healthy(void) const
|
bool AP_InertialSensor_HIL::healthy(void)
|
||||||
{
|
{
|
||||||
uint32_t tnow = hal.scheduler->micros();
|
uint32_t tnow = hal.scheduler->micros();
|
||||||
if ((tnow - _last_accel_usec) > 40000) {
|
if ((tnow - _last_accel_usec) > 40000) {
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
bool wait_for_sample(uint16_t timeout_ms);
|
bool wait_for_sample(uint16_t timeout_ms);
|
||||||
void set_accel(const Vector3f &accel);
|
void set_accel(const Vector3f &accel);
|
||||||
void set_gyro(const Vector3f &gyro);
|
void set_gyro(const Vector3f &gyro);
|
||||||
bool healthy(void) const;
|
bool healthy(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint16_t _init_sensor( Sample_rate sample_rate );
|
uint16_t _init_sensor( Sample_rate sample_rate );
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
float get_delta_time();
|
float get_delta_time();
|
||||||
|
|
||||||
uint16_t error_count(void) const { return _error_count; }
|
uint16_t error_count(void) const { return _error_count; }
|
||||||
bool healthy(void) const { return _error_count <= 4; }
|
bool healthy(void) { return _error_count <= 4; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint16_t _init_sensor( Sample_rate sample_rate );
|
uint16_t _init_sensor( Sample_rate sample_rate );
|
||||||
|
|
|
@ -131,6 +131,10 @@ void AP_InertialSensor_PX4::_get_sample(void)
|
||||||
struct accel_report accel_report;
|
struct accel_report accel_report;
|
||||||
struct gyro_report gyro_report;
|
struct gyro_report gyro_report;
|
||||||
|
|
||||||
|
if (_accel_fd == -1 || _gyro_fd == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (::read(_accel_fd, &accel_report, sizeof(accel_report)) == sizeof(accel_report) &&
|
while (::read(_accel_fd, &accel_report, sizeof(accel_report)) == sizeof(accel_report) &&
|
||||||
accel_report.timestamp != _last_accel_timestamp) {
|
accel_report.timestamp != _last_accel_timestamp) {
|
||||||
_accel_in = Vector3f(accel_report.x, accel_report.y, accel_report.z);
|
_accel_in = Vector3f(accel_report.x, accel_report.y, accel_report.z);
|
||||||
|
@ -178,9 +182,22 @@ bool AP_InertialSensor_PX4::wait_for_sample(uint16_t timeout_ms)
|
||||||
/**
|
/**
|
||||||
try to detect bad accel/gyro sensors
|
try to detect bad accel/gyro sensors
|
||||||
*/
|
*/
|
||||||
bool AP_InertialSensor_PX4::healthy(void) const
|
bool AP_InertialSensor_PX4::healthy(void)
|
||||||
{
|
{
|
||||||
|
if (_sample_time_usec == 0) {
|
||||||
|
// not initialised yet, show as healthy to prevent scary GCS
|
||||||
|
// warnings
|
||||||
|
return true;
|
||||||
|
}
|
||||||
uint64_t tnow = hrt_absolute_time();
|
uint64_t tnow = hrt_absolute_time();
|
||||||
|
|
||||||
|
if ((tnow - _last_accel_timestamp) > 2*_sample_time_usec ||
|
||||||
|
(tnow - _last_gyro_timestamp) > 2*_sample_time_usec) {
|
||||||
|
// see if new samples are available
|
||||||
|
_get_sample();
|
||||||
|
tnow = hrt_absolute_time();
|
||||||
|
}
|
||||||
|
|
||||||
if ((tnow - _last_accel_timestamp) > 2*_sample_time_usec) {
|
if ((tnow - _last_accel_timestamp) > 2*_sample_time_usec) {
|
||||||
// accels have not updated
|
// accels have not updated
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -17,7 +17,12 @@ class AP_InertialSensor_PX4 : public AP_InertialSensor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AP_InertialSensor_PX4() : AP_InertialSensor() {}
|
AP_InertialSensor_PX4() :
|
||||||
|
AP_InertialSensor(),
|
||||||
|
_sample_time_usec(0),
|
||||||
|
_accel_fd(-1),
|
||||||
|
_gyro_fd(-1)
|
||||||
|
{}
|
||||||
|
|
||||||
/* Concrete implementation of AP_InertialSensor functions: */
|
/* Concrete implementation of AP_InertialSensor functions: */
|
||||||
bool update();
|
bool update();
|
||||||
|
@ -25,7 +30,7 @@ public:
|
||||||
float get_gyro_drift_rate();
|
float get_gyro_drift_rate();
|
||||||
bool sample_available();
|
bool sample_available();
|
||||||
bool wait_for_sample(uint16_t timeout_ms);
|
bool wait_for_sample(uint16_t timeout_ms);
|
||||||
bool healthy(void) const;
|
bool healthy(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t _init_sensor( Sample_rate sample_rate );
|
uint16_t _init_sensor( Sample_rate sample_rate );
|
||||||
|
|
Loading…
Reference in New Issue