Skip to content

Commit

Permalink
Merge pull request #12 from nasa/develop
Browse files Browse the repository at this point in the history
Release 1.0.1

Changes include:
* Bugfix with structure of InputEqn to make Battery Models interchangeable 
* Defined x0Variance in Model
  • Loading branch information
teubert authored Oct 15, 2020
2 parents beae137 + 5ed3878 commit b99404f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
23 changes: 13 additions & 10 deletions MATLAB/+BatteryCircuit/InputEqn.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function U = InputEqn(parameters,t,u)
function U = InputEqn(parameters,t,inputParameters)
% InputEqn Compute battery inputs for the given time and input parameters
%
% U = InputEqn(parameters,t,inputParameters) computes the inputs to the
Expand Down Expand Up @@ -31,15 +31,18 @@
% If u specified, interpret as variable loading scheme, where u is a
% vector with an even number of elements. The first of the pair of
% numbers is the magnitude of the load, the second is the duration.
loads = u(1:2:end);
durations = u(2:2:end);
times = [0 cumsum(durations)];
% Find which load corresponds to given time
loadIndex = find(t>=times,1,'last');
if loadIndex>length(loads)
current = loads(end);
else
current = loads(loadIndex);
for ii = 1:size(inputParameters,2)
u = inputParameters(:,ii);
loads = u(1:2:end);
durations = u(2:2:end);
times = [0; cumsum(durations)];
% Find which load corresponds to given time
loadIndex = find(t>=times,1,'last');
if loadIndex>length(loads)
current(ii) = loads(end);
else
current(ii) = loads(loadIndex);
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion MATLAB/+BatteryCircuit/test.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
% Simulate for a variable load profile
% Specified by a sequence of pairs of numbers, where the first is the load
% (in Watts) and the second is the duration (in seconds).
loads = [2 10*60 1 5*60 4 15*60 2 20*60 3 10*60];
loads = [2; 10*60; 1; 5*60; 4; 15*60; 2; 20*60; 3; 10*60];
battery.inputEqnHandle = @(P,t)BatteryCircuit.InputEqn(P,t,loads);
[T,X,U,Z] = battery.simulate(3000,'printTime',60);

Expand Down
10 changes: 10 additions & 0 deletions MATLAB/+Model/Model.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

V; % Process noise variances (vector)
N; % Sensor noise variances for current sensor set (vector)
x0Variance; % Initial states variance (vector)
P; % Static parameters structure

indices; % Structure to get indices of states, inputs, outputs by name
Expand Down Expand Up @@ -130,6 +131,15 @@
M.N(i,1) = M.outputs(i).Noise;
end

% Set up initial states variances vector
for i=1:length(M.states)
if isfield(M.states(i),'x0Variance')
M.x0Variance(i,1) = M.states(i).x0Variance;
else
M.x0Variance(i,1)= M.states(i).Noise;
end
end

% Setup indices structure
M.setIndices();
end
Expand Down

0 comments on commit b99404f

Please sign in to comment.