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 31062231be272098fcaa1619670c9809cb64ee12..7730774f410d0b3dfa9f40d271130dc6738017f3 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 e3564e50599513ae7f9881cbbf4fbf8111bcfd7d..14955ff159d208fe8956e981bd03b7b33916d497 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 93ee2f07464440c850e1ce23d05de79c05b6c6d3..d8417ab0fbc1310feb34adcac75d9cd3973f9c90 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 f97122129ede014bc782e042979d4f39512e40d0..ba35e399f33d7371a2acb6739cbcbf3afed41bb7 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 = [];