Unreal : GetAGLevel returns NaN so the airplane crashes instantly #862
Replies: 9 comments 3 replies
-
I know you already started an issue but I figured I would copy/paste my reply there for others in the future:
|
Beta Was this translation helpful? Give feedback.
-
@demonixis those logs, without a detailed explanation of what you actually did with your code, are far from being a clue to the reader. If you want to get some help I think you should give more context: What's your FDM model, what are the initial conditions, what sequence of inputs are you providing to the model, etc. |
Beta Was this translation helpful? Give feedback.
-
@agodemar here is what I've discovered so far... SetupUnreal: 5.1.1
App Setup and PawnThe aircraft is not possessed by the Player. Instead a Character is parented to the Airplane, and this is the character that controls the airplane. It allows me to have two pilots controlling the aircraft at the same time. Collisions are disabled on Character before parenting them to the Aircraft. Collisions on the Aircraft are disabled too because it's handled by GroundCheck. Simulate Physics is also disabled, exactly like the Unreal example. Update CodeI've an void AAircraft::UpdateJSBSim(const float DeltaTime)
{
#if PLATFORM_WINDOWS
UJSBSimMovementComponent* JsbSimFdm = Cast<UJSBSimMovementComponent>(JsbSimComponent);
if (JsbSimFdm == nullptr) return;
// Update Commands
FFlightControlCommands& Commands = JsbSimFdm->Commands;
Commands.Aileron = RollInput;
Commands.Elevator = PitchInput;
Commands.Rudder = YawInput;
Commands.Flap = FlapsInput;
Commands.Spoiler = 0;
Commands.Steer = YawInput;
Commands.CenterBrake = BrakesInput;
Commands.LeftBrake = BrakesInput;
Commands.GearDown = 1;
Commands.ParkingBrake = ParkingBrakesInput;
Commands.PitchTrim = PitchTrim;
Commands.RollTrim = RollTrim;
Commands.RightBrake = BrakesInput;
Commands.SpeedBrake = 0;
Commands.YawTrim = 0;
for(int i = 0; i < JsbSimFdm->EngineCommands.Num(); i++)
{
FEngineCommand& Engine = JsbSimFdm->EngineCommands[i];
Engine.Throttle = ThrottleInput;
Engine.Magnetos = EMagnetosMode::Both;// static_cast<EMagnetosMode>(MagnetoInput);
//Engine.Mixture = 0;// MixtureInput;
Engine.Starter = bEngineStarted;// EngineStarterInput;
Engine.Running = bEngineStarted;
}
#endif
} The values passed to Commands/Engines structures are clamped to -1/1 when they're float type. BehaviourI can takeoff and sometimes fly. But I often get NaN and an exception in Unreal. I know how to reproduce the exception easily. For that I've to :
The airplane start to fall forward and get speed, then I got a lot of NaNs logged in the console with an exception. If the angle is low, I can land without problem. If the angle of attack is to high it gets NaNs. The logsI added a lot of logs in the Unreal plugin, it seems that the GetAGLevel function causes the problem. I log the return value at each frame. it's interesting to note that this function returns 0 many time just before it gets NaN. I've noted that data are sometime inconsistant, for instance the following data was captured during the airplane fall LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=1.353263
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=1.353263
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=-0.078834
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=-0.055326
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=-0.049509
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.551602
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=1.902418
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=1.931474
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=1.353263
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=-0.078834
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=-0.055326
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=-0.049509
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.551602
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=1.902418
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=1.931474
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=1.353278
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=1.353278
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=1.353278 The NaNs LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=53.533254
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=54.419378
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=52.996474
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=54.472643
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=58.711977
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=51.604072
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogNiagara: Warning: NiagaraComponent(NiagaraComponent /Game/Maps/99_Sandbox/UEDPIE_0_Airport_3.Airport_3:PersistentLevel.BP_Player_C_0.TeleportTraceNiagaraSystem - NiagaraSystem /Game/Vendors/VRTemplate/VFX/NS_TeleportTrace.NS_TeleportTrace) required LWC tile recache and was reset.
LogParticles: Warning: PSC(ParticleSystemComponent /Game/Maps/99_Sandbox/UEDPIE_0_Airport_3.Airport_3:PersistentLevel.BP_LaserPointer_GEN_VARIABLE_BP_LaserPointer_C_CAT_0.PS_LaserBeam - ParticleSystem /Game/Effects/LaserBeam/PS_LaserBeam.PS_LaserBeam) required LWC tile recache and was reset.
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogNiagara: Warning: NiagaraComponent(NiagaraComponent /Game/Maps/99_Sandbox/UEDPIE_0_Airport_3.Airport_3:PersistentLevel.BP_Player_C_0.TeleportTraceNiagaraSystem - NiagaraSystem /Game/Vendors/VRTemplate/VFX/NS_TeleportTrace.NS_TeleportTrace) required LWC tile recache and was reset.
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Error: UEGroundCallback::GetAGLevel FGLocation contains NaN
LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Error: UEGroundCallback::GetAGLevel FGLocation contains NaN The double UEGroundCallback::GetAGLevel(const FGLocation& location, FGLocation& contact, FGColumnVector3& normal, FGColumnVector3& vel, FGColumnVector3& angularVel) const
{
vel.InitMatrix();
angularVel.InitMatrix();
FVector ECEFLocation = FVector(location(1), location(2), location(3)) * FEET_TO_METER;
if (ECEFLocation.ContainsNaN())
{
UE_LOG(LogJSBSim, Error, TEXT("UEGroundCallback::GetAGLevel FGLocation contains NaN"));
// End of the code
} After few frames a new NaN arrives LogJSBSim: Display: UJSBSimMovementComponent::GetAGLevel HAT=0.000000
LogJSBSim: Error: UJSBSimMovementComponent::Tick EngineLocation contains NaN In the following code (in the UJSBSimMovementComponent::Tick), we can see that FTransform ENUTransform = GeoReferencingSystem->GetTangentTransformAtECEFLocation(
AircraftState.ECEFLocation);
FRotator LocalUERotation(AircraftState.LocalEulerAngles);
LocalUERotation.Yaw = LocalUERotation.Yaw - 90.0;
// JSBSim heading is aero heading (0 at north). We have to remove 90 because in UE, 0 is pointing east.
FQuat EngineRotationQuat = ENUTransform.TransformRotation(LocalUERotation.Quaternion());
FMatrix EngineRotation;
EngineRotationQuat.ToMatrix(EngineRotation);
FVector CGOffsetWorld = EngineRotation.TransformPosition(CGLocalPosition);
// Computes Location in engine frame
FVector CGWorldPosition;
GeoReferencingSystem->ECEFToEngine(AircraftState.ECEFLocation, CGWorldPosition);
FVector EngineLocation = CGWorldPosition - CGOffsetWorld; And the the exception LogOutputDevice: Error: === Handled ensure: ===
LogOutputDevice: Error: Ensure condition failed: Y != 0 [File:D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\GenericPlatform\GenericPlatformMath.cpp] [Line: 124]
LogOutputDevice: Error: FMath::FMod(X=-353117930375765884928.000000, Y=0.000000) : Y is zero, this is invalid and would result in NaN!
LogOutputDevice: Error: Stack:
LogOutputDevice: Error: [Callstack] 0x00007fff45a80410 UnrealEditor-Core.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fff30e4a194 UnrealEditor-Renderer.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fff30c3ddd8 UnrealEditor-Renderer.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fff30c26d42 UnrealEditor-Renderer.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fff30c82c33 UnrealEditor-Renderer.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fff300ea141 UnrealEditor-Renderer.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fff30c32d04 UnrealEditor-Renderer.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fff30bff967 UnrealEditor-Renderer.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fff30c17ff1 UnrealEditor-Renderer.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fff30c1fe18 UnrealEditor-Renderer.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fff459e2fdd UnrealEditor-Core.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fff459e352e UnrealEditor-Core.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fff4090f804 UnrealEditor-RenderCore.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fff40913b54 UnrealEditor-RenderCore.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fff46105342 UnrealEditor-Core.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fff460fd230 UnrealEditor-Core.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fffafd626bd KERNEL32.DLL!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007fffb174a9f8 ntdll.dll!UnknownFunction [] I hope it helps a bit to find why I got NaNs. |
Beta Was this translation helpful? Give feedback.
-
So I don't see any comment about trying to flare/land? Just push the stick forward and 'crash' into the ground?
Or are you flaring and increasing the AoA, or do you mean the flight path angle? Assuming more of a 'crash' into the ground I wonder if you aren't running into this issue/discussion - #819 |
Beta Was this translation helpful? Give feedback.
-
Okay So at 51s into the video you have an AGL of 141.54ft and VS of -30ft/s and none of the gear/contact points have WOW (Weight On Wheel) set. And then at 52s into the video you have landing gear/contact point 0 with WOW and an AGL of 2.57ft even though the altimeter shows you > 100ft. There is also a video frame in-between showing a WOW while AGL is 137.43ft. So looks like some terrain lookup going bad? And it seems it could be similiar to this issue - #711 although in that case you could see a massive force value when WOW was triggered. Note the comment in that issue:
|
Beta Was this translation helpful? Give feedback.
-
Uncommenting the debug line seen below, in the GetALevel function and also checking the name of the component in the HitResult would confirm if the aircraft is self-colliding or colliding with an unintended object. |
Beta Was this translation helpful? Give feedback.
-
Well I think I found the problem, sometimes the I changed the code like this FHitResult HitResult = FHitResult();
static const FName LineTraceSingleName(TEXT("AGLevelLineTrace"));
FCollisionQueryParams CollisionParams(LineTraceSingleName);
CollisionParams.bTraceComplex = true;
CollisionParams.AddIgnoredActor(Parent);
FCollisionObjectQueryParams ObjectParams = FCollisionObjectQueryParams(ECC_WorldStatic);
//ObjectParams.AddObjectTypesToQuery(ECC_WorldDynamic);
//ObjectParams.AddObjectTypesToQuery(ECC_Pawn);
//ObjectParams.AddObjectTypesToQuery(ECC_Visibility); Now it works well all the time without any NaN Is it fine if I submit a pull request with a parameter to only line trace on static objects instead of static + dynamic? |
Beta Was this translation helpful? Give feedback.
-
I think the second solution is just fine. I can create the PR with this change tomorrow. Still doing some tests. Now it works, I'm playing a bit with the physics and it's close to a real aircraft, I love it :) |
Beta Was this translation helpful? Give feedback.
-
There is no need for a pull request. These changes would be useful for your specific project and your game design. Also for reference, I have no issues when attaching a Character class to the aircraft. I disabled collision on the Capsule Component of the Character and everything works normally with no bugs. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I'm integrating JSBSim into my simulator. I've an issue after the takeoff, the airplane is teleported instantly far away few seconds after the takeoff. It's perfect at the begining then it's teleported for some reason.
I've a GeoReference actor on the scene, it's setup the same than the Unreal demo project into this repository. I got this error
Any clues?
Edit: The GetAGLevel function generates a NAN value, which break the function call. After that the aircraft status is crashed.
Looks like it's the same problem in this issue
Thanks
Beta Was this translation helpful? Give feedback.
All reactions