Stable outputs when re-running initial conditions #455
Replies: 16 comments 14 replies
-
Hmm, so if you look closely enough run 2 and 3 aren't identical either. One issue I spotted with the F-15 model that may explain these differences is that the control surfaces have Unless there is specific code during the So as a quick test, remove the |
Beta Was this translation helpful? Give feedback.
-
Hmm. on closer inspection of the F15 xml I see the <channel name="Pitch">
<summer name="Pitch Trim Sum">
<input>fcs/elevator-cmd-norm</input>
<input>fcs/pitch-trim-cmd-norm</input>
<clipto>
<min>-1</min>
<max>1</max>
</clipto>
</summer>
<kinematic name="elevator position">
<input>fcs/pitch-trim-sum</input>
<traverse>
<setting>
<position>-1</position>
<time>0.6</time>
</setting>
<setting>
<position>1</position>
<time>0.6</time>
</setting>
</traverse>
<output>fcs/elevator-pos-norm</output>
</kinematic>
<aerosurface_scale name="elevator position">
<input>fcs/pitch-trim-sum</input>
<gain>0.01745</gain>
<domain>
<min>-1</min>
<max>1</max>
</domain>
<range>
<min>-26</min>
<max>15</max>
</range>
<output>fcs/elevator-pos-rad</output>
</aerosurface_scale> And double-checking. fdm['fcs/elevator-cmd-norm'] = 1
# Initialize the aircraft with initial conditions
fdm.run_ic()
for i in range(0, 80):
cmd = fdm['fcs/elevator-cmd-norm']
norm = fdm['fcs/elevator-pos-norm']
pos = fdm['fcs/elevator-pos-rad']
print(cmd, norm, pos)
fdm.run() Sure enough 1.0 0.05555555555555556 0.26175
1.0 0.08333333333333334 0.26175
1.0 0.11111111111111112 0.26175
1.0 0.1388888888888889 0.26175
1.0 0.16666666666666669 0.26175
1.0 0.19444444444444448 0.26175
1.0 0.22222222222222227 0.26175
1.0 0.25000000000000006 0.26175
1.0 0.27777777777777785 0.26175
1.0 0.30555555555555564 0.26175
1.0 0.3333333333333334 0.26175
1.0 0.3611111111111112 0.26175
1.0 0.388888888888889 0.26175
1.0 0.4166666666666668 0.26175
1.0 0.4444444444444446 0.26175
1.0 0.4722222222222224 0.26175
1.0 0.5000000000000001 0.26175
1.0 0.5277777777777779 0.26175
1.0 0.5555555555555557 0.26175
1.0 0.5833333333333335 0.26175
1.0 0.6111111111111113 0.26175
1.0 0.6388888888888891 0.26175
1.0 0.6666666666666669 0.26175
1.0 0.6944444444444446 0.26175
1.0 0.7222222222222224 0.26175
1.0 0.7500000000000002 0.26175
1.0 0.777777777777778 0.26175
1.0 0.8055555555555558 0.26175
1.0 0.8333333333333336 0.26175
1.0 0.8611111111111114 0.26175
1.0 0.8888888888888892 0.26175
1.0 0.916666666666667 0.26175
1.0 0.9444444444444448 0.26175
1.0 0.9722222222222225 0.26175
1.0 1.0 0.26175
1.0 1.0 0.26175 |
Beta Was this translation helpful? Give feedback.
-
Implemented a quick python version to see if I could reproduce what you're seeing. Haven't tried matching your exact initial conditions yet. import jsbsim
# The path supplied to FGFDMExec is the location of the folders "aircraft", "engines" and "systems"
fdm = jsbsim.FGFDMExec('..\\')
# Load the aircraft
fdm.load_model('f15')
# Set engines running
fdm['propulsion/engine[0]/set-running'] = 1
fdm['propulsion/engine[1]/set-running'] = 1
results = []
fdm['ic/h-sl-ft'] = 30000
fdm['ic/vc-kts'] = 285
fdm['ic/gamma-deg'] = 0
fdm['fcs/elevator-cmd-norm'] = -0.05
results = { 'attitude' : [], 'bodyVelocities': [], 'bodyRates': [], 'forces': [], 'moments': [] }
for i in range(0, 10):
fdm.run_ic()
attitude = "Attitude: {0}, {1}, {2}".format(fdm['attitude/theta-deg'], fdm['attitude/phi-deg'], fdm['attitude/psi-deg'])
bodyVelocities = "Velocity (u,v,w): {0}, {1}, {2}".format(fdm['velocities/u-fps'], fdm['velocities/v-fps'], fdm['velocities/w-fps'])
bodyRates = "Rates (p,q,r): {0}, {1}, {2}".format(fdm['velocities/p-rad_sec'], fdm['velocities/q-rad_sec'], fdm['velocities/r-rad_sec'])
forces = "Aero Forces (body): (x,y,z): {0}, {1}, {2}".format(fdm['forces/fbx-aero-lbs'], fdm['forces/fby-aero-lbs'], fdm['forces/fbz-aero-lbs'])
moments = "Aero Moments (body): (x,y,z): {0}, {1}, {2}".format(fdm['moments/l-aero-lbsft'], fdm['moments/m-aero-lbsft'], fdm['moments/n-aero-lbsft'])
results['attitude'].append(attitude)
results['bodyVelocities'].append(bodyVelocities)
results['bodyRates'].append(bodyRates)
results['forces'].append(forces)
results['moments'].append(moments)
for key in results:
for item in results[key]:
print(item)
print('') In terms of results: Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Aero Forces (body): (x,y,z): -2989.237635695297, 0.0, -6432.800167182645
Aero Forces (body): (x,y,z): -2989.237635695297, 0.0, -6398.291844587653
Aero Forces (body): (x,y,z): -2989.237635695297, 0.0, -6398.2470975854985
Aero Forces (body): (x,y,z): -2989.237635695297, 0.0, -6398.247039561983
Aero Forces (body): (x,y,z): -2989.237635695297, 0.0, -6398.247039486743
Aero Forces (body): (x,y,z): -2989.237635695297, 0.0, -6398.247039486646
Aero Forces (body): (x,y,z): -2989.237635695297, 0.0, -6398.247039486646
Aero Forces (body): (x,y,z): -2989.237635695297, 0.0, -6398.247039486646
Aero Forces (body): (x,y,z): -2989.237635695297, 0.0, -6398.247039486646
Aero Forces (body): (x,y,z): -2989.237635695297, 0.0, -6398.247039486646
Aero Moments (body): (x,y,z): 0.0, 11334.51069592438, 0.0
Aero Moments (body): (x,y,z): 0.0, 11724.054850442746, 0.0
Aero Moments (body): (x,y,z): 0.0, 11724.559973027981, 0.0
Aero Moments (body): (x,y,z): 0.0, 11724.560628021318, 0.0
Aero Moments (body): (x,y,z): 0.0, 11724.560628870651, 0.0
Aero Moments (body): (x,y,z): 0.0, 11724.560628871754, 0.0
Aero Moments (body): (x,y,z): 0.0, 11724.560628871754, 0.0
Aero Moments (body): (x,y,z): 0.0, 11724.560628871754, 0.0
Aero Moments (body): (x,y,z): 0.0, 11724.560628871754, 0.0
Aero Moments (body): (x,y,z): 0.0, 11724.560628871754, 0.0 So what's interesting and perplexing is that the aero forces and moments are only identical from run 6 onwards. |
Beta Was this translation helpful? Give feedback.
-
Hmm, so if I simply switch from the f15 model to the 737 model in my test script above these are the results I get for the 737, basically the aero forces and moments are identical for all 10 runs. So it appears there is something different about the f15 model. Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Attitude: 1.2722218725854067e-14, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Velocity (u,v,w): 749.8178322058461, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Rates (p,q,r): 0.0, 0.0, 0.0
Aero Forces (body): (x,y,z): -11303.996708792423, 0.0, -57760.53469486948
Aero Forces (body): (x,y,z): -11303.996708792423, 0.0, -57760.53469486948
Aero Forces (body): (x,y,z): -11303.996708792423, 0.0, -57760.53469486948
Aero Forces (body): (x,y,z): -11303.996708792423, 0.0, -57760.53469486948
Aero Forces (body): (x,y,z): -11303.996708792423, 0.0, -57760.53469486948
Aero Forces (body): (x,y,z): -11303.996708792423, 0.0, -57760.53469486948
Aero Forces (body): (x,y,z): -11303.996708792423, 0.0, -57760.53469486948
Aero Forces (body): (x,y,z): -11303.996708792423, 0.0, -57760.53469486948
Aero Forces (body): (x,y,z): -11303.996708792423, 0.0, -57760.53469486948
Aero Forces (body): (x,y,z): -11303.996708792423, 0.0, -57760.53469486948
Aero Moments (body): (x,y,z): 0.0, 24710.507804375156, 0.0
Aero Moments (body): (x,y,z): 0.0, 24710.507804375156, 0.0
Aero Moments (body): (x,y,z): 0.0, 24710.507804375156, 0.0
Aero Moments (body): (x,y,z): 0.0, 24710.507804375156, 0.0
Aero Moments (body): (x,y,z): 0.0, 24710.507804375156, 0.0
Aero Moments (body): (x,y,z): 0.0, 24710.507804375156, 0.0
Aero Moments (body): (x,y,z): 0.0, 24710.507804375156, 0.0
Aero Moments (body): (x,y,z): 0.0, 24710.507804375156, 0.0
Aero Moments (body): (x,y,z): 0.0, 24710.507804375156, 0.0
Aero Moments (body): (x,y,z): 0.0, 24710.507804375156, 0.0 |
Beta Was this translation helpful? Give feedback.
-
So I started looking at and logging each of the lift forces, i.e. Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, -1978.8144291296521, -0.0, 994.1024816676367
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, -1978.8144291296521, -0.0, 959.5941590726438
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, -1978.8144291296521, -0.0, 959.5494120704899
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, -1978.8144291296521, -0.0, 959.5493540469741
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, -1978.8144291296521, -0.0, 959.5493539717348
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, -1978.8144291296521, -0.0, 959.5493539716374
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, -1978.8144291296521, -0.0, 959.5493539716374
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, -1978.8144291296521, -0.0, 959.5493539716374
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, -1978.8144291296521, -0.0, 959.5493539716374
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, -1978.8144291296521, -0.0, 959.5493539716374 And it looks like I've found the culprit, i.e. Alpha-dot: 0.035647635065063944
Alpha-dot: 0.03441019716177031
Alpha-dot: 0.03440859257388077
Alpha-dot: 0.03440859049320886
Alpha-dot: 0.03440859049051084
Alpha-dot: 0.034408590490507346
Alpha-dot: 0.034408590490507346
Alpha-dot: 0.034408590490507346
Alpha-dot: 0.034408590490507346
Alpha-dot: 0.034408590490507346 So we'll need to investigate why alpha-dot varies across initialization runs. The 737 model doesn't include |
Beta Was this translation helpful? Give feedback.
-
So alpha = atan2(vAeroUVW(eW), vAeroUVW(eU));
adot = (vAeroUVW(eU)*in.vUVWdot(eW) - vAeroUVW(eW)*in.vUVWdot(eU))/mUW; And in your original post you listed: uvw = 328.812, 0, -19.8312
uvw = 328.812, 0, -19.8312
uvw = 328.812, 0, -19.8312
uvw_dot = 1.65332, -1.32186e-17, 26.7752
uvw_dot = 1.65502, -1.32186e-17, 26.8034
uvw_dot = 1.65503, -1.32186e-17, 26.8034 In other words So the question is why the variance in |
Beta Was this translation helpful? Give feedback.
-
So Lines 644 to 654 in 375f5be Which uses the current derivative to initialize a past value deque 5 deep, which explains where the magical 6 runs comes from in terms of things stabilizing after 6 runs. jsbsim/src/models/FGPropagate.cpp Lines 188 to 196 in 375f5be |
Beta Was this translation helpful? Give feedback.
-
I think there is a misunderstanding: If you want a complete reinitialization of JSBSim, you should call Lines 690 to 704 in a632306 You can get the same result by setting the property simulation/reset to any value. In the case where you want the outputs to be reinitialized as well, you should set the property (or call the method) to 1.
|
Beta Was this translation helpful? Give feedback.
-
Here was my thinking, although I haven't had a chance to set a breakpoint and double-check, it was getting late last night and it's getting late again. So at the time of the very first call to Now when the second call to So basically the first 5 calls to Ah, as I was about to post this I just saw your subsequent reply which mentions the use of And it also means we just got lucky with the 737 model which did have the exact same forces and moments for all 10 runs. |
Beta Was this translation helpful? Give feedback.
-
@rjmccabe3701 so I tested @bcoconni's suggestion of using for i in range(0, 10):
#fdm.run_ic()
fdm.reset_to_initial_conditions(1) And sure enough the f15 model now shows identical forces, moments, etc. for all 10 runs. Aero Forces (body): (x,y,z): -2837.977475144025, 0.0, -8340.35799301889
Aero Forces (body): (x,y,z): -2837.977475144025, 0.0, -8340.35799301889
Aero Forces (body): (x,y,z): -2837.977475144025, 0.0, -8340.35799301889
Aero Forces (body): (x,y,z): -2837.977475144025, 0.0, -8340.35799301889
Aero Forces (body): (x,y,z): -2837.977475144025, 0.0, -8340.35799301889
Aero Forces (body): (x,y,z): -2837.977475144025, 0.0, -8340.35799301889
Aero Forces (body): (x,y,z): -2837.977475144025, 0.0, -8340.35799301889
Aero Forces (body): (x,y,z): -2837.977475144025, 0.0, -8340.35799301889
Aero Forces (body): (x,y,z): -2837.977475144025, 0.0, -8340.35799301889
Aero Forces (body): (x,y,z): -2837.977475144025, 0.0, -8340.35799301889
Aero Moments (body): (x,y,z): 0.0, -13585.026738264562, 0.0
Aero Moments (body): (x,y,z): 0.0, -13585.026738264562, 0.0
Aero Moments (body): (x,y,z): 0.0, -13585.026738264562, 0.0
Aero Moments (body): (x,y,z): 0.0, -13585.026738264562, 0.0
Aero Moments (body): (x,y,z): 0.0, -13585.026738264562, 0.0
Aero Moments (body): (x,y,z): 0.0, -13585.026738264562, 0.0
Aero Moments (body): (x,y,z): 0.0, -13585.026738264562, 0.0
Aero Moments (body): (x,y,z): 0.0, -13585.026738264562, 0.0
Aero Moments (body): (x,y,z): 0.0, -13585.026738264562, 0.0
Aero Moments (body): (x,y,z): 0.0, -13585.026738264562, 0.0
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, 0.0, -0.0, 922.8458783742286
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, 0.0, -0.0, 922.8458783742286
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, 0.0, -0.0, 922.8458783742286
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, 0.0, -0.0, 922.8458783742286
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, 0.0, -0.0, 922.8458783742286
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, 0.0, -0.0, 922.8458783742286
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, 0.0, -0.0, 922.8458783742286
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, 0.0, -0.0, 922.8458783742286
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, 0.0, -0.0, 922.8458783742286
Lift forces (CLalpha, CLDe, CLq, CLadot): 7417.512114644661, 0.0, -0.0, 922.8458783742286 However it's currently not an ideal replacement for what you're trying to achieve. If you look closely you'll see that fdm['ic/h-sl-ft'] = 30000
fdm['ic/vc-kts'] = 285
fdm['ic/gamma-deg'] = 0
fdm['fcs/elevator-cmd-norm'] = -0.05 That's because as @bcoconni mentioned One option is to expand the argument options to void FGFDMExec::ResetToInitialConditions(int mode)
{
if (Constructing) return;
const int START_NEW_OUTPUT = 0x1;
const int DONT_EXECUTE_RUN_IC = 0x2;
if (mode & START_NEW_OUTPUT) Output->SetStartNewOutput();
InitializeModels();
if (Script)
Script->ResetEvents();
else
Setsim_time(0.0);
if (!(mode & DONT_EXECUTE_RUN_IC))
RunIC();
} So you would then be able to use code along these lines to achieve what you want. fdm['ic/h-sl-ft'] = 30000
fdm['ic/vc-kts'] = 285
fdm['ic/gamma-deg'] = 0
for i in range(0, 10):
fdm.reset_to_initial_conditions(3)
fdm['propulsion/engine[0]/set-running'] = 1
fdm['propulsion/engine[1]/set-running'] = 1
fdm['fcs/elevator-cmd-norm'] = -0.05
fdm.run_ic() |
Beta Was this translation helpful? Give feedback.
-
@rjmccabe3701 I noticed an issue with your drag calculation, not related to the issue with multiple initializations. auto aero = fdmex->GetAerodynamics();
outputs->forces[0] = aero->GetForces(1) * PoundsToNewtons;
outputs->forces[1] = aero->GetForces(2) * PoundsToNewtons;
outputs->forces[2] = aero->GetForces(3) * PoundsToNewtons;
outputs->drag = -1* aero->GetForces(1) * PoundsToNewtons; The drag issue is that JSBSim provides the forces and moments in all 3 axes, i.e. body, stability and wind. jsbsim/src/models/FGAerodynamics.cpp Lines 567 to 584 in a632306 |
Beta Was this translation helpful? Give feedback.
-
@rjmccabe3701 out of interest what are you using Jsbsim for? |
Beta Was this translation helpful? Give feedback.
-
@rjmccabe3701 always interesting to find out about real-world usage of JSBSim. Talking of using JSBSim to generate performance related graphs coincidentally there was a discussion on this recently - #428 In terms of using MATLAB for the trim calculations any particular reason you used MATLAB as opposed to the JSBSim's trim routines? Lastly in terms of MATLAB and JSBSim integration there is a current pull request to add support for JSBSim as a Matlab/Simulink S-Function here - #445 How are you integrating MATLAB and JSBSim? |
Beta Was this translation helpful? Give feedback.
-
In terms of some of the extreme points failing to trim it could be related to the default range of alpha values being used by the trim solver in JSBSim, e.g. take a look at the following comment, default appears to be a maximum of 7.5 degrees, but you can change the range. |
Beta Was this translation helpful? Give feedback.
-
@rjmccabe3701 how were you trimming in JSBSim for your EM graphs? Were you using the |
Beta Was this translation helpful? Give feedback.
-
Or were you using the void FGTrim::setupTurn(void){
double g,phi;
phi = fgic.GetPhiRadIC();
if( fabs(phi) > 0.001 && fabs(phi) < 1.56 ) {
targetNlf = 1 / cos(phi);
g = fdmex->GetInertial()->GetGravity().Magnitude();
psidot = g*tan(phi) / fgic.GetUBodyFpsIC();
cout << targetNlf << ", " << psidot << endl;
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I noticed that the
FGFDMexec
class doesn't reinitialize itself correctly if you callRunIC()
multiple times.Here is a test program that illustrates the weird behavior:
Here is a test program that queries the forces, moments, etc of the aircraft three times with the same
initial conditions.
I am expecting 3 identical sets of outputs, but it looks like the first time I call it I get different answers:
What am I doing wrong? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions