C++ Module: tempMeasurement

Executive Summary

Models the addition of noise, bias, and faults to temperature measurements.

Message Connection Descriptions

The following table lists all module input and output messages. The module msg connection is set by the user from python. The msg type contains a link to the message structure definition, while the description provides information on what this message is used for.

tempMeasurement module input and output messages

Module I/O Messages

Msg Variable Name

Msg Type

Description

tempInMsg

TemperatureMsgPayload

True temperature measurement.

tempOutMsg

TemperatureMsgPayload

Sensed temperature measurement with corruptions.

Detailed Module Description

This module simulates the corruption of a true thermal measurement by noise, bias, and three faults:

  • TEMP_FAULT_STUCK_VALUE is faulty behavior where the measurement sticks to a specific value

  • TEMP_FAULT_STUCK_CURRENT fixes the measurement to the value

  • TEMP_FAULT_SPIKING is faulty behavior where the measurement spikes to a specified multiplier times the actual value, with a given probability

  • TEMP_FAULT_NOMINAL has no faulty behavior but may still have noise and bias

The sensor noise state follows

\[e_{k+1} = a e_k + \sigma z_k, \qquad z_k \sim \mathcal{N}(0, 1),\]

where senNoiseStd configures \(\sigma\) and setAMatrix() configures the one-by-one propagation matrix \(a\). The propagation matrix defaults to zero, so setting senNoiseStd alone produces independent white Gaussian measurement noise with the requested standard deviation. RNGSeed controls the repeatable random sequence.

A correlated process or random walk must be configured explicitly. For example, identity propagation with a positive walkBounds creates a bounded random walk:

tempMeasurementModel.setAMatrix([[1.0]])
tempMeasurementModel.walkBounds = 10.0  # [C]

A positive walkBounds value is an exact hard bound on the noise state. A non-positive value disables clipping. Bias and noise are applied before fault handling. The stuck-value and stuck-current faults replace the noisy, biased measurement, while the spiking fault multiplies it by spikeAmount when a spike occurs.

User Guide

Fault Parameters

This module has several parameters that are set to default values:

Default Module Parameters

Parameter

Description

Default Value

faultState

Sets the fault status.

TEMP_FAULT_NOMINAL

senBias

Sets the bias value.

0.0

senNoiseStd

Sets the standard deviation for sensor noise.

0.0

walkBounds

Sets an optional hard bound on the sensor noise state.

-1.0 (disabled)

stuckValue

Temperature at which the reading is stuck for fault mode TEMP_FAULT_STUCK_VALUE.

0.0

spikeProbability

Probability of a spike when in fault mode TEMP_FAULT_SPIKING. Between 0 and 1.

0.1

spikeAmount

Sensed temperature multiplier when spiking for fault mode TEMP_FAULT_SPIKING.

2.0

Module Setup

The module is created in python using, for example:

1tempMeasurementModel = tempMeasurement.TempMeasurement()
2tempMeasurementModel.ModelTag = 'tempMeasModel'

A sample setup is done using:

1tempMeasurementModel.senBias = 1.0  # [C] bias amount
2tempMeasurementModel.senNoiseStd = 5.0  # [C] white-noise standard deviation
3tempMeasurementModel.stuckValue = 10.0  # [C] if the sensor gets stuck, stuck at 10 degrees C
4tempMeasurementModel.spikeProbability = 0.3  # [-] 30% chance of spiking at each time step
5tempMeasurementModel.spikeAmount = 10.0  # [-] 10x the actual sensed value if the spike happens

The incoming temperature message must be connected to the module:

1tempMeasurementModel.tempInMsg.subscribeTo(sensorThermalModel.temperatureOutMsg)

The fault state is changed by the user to spiking, for example, by setting:

1tempMeasurementModel.faultState = tempMeasurement.TEMP_FAULT_SPIKING

Enums

enum TempFaultState_t

Values:

enumerator TEMP_FAULT_NOMINAL
enumerator TEMP_FAULT_STUCK_CURRENT
enumerator TEMP_FAULT_STUCK_VALUE
enumerator TEMP_FAULT_SPIKING
enumerator TEMP_FAULT_BIASED
enumerator TEMP_FAULT_GAUSS_MARKOV
class TempMeasurement : public SysModel
#include <tempMeasurement.h>

Models a sensor to add noise, bias, and faults to temperature measurements.

Public Functions

TempMeasurement()

This is the constructor for the module class. It sets default variable values and initializes the various parts of the model. Don’t allow random walk by default.

~TempMeasurement()
void Reset(uint64_t CurrentSimNanos)

This method is used to reset the module and checks that required input messages are connected.

void UpdateState(uint64_t CurrentSimNanos)

This is the main method that gets called every time the module is updated.

void setAMatrix(const Eigen::VectorXd &propMatrix)

Set the sensor-error propagation matrix.

Parameters:

propMatrix – One-by-one propagation matrix.

Eigen::VectorXd getAMatrix() const

Get the sensor-error propagation matrix.

Returns:

Current one-by-one propagation matrix.

Public Members

ReadFunctor<TemperatureMsgPayload> tempInMsg

True temperature measurement.

Message<TemperatureMsgPayload> tempOutMsg

Sensed temperature measurement.

BSKLogger bskLogger

&#8212; BSK Logging

TempFaultState_t faultState

[-] Fault status variable

double senBias = {}

[C] Sensor bias value

double senNoiseStd = {}

[C] Sensor process-noise standard deviation

double walkBounds

[C] Hard bound on the noise state; non-positive disables clipping

double stuckValue = {}

[C] Value for temp sensor to get stuck at

double spikeProbability

[-] Probability of spiking at each time step (between 0 and 1)

double spikeAmount

[-] Spike multiplier

Private Functions

void applySensorErrors()

This method adds noise, bias, and fault behaviors to the read-in temperature message.

Private Members

double trueTemperature = {}

[C] Truth value for the temperature measurement

double sensedTemperature = {}

[C] Temperature measurement as corrupted by noise and faults

double pastValue = {}

[C] Measurement from last update (used only for faults)

std::minstd_rand spikeProbabilityGenerator

[-] Generator for calculating probability of a fault spike

GaussMarkov noiseModel

[-] Gauss-Markov noise generation model

Eigen::VectorXd propagationMatrix

[-] Sensor-error propagation matrix; defaults to zero