diff --git a/libraries/AP_InertialSensor/AP_InertialSensor.cpp b/libraries/AP_InertialSensor/AP_InertialSensor.cpp index cb691f5f89..f03bcd3fa3 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor.cpp +++ b/libraries/AP_InertialSensor/AP_InertialSensor.cpp @@ -1301,6 +1301,51 @@ check_sample: _have_sample = true; } + +/* + get delta angles + */ +bool AP_InertialSensor::get_delta_angle(uint8_t i, Vector3f &delta_angle) const +{ + if (_delta_angle_valid[i]) { + delta_angle = _delta_angle[i]; + return true; + } else if (get_gyro_health(i)) { + // provide delta angle from raw gyro, so we use the same code + // at higher level + delta_angle = get_gyro(i) * get_delta_time(); + return true; + } + return false; +} + +/* + get delta velocity if available +*/ +bool AP_InertialSensor::get_delta_velocity(uint8_t i, Vector3f &delta_velocity) const +{ + if (_delta_velocity_valid[i]) { + delta_velocity = _delta_velocity[i]; + return true; + } else if (get_accel_health(i)) { + delta_velocity = get_accel(i) * get_delta_time(); + return true; + } + return false; +} + +/* + return delta_time for the delta_velocity + */ +float AP_InertialSensor::get_delta_velocity_dt(uint8_t i) const +{ + if (_delta_velocity_valid[i]) { + return _delta_velocity_dt[i]; + } + return get_delta_time(); +} + + /* support for setting accel and gyro vectors, for use by HIL */ diff --git a/libraries/AP_InertialSensor/AP_InertialSensor.h b/libraries/AP_InertialSensor/AP_InertialSensor.h index 1f3c7fee1d..cd6ce813d7 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor.h +++ b/libraries/AP_InertialSensor/AP_InertialSensor.h @@ -118,23 +118,14 @@ public: const Vector3f &get_gyro_offsets(void) const { return get_gyro_offsets(_primary_gyro); } //get delta angle if available - bool get_delta_angle(uint8_t i, Vector3f &delta_angle) const { - if(_delta_angle_valid[i]) delta_angle = _delta_angle[i]; - return _delta_angle_valid[i]; - } - + bool get_delta_angle(uint8_t i, Vector3f &delta_angle) const; bool get_delta_angle(Vector3f &delta_angle) const { return get_delta_angle(_primary_gyro, delta_angle); } //get delta velocity if available - bool get_delta_velocity(uint8_t i, Vector3f &delta_velocity) const { - if(_delta_velocity_valid[i]) delta_velocity = _delta_velocity[i]; - return _delta_velocity_valid[i]; - } + bool get_delta_velocity(uint8_t i, Vector3f &delta_velocity) const; bool get_delta_velocity(Vector3f &delta_velocity) const { return get_delta_velocity(_primary_accel, delta_velocity); } - float get_delta_velocity_dt(uint8_t i) const { - return _delta_velocity_dt[i]; - } + float get_delta_velocity_dt(uint8_t i) const; float get_delta_velocity_dt() const { return get_delta_velocity_dt(_primary_accel); } /// Fetch the current accelerometer values