diff --git a/MATLAB/+Observers/ExtendedKalmanFilter.m b/MATLAB/+Observers/ExtendedKalmanFilter.m index 5eb644d..2625301 100644 --- a/MATLAB/+Observers/ExtendedKalmanFilter.m +++ b/MATLAB/+Observers/ExtendedKalmanFilter.m @@ -23,7 +23,7 @@ % See also Observers.Observer, Observers.KalmanFilter, % Observers.UnscentedKalmanFilter % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved. diff --git a/MATLAB/+Observers/KalmanFilter.m b/MATLAB/+Observers/KalmanFilter.m index 71c5f4e..4f6e718 100644 --- a/MATLAB/+Observers/KalmanFilter.m +++ b/MATLAB/+Observers/KalmanFilter.m @@ -29,7 +29,7 @@ % See also Observers.Observer, Observers.ExtendedKalmanFilter, % Observers.UnscentedKalmanFilter % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved. diff --git a/MATLAB/+Observers/Observer.m b/MATLAB/+Observers/Observer.m index f9274a6..ae08c36 100644 --- a/MATLAB/+Observers/Observer.m +++ b/MATLAB/+Observers/Observer.m @@ -15,7 +15,7 @@ % See also Observers.KalmanFilter, Observers.ExtendedKalmanFilter, % Observers.ParticleFilter, Observers.UnscentedKalmanFilter % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved. diff --git a/MATLAB/+Observers/ParticleFilter.m b/MATLAB/+Observers/ParticleFilter.m index 8dc60f3..ac090ca 100644 --- a/MATLAB/+Observers/ParticleFilter.m +++ b/MATLAB/+Observers/ParticleFilter.m @@ -32,7 +32,7 @@ % getStateEstimate(PF) - Return a state estimate structure with samples % and weights fields % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved. diff --git a/MATLAB/+Observers/UnscentedKalmanFilter.m b/MATLAB/+Observers/UnscentedKalmanFilter.m index cb23ce3..a60ed67 100644 --- a/MATLAB/+Observers/UnscentedKalmanFilter.m +++ b/MATLAB/+Observers/UnscentedKalmanFilter.m @@ -25,7 +25,7 @@ % Observers.ExtendedKalmanFilter, Observers.ParticleFilter, % Observers.computeSigmaPoints % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved. diff --git a/MATLAB/+Observers/computeSigmaPoints.m b/MATLAB/+Observers/computeSigmaPoints.m index 702e444..4a1aafa 100644 --- a/MATLAB/+Observers/computeSigmaPoints.m +++ b/MATLAB/+Observers/computeSigmaPoints.m @@ -33,7 +33,7 @@ % See also Observers.wmean, Observers.wcov, % Observers.UnscentedKalmanFilter % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved. diff --git a/MATLAB/+Observers/meanCovSampler.m b/MATLAB/+Observers/meanCovSampler.m index f500cbc..405ea34 100644 --- a/MATLAB/+Observers/meanCovSampler.m +++ b/MATLAB/+Observers/meanCovSampler.m @@ -16,7 +16,7 @@ % See also Observers.KalmanFilter, Observers.ExtendedKalmanFilter, % Observers.UnscentedKalmanFilter % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved. diff --git a/MATLAB/+Observers/wcov.m b/MATLAB/+Observers/wcov.m index dad7a4b..9df4733 100644 --- a/MATLAB/+Observers/wcov.m +++ b/MATLAB/+Observers/wcov.m @@ -14,7 +14,7 @@ % % See also Observers.wmean % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved. diff --git a/MATLAB/+Observers/wmean.m b/MATLAB/+Observers/wmean.m index a9b4120..1d14ae9 100644 --- a/MATLAB/+Observers/wmean.m +++ b/MATLAB/+Observers/wmean.m @@ -10,7 +10,7 @@ % % See also Observers.wcov % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved. diff --git a/MATLAB/+Prognosis/Predictor.m b/MATLAB/+Prognosis/Predictor.m index e232ea9..a9d562a 100644 --- a/MATLAB/+Prognosis/Predictor.m +++ b/MATLAB/+Prognosis/Predictor.m @@ -32,7 +32,7 @@ % % See also Prognosis.Prognoser, Model.PrognosticsModel % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved. diff --git a/MATLAB/+Prognosis/Prognoser.m b/MATLAB/+Prognosis/Prognoser.m index 9557bdc..a713dff 100644 --- a/MATLAB/+Prognosis/Prognoser.m +++ b/MATLAB/+Prognosis/Prognoser.m @@ -14,7 +14,7 @@ % % See also Model.PrognosticsModel, Observers.Observer, Prognosis.Predictor % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved. diff --git a/MATLAB/testKalmanFilter.m b/MATLAB/testKalmanFilter.m index d91f4bc..2a361a9 100644 --- a/MATLAB/testKalmanFilter.m +++ b/MATLAB/testKalmanFilter.m @@ -1,7 +1,7 @@ function testKalmanFilter % tesKalmanFilter Test Kalman filter class with a simple model. % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved. diff --git a/MATLAB/testParticleFilter.m b/MATLAB/testParticleFilter.m index 2d5d976..6e46c9b 100644 --- a/MATLAB/testParticleFilter.m +++ b/MATLAB/testParticleFilter.m @@ -1,7 +1,7 @@ function testParticleFilter % testParticleFilter Test particle filter algorithm on Battery model % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved. diff --git a/MATLAB/testPredictor.m b/MATLAB/testPredictor.m index aea4ecf..546985b 100644 --- a/MATLAB/testPredictor.m +++ b/MATLAB/testPredictor.m @@ -1,7 +1,7 @@ function testPredictor % testPredictor Test Predictor class for Battery model % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved. diff --git a/MATLAB/testPrognoser.m b/MATLAB/testPrognoser.m index 64ba281..146aabb 100644 --- a/MATLAB/testPrognoser.m +++ b/MATLAB/testPrognoser.m @@ -1,24 +1,32 @@ function testPrognoser % testPrognoser Test Prognoser class for Battery model % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved. % Create battery model -battery = Battery.Create; +%batt = BatteryCircuit.Create; +batt = Battery.Create; % Set variable input profile -loads = [8; 10*60; 4; 5*60; 12; 15*60; 5; 20*60; 10; 10*60]; +% Dependent on model (circuit uses current, electrochemistry uses power) +if strcmp(batt.name,'BatteryCircuit') + loads = [2.63; 100*60]; +elseif strcmp(batt.name,'Battery') + loads = [8; 100*60]; +else + error('Model ' + batt.name + ' not supported'); +end % Set up noise covariance matrices -Q = diag(battery.V); -R = diag(battery.N); +Q = diag(batt.V); +R = diag(batt.N); % Create UKF -UKF = Observers.UnscentedKalmanFilter(@battery.stateEqn,@battery.outputEqn,... - Q,R,'symmetric',3-8,1); +UKF = Observers.UnscentedKalmanFilter(@batt.stateEqn,@batt.outputEqn,... + Q,R,'symmetric',3-size(batt.states,2),1); % Create sample generator for input equation parameters % For each of the 5 load segments, sample from a uniform distribution with @@ -31,17 +39,18 @@ % Create Prognoser horizon = 5000; numSamples = 100; -prognoser = Prognosis.Prognoser('model',battery,'observer',UKF,... +prognoser = Prognosis.Prognoser('model',batt,'observer',UKF,... 'horizon',horizon,'numSamples',numSamples,... 'stateSampler',@Observers.meanCovSampler,... 'inputParameterSampler',inputParameterSampler,... - 'processNoiseSampler',@battery.generateProcessNoise); + 'processNoiseSampler',@batt.generateProcessNoise); % Get initial state for battery simulation t0 = 0; -[x0,u0,z0] = battery.getDefaultInitialization(t0,loads); +[x0,u0,z0] = batt.getDefaultInitialization(t0,loads); % Update/initialize prognoser based on initial data +prognoser.initialize(t0,x0,u0); prognoser.update(t0,u0,z0); % Set up output data matrices @@ -68,11 +77,11 @@ % Simulate battery and run prognoser for i=2:length(T) % Update state from T(i-1) to T(i) - x = battery.stateEqn(T(i-1),x,u,battery.generateProcessNoise(),dt); + x = batt.stateEqn(T(i-1),x,u,batt.generateProcessNoise(),dt); % Get inputs for time T(i) - u = battery.inputEqn(T(i),loads); + u = batt.inputEqn(T(i),loads); % Compute outputs for time T(i) - z = battery.outputEqn(T(i),x,u,battery.generateSensorNoise()); + z = batt.outputEqn(T(i),x,u,batt.generateSensorNoise()); % Update step for prognoser prognoser.update(T(i),u,z); @@ -83,7 +92,7 @@ % Print some status fprintf('Time: %g s\n',T(i)); - battery.printOutputs(z); + batt.printOutputs(z); fprintf(' EOD: %g s\n',mean(prognoser.predictor.predictions.thresholdTimes)); % Save some prediction data @@ -115,8 +124,14 @@ legend('Measured','Estimated'); % Compute actual end of discharge time, giving the exact loading parameters -battery.inputEqnHandle = @(P,t)Battery.InputEqn(P,t,loads); -T = battery.simulateToThreshold(); +if strcmp(batt.name,'BatteryCircuit') + batt.inputEqnHandle = @(P,t)BatteryCircuit.InputEqn(P,t,loads); +elseif strcmp(batt.name,'Battery') + batt.inputEqnHandle = @(P,t)Battery.InputEqn(P,t,loads); +else + error('Model ' + batt.name + ' not supported'); +end +T = batt.simulateToThreshold(); trueEOD = T(end); % Plot prediction results @@ -124,7 +139,7 @@ plot(predictionTimes,EODMean,'o',predictionTimes,EODMin,'o',... predictionTimes,EODMax,'o',predictionTimes,... trueEOD*ones(size(predictionTimes)),'o'); -legend('Predicted EOD Mean','Predicted EOD Max','Predicted EOD Min',... +legend('Predicted EOD Mean','Predicted EOD Min','Predicted EOD Max',... 'True EOD'); axis tight; xlabel('Time (s)') diff --git a/MATLAB/testUnscentedKalmanFilter.m b/MATLAB/testUnscentedKalmanFilter.m index 5f5554c..f15e282 100644 --- a/MATLAB/testUnscentedKalmanFilter.m +++ b/MATLAB/testUnscentedKalmanFilter.m @@ -1,7 +1,7 @@ function testUnscentedKalmanFilter % testUnscentedKalmanFilter Test UKF algorithm on Battery model % -% Copyright (c) 2016 United States Government as represented by the +% Copyright (c) 2016 United States Government as represented by the % Administrator of the National Aeronautics and Space Administration. % No copyright is claimed in the United States under Title 17, U.S. % Code. All Other Rights Reserved.