Skip to content

Commit 90c375a

Browse files
committed
LVD:
1) Added thrust to weight termination condition 2) Updates to some of the steering angles term conditions to make them go 0-360 deg for easier termination convergence. 3) Fixed a bug in altitude optim var.
1 parent afefd5d commit 90c375a

10 files changed

Lines changed: 185 additions & 5 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
classdef SeaLevelThrustToWeightTermCondition < AbstractEventTerminationCondition
2+
%SeaLevelThrustToWeightTermCondition Summary of this class goes here
3+
% Detailed explanation goes here
4+
5+
properties
6+
targetTtW(1,1) double = 0;
7+
8+
dryMass(1,1) double = 0;
9+
tankStates(1,:) LaunchVehicleTankState
10+
stgStates(1,:) LaunchVehicleStageState
11+
lvState(1,:) LaunchVehicleState
12+
throttleModel AbstractThrottleModel = ThrottlePolyModel.getDefaultThrottleModel();
13+
bodyInfo KSPTOT_BodyInfo
14+
end
15+
16+
methods
17+
function obj = SeaLevelThrustToWeightTermCondition(targetTtW)
18+
obj.targetTtW = targetTtW;
19+
end
20+
21+
function evtTermCondFcnHndl = getEventTermCondFuncHandle(obj)
22+
evtTermCondFcnHndl = @(t,y) obj.eventTermCond(t,y, obj.targetTtW, obj.dryMass, obj.stgStates, obj.lvState, obj.throttleModel, obj.tankStates, obj.bodyInfo);
23+
end
24+
25+
function initTermCondition(obj, initialStateLogEntry)
26+
obj.bodyInfo = initialStateLogEntry.centralBody;
27+
obj.dryMass = initialStateLogEntry.getTotalVehicleDryMass();
28+
29+
obj.tankStates = initialStateLogEntry.getAllActiveTankStates();
30+
obj.stgStates = initialStateLogEntry.stageStates;
31+
obj.lvState = initialStateLogEntry.lvState;
32+
obj.throttleModel = initialStateLogEntry.throttleModel;
33+
end
34+
35+
function name = getName(obj)
36+
name = sprintf('Thrust to Weight Ratio (Sea Level) (%.3f)', obj.targetTtW);
37+
end
38+
39+
function params = getTermCondUiStruct(obj)
40+
params = struct();
41+
42+
params.paramName = 'Target T2W';
43+
params.paramUnit = '';
44+
params.useParam = 'on';
45+
params.useStages = 'off';
46+
params.useTanks = 'off';
47+
params.useEngines = 'off';
48+
49+
params.value = obj.targetTtW;
50+
params.refStage = LaunchVehicleStage.empty(1,0);
51+
params.refTank = LaunchVehicleEngine.empty(1,0);
52+
params.refEngine = LaunchVehicleEngine.empty(1,0);
53+
end
54+
55+
function optVar = getNewOptVar(obj)
56+
optVar = Thr2WghtTermCondOptimVar(obj);
57+
end
58+
59+
function optVar = getExistingOptVar(obj)
60+
optVar = obj.optVar;
61+
end
62+
63+
function tf = usesStage(obj, stage)
64+
tf = false;
65+
end
66+
67+
function tf = usesEngine(obj, engine)
68+
tf = false;
69+
end
70+
71+
function tf = usesTank(obj, tank)
72+
tf = false;
73+
end
74+
75+
function tf = usesEngineToTankConn(obj, engineToTank)
76+
tf = false;
77+
end
78+
end
79+
80+
methods(Static)
81+
function termCond = getTermCondForParams(paramValue, stage, tank, engine)
82+
termCond = SeaLevelThrustToWeightTermCondition((paramValue));
83+
end
84+
end
85+
86+
methods(Static, Access=private)
87+
function [value,isterminal,direction] = eventTermCond(t,y, targetTtW, dryMass, stgStates, lvState, throttleModel, tankStates, bodyInfo)
88+
ut = t;
89+
rVect = y(1:3);
90+
tankMasses = y(7:end);
91+
throttle = throttleModel.getThrottleAtTime(ut);
92+
93+
altitude = norm(rVect) - bodyInfo.radius;
94+
presskPa = getPressureAtAltitude(bodyInfo, altitude);
95+
96+
[~, totalThrust]= LaunchVehicleStateLogEntry.getTankMassFlowRatesDueToEngines(tankStates, stgStates, throttle, lvState, presskPa);
97+
98+
totalMass = (dryMass + sum(tankMasses))*1000; %kg
99+
gSlAccel = (bodyInfo.gm / ((bodyInfo.radius)^2))*1000; %m/s^2
100+
totalSlWeight = totalMass*gSlAccel; %kg*m/s^2 = N
101+
102+
totalThrust = totalThrust * 1000; % N
103+
104+
twRatio = totalThrust/totalSlWeight;
105+
106+
value = twRatio - targetTtW;
107+
isterminal = 1;
108+
direction = 0;
109+
end
110+
end
111+
end

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
SideSlipAngle('Side Slip Angle','SideSlipAngleTermCondition');
1313
TankMass('Tank Mass','TankMassTermCondition');
1414
ThrottleSetting('Throttle Setting','ThrottleTermCondition');
15+
ThrustToWeightRatio('Thrust to Weight Ratio (Sea Level)','SeaLevelThrustToWeightTermCondition');
1516
TrueAnomaly('True Anomaly','TrueAnomalyTermCondition');
1617
YawAngle('Yaw Angle','YawTermCondition');
1718
end

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ function initTermCondition(obj, initialStateLogEntry)
8282
dcm = steeringModel.getBody2InertialDcmAtTime(ut, rVect, vVect, bodyInfo);
8383
[bankAng,~,~] = computeAeroAnglesFromBodyAxes(rVect, vVect, dcm(:,1), dcm(:,2), dcm(:,3));
8484

85+
bankAng = AngleZero2Pi(bankAng);
86+
8587
value = bankAng - targetBankAngle;
8688
isterminal = 1;
8789
direction = 0;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ function initTermCondition(obj, initialStateLogEntry)
8282
dcm = steeringModel.getBody2InertialDcmAtTime(ut, rVect, vVect, bodyInfo);
8383
[rollAngle,~,~] = computeEulerAnglesFromInertialBodyAxes(ut, rVect, vVect, bodyInfo, dcm(:,1), dcm(:,2), dcm(:,3));
8484

85+
rollAngle = AngleZero2Pi(rollAngle);
86+
8587
value = rollAngle - targetRollAngle;
8688
isterminal = 1;
8789
direction = 0;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ function initTermCondition(obj, initialStateLogEntry)
8282
dcm = steeringModel.getBody2InertialDcmAtTime(ut, rVect, vVect, bodyInfo);
8383
[~,~,angOfSideslip] = computeAeroAnglesFromBodyAxes(rVect, vVect, dcm(:,1), dcm(:,2), dcm(:,3));
8484

85+
angOfSideslip = AngleZero2Pi(angOfSideslip);
86+
8587
value = angOfSideslip - targetSlipAngle;
8688
isterminal = 1;
8789
direction = 0;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ function initTermCondition(obj, initialStateLogEntry)
8282
dcm = steeringModel.getBody2InertialDcmAtTime(ut, rVect, vVect, bodyInfo);
8383
[~,~,yawAngle] = computeEulerAnglesFromInertialBodyAxes(ut, rVect, vVect, bodyInfo, dcm(:,1), dcm(:,2), dcm(:,3));
8484

85+
yawAngle = AngleZero2Pi(yawAngle);
86+
8587
value = yawAngle - targetYawAngle;
8688
isterminal = 1;
8789
direction = 0;

helper_methods/ksptot_ma/launch_vehicle_designer/classes/Optimization/variables/@AltitudeOptimizationVariable/AltitudeOptimizationVariable.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
end
2929

3030
function [lb, ub] = getBndsForVariable(obj)
31-
lb = obj.lwrBnd(obj.useTf);
32-
ub = obj.uprBnd(obj.useTf);
31+
lb = obj.lb(obj.useTf);
32+
ub = obj.ub(obj.useTf);
3333
end
3434

