emulator

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 5 Imported by: 1

README

Emulator - generating high-resolution sensor data

This Go module emulates data for voltage, current, and temperature sensors.

For voltage and current sensors, it allows typical parameters for three-phase systems to be specified, and it outputs waveform samples. It supports arbitrary sampling rates and other signal parameters.

"Anomalies" can be superimposed on the generated data to create abnormal conditions for testing alarms or other scenarios.

Code example

Each emulator instance can implement up to one of each of: three-phase voltage (V), three-phase current (I), and temperature (T). Outputs values are updated every time step, Ts, for a given sampling rate. Only the outputs for initialised V, I, and T objects will be updated each time step.

// base parameters
samplingRate := 14400
freq := 50.0

// create an emulator instance
emu := NewEmulator(samplingRate, freq)

// specify three-phase voltage parameters
emu.V = &ThreePhaseEmulation{
    PosSeqMag:   400000.0 / math.Sqrt(3) * math.Sqrt(2),
    NoiseMax:    0.000001,
    PhaseOffset: phaseOffsetDeg * math.Pi / 180.0,
}

// specify three-phase current parameters
emu.I = &ThreePhaseEmulation{
    PosSeqMag:       500.0,
    PhaseOffset:     phaseOffsetDeg * math.Pi / 180.0,
    HarmonicNumbers: []float64{5, 7, 11, 13, 17, 19, 23, 25},
    HarmonicMags:    []float64{0.2164, 0.1242, 0.0892, 0.0693, 0.0541, 0.0458, 0.0370, 0.0332},
    HarmonicAngs:    []float64{171.5, 100.4, -52.4, 128.3, 80.0, 2.9, -146.8, 133.9},
    NoiseMax:        0.000001,
}

// specify temperature parameters
emu.T = &TemperatureEmulation{
    MeanTemperature: 30.0,
    NoiseMax:        0.01,
    Anomaly: Anomaly{
        InstantaneousAnomalyMagnitude:   30,
        InstantaneousAnomalyProbability: 0.01,
    },
}

// execute one full waveform period of samples using the Step() function
step := 0
var results []bool
for step < samplingRate {
    emulator.Step()
    results = append(results, emulator.T.Anomaly.isInstantaneousAnomaly)
    step += 1
}

Anomalies

Two types of "anomaly" can be added to the data to create interesting scenarios:

  1. Instantaneous: based on a probability factor, activate an instantaneous change to the selected parameter
  2. Periodic "trends": apply a sawtooth shape to the parameter

The parameter TrendAnomalyMagnitude has the following effects:

Sensor type Name of item Modulated parameter Effect Units
Voltage/current PosSeqMagAnomaly Positive sequence magnitude Adds/subtracts positive sequence magnitude Volts or Amps
Voltage/current PosSeqAngAnomaly Positive sequence angle Adds/subtracts positive sequence angle Degrees
Voltage/current PhaseAMagAnomaly Phase A magnitude Adds/subtracts phase A magnitude Volts or Amps
Voltage/current FreqAnomaly Frequency Adds/subtracts signal frequency Hz
Voltage/current HarmonicsAnomaly All harmonics magnitudes Adds/subtracts all harmonic magnitudes per unit
Temperature Anomaly Temperature value Adds/subtracts instantaneous temperature value Degrees C

Documentation

Index

Constants

View Source
const (
	SinglePhaseFault     = iota
	ThreePhaseFault      = iota
	OverVoltage          = iota
	UnderVoltage         = iota
	OverFrequency        = iota
	UnderFrequency       = iota
	CapacitorOverCurrent = iota
)

Emulated event types

View Source
const EmulatedFaultCurrentMagnitude = 80

EmulatedFaultCurrentMagnitude is the additional fault current magnitude added to one circuit end

View Source
const EmulatedFaultStartSamples = 1000

EmulatedFaultStartSamples is the number of samples before initiating an emulated fault

View Source
const MaxEmulatedCapacitorOverCurrentSamples = 8000

MaxEmulatedCapacitorOverCurrentSamples is the number of samples for emulating a fault

View Source
const MaxEmulatedFaultDurationSamples = 6000

MaxEmulatedFaultDurationSamples is the number of samples for emulating a fault

View Source
const MaxEmulatedFrequencyDurationSamples = 8000

MaxEmulatedFrequencyDurationSamples is the number of samples for emulating frequency deviations

View Source
const TwoPiOverThree = 2 * math.Pi / 3

Variables

This section is empty.

Functions

This section is empty.

Types

type Anomaly

