Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim succeeds and results in NaN values #935

Open
1 of 3 tasks
7x11x13 opened this issue Jun 29, 2023 · 1 comment
Open
1 of 3 tasks

Trim succeeds and results in NaN values #935

7x11x13 opened this issue Jun 29, 2023 · 1 comment

Comments

@7x11x13
Copy link

7x11x13 commented Jun 29, 2023

I'm submitting a ...

  • bug report
  • feature request
  • support request => Please do not submit support request here, see note at the top of this template.

Describe the issue
I've been debugging a crash in an Unreal Engine project and found the cause to stem from the FGTrim::DoTrim routine (although maybe it also stems from improper initial conditions? I'm not entirely sure).

What is the current behavior?
When executing a ground trim, if the initial altitude above ground level is 0, the trim routine will succeed but set the altitude axis control value to NaN. This also happens whenever the control value min = control value max for any axis. This happens due to the following code in FGTrim::solve:

d0=fabs(x3-x1);
//iterations
//max_sub_iterations=axis.GetIterationLimit();
while ( (axis.InTolerance() == false )
&& (fabs(d) > eps) && (Nsub < max_sub_iterations)) {
Nsub++;
d=(x3-x1)/d0;
x2=x1-d*d0*f1/(f3-f1);
axis.SetControl(x2);
axis.Run();

When x1 = x3, as it does in the case of a ground trim at 0 altitude (according to line 216), d0 will be 0 and x2 will be NaN, which causes everything else to be NaN, and the trim succeeds with NaN altitude (which causes a crash in Unreal Engine).

What is the expected behavior?
I believe the solve method should check if d0 is 0 and if so, set x1 as the control value, see if the axis is within tolerance, and return accordingly, since the potential solution space is narrowed to just that one value. Something like the following placed at line 558:

d0=fabs(x3-x1);
if (d0 <= eps) {
  axis.SetControl(x1);
  axis.Run();
  return axis.InTolerance();
}

What is the motivation / use case for changing the behavior?

It's misleading for the trim routine to succeed and yet return NaN values which can potentially lead to crashes, so I believe this special case should be dealt with by the trim routine.

Please tell us about your environment:

  • OS: Windows 10
  • JSBSim version: latest commit (6c1abbe)
  • C++

Other information
I'm new to JSBSim so apologies if my terminology is incorrect or if I've made some other mistake.

@seanmcleod
Copy link
Member

if the initial altitude above ground level is 0,

Hmm, I haven't looked at the trim code in detail yet, but whenever I see an AGL of 0 the immediate issue that comes to mind which comes up fairly frequently is that means the gear and it's spring are massively compressed, since the AGL is relative to the CG and not the bottom of the gear.

This sort of massive compression of the gear spring with it's spring coefficient often means you get a massive rebound of the aircraft, sometimes to such an extent that you end up with NaNs.

Now I'm not sure whether in this case, i.e. ground trim in particular that the ground trim code is handling this issue specifically or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants