From 9a0b88ed4c29eea49f6b337960714e4f9f2fe153 Mon Sep 17 00:00:00 2001 From: Stefano Belletti <stefano.belletti@skywarder.eu> Date: Fri, 17 Jan 2025 10:27:21 +0100 Subject: [PATCH] Name change for class Sensor2D --- .../sensors/{Sensor2D.m => Sensor1D.m} | 19 +++++++++++++------ commonFunctions/sensors/Sensor3D.m | 2 +- commonFunctions/sensors/SensorGPS.m | 2 +- .../initSensors2024_Lyra_Portugal_October.m | 10 +++++----- 4 files changed, 20 insertions(+), 13 deletions(-) rename commonFunctions/sensors/{Sensor2D.m => Sensor1D.m} (90%) diff --git a/commonFunctions/sensors/Sensor2D.m b/commonFunctions/sensors/Sensor1D.m similarity index 90% rename from commonFunctions/sensors/Sensor2D.m rename to commonFunctions/sensors/Sensor1D.m index 3106223..7730774 100644 --- a/commonFunctions/sensors/Sensor2D.m +++ b/commonFunctions/sensors/Sensor1D.m @@ -1,13 +1,13 @@ -classdef Sensor2D < handle +classdef Sensor1D < handle % Author: Stefano Belletti, Samuel Flore % Skyward Experimental Rocketry | AVN - GNC % email: stefano.belletti@skywarder.eu % Release date: 18/11/2024 % - % Sensor class for 2D sensors + % Sensor class for 1D sensors % - % Creating a new sensor: [obj] = Sensor2D() + % Creating a new sensor: [obj] = Sensor1D() properties minMeasurementRange; % Max limit of sensor @@ -15,7 +15,7 @@ classdef Sensor2D < handle bit; % Number of bits for the sensor (if available) resolution; % resolution of the sensor (set internally if bit is available) dt; % Sampling time - + % noises noiseType; % White (default) or Pink noiseDataTrack1; @@ -29,11 +29,13 @@ classdef Sensor2D < handle end methods (Access = 'public') - function obj = Sensor2D() + function obj = Sensor1D() % creating a new sensor end function [outputArg] = sens(obj,inputArg,temp,t) + % Sens loop: here the ideal input is transformed into the real + % output inputArg = obj.addOffset(inputArg); inputArg = obj.add2DOffset(inputArg,temp); inputArg = obj.addTempOffset(inputArg,temp); @@ -46,6 +48,7 @@ classdef Sensor2D < handle methods (Access = 'protected') function outputArg = addOffset(obj,inputArg) + % Adding offset to a 2D sensor if (~isempty(obj.offset)) inputArg=inputArg+ones(size(inputArg)).*obj.offset; end @@ -60,6 +63,7 @@ classdef Sensor2D < handle end function outputArg = addTempOffset(obj,inputArg,temp) + % Add temperature offset if (~isempty(obj.tempOffset)) inputArg=inputArg+ones(size(inputArg)).*temp*obj.tempOffset; end @@ -67,6 +71,7 @@ classdef Sensor2D < handle end function outputArg = addNoise(obj,inputArg,t) + % Add noise if ~isempty(obj.noiseVariance) % check for old results inputArg = inputArg + sqrt(obj.noiseVariance).*randn(length(inputArg),1); elseif ~isempty(obj.noiseDataTrack1) @@ -85,6 +90,7 @@ classdef Sensor2D < handle end function outputArg = quantization(obj,inputArg) + % Quantization of the input if isempty(obj.resolution) if (~isempty(obj.maxMeasurementRange)) && (~isempty(obj.minMeasurementRange)) && (~isempty(obj.bit)) obj.resolution = (obj.maxMeasurementRange - obj.minMeasurementRange)/(2^obj.bit); @@ -96,7 +102,8 @@ classdef Sensor2D < handle outputArg = inputArg; end - function outputArg = saturation(obj,inputArg) + function outputArg = saturation(obj,inputArg) + % Add sensor saturation % checks if sensor data is lower than min possible value if (~isempty(obj.minMeasurementRange)) inputArg(inputArg<obj.minMeasurementRange)=obj.minMeasurementRange; diff --git a/commonFunctions/sensors/Sensor3D.m b/commonFunctions/sensors/Sensor3D.m index e3564e5..14955ff 100644 --- a/commonFunctions/sensors/Sensor3D.m +++ b/commonFunctions/sensors/Sensor3D.m @@ -1,4 +1,4 @@ -classdef Sensor3D < Sensor2D +classdef Sensor3D < Sensor1D % Author: Stefano Belletti, Samuel Flore % Skyward Experimental Rocketry | AVN - GNC diff --git a/commonFunctions/sensors/SensorGPS.m b/commonFunctions/sensors/SensorGPS.m index 93ee2f0..d8417ab 100644 --- a/commonFunctions/sensors/SensorGPS.m +++ b/commonFunctions/sensors/SensorGPS.m @@ -23,7 +23,7 @@ classdef SensorGPS < Sensor3D mLon= 1 / (111412.87733*cosd(mLat)) * state(2) + lon0; inputArg = [mLat; mLon; state(3:end)]; - [outMeas] = sens@Sensor2D(obj,inputArg,temp,t); + [outMeas] = sens@Sensor1D(obj,inputArg,temp,t); outPos = outMeas(1:3); outVel = outMeas(4:6); end diff --git a/data/2024_Lyra_Portugal_October/initSensors2024_Lyra_Portugal_October.m b/data/2024_Lyra_Portugal_October/initSensors2024_Lyra_Portugal_October.m index f971221..ba35e39 100644 --- a/data/2024_Lyra_Portugal_October/initSensors2024_Lyra_Portugal_October.m +++ b/data/2024_Lyra_Portugal_October/initSensors2024_Lyra_Portugal_October.m @@ -160,7 +160,7 @@ sensorSettings.spheroid = wgs84Ellipsoid; %% initial chamber pressure sensor NAT825281 % NOTE: pressure in mbar, temp should be in C°; % check 2D offset for chamber pressure sensor -sensorSettings.comb_chamber = Sensor2D(); +sensorSettings.comb_chamber = Sensor1D(); sensorSettings.comb_chamber = loadSensorNoiseData(sensorSettings.comb_chamber, Lyra_Port_sensor_vect, "motor_Motor_TopTankPressureData.csv", 1); % sensorSettings.comb_chamber.noiseVariance = 60000; % mbar @@ -173,7 +173,7 @@ sensorSettings.comb_chamber.offset = 0; %% pitot % static pressure -sensorSettings.pitot_static = Sensor2D(); +sensorSettings.pitot_static = Sensor1D(); sensorSettings.pitot_static.maxMeasurementRange = 1034.21; % mbar (15 psi) sensorSettings.pitot_static.minMeasurementRange = 0; sensorSettings.pitot_static.bit = 12; @@ -182,7 +182,7 @@ sensorSettings.pitot_static = loadSensorNoiseData(sensorSettings.pitot_static, L % sensorSettings.pitot_static.noiseVariance = 0.043043; % from flight logs % total pressure -sensorSettings.pitot_total = Sensor2D(); +sensorSettings.pitot_total = Sensor1D(); sensorSettings.pitot_total.maxMeasurementRange = 2*1034.21; % mbar (30 psi) sensorSettings.pitot_total.minMeasurementRange = 0; sensorSettings.pitot_total.bit = 12; @@ -215,7 +215,7 @@ end if found obj.noiseType = vect(ii).noise_type; - if strcmp("Sensor2D", class(obj)) || strcmp("SensorFault", class(obj)) + if strcmp("Sensor1D", class(obj)) || strcmp("SensorFault", class(obj)) obj.noiseDataTrack1 = vect(ii).track1; obj.noiseFactor = vect(ii).factor; elseif strcmp("Sensor3D", class(obj)) || strcmp("SensorGPS", class(obj)) @@ -227,7 +227,7 @@ if found error("Sensor not defined") end else - if strcmp("Sensor2D", class(obj)) || strcmp("SensorFault", class(obj)) + if strcmp("Sensor1D", class(obj)) || strcmp("SensorFault", class(obj)) obj.noiseDataTrack1 = []; elseif strcmp("Sensor3D", class(obj)) || strcmp("SensorGPS", class(obj)) obj.noiseDataTrack1 = []; -- GitLab