Skip to content

Commit

Permalink
move stats to utils namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
rtlopez committed Nov 3, 2024
1 parent a87f8a9 commit 54adccf
Show file tree
Hide file tree
Showing 19 changed files with 284 additions and 247 deletions.
2 changes: 1 addition & 1 deletion lib/Espfc/src/Blackbox/Blackbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ int FAST_CODE_ATTR Blackbox::update()
if(!_model.blackboxEnabled()) return 0;
if(_model.config.blackbox.dev == BLACKBOX_DEV_SERIAL && !_serial) return 0;

Stats::Measure measure(_model.state.stats, COUNTER_BLACKBOX);
Utils::Stats::Measure measure(_model.state.stats, COUNTER_BLACKBOX);

uint32_t startTime = micros();
updateArmed();
Expand Down
2 changes: 1 addition & 1 deletion lib/Espfc/src/Control/Actuator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int Actuator::begin()
int Actuator::update()
{
uint32_t startTime = micros();
Stats::Measure(_model.state.stats, COUNTER_ACTUATOR);
Utils::Stats::Measure(_model.state.stats, COUNTER_ACTUATOR);
updateArmingDisabled();
updateModeMask();
updateArmed();
Expand Down
4 changes: 2 additions & 2 deletions lib/Espfc/src/Control/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int FAST_CODE_ATTR Controller::update()
}

{
Stats::Measure(_model.state.stats, COUNTER_OUTER_PID);
Utils::Stats::Measure(_model.state.stats, COUNTER_OUTER_PID);
resetIterm();
if(_model.config.mixer.type == FC_MIXER_GIMBAL)
{
Expand All @@ -37,7 +37,7 @@ int FAST_CODE_ATTR Controller::update()
}

{
Stats::Measure(_model.state.stats, COUNTER_INNER_PID);
Utils::Stats::Measure(_model.state.stats, COUNTER_INNER_PID);
if(_model.config.mixer.type == FC_MIXER_GIMBAL)
{
innerLoopRobot();
Expand Down
2 changes: 1 addition & 1 deletion lib/Espfc/src/Control/Fusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void Fusion::restoreGain()

int FAST_CODE_ATTR Fusion::update()
{
Stats::Measure measure(_model.state.stats, COUNTER_IMU_FUSION);
Utils::Stats::Measure measure(_model.state.stats, COUNTER_IMU_FUSION);

if(_model.accelActive())
{
Expand Down
4 changes: 2 additions & 2 deletions lib/Espfc/src/Espfc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int FAST_CODE_ATTR Espfc::update(bool externalTrigger)
{
if(!_model.state.gyro.timer.check()) return 0;
}
Stats::Measure measure(_model.state.stats, COUNTER_CPU_0);
Utils::Stats::Measure measure(_model.state.stats, COUNTER_CPU_0);

#if defined(ESPFC_MULTI_CORE)

Expand Down Expand Up @@ -102,7 +102,7 @@ int FAST_CODE_ATTR Espfc::updateOther()
}
Event e = _model.state.appQueue.receive();

Stats::Measure measure(_model.state.stats, COUNTER_CPU_1);
Utils::Stats::Measure measure(_model.state.stats, COUNTER_CPU_1);

switch(e.type)
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Espfc/src/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int FAST_CODE_ATTR Input::update()

InputStatus FAST_CODE_ATTR Input::readInputs()
{
Stats::Measure readMeasure(_model.state.stats, COUNTER_INPUT_READ);
Utils::Stats::Measure readMeasure(_model.state.stats, COUNTER_INPUT_READ);
uint32_t startTime = micros();

InputStatus status = _device->update();
Expand Down Expand Up @@ -183,7 +183,7 @@ void FAST_CODE_ATTR Input::processInputs()

bool FAST_CODE_ATTR Input::failsafe(InputStatus status)
{
Stats::Measure readMeasure(_model.state.stats, COUNTER_FAILSAFE);
Utils::Stats::Measure readMeasure(_model.state.stats, COUNTER_FAILSAFE);

if(_model.isSwitchActive(MODE_FAILSAFE))
{
Expand Down Expand Up @@ -251,7 +251,7 @@ void FAST_CODE_ATTR Input::failsafeStage2()

void FAST_CODE_ATTR Input::filterInputs(InputStatus status)
{
Stats::Measure filterMeasure(_model.state.stats, COUNTER_INPUT_FILTER);
Utils::Stats::Measure filterMeasure(_model.state.stats, COUNTER_INPUT_FILTER);
uint32_t startTime = micros();

const bool newFrame = status != INPUT_IDLE;
Expand Down
4 changes: 2 additions & 2 deletions lib/Espfc/src/ModelState.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "Kalman.h"
#include "Utils/Filter.h"
#include "Utils/Timer.h"
#include "Stats.h"
#include "Utils/Stats.h"
#include "Device/SerialDevice.h"
#include "Math/FreqAnalyzer.h"
#include "Msp/Msp.h"
Expand Down Expand Up @@ -351,7 +351,7 @@ struct ModelState
Utils::Timer telemetryTimer;

ModeState mode;
Stats stats;
Utils::Stats stats;

int16_t debug[DEBUG_VALUE_COUNT];

Expand Down
6 changes: 3 additions & 3 deletions lib/Espfc/src/Output/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ int FAST_CODE_ATTR Mixer::update()

void FAST_CODE_ATTR Mixer::updateMixer(const MixerConfig& mixer, float * outputs)
{
Stats::Measure mixerMeasure(_model.state.stats, COUNTER_MIXER);
Utils::Stats::Measure mixerMeasure(_model.state.stats, COUNTER_MIXER);

float sources[MIXER_SOURCE_MAX];
sources[MIXER_SOURCE_NULL] = 0;
Expand Down Expand Up @@ -236,7 +236,7 @@ float FAST_CODE_ATTR Mixer::limitOutput(float output, const OutputChannelConfig&

void FAST_CODE_ATTR Mixer::writeOutput(const MixerConfig& mixer, float * out)
{
Stats::Measure mixerMeasure(_model.state.stats, COUNTER_MIXER_WRITE);
Utils::Stats::Measure mixerMeasure(_model.state.stats, COUNTER_MIXER_WRITE);

bool stop = _stop();
for(size_t i = 0; i < OUTPUT_CHANNELS; i++)
Expand Down Expand Up @@ -280,7 +280,7 @@ void FAST_CODE_ATTR Mixer::writeOutput(const MixerConfig& mixer, float * out)

void FAST_CODE_ATTR Mixer::readTelemetry()
{
Stats::Measure mixerMeasure(_model.state.stats, COUNTER_MIXER_READ);
Utils::Stats::Measure mixerMeasure(_model.state.stats, COUNTER_MIXER_READ);
if(!_model.config.output.dshotTelemetry || !_motor) return;

for(size_t i = 0; i < OUTPUT_CHANNELS; i++)
Expand Down
4 changes: 2 additions & 2 deletions lib/Espfc/src/Sensor/AccelSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int FAST_CODE_ATTR AccelSensor::read()

//if(!_model.state.accel.timer.check()) return 0;

Stats::Measure measure(_model.state.stats, COUNTER_ACCEL_READ);
Utils::Stats::Measure measure(_model.state.stats, COUNTER_ACCEL_READ);
_gyro->readAccel(_model.state.accel.raw);

return 1;
Expand All @@ -54,7 +54,7 @@ int FAST_CODE_ATTR AccelSensor::filter()
{
if(!_model.accelActive()) return 0;

Stats::Measure measure(_model.state.stats, COUNTER_ACCEL_FILTER);
Utils::Stats::Measure measure(_model.state.stats, COUNTER_ACCEL_FILTER);

_model.state.accel.adc = (VectorFloat)_model.state.accel.raw * _model.state.accel.scale;

Expand Down
2 changes: 1 addition & 1 deletion lib/Espfc/src/Sensor/BaroSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int BaroSensor::read()

if(_wait > micros()) return 0;

Stats::Measure measure(_model.state.stats, COUNTER_BARO);
Utils::Stats::Measure measure(_model.state.stats, COUNTER_BARO);

if(_model.config.debug.mode == DEBUG_BARO)
{
Expand Down
8 changes: 4 additions & 4 deletions lib/Espfc/src/Sensor/GyroSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int FAST_CODE_ATTR GyroSensor::read()
{
if (!_model.gyroActive()) return 0;

Stats::Measure measure(_model.state.stats, COUNTER_GYRO_READ);
Utils::Stats::Measure measure(_model.state.stats, COUNTER_GYRO_READ);

_gyro->readGyro(_model.state.gyro.raw);

Expand All @@ -88,7 +88,7 @@ int FAST_CODE_ATTR GyroSensor::filter()
{
if (!_model.gyroActive()) return 0;

Stats::Measure measure(_model.state.stats, COUNTER_GYRO_FILTER);
Utils::Stats::Measure measure(_model.state.stats, COUNTER_GYRO_FILTER);

_model.state.gyro.adc = _model.state.gyro.sampled;

Expand Down Expand Up @@ -163,7 +163,7 @@ void FAST_CODE_ATTR GyroSensor::rpmFilterUpdate()
{
if (!_rpm_enabled) return;

Stats::Measure measure(_model.state.stats, COUNTER_RPM_UPDATE);
Utils::Stats::Measure measure(_model.state.stats, COUNTER_RPM_UPDATE);

const float motorFreq = _model.state.output.telemetry.freq[_rpm_motor_index];
for (size_t n = 0; n < _model.config.gyro.rpmFilter.harmonics; n++)
Expand Down Expand Up @@ -199,7 +199,7 @@ void FAST_CODE_ATTR GyroSensor::dynNotchFilterUpdate()

if (_dyn_notch_enabled || _dyn_notch_debug)
{
Stats::Measure measure(_model.state.stats, COUNTER_GYRO_FFT);
Utils::Stats::Measure measure(_model.state.stats, COUNTER_GYRO_FFT);

const float q = _model.config.gyro.dynamicFilter.q * 0.01;
bool feed = _model.state.loopTimer.iteration % _dyn_notch_denom == 0;
Expand Down
4 changes: 2 additions & 2 deletions lib/Espfc/src/Sensor/MagSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int MagSensor::read()
{
if(!_mag || !_model.magActive() || !_model.state.mag.timer.check()) return 0;

Stats::Measure measure(_model.state.stats, COUNTER_MAG_READ);
Utils::Stats::Measure measure(_model.state.stats, COUNTER_MAG_READ);
_mag->readMag(_model.state.mag.raw);

return 1;
Expand All @@ -52,7 +52,7 @@ int MagSensor::filter()
{
if(!_mag || !_model.magActive()) return 0;

Stats::Measure measure(_model.state.stats, COUNTER_MAG_FILTER);
Utils::Stats::Measure measure(_model.state.stats, COUNTER_MAG_FILTER);

_model.state.mag.adc = _mag->convert(_model.state.mag.raw);

Expand Down
2 changes: 1 addition & 1 deletion lib/Espfc/src/Sensor/VoltageSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int VoltageSensor::update()
{
if (!_model.state.battery.timer.check()) return 0;

Stats::Measure measure(_model.state.stats, COUNTER_BATTERY);
Utils::Stats::Measure measure(_model.state.stats, COUNTER_BATTERY);

switch (_state)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Espfc/src/SerialManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int FAST_CODE_ATTR SerialManager::update()
{
if(!serialRx)
{
Stats::Measure measure(_model.state.stats, COUNTER_SERIAL);
Utils::Stats::Measure measure(_model.state.stats, COUNTER_SERIAL);
size_t len = stream->available();
if(len > 0)
{
Expand Down
Loading

0 comments on commit 54adccf

Please sign in to comment.