type Anomaly struct {
	InstantaneousAnomalyProbability float64
	InstantaneousAnomalyMagnitude   float64

	// trend anomalies, providing periodic positive or negative slopes of given magnitude and duration
	IsTrendAnomaly        bool    `yaml:"IsTrendAnomaly"`
	IsRisingTrendAnomaly  bool    `yaml:"IsRisingTrendAnomaly"`
	TrendAnomalyDuration  float64 `yaml:"TrendAnomalyDuration"` // duration in seconds
	TrendStartDelay       float64 `yaml:"TrendStartDelay"`      // duration in seconds
	TrendStartIndex       int     `yaml:"TrendStartIndex"`      // number of time step ticks
	TrendAnomalyIndex     int     `yaml:"TrendAnomalyIndex"`    // number of time step ticks
	TrendAnomalyMagnitude float64 `yaml:"TrendAnomalyMagnitude"`
	// contains filtered or unexported fields
}

type Emulator

type Emulator struct {
	// common inputs
	SamplingRate int     `yaml:"SamplingRate"` // The sampling rate of the emulator
	Ts           float64 `yaml:"Ts"`           // The time step for a given sampling rate
	Fnom         float64 `yaml:"Fnom"`         // Nominal frequency
	Fdeviation   float64 `yaml:"Fdeviation"`   // Frequency deviation

	V *ThreePhaseEmulation `yaml:"VoltageEmulator,omitempty"` // Voltage Emulator
	I *ThreePhaseEmulation `yaml:"CurrentEmulator,omitempty"` // Current Emulator

	T   *TemperatureEmulation `yaml:"TemperatureEmulator,omitempty"` // Temperature Emulation
	Sag *SagEmulation         `yaml:"SagEmulator,omitempty"`         // Sag Emulator

	// common state
	SmpCnt int `yaml:"-"`
	// contains filtered or unexported fields
}

Emulator encapsulates the waveform emulation of three-phase voltage, three-phase current, or temperature

func NewEmulator

func NewEmulator(samplingRate int, frequency float64) *Emulator

func (*Emulator) StartEvent

func (e *Emulator) StartEvent(eventType int)

StartEvent initiates an emulated event

func (*Emulator) Step

func (e *Emulator) Step()

Step performs one iteration of the waveform generation for the given time step, Ts

type SagEmulation

type SagEmulation struct {
	MeanStrain                float64 `yaml:"MeanStrain,omitempty"`                // Mean strain
	MeanSag                   float64 `yaml:"MeanSag,omitempty"`                   // Mean sag
	MeanCalculatedTemperature float64 `yaml:"MeanCalculatedTemperature,omitempty"` // Mean calculated temperature

	// outputs
	TotalStrain           float64 `yaml:"-"` // Total strain
	Sag                   float64 `yaml:"-"` // Sag
	CalculatedTemperature float64 `yaml:"-"` // Calculated temperature
}

type TemperatureEmulation

type TemperatureEmulation struct {
	MeanTemperature float64 `yaml:"MeanTemperature"`         // Mean temperature
	NoiseMax        float64 `yaml:"NoiseMax"`                // Maximum noise
	ModulationMag   float64 `yaml:"ModulationMag,omitempty"` // Magnitude modulation

	Anomaly Anomaly `yaml:"Anomaly"` // Anomaly

	T float64 `yaml:"-"`
}

type ThreePhaseEmulation

type ThreePhaseEmulation struct {
	// inputs
	PosSeqMag       float64   `yaml:"PosSeqMag"`                      // Positive Sequence Magnitude
	PhaseOffset     float64   `yaml:"PhaseOffset,omitempty"`          // Phase Offset
	NegSeqMag       float64   `yaml:"NegSeqMag,omitempty"`            // Negative Sequence Magnitude
	NegSeqAng       float64   `yaml:"NegSeqAng,omitempty"`            // Negative Sequence Angle
	ZeroSeqMag      float64   `yaml:"ZeroSeqMag,omitempty"`           // Zero Sequence Magnitude
	ZeroSeqAng      float64   `yaml:"ZeroSeqAng,omitempty"`           // Zero Sequence Angle
	HarmonicNumbers []float64 `yaml:"HarmonicNumbers,flow,omitempty"` // Harmonic Numbers
	HarmonicMags    []float64 `yaml:"HarmonicMags,flow,omitempty"`    // Harmonic magnitudes in pu, relative to PosSeqMag
	HarmonicAngs    []float64 `yaml:"HarmonicAngs,flow,omitempty"`    // Harmonic Angles
	NoiseMax        float64   `yaml:"NoiseMax,omitempty"`             // Maximum noise

	// define anomalies
	PosSeqMagAnomaly Anomaly // positive sequence magnitude anomaly
	PosSeqAngAnomaly Anomaly // positive sequence angle anomaly
	PhaseAMagAnomaly Anomaly // phase A magnitude anomaly
	FreqAnomaly      Anomaly // frequency anomaly
	HarmonicsAnomaly Anomaly // harmonics magnitude anomaly

	// event emulation
	FaultPhaseAMag        float64 `yaml:"-"`
	FaultPosSeqMag        float64 `yaml:"-"`
	FaultRemainingSamples int     `yaml:"-"`

	// state change
	PosSeqMagNew      float64 `yaml:"-"`
	PosSeqMagRampRate float64 `yaml:"-"`

	// outputs
	A, B, C float64 `yaml:"-"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL