Sensor Class#

class rocketpy.sensors.Sensor[source]#

Abstract class for sensors

Variables:
  • sampling_rate (float) – Sample rate of the sensor in Hz.

  • measurement_range (float, tuple) – The measurement range of the sensor in the sensor units.

  • resolution (float) – The resolution of the sensor in sensor units/LSB.

  • noise_density (float, list) – The noise density of the sensor in sensor units/√Hz.

  • noise_variance (float, list) – The variance of the noise of the sensor in sensor units^2.

  • random_walk_density (float, list) – The random walk density of the sensor in sensor units/√Hz.

  • random_walk_variance (float, list) – The variance of the random walk of the sensor in sensor units^2.

  • constant_bias (float, list) – The constant bias of the sensor in sensor units.

  • operating_temperature (float) – The operating temperature of the sensor in Kelvin.

  • temperature_bias (float, list) – The temperature bias of the sensor in sensor units/K.

  • temperature_scale_factor (float, list) – The temperature scale factor of the sensor in %/K.

  • name (str) – The name of the sensor.

  • measurement (float) – The measurement of the sensor after quantization, noise and temperature drift.

  • measured_data (list) – The stored measured data of the sensor after quantization, noise and temperature drift.

__init__(sampling_rate, measurement_range=inf, resolution=0, noise_density=0, noise_variance=1, random_walk_density=0, random_walk_variance=1, constant_bias=0, operating_temperature=25, temperature_bias=0, temperature_scale_factor=0, name='Sensor')[source]#

Initialize the accelerometer sensor

Parameters:
  • sampling_rate (float) – Sample rate of the sensor

  • measurement_range (float, tuple, optional) – The measurement range of the sensor in the sensor units. If a float, the same range is applied both for positive and negative values. If a tuple, the first value is the positive range and the second value is the negative range. Default is np.inf.

  • resolution (float, optional) – The resolution of the sensor in sensor units/LSB. Default is 0, meaning no quantization is applied.

  • noise_density (float, list, optional) – The noise density of the sensor for a Gaussian white noise in sensor units/√Hz. Sometimes called “white noise drift”, “angular random walk” for gyroscopes, “velocity random walk” for accelerometers or “(rate) noise density”. Default is 0, meaning no noise is applied.

  • noise_variance (float, list, optional) – The noise variance of the sensor for a Gaussian white noise in sensor units^2. Default is 1, meaning the noise is normally distributed with a standard deviation of 1 unit.

  • random_walk_density (float, list, optional) – The random walk density of the sensor for a Gaussian random walk in sensor units/√Hz. Sometimes called “bias (in)stability” or “bias drift”. Default is 0, meaning no random walk is applied.

  • random_walk_variance (float, list, optional) – The random walk variance of the sensor for a Gaussian random walk in sensor units^2. Default is 1, meaning the noise is normally distributed with a standard deviation of 1 unit.

  • constant_bias (float, list, optional) – The constant bias of the sensor in sensor units. Default is 0, meaning no constant bias is applied.

  • operating_temperature (float, optional) – The operating temperature of the sensor in Kelvin. At 298.15 K (25 °C), the sensor is assumed to operate ideally, no temperature related noise is applied. Default is 298.15.

  • temperature_bias (float, list, optional) – The temperature bias of the sensor in sensor units/K. Default is 0, meaning no temperature bias is applied.

  • temperature_scale_factor (float, list, optional) – The temperature scale factor of the sensor in %/K. Default is 0, meaning no temperature scale factor is applied.

  • name (str, optional) – The name of the sensor. Default is “Sensor”.

Return type:

None

See also

TODO

_reset(simulated_rocket)[source]#

Reset the sensor data for a new simulation.

_save_data_single(data)[source]#

Save the measured data to the sensor data list for a sensor that is added only once to the simulated rocket.

_save_data_multiple(data)[source]#

Save the measured data to the sensor data list for a sensor that is added multiple times to the simulated rocket.

abstract measure(time, **kwargs)[source]#

Measure the sensor data at a given time

abstract quantize(value)[source]#

Quantize the sensor measurement

abstract apply_noise(value)[source]#

Add noise to the sensor measurement

abstract apply_temperature_drift(value)[source]#

Apply temperature drift to the sensor measurement

abstract export_measured_data(filename, file_format='csv')[source]#

Export the measured values to a file

_generic_export_measured_data(filename, file_format, data_labels)[source]#

Export the measured values to a file given the data labels of each sensor.

Parameters:
  • sensor (Sensor) – Sensor object to export the measured values from.

  • filename (str) – Name of the file to export the values to

  • file_format (str) – file_format of the file to export the values to. Options are “csv” and “json”. Default is “csv”.

  • data_labels (tuple) – Tuple of strings representing the labels for the data columns

Return type:

None