Skip to content

Commit

Permalink
LVD: Added SoI transition capability to LVD.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arrowstar committed Nov 3, 2018
1 parent 81b3345 commit 11b9af0
Show file tree
Hide file tree
Showing 17 changed files with 271 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
classdef(Abstract) AbstractIntegrationTerminationCause < matlab.mixin.SetGet & matlab.mixin.Heterogeneous
%AbstractIntegrationTerminationCause Summary of this class goes here
% Detailed explanation goes here

properties

end

methods
tf = shouldRestartIntegration(obj)

newStateLogEntry = getRestartInitialState(obj, stateLogEntry)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
classdef EventTermCondIntTermCause < AbstractIntegrationTerminationCause
%EventTermCondIntTermCause Summary of this class goes here
% Detailed explanation goes here

properties

end

methods
function obj = EventTermCondIntTermCause()

end

function tf = shouldRestartIntegration(obj)
tf = false;
end

function newStateLogEntry = getRestartInitialState(obj, stateLogEntry)
newStateLogEntry = stateLogEntry; %should probably never be called
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
classdef MaxEventSimTimeIntTermCause < AbstractIntegrationTerminationCause
%MaxEventSimTimeIntTermCause Summary of this class goes here
% Detailed explanation goes here

properties

end

methods
function obj = MaxEventSimTimeIntTermCause()

end

function tf = shouldRestartIntegration(obj)
tf = false;
end

function newStateLogEntry = getRestartInitialState(obj, stateLogEntry)
newStateLogEntry = stateLogEntry; %should probably never be called
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
classdef MinAltitudeIntTermCause < AbstractIntegrationTerminationCause
%MinAltitudeIntTermCause Summary of this class goes here
% Detailed explanation goes here

properties

end

methods
function obj = MinAltitudeIntTermCause()

end

function tf = shouldRestartIntegration(obj)
tf = false;
end

function newStateLogEntry = getRestartInitialState(obj, stateLogEntry)
newStateLogEntry = stateLogEntry; %should probably never be called
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
classdef SoITransitionDownIntTermCause < AbstractIntegrationTerminationCause
%SoITransitionDownIntTermCause Summary of this class goes here
% Detailed explanation goes here

properties
fromBody(1,1) KSPTOT_BodyInfo
toBody(1,1) KSPTOT_BodyInfo
celBodyData struct
end

methods
function obj = SoITransitionDownIntTermCause(fromBody, toBody, celBodyData)
obj.fromBody = fromBody;
obj.toBody = toBody;
obj.celBodyData = celBodyData;
end

function tf = shouldRestartIntegration(obj)
tf = true;
end

function newStateLogEntry = getRestartInitialState(obj, stateLogEntry)
% bodyInfo = stateLogEntry.centralBody;
ut = stateLogEntry.time;
rVect = reshape(stateLogEntry.position,1,3);
vVect = reshape(stateLogEntry.velocity,1,3);

[rVectDown, vVectDown] = convertRVVectOnDownwardsSoITransition(obj.toBody, obj.celBodyData, ut, rVect, vVect);

dcm = stateLogEntry.attitude.dcm;

newStateLogEntry = stateLogEntry.deepCopy();
newStateLogEntry.position = rVectDown;
newStateLogEntry.velocity = vVectDown;
newStateLogEntry.centralBody = obj.toBody;
newStateLogEntry.steeringModel = stateLogEntry.steeringModel.deepCopy();

newStateLogEntry.steeringModel.setContinuityTerms(true, true, true);
newStateLogEntry.steeringModel.setConstsFromDcmAndContinuitySettings(dcm, ut, rVectDown, vVectDown, obj.toBody);
newStateLogEntry.steeringModel.setT0(ut);
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
classdef SoITransitionUpIntTermCause < AbstractIntegrationTerminationCause
%SoITransitionUpIntTermCause Summary of this class goes here
% Detailed explanation goes here

properties
fromBody(1,1) KSPTOT_BodyInfo
toBody KSPTOT_BodyInfo
celBodyData struct
end

methods
function obj = SoITransitionUpIntTermCause(fromBody, toBody, celBodyData)
obj.fromBody = fromBody;
obj.toBody = toBody;
obj.celBodyData = celBodyData;
end

function tf = shouldRestartIntegration(obj)
tf = true;
end

function newStateLogEntry = getRestartInitialState(obj, stateLogEntry)
bodyInfo = stateLogEntry.centralBody;
ut = stateLogEntry.time;
rVect = reshape(stateLogEntry.position,1,3);
vVect = reshape(stateLogEntry.velocity,1,3);

[rVectUp, vVectUp] = convertRVVectOnUpwardsSoITransition(bodyInfo, obj.celBodyData, ut, rVect, vVect);

dcm = stateLogEntry.attitude.dcm;

newStateLogEntry = stateLogEntry.deepCopy();
newStateLogEntry.position = rVectUp;
newStateLogEntry.velocity = vVectUp;
newStateLogEntry.centralBody = obj.toBody;
newStateLogEntry.steeringModel = stateLogEntry.steeringModel.deepCopy();

newStateLogEntry.steeringModel.setContinuityTerms(true, true, true);
newStateLogEntry.steeringModel.setConstsFromDcmAndContinuitySettings(dcm, ut, rVectUp, vVectUp, obj.toBody);
newStateLogEntry.steeringModel.setT0(ut);
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

[angle1Cont, angle2Cont, angle3Cont] = getContinuityTerms(obj)

newSteeringModel = deepCopy(obj)

optVar = getNewOptVar(obj)

optVar = getExistingOptVar(obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ function setConstsFromDcmAndContinuitySettings(obj, dcm, ut, rVect, vVect, bodyI
angle3Name = 'Side Slip';
end

function newSteeringModel = deepCopy(obj)
newSteeringModel = AeroAnglesPolySteeringModel(obj.bankModel.deepCopy(), obj.aoAModel.deepCopy(), obj.slipModel.deepCopy());
newSteeringModel.bankContinuity = obj.bankContinuity;
newSteeringModel.aoAContinuity = obj.aoAContinuity;
newSteeringModel.slipContinuity = obj.slipContinuity;
end

function optVar = getNewOptVar(obj)
optVar = SetAeroSteeringModelActionOptimVar(obj);
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ function setConstsFromDcmAndContinuitySettings(obj, dcm, ut, rVect, vVect, bodyI
angle3Name = 'Side Slip';
end

function newSteeringModel = deepCopy(obj)
newSteeringModel = InertialAeroAnglesPolySteeringModel(obj.bankModel.deepCopy(), obj.aoAModel.deepCopy(), obj.slipModel.deepCopy());
newSteeringModel.bankContinuity = obj.bankContinuity;
newSteeringModel.aoAContinuity = obj.aoAContinuity;
newSteeringModel.slipContinuity = obj.slipContinuity;
end

function optVar = getNewOptVar(obj)
optVar = SetAeroSteeringModelActionOptimVar(obj);
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@

value = obj.constTerm + dt*obj.linearTerm + (1/2)*obj.accelTerm*dt^2;
end

function newPolyModel = deepCopy(obj)
newPolyModel = PolynominalModel(obj.t0, obj.constTerm, obj.linearTerm, obj.accelTerm);
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
pitchModel(1,1) PolynominalModel = PolynominalModel(0,0,0,0);
yawModel(1,1) PolynominalModel = PolynominalModel(0,0,0,0);

rollContinuity(1,1) logical = true;
pitchContinuity(1,1) logical = true;
yawContinuity(1,1) logical = true;
rollContinuity(1,1) logical = false;
pitchContinuity(1,1) logical = false;
yawContinuity(1,1) logical = false;
end

methods
Expand Down Expand Up @@ -97,6 +97,13 @@ function setConstsFromDcmAndContinuitySettings(obj, dcm, ut, rVect, vVect, bodyI
angle3Name = 'Yaw';
end

function newSteeringModel = deepCopy(obj)
newSteeringModel = RollPitchYawPolySteeringModel(obj.rollModel.deepCopy(), obj.pitchModel.deepCopy(), obj.yawModel.deepCopy());
newSteeringModel.rollContinuity = obj.rollContinuity;
newSteeringModel.pitchContinuity = obj.pitchContinuity;
newSteeringModel.yawContinuity = obj.yawContinuity;
end

function optVar = getNewOptVar(obj)
optVar = SetRPYSteeringModelActionOptimVar(obj);
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,48 @@
odeOutputFun = @(t,y,flag) obj.odeOutput(t,y,flag, now()*86400);
options = odeset('RelTol',obj.relTol, 'AbsTol',obj.absTol, 'NonNegative',tankStateInds, 'Events',odeEventsFun, 'NormControl','on', 'OutputFcn',odeOutputFun);

[value,isterminal,~] = odeEventsFun(tspan(1), y0);
[value,isterminal,~,causes] = odeEventsFun(tspan(1), y0);
if(any(abs(value)<=1E-6))
if(any(isterminal(abs(value)<1E-6)) == 1)
t = tspan(1);
y = y0;
newStateLogEntries = eventInitStateLogEntry.createStateLogEntryFromIntegratorOutputRow(t, y, eventInitStateLogEntry);
ie = find(abs(value)<1E-6);

return;
stopIntegration = false;
for(i=1:length(ie))
if(causes(ie(i)).shouldRestartIntegration() == false)
stopIntegration = true;
end
end

if(stopIntegration)
t = tspan(1);
y = y0;
newStateLogEntries = eventInitStateLogEntry.createStateLogEntryFromIntegratorOutputRow(t, y, eventInitStateLogEntry);

return;
end
end
end

[t,y] = obj.integrator(odefun,tspan,y0,options);

% newStateLogEntries = LaunchVehicleStateLogEntry.empty(length(t),0);
[t,y,~,~,ie] = obj.integrator(odefun,tspan,y0,options);
newStateLogEntries = eventInitStateLogEntry.createStateLogEntryFromIntegratorOutputRow(t, y, eventInitStateLogEntry);

if(not(isempty(ie)))
finalStateLogEntry = newStateLogEntries(end);
[tF,yF, ~] = finalStateLogEntry.getIntegratorStateRepresentation();
[~,~,~,causes] = odeEventsFun(tF, yF);

cause = causes(ie(1));

if(cause.shouldRestartIntegration())
newFinalStateLogEntry = cause.getRestartInitialState(finalStateLogEntry);

[tRestart,yRestart,newStateLogEntriesRestart] = obj.integrateOneEvent(event, newFinalStateLogEntry);

t = vertcat(t,tRestart);
y = vertcat(y,yRestart);
newStateLogEntries = horzcat(newStateLogEntries,newStateLogEntriesRestart);
end
end
end
end

Expand Down Expand Up @@ -140,8 +167,9 @@
dydt(7:end) = tankMassDots;
end

function [value,isterminal,direction] = odeEvents(t,y, obj, eventInitStateLogEntry, evtTermCond)
function [value,isterminal,direction, causes] = odeEvents(t,y, obj, eventInitStateLogEntry, evtTermCond)
celBodyData = obj.celBodyData;
causes = AbstractIntegrationTerminationCause.empty(0,1);

sizeY = size(y);
if(sizeY(2) > sizeY(1))
Expand All @@ -157,16 +185,22 @@
value(1) = altitude - obj.minAltitude;
isterminal(1) = 1;
direction(1) = -1;
causes(1) = MinAltitudeIntTermCause();

%Max Radius (SoI Radius) Constraint
%Max Radius (SoI Radius) Constraint (Leave SOI Upwards)
parentBodyInfo = getParentBodyInfo(bodyInfo, celBodyData);
rSOI = getSOIRadius(bodyInfo, parentBodyInfo);
radius = norm(rVect);

if(isempty(parentBodyInfo))
parentBodyInfo = KSPTOT_BodyInfo.empty(0,1);
end

value(2) = rSOI - radius;
isterminal(2) = 1;
direction(2) = 1;

direction(2) = -1;
causes(2) = SoITransitionUpIntTermCause(bodyInfo, parentBodyInfo, celBodyData);

%Leave SoI Downwards
children = getChildrenOfParentInfo(celBodyData, bodyInfo.name);
for(i=1:length(children))
Expand All @@ -180,10 +214,12 @@
value(end+1) = distToChild - rSOI; %#ok<AGROW>
isterminal(end+1) = 1; %#ok<AGROW>
direction(end+1) = -1; %#ok<AGROW>
causes(end+1) = SoITransitionDownIntTermCause(bodyInfo, childBodyInfo, celBodyData); %#ok<AGROW>
end

%Event Termination Condition
[value(end+1),isterminal(end+1),direction(end+1)] = evtTermCond(t,y);
causes(end+1) = EventTermCondIntTermCause();
end

function status = odeOutput(t,y,flag, intStartTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,17 +463,9 @@ function genPlotsButton_Callback(hObject, eventdata, handles)
end

if(ismember(taskStr,maTaskList))
try
[depVarValues(i,j), depVarUnits{j}, prevDistTraveled] = ma_getDepVarValueUnit(i, maSubLog, taskStr, prevDistTraveled, refBodyId, otherSCId, stationID, propNames, [], celBodyData, false);
catch ME
a = 1;
end
else
try
[depVarValues(i,j), depVarUnits{j}] = lvd_getDepVarValueUnit(i, lvdSubLog, taskStr, refBodyId, celBodyData, false);
catch ME
a = 1;
end
end
end
end
Expand Down
Loading

0 comments on commit 11b9af0

Please sign in to comment.