Skip to content

Commit

Permalink
move timer to utils, drop timer dependency in escdriver
Browse files Browse the repository at this point in the history
  • Loading branch information
rtlopez committed Nov 3, 2024
1 parent 42aad6a commit a87f8a9
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 22 deletions.
1 change: 0 additions & 1 deletion lib/EscDriver/src/EscDriverEsp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ int EscDriverEsp32::begin(const EscConfig& conf)
_interval = TO_INTERVAL_US(_rate);
_digital = isDigital(_protocol);
_dshot_tlm = conf.dshotTelemetry && (_protocol == ESC_PROTOCOL_DSHOT300 || _protocol == ESC_PROTOCOL_DSHOT600);
_timer.setInterval(1000000);

return 1;
}
Expand Down
2 changes: 0 additions & 2 deletions lib/EscDriver/src/EscDriverEsp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "EscDriver.h"
#include <driver/rmt.h>
#include "Timer.h"

class EscDriverEsp32: public EscDriverBase
{
Expand Down Expand Up @@ -120,7 +119,6 @@ class EscDriverEsp32: public EscDriverBase

static bool _tx_end_installed;
static EscDriverEsp32* instances[];
Espfc::Timer _timer;
};

#endif
Expand Down
4 changes: 4 additions & 0 deletions lib/Espfc/src/Control/Rates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Espfc {

namespace Control {

constexpr float SETPOINT_RATE_LIMIT = 1998.0f;
constexpr float RC_RATE_INCREMENTAL = 14.54f;

Expand Down Expand Up @@ -111,3 +113,5 @@ float FAST_CODE_ATTR Rates::quick(const int axis, float rcCommandf, const float
}

}

}
6 changes: 5 additions & 1 deletion lib/Espfc/src/Control/Rates.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ enum RateType {
RATES_TYPE_QUICK,
};

namespace Control {

class Rates
{
public:
Expand Down Expand Up @@ -50,4 +52,6 @@ class Rates
int16_t rateLimit[3];
};

} // namespace Espfc
}

}
26 changes: 13 additions & 13 deletions lib/Espfc/src/ModelState.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include "Control/Pid.h"
#include "Kalman.h"
#include "Utils/Filter.h"
#include "Utils/Timer.h"
#include "Stats.h"
#include "Timer.h"
#include "Device/SerialDevice.h"
#include "Math/FreqAnalyzer.h"
#include "Msp/Msp.h"
Expand Down Expand Up @@ -80,7 +80,7 @@ class BuzzerState
return idx >= BUZZER_MAX_EVENTS;
}

Timer timer;
Utils::Timer timer;
BuzzerEvent events[BUZZER_MAX_EVENTS];
size_t idx;
int32_t beeperMask;
Expand All @@ -105,7 +105,7 @@ class BatteryState
float percentage;
int8_t cells;
int8_t samples;
Timer timer;
Utils::Timer timer;
};

enum CalibrationState {
Expand Down Expand Up @@ -196,12 +196,12 @@ struct InputState

Utils::Filter filter[AXIS_COUNT_RPYT];

Timer timer;
Utils::Timer timer;
};

struct MixerState
{
Timer timer;
Utils::Timer timer;
float minThrottle;
float maxThrottle;
bool digitalOutput;
Expand All @@ -219,7 +219,7 @@ struct MagState
VectorInt16 raw;
VectorFloat adc;
Utils::Filter filter[3];
Timer timer;
Utils::Timer timer;

int calibrationSamples;
int calibrationState;
Expand Down Expand Up @@ -277,8 +277,8 @@ struct GyroState
Utils::Filter rpmFilter[RPM_FILTER_MOTOR_MAX][RPM_FILTER_HARMONICS_MAX][AXIS_COUNT_RPY];
Utils::Filter rpmFreqFilter[RPM_FILTER_MOTOR_MAX];

Timer timer;
Timer dynamicFilterTimer;
Utils::Timer timer;
Utils::Timer dynamicFilterTimer;
};

struct AccelState
Expand All @@ -288,7 +288,7 @@ struct AccelState
VectorFloat adc;
VectorFloat prev;
Utils::Filter filter[AXIS_COUNT_RPY];
Timer timer;
Utils::Timer timer;

float scale;
VectorFloat bias;
Expand Down Expand Up @@ -345,10 +345,10 @@ struct ModelState
OutputState output;

int32_t loopRate;
Timer loopTimer;
Utils::Timer loopTimer;

Timer actuatorTimer;
Timer telemetryTimer;
Utils::Timer actuatorTimer;
Utils::Timer telemetryTimer;

ModeState mode;
Stats stats;
Expand All @@ -366,7 +366,7 @@ struct ModelState
int16_t i2cErrorDelta;

SerialPortState serial[SERIAL_UART_COUNT];
Timer serialTimer;
Utils::Timer serialTimer;

Target::Queue appQueue;

Expand Down
4 changes: 2 additions & 2 deletions lib/Espfc/src/Stats.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _ESPFC_STATS_H_
#define _ESPFC_STATS_H_

#include "Timer.h"
#include "Utils/Timer.h"

namespace Espfc {

Expand Down Expand Up @@ -201,7 +201,7 @@ class Stats
}
}

Timer timer;
Utils::Timer timer;

private:
uint32_t _start[COUNTER_COUNT];
Expand Down
6 changes: 5 additions & 1 deletion lib/Espfc/src/Timer.cpp → lib/Espfc/src/Utils/Timer.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <Arduino.h>
#include "Timer.h"
#include "Utils/Timer.h"
#include "Utils/MemoryHelper.h"

namespace Espfc {

namespace Utils {

Timer::Timer(): interval(0), last(0), next(0), iteration(0), delta(0)
{
}
Expand Down Expand Up @@ -68,3 +70,5 @@ bool FAST_CODE_ATTR Timer::syncTo(const Timer& t, uint32_t slot)
}

}

}
4 changes: 4 additions & 0 deletions lib/Espfc/src/Timer.h → lib/Espfc/src/Utils/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Espfc {

namespace Utils {

class Timer
{
public:
Expand All @@ -29,3 +31,5 @@ class Timer
};

}

}
7 changes: 5 additions & 2 deletions test/test_fc/test_fc.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#include <unity.h>
#include <ArduinoFake.h>
#include <EscDriver.h>
#include "Timer.h"
#include "Utils/Timer.h"
#include "Model.h"
#include "Control/Controller.h"
#include "Control/Actuator.h"
#include "Output/Mixer.h"

using namespace fakeit;
using namespace Espfc;
using namespace Espfc::Control;
using Espfc::Control::Rates;
using Espfc::Control::Controller;
using Espfc::Control::Actuator;
using Espfc::Utils::Timer;

/*void setUp(void)
{
Expand Down

0 comments on commit a87f8a9

Please sign in to comment.