Skip to content
Snippets Groups Projects
Commit 9a0b88ed authored by Stefano Belletti's avatar Stefano Belletti
Browse files

Name change for class Sensor2D

parent 4ca8ee90
Branches
No related tags found
1 merge request!46Sensor class dev
classdef Sensor2D < handle classdef Sensor1D < handle
% Author: Stefano Belletti, Samuel Flore % Author: Stefano Belletti, Samuel Flore
% Skyward Experimental Rocketry | AVN - GNC % Skyward Experimental Rocketry | AVN - GNC
% email: stefano.belletti@skywarder.eu % email: stefano.belletti@skywarder.eu
% Release date: 18/11/2024 % 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 properties
minMeasurementRange; % Max limit of sensor minMeasurementRange; % Max limit of sensor
...@@ -29,11 +29,13 @@ classdef Sensor2D < handle ...@@ -29,11 +29,13 @@ classdef Sensor2D < handle
end end
methods (Access = 'public') methods (Access = 'public')
function obj = Sensor2D() function obj = Sensor1D()
% creating a new sensor % creating a new sensor
end end
function [outputArg] = sens(obj,inputArg,temp,t) 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.addOffset(inputArg);
inputArg = obj.add2DOffset(inputArg,temp); inputArg = obj.add2DOffset(inputArg,temp);
inputArg = obj.addTempOffset(inputArg,temp); inputArg = obj.addTempOffset(inputArg,temp);
...@@ -46,6 +48,7 @@ classdef Sensor2D < handle ...@@ -46,6 +48,7 @@ classdef Sensor2D < handle
methods (Access = 'protected') methods (Access = 'protected')
function outputArg = addOffset(obj,inputArg) function outputArg = addOffset(obj,inputArg)
% Adding offset to a 2D sensor
if (~isempty(obj.offset)) if (~isempty(obj.offset))
inputArg=inputArg+ones(size(inputArg)).*obj.offset; inputArg=inputArg+ones(size(inputArg)).*obj.offset;
end end
...@@ -60,6 +63,7 @@ classdef Sensor2D < handle ...@@ -60,6 +63,7 @@ classdef Sensor2D < handle
end end
function outputArg = addTempOffset(obj,inputArg,temp) function outputArg = addTempOffset(obj,inputArg,temp)
% Add temperature offset
if (~isempty(obj.tempOffset)) if (~isempty(obj.tempOffset))
inputArg=inputArg+ones(size(inputArg)).*temp*obj.tempOffset; inputArg=inputArg+ones(size(inputArg)).*temp*obj.tempOffset;
end end
...@@ -67,6 +71,7 @@ classdef Sensor2D < handle ...@@ -67,6 +71,7 @@ classdef Sensor2D < handle
end end
function outputArg = addNoise(obj,inputArg,t) function outputArg = addNoise(obj,inputArg,t)
% Add noise
if ~isempty(obj.noiseVariance) % check for old results if ~isempty(obj.noiseVariance) % check for old results
inputArg = inputArg + sqrt(obj.noiseVariance).*randn(length(inputArg),1); inputArg = inputArg + sqrt(obj.noiseVariance).*randn(length(inputArg),1);
elseif ~isempty(obj.noiseDataTrack1) elseif ~isempty(obj.noiseDataTrack1)
...@@ -85,6 +90,7 @@ classdef Sensor2D < handle ...@@ -85,6 +90,7 @@ classdef Sensor2D < handle
end end
function outputArg = quantization(obj,inputArg) function outputArg = quantization(obj,inputArg)
% Quantization of the input
if isempty(obj.resolution) if isempty(obj.resolution)
if (~isempty(obj.maxMeasurementRange)) && (~isempty(obj.minMeasurementRange)) && (~isempty(obj.bit)) if (~isempty(obj.maxMeasurementRange)) && (~isempty(obj.minMeasurementRange)) && (~isempty(obj.bit))
obj.resolution = (obj.maxMeasurementRange - obj.minMeasurementRange)/(2^obj.bit); obj.resolution = (obj.maxMeasurementRange - obj.minMeasurementRange)/(2^obj.bit);
...@@ -97,6 +103,7 @@ classdef Sensor2D < handle ...@@ -97,6 +103,7 @@ classdef Sensor2D < handle
end end
function outputArg = saturation(obj,inputArg) function outputArg = saturation(obj,inputArg)
% Add sensor saturation
% checks if sensor data is lower than min possible value % checks if sensor data is lower than min possible value
if (~isempty(obj.minMeasurementRange)) if (~isempty(obj.minMeasurementRange))
inputArg(inputArg<obj.minMeasurementRange)=obj.minMeasurementRange; inputArg(inputArg<obj.minMeasurementRange)=obj.minMeasurementRange;
......
classdef Sensor3D < Sensor2D classdef Sensor3D < Sensor1D
% Author: Stefano Belletti, Samuel Flore % Author: Stefano Belletti, Samuel Flore
% Skyward Experimental Rocketry | AVN - GNC % Skyward Experimental Rocketry | AVN - GNC
......
...@@ -23,7 +23,7 @@ classdef SensorGPS < Sensor3D ...@@ -23,7 +23,7 @@ classdef SensorGPS < Sensor3D
mLon= 1 / (111412.87733*cosd(mLat)) * state(2) + lon0; mLon= 1 / (111412.87733*cosd(mLat)) * state(2) + lon0;
inputArg = [mLat; mLon; state(3:end)]; inputArg = [mLat; mLon; state(3:end)];
[outMeas] = sens@Sensor2D(obj,inputArg,temp,t); [outMeas] = sens@Sensor1D(obj,inputArg,temp,t);
outPos = outMeas(1:3); outPos = outMeas(1:3);
outVel = outMeas(4:6); outVel = outMeas(4:6);
end end
......
...@@ -160,7 +160,7 @@ sensorSettings.spheroid = wgs84Ellipsoid; ...@@ -160,7 +160,7 @@ sensorSettings.spheroid = wgs84Ellipsoid;
%% initial chamber pressure sensor NAT825281 %% initial chamber pressure sensor NAT825281
% NOTE: pressure in mbar, temp should be in C°; % NOTE: pressure in mbar, temp should be in C°;
% check 2D offset for chamber pressure sensor % 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 = loadSensorNoiseData(sensorSettings.comb_chamber, Lyra_Port_sensor_vect, "motor_Motor_TopTankPressureData.csv", 1);
% sensorSettings.comb_chamber.noiseVariance = 60000; % mbar % sensorSettings.comb_chamber.noiseVariance = 60000; % mbar
...@@ -173,7 +173,7 @@ sensorSettings.comb_chamber.offset = 0; ...@@ -173,7 +173,7 @@ sensorSettings.comb_chamber.offset = 0;
%% pitot %% pitot
% static pressure % static pressure
sensorSettings.pitot_static = Sensor2D(); sensorSettings.pitot_static = Sensor1D();
sensorSettings.pitot_static.maxMeasurementRange = 1034.21; % mbar (15 psi) sensorSettings.pitot_static.maxMeasurementRange = 1034.21; % mbar (15 psi)
sensorSettings.pitot_static.minMeasurementRange = 0; sensorSettings.pitot_static.minMeasurementRange = 0;
sensorSettings.pitot_static.bit = 12; sensorSettings.pitot_static.bit = 12;
...@@ -182,7 +182,7 @@ sensorSettings.pitot_static = loadSensorNoiseData(sensorSettings.pitot_static, L ...@@ -182,7 +182,7 @@ sensorSettings.pitot_static = loadSensorNoiseData(sensorSettings.pitot_static, L
% sensorSettings.pitot_static.noiseVariance = 0.043043; % from flight logs % sensorSettings.pitot_static.noiseVariance = 0.043043; % from flight logs
% total pressure % total pressure
sensorSettings.pitot_total = Sensor2D(); sensorSettings.pitot_total = Sensor1D();
sensorSettings.pitot_total.maxMeasurementRange = 2*1034.21; % mbar (30 psi) sensorSettings.pitot_total.maxMeasurementRange = 2*1034.21; % mbar (30 psi)
sensorSettings.pitot_total.minMeasurementRange = 0; sensorSettings.pitot_total.minMeasurementRange = 0;
sensorSettings.pitot_total.bit = 12; sensorSettings.pitot_total.bit = 12;
...@@ -215,7 +215,7 @@ end ...@@ -215,7 +215,7 @@ end
if found if found
obj.noiseType = vect(ii).noise_type; 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.noiseDataTrack1 = vect(ii).track1;
obj.noiseFactor = vect(ii).factor; obj.noiseFactor = vect(ii).factor;
elseif strcmp("Sensor3D", class(obj)) || strcmp("SensorGPS", class(obj)) elseif strcmp("Sensor3D", class(obj)) || strcmp("SensorGPS", class(obj))
...@@ -227,7 +227,7 @@ if found ...@@ -227,7 +227,7 @@ if found
error("Sensor not defined") error("Sensor not defined")
end end
else else
if strcmp("Sensor2D", class(obj)) || strcmp("SensorFault", class(obj)) if strcmp("Sensor1D", class(obj)) || strcmp("SensorFault", class(obj))
obj.noiseDataTrack1 = []; obj.noiseDataTrack1 = [];
elseif strcmp("Sensor3D", class(obj)) || strcmp("SensorGPS", class(obj)) elseif strcmp("Sensor3D", class(obj)) || strcmp("SensorGPS", class(obj))
obj.noiseDataTrack1 = []; obj.noiseDataTrack1 = [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment