Skip to content

Commit a88eede

Browse files
committed
LVD:
1) Added bank angle termination condition 2) Added a typical X parameter to the optimization to help with convergence 3) Fixed bug with deleting an event without looking at constraints and the objective function to see if they used that event. 4) Fixed a number of other bugs.
1 parent 8a09fbb commit a88eede

29 files changed

Lines changed: 467 additions & 41 deletions

File tree

helper_methods/ksptot_ma/launch_vehicle_designer/classes/@LvdData/LvdData.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@
167167
coastDurVar.setBndsForVariable(0, 130);
168168
lvdOptim.vars.addVariable(coastDurVar);
169169

170-
const1 = GenericMAConstraint('Eccentricity', evt6, 0, 0, struct.empty(1,0), struct.empty(1,0), celBodyData.kerbin);
170+
const1 = GenericMAConstraint('Eccentricity', evt5, 0, 0, struct.empty(1,0), struct.empty(1,0), celBodyData.kerbin);
171171
lvdOptim.constraints.addConstraint(const1);
172172

173173
% const2 = GenericMAConstraint('Semi-major Axis', evt6, 700, 700, struct.empty(1,0), struct.empty(1,0), celBodyData.kerbin);
174174
% lvdOptim.constraints.addConstraint(const2);
175175

176-
const3 = GenericMAConstraint('Altitude', evt6, 75, realmax, struct.empty(1,0), struct.empty(1,0), celBodyData.kerbin);
176+
const3 = GenericMAConstraint('Altitude', evt5, 75, 10000, struct.empty(1,0), struct.empty(1,0), celBodyData.kerbin);
177177
lvdOptim.constraints.addConstraint(const3);
178178

179179
lvdData.optimizer = lvdOptim;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
classdef SetHoldDownClampActiveStateAction < AbstractEventAction
2+
%SetStageActiveStateAction Summary of this class goes here
3+
% Detailed explanation goes here
4+
5+
properties
6+
activeStateToSet(1,1) logical = false;
7+
end
8+
9+
methods
10+
function obj = SetHoldDownClampActiveStateAction(activeStateToSet)
11+
if(nargin > 0)
12+
obj.activeStateToSet = activeStateToSet;
13+
end
14+
15+
obj.id = rand();
16+
end
17+
18+
function newStateLogEntry = exectuteAction(obj, stateLogEntry)
19+
newStateLogEntry = stateLogEntry.deepCopy();
20+
newStateLogEntry.lvState.holdDownEnabled = obj.activeStateToSet;
21+
end
22+
23+
function initAction(obj, initialStateLogEntry)
24+
%nothing
25+
end
26+
27+
function name = getName(obj)
28+
if(obj.activeStateToSet)
29+
tf = 'Active';
30+
else
31+
tf = 'Inactive';
32+
end
33+
34+
name = sprintf('Set Hold Down Clamp State (%s)', tf);
35+
end
36+
37+
function tf = usesStage(obj, stage)
38+
tf = false;
39+
end
40+
41+
function tf = usesEngine(obj, engine)
42+
tf = false;
43+
end
44+
45+
function tf = usesTank(obj, tank)
46+
tf = false;
47+
end
48+
49+
function tf = usesEngineToTankConn(obj, engineToTank)
50+
tf = false;
51+
end
52+
53+
function [tf, vars] = hasActiveOptimVar(obj)
54+
tf = false;
55+
vars = AbstractOptimizationVariable.empty(0,1);
56+
end
57+
end
58+
59+
methods(Static)
60+
function addActionTf = openEditActionUI(action, lv)
61+
addActionTf = lvd_EditActionSetClampStateGUI(action);
62+
end
63+
end
64+
end

helper_methods/ksptot_ma/launch_vehicle_designer/classes/Events/termConditions/@TerminationConditionEnum/TerminationConditionEnum.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
% Detailed explanation goes here
44

55
enumeration
6-
Altitude('Altitude','AltitudeTermCondition')
7-
TankMass('TankMass','TankMassTermCondition')
8-
EventDuration('Event Duration','EventDurationTermCondition');
6+
Altitude('Altitude','AltitudeTermCondition');
97
AngleOfAttack('Angle of Attack','AngleOfAttackTermCondition');
10-
TrueAnomaly('True Anomaly','TrueAnomalyTermCondition')
8+
BankAngle('Bank Angle','BankAngleTermCondition');
9+
EventDuration('Event Duration','EventDurationTermCondition');
10+
TankMass('Tank Mass','TankMassTermCondition');
11+
TrueAnomaly('True Anomaly','TrueAnomalyTermCondition');
12+
13+
1114
end
1215