3535
function [lb, ub] = getAllBndsForVariable(obj)

helper_methods/ksptot_ma/launch_vehicle_designer/classes/Optimization/variables/@TankMassOptimizationVariable/TankMassOptimizationVariable.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function setBndsForVariable(obj, lb, ub)
4343
end
4444

4545
function useTf = getUseTfForVariable(obj)
46-
useTf = true;
46+
useTf = obj.useTf;
4747
end
4848

4949
function setUseTfForVariable(obj, useTf)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
classdef Thr2WghtTermCondOptimVar < AbstractOptimizationVariable
2+
%Thr2WghtTermCondOptimVar Thrust to weight ratio termination condition
3+
%variable
4+
% Detailed explanation goes here
5+
6+
properties
7+
varObj(1,1) SeaLevelThrustToWeightTermCondition = SeaLevelThrustToWeightTermCondition(1);
8+
9+
lb(1,1) double = 0;
10+
ub(1,1) double = 0;
11+
12+
useTf(1,1) = false;
13+
end
14+
15+
methods
16+
function obj = Thr2WghtTermCondOptimVar(varObj)
17+
obj.varObj = varObj;
18+
obj.varObj.optVar = obj;
19+
20+
obj.id = rand();
21+
end
22+
23+
function x = getXsForVariable(obj)
24+
x = [];
25+
26+
if(obj.useTf)
27+
x = obj.varObj.targetTtW;
28+
end
29+
end
30+
31+
function [lb, ub] = getBndsForVariable(obj)
32+
lb = obj.lb(obj.useTf);
33+
ub = obj.ub(obj.useTf);
34+
end
35+
36+
function [lb, ub] = getAllBndsForVariable(obj)
37+
lb = obj.lb;
38+
ub = obj.ub;
39+
end
40+
41+
function setBndsForVariable(obj, lb, ub)
42+
obj.lb = lb;
43+
obj.ub = ub;
44+
end
45+
46+
function useTf = getUseTfForVariable(obj)
47+
useTf = obj.useTf;
48+
end
49+
50+
function setUseTfForVariable(obj, useTf)
51+
obj.useTf = useTf;
52+
end
53+
54+
function updateObjWithVarValue(obj, x)
55+
obj.varObj.targetTtW = x;
56+
end
57+
end
58+
end

helper_methods/ksptot_ma/launch_vehicle_designer/classes/StateLog/@LaunchVehicleStateLogEntry/LaunchVehicleStateLogEntry.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,11 @@ function updateTankStatesWithNewMasses(obj, newTankMasses)
181181
end
182182
end
183183

184-
function tankMDots = getTankMassFlowRatesDueToEngines(tankStates, stgStates, throttle, lvState, presskPa)
184+
function [tankMDots, totalThrust]= getTankMassFlowRatesDueToEngines(tankStates, stgStates, throttle, lvState, presskPa)
185185
% tankStates = obj.getAllActiveTankStates();
186186
tankMDots = zeros(size(tankStates));
187187
tankMDots = tankMDots(:);
188+
totalThrust = 0;
188189

189190
% stgStates = obj.stageStates;
190191
for(i=1:length(stgStates)) %#ok<*NO4LP>
@@ -198,9 +199,10 @@ function updateTankStatesWithNewMasses(obj, newTankMasses)
198199

199200
if(engineState.active)
200201
engine = engineState.engine;
201-
[~, mdot] = engine.getThrustFlowRateForPressure(presskPa); %total mass flow through engine
202+
[thrust, mdot] = engine.getThrustFlowRateForPressure(presskPa); %total mass flow through engine
202203
adjustedThrottle = engine.adjustThrottleForMinMax(throttle);
203204
mdot = adjustedThrottle * mdot;
205+
totalThrust = totalThrust + adjustedThrottle*thrust;
204206

205207
tanks = lvState.getTanksConnectedToEngine(engine);
206208

0 commit comments

Comments
 (0)