Code refactoring
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: https://pvs-studio.com
|
||||
|
||||
#include "Sensors.hpp"
|
||||
|
||||
Sensors::Sensors(Barometer *barometer, MPU *mpu, Kalman2DFilter *filter, BatteryController *battery, bool loop_on_fail) {
|
||||
Sensors::Sensors(Barometer *barometer, MPU *mpu, Kalman2DFilter *filter,
|
||||
BatteryController *battery, volatile bool loop_on_fail) {
|
||||
assert(barometer != nullptr);
|
||||
assert(mpu != nullptr);
|
||||
assert(filter != nullptr);
|
||||
@@ -56,7 +60,7 @@ float Sensors::rawFlightHeight(void) const {
|
||||
|
||||
float Sensors::flightHeight(void) const {
|
||||
/* Returns flight height from cache immediatly */
|
||||
if (_flightHeightFromBarometer == NAN) {
|
||||
if (_flightHeightFromBarometer == 0.f) {
|
||||
ESP_LOGW(_tag, "flightHeight called, but tick() has called never");
|
||||
return rawFlightHeight();
|
||||
} else {
|
||||
@@ -65,7 +69,7 @@ float Sensors::flightHeight(void) const {
|
||||
}
|
||||
|
||||
MpuData Sensors::mpuData() const {
|
||||
if (_mpuData.ax == NAN and _mpuData.gravity == NAN) {
|
||||
if (_mpuData.ax == 0.f and _mpuData.gravity == 0.f) {
|
||||
ESP_LOGW(_tag, "MPU data looks like .tick() has never called");
|
||||
}
|
||||
return _mpuData;
|
||||
@@ -78,7 +82,8 @@ bool Sensors::tick(void) {
|
||||
bool err;
|
||||
bool isMpuDataReady = _mpu->tick(err);
|
||||
if (isMpuDataReady and !err) {
|
||||
_2d_filter->filter(_mpu->accZInertial(), _barometer->flightHeight(), _flightHeightFromBarometer, _zVelocityAltitude);
|
||||
_2d_filter->filter(_mpu->accZInertial(), _barometer->flightHeight(),
|
||||
_flightHeightFromBarometer, _zVelocityAltitude);
|
||||
_mpuData = { .ax = _mpu->ax(),
|
||||
.ay = _mpu->ay(),
|
||||
.az = _mpu->az(),
|
||||
|
||||
Reference in New Issue
Block a user