2025-01-14 14:42:39 +00:00
|
|
|
/* PMU hook.
|
2022-06-01 18:15:29 +02:00
|
|
|
*
|
2025-01-14 14:42:39 +00:00
|
|
|
* Author: Manuel Pitz <manuel.pitz@eonerc.rwth-aachen.de>
|
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2022-06-01 18:15:29 +02:00
|
|
|
|
|
|
|
#include <villas/dsp/window_cosine.hpp>
|
|
|
|
#include <villas/hook.hpp>
|
|
|
|
#include <villas/sample.hpp>
|
|
|
|
|
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
|
|
|
|
class PmuHook : public MultiSignalHook {
|
|
|
|
|
|
|
|
protected:
|
2025-01-14 14:42:39 +00:00
|
|
|
enum class Status { INVALID, VALID };
|
|
|
|
|
|
|
|
struct Phasor {
|
|
|
|
double frequency;
|
|
|
|
double amplitude;
|
|
|
|
double phase;
|
|
|
|
double rocof; // Rate of change of frequency.
|
|
|
|
Status valid;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class WindowType { NONE, FLATTOP, HANN, HAMMING, NUTTAL, BLACKMAN };
|
|
|
|
|
|
|
|
enum class TimeAlign {
|
|
|
|
LEFT,
|
|
|
|
CENTER,
|
|
|
|
RIGHT,
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<dsp::CosineWindow<double> *> windows;
|
|
|
|
dsp::Window<timespec> *windowsTs;
|
|
|
|
std::vector<Phasor> lastPhasors;
|
|
|
|
|
|
|
|
enum TimeAlign timeAlignType;
|
|
|
|
enum WindowType windowType;
|
|
|
|
|
|
|
|
unsigned sampleRate;
|
|
|
|
double phasorRate;
|
|
|
|
double nominalFreq;
|
|
|
|
double numberPlc;
|
|
|
|
unsigned windowSize;
|
|
|
|
bool channelNameEnable;
|
|
|
|
double angleUnitFactor;
|
|
|
|
uint64_t lastSequence;
|
|
|
|
timespec nextRun;
|
|
|
|
bool init;
|
|
|
|
unsigned initSampleCount;
|
|
|
|
// Correction factors.
|
|
|
|
double phaseOffset;
|
|
|
|
double amplitudeOffset;
|
|
|
|
double frequencyOffset;
|
|
|
|
double rocofOffset;
|
2022-06-01 18:15:29 +02:00
|
|
|
|
|
|
|
public:
|
2025-01-14 14:42:39 +00:00
|
|
|
PmuHook(Path *p, Node *n, int fl, int prio, bool en = true);
|
2022-06-01 18:15:29 +02:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
virtual void prepare();
|
2022-06-01 18:15:29 +02:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
virtual void parse(json_t *json);
|
2022-06-01 18:15:29 +02:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
virtual Hook::Reason process(struct Sample *smp);
|
2022-06-01 18:15:29 +02:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
virtual Phasor estimatePhasor(dsp::CosineWindow<double> *window,
|
|
|
|
Phasor lastPhasor);
|
2022-06-01 18:15:29 +02:00
|
|
|
};
|
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|