1316
properties

helper_methods/ksptot_ma/launch_vehicle_designer/classes/Events/termConditions/attitude/@AngleOfAttackTermCondition/AngleOfAttackTermCondition.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function initTermCondition(obj, initialStateLogEntry)
6969

7070
methods(Static)
7171
function termCond = getTermCondForParams(paramValue, stage, tank, engine)
72-
termCond = AngleOfAttackTermCondition(deg2rad(paramValue));
72+
termCond = AngleOfAttackTermCondition((paramValue));
7373
end
7474
end
7575

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
classdef BankAngleTermCondition < AbstractEventTerminationCondition
2+
%BankAngleTermCondition Summary of this class goes here
3+
% Detailed explanation goes here
4+
5+
properties
6+
steeringModel(1,1) AbstractSteeringModel = RollPitchYawPolySteeringModel.getDefaultSteeringModel();
7+
targetBankAngle(1,1) double = 0;
8+
bodyInfo KSPTOT_BodyInfo
9+
end
10+
11+
methods
12+
function obj = BankAngleTermCondition(targetBankAngle)
13+
obj.targetBankAngle = targetBankAngle;
14+
end
15+
16+
function evtTermCondFcnHndl = getEventTermCondFuncHandle(obj)
17+
evtTermCondFcnHndl = @(t,y) obj.eventTermCond(t,y, obj.targetBankAngle, obj.steeringModel, obj.bodyInfo);
18+
end
19+
20+
function initTermCondition(obj, initialStateLogEntry)
21+
obj.steeringModel = initialStateLogEntry.steeringModel;
22+
obj.bodyInfo = initialStateLogEntry.centralBody;
23+
end
24+
25+
function name = getName(obj)
26+
name = sprintf('Bank Angle (%.3f deg)', rad2deg(obj.targetBankAngle));
27+
end
28+
29+
function params = getTermCondUiStruct(obj)
30+
params = struct();
31+
32+
params.paramName = 'Target Bank Angle';
33+
params.paramUnit = 'deg';
34+
params.useParam = 'on';
35+
params.useStages = 'off';
36+
params.useTanks = 'off';
37+
params.useEngines = 'off';
38+
39+
params.value = rad2deg(obj.targetBankAngle);
40+
params.refStage = LaunchVehicleStage.empty(1,0);
41+
params.refTank = LaunchVehicleEngine.empty(1,0);
42+
params.refEngine = LaunchVehicleEngine.empty(1,0);
43+
end
44+
45+
function optVar = getNewOptVar(obj)
46+
optVar = BankAngleTermCondOptimizationVariable(obj);
47+
end
48+
49+
function optVar = getExistingOptVar(obj)
50+
optVar = obj.optVar;
51+
end
52+
53+
function tf = usesStage(obj, stage)
54+
tf = false;
55+
end
56+
57+
function tf = usesEngine(obj, engine)
58+
tf = false;
59+
end
60+
61+
function tf = usesTank(obj, tank)
62+
tf = false;
63+
end
64+
65+
function tf = usesEngineToTankConn(obj, engineToTank)
66+
tf = false;
67+
end
68+
end
69+
70+
methods(Static)
71+
function termCond = getTermCondForParams(paramValue, stage, tank, engine)
72+
termCond = BankAngleTermCondition((paramValue));
73+
end
74+
end
75+
76+
methods(Static, Access=private)
77+
function [value,isterminal,direction] = eventTermCond(t,y, targetBankAngle, steeringModel, bodyInfo)
78+
ut = t;
79+
rVect = y(1:3);
80+
vVect = y(4:6);
81+
82+
dcm = steeringModel.getBody2InertialDcmAtTime(ut, rVect, vVect, bodyInfo);
83+
[bankAng,~,~] = computeAeroAnglesFromBodyAxes(rVect, vVect, dcm(:,1), dcm(:,2), dcm(:,3));
84+
85+
value = bankAng - targetBankAngle;
86+
isterminal = 1;
87+
direction = 0;
88+
end
89+
end
90+
end

helper_methods/ksptot_ma/launch_vehicle_designer/classes/ForceModels/@ThrustForceModel/ThrustForceModel.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,10 @@
4343
tank = tanks(k);
4444
tankState = tankStates([tankStates.tank] == tank);
4545

46-
try
4746
if(tankState.tankMass > 0) %just check to make sure the engine is connected to fuel somewhere
4847
propExistsInATank = true;
4948
break;
5049
end
51-
catch ME
52-
a = 1;
53-
end
5450
end
5551

5652
if(propExistsInATank)

helper_methods/ksptot_ma/launch_vehicle_designer/classes/ForceModels/steering/@AbstractAnglePolySteeringModel/AbstractAnglePolySteeringModel.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
[tf, lb, ub] = getAngleNModelOptVarParams(obj, n)
1111

12-
function addActionTf = openEditSteeringModelUI(obj, lv)
13-
fakeAction = struct();
14-
fakeAction.steeringModel = obj;
12+
function [addActionTf, steeringModel] = openEditSteeringModelUI(obj, lv)
13+
fakeAction = SetSteeringModelAction(obj);
1514

1615
addActionTf = lvd_EditActionSetSteeringModelGUI(fakeAction, lv);
16+
steeringModel = fakeAction.steeringModel;
1717
end
1818
end
1919
end

helper_methods/ksptot_ma/launch_vehicle_designer/classes/Optimization/@LvdOptimization/LvdOptimization.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ function optimize(obj, writeOutput)
2323
objFuncWrapper = @(x) obj.objFcn.evalObjFcn(x);
2424
x0All = obj.vars.getTotalXVector();
2525
[lbAll, ubAll] = obj.vars.getTotalBndsVector();
26+
typicalX = obj.vars.getTypicalXVector();
2627
nonlcon = @(x) obj.constraints.evalConstraints(x);
2728

2829
optimAlg = 'interior-point';
2930
usePara = true;
30-
options = optimoptions('fmincon','Algorithm',optimAlg, 'Diagnostics','on', 'Display','iter-detailed','TolFun',1E-10,'TolX',1E-10,'TolCon',1E-10,'ScaleProblem','none','MaxIter',500,'UseParallel',usePara,'OutputFcn',[],'HonorBounds',true,'MaxFunctionEvaluations',3000, 'FunValCheck','on');
31+
options = optimoptions('fmincon','Algorithm',optimAlg, 'Diagnostics','on', 'Display','iter-detailed','TolFun',1E-10,'TolX',1E-10,'TolCon',1E-10,'ScaleProblem','obj-and-constr','TypicalX',typicalX,'MaxIter',500,'UseParallel',usePara,'OutputFcn',[],'HonorBounds',true,'MaxFunctionEvaluations',3000, 'FunValCheck','on');
3132
problem = createOptimProblem('fmincon', 'objective',objFuncWrapper, 'x0', x0All, 'lb', lbAll, 'ub', ubAll, 'nonlcon', nonlcon, 'options', options);
3233

3334
problem.lvdData = obj.lvdData; %need to get lvdData in somehow

helper_methods/ksptot_ma/launch_vehicle_designer/classes/Optimization/constraints/@AbstractConstraint/AbstractConstraint.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
tf = usesEngineToTankConn(obj, engineToTank)
1919

20+
tf = usesEvent(obj, event);
21+
2022
name = getName(obj)
2123

2224
addConstraintTf = openEditConstraintUI(obj, lvdData);

helper_methods/ksptot_ma/launch_vehicle_designer/classes/Optimization/constraints/@ConstraintSet/ConstraintSet.m

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ function removeConstraint(obj, const)
117117
tf = tf || obj.consts(i).usesEngineToTankConn(engineToTank);
118118
end
119119
end
120+
121+
function removeConstraintsThatUseEvent(obj, event)
122+
indsToRemove = [];
123+
for(i=1:length(obj.consts))
124+
c = obj.consts(i);
125+
126+
if(c.usesEvent(event))
127+
indsToRemove(end+1) = i;
128+
end
129+
end
130+
131+
for(i=length(indsToRemove):-1:1)
132+
indToRemove = indsToRemove(i);
133+
c = obj.consts(indToRemove);
134+
obj.removeConstraint(c);
135+
end
136+
end
120137
end
121-
end
122-
138+
end

0 commit comments

Comments
 (0)