JSBSim-Team / jsbsim

An open source flight dynamics & control software library
GNU Lesser General Public License v2.1
1.22k stars 420 forks source link

Aircraft crashed on air when rolling consecutively #1042

Closed nmfarras closed 2 months ago

nmfarras commented 2 months ago

I'm submitting a ...

I've tried to replicate the A DIY Flight Simulator tutorial and now recreate it for fighter F16 using available F16 jsbsim model. I happen to get the aircraft crashed when still on the air.

When i fly the aircraft and roll it multiple time (like 2 or more in a row) there is a chance the simulation stop and the log message says "Aircraft Crashed" as shown below.

image

Is there anyone who know why this happen even though i'am not crashing it to the ground. Is it how the jsbsim handle things or bug on jsbsim plug in on UE? I appreciate if anyone know how to handle it or what should be done to avoid this. Thanks!

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

I create it on:

seanmcleod commented 2 months ago

So the crash message you're seeing is coming from this piece of code:

https://github.com/JSBSim-Team/jsbsim/blob/92daf8953c32a0a602ab0f48240a07c4a04aadb9/UnrealEngine/Plugins/JSBSimFlightDynamicsModel/Source/JSBSimFlightDynamicsModel/Private/JSBSimMovementComponent.cpp#L261-L265

Which is triggered if the AGL altitude is less than -10.

https://github.com/JSBSim-Team/jsbsim/blob/92daf8953c32a0a602ab0f48240a07c4a04aadb9/UnrealEngine/Plugins/JSBSimFlightDynamicsModel/Source/JSBSimFlightDynamicsModel/Private/JSBSimMovementComponent.cpp#L693-L699

Now in order to calculate the AGL altitude JSBSim needs information on the terrain elevation. So my guess is that in some areas while rolling a very large terrain elevation is being reported.

Looking at your screenshot I see a message - "YOUR SCENE CONTAINS A SKYDOME MESH.... BUT IT DOES NOT COVER THAT PART..."

Is this mesh issue possibly causing an issue with the terrain elevation lookup?

gallonmate commented 2 months ago

You're likely detecting parts of the aircraft model or the player. etc, while rolling, instead of the ground. The UE5 plugin does a line trace to find the ground mesh. When you roll your plane, something is likely rolling into the line trace and triggering it. See this comment https://github.com/JSBSim-Team/jsbsim/discussions/862#discussioncomment-5512289 and the discussion in there for your options to correct it. It's up to you how to you want to setup your collision channels for your models/game.

nmfarras commented 2 months ago

You're likely detecting parts of the aircraft model or the player. etc, while rolling, instead of the ground. The UE5 plugin does a line trace to find the ground mesh. When you roll your plane, something is likely rolling into the line trace and triggering it. See this comment #862 (comment) and the discussion in there for your options to correct it. It's up to you how to you want to setup your collision channels for your models/game.

All right I just come back online and will check it out.

So the crash message you're seeing is coming from this piece of code:

https://github.com/JSBSim-Team/jsbsim/blob/92daf8953c32a0a602ab0f48240a07c4a04aadb9/UnrealEngine/Plugins/JSBSimFlightDynamicsModel/Source/JSBSimFlightDynamicsModel/Private/JSBSimMovementComponent.cpp#L261-L265

Which is triggered if the AGL altitude is less than -10.

https://github.com/JSBSim-Team/jsbsim/blob/92daf8953c32a0a602ab0f48240a07c4a04aadb9/UnrealEngine/Plugins/JSBSimFlightDynamicsModel/Source/JSBSimFlightDynamicsModel/Private/JSBSimMovementComponent.cpp#L693-L699

Now in order to calculate the AGL altitude JSBSim needs information on the terrain elevation. So my guess is that in some areas while rolling a very large terrain elevation is being reported.

Looking at your screenshot I see a message - "YOUR SCENE CONTAINS A SKYDOME MESH.... BUT IT DOES NOT COVER THAT PART..."

Is this mesh issue possibly causing an issue with the terrain elevation lookup?

"YOUR SCENE CONTAINS A SKYDOME MESH.... BUT IT DOES NOT COVER THAT PART..." thing is related to environment pawn not finish rendering i guess. Cause when i fly normally and the message come out and the sky become black like that, it will become normal after few second. I guess this is not the problem, maybe. But the reference to AGL and such is useful. Thank you!

nmfarras commented 2 months ago

You're likely detecting parts of the aircraft model or the player. etc, while rolling, instead of the ground. The UE5 plugin does a line trace to find the ground mesh. When you roll your plane, something is likely rolling into the line trace and triggering it. See this comment #862 (comment) and the discussion in there for your options to correct it. It's up to you how to you want to setup your collision channels for your models/game.

@gallonmate I have a question. I check the issues and i am curious for line trace from which point it emit? does it use one of parameter set from xml file as the source? or it come from this "orange color" boundary that come after activating jsbsim plugin?

image

If i want to disabled collision from player like suggest from this and this Where should i go? Cause i think i already set ignore collision in my blueprint and skeletal mesh as follow

image

image

And this is the level outline in case needed

image

gallonmate commented 2 months ago

The code all starts here: https://github.com/JSBSim-Team/jsbsim/blob/10ac2036d8b5ac6d840a105f41062c603e952e6a/UnrealEngine/Plugins/JSBSimFlightDynamicsModel/Source/JSBSimFlightDynamicsModel/Private/JSBSimMovementComponent.cpp#L182

The line trace itself uses the aircraft transform + 200 units up and the end point always straight down. I guess I should have clarified, the line trace code is already setup to ignore anything attached to the aircraft blueprint. So it might take some more work to find out what the line trace is actually hitting. If you are not spawning any players/characters and it's just the aircraft blueprint, then maybe it's colliding with some part of the cesium system that it's not supposed to.

If you want to fiqure it out, you have two options: You can edit or debug the plugin in c++ to fiqure out what you're hitting. For example you can roll the aircraft until you crash then check the call stack in VS and see what the line trace's Hitresult shows for the object hit. Or you can add some c++ code to print the line trace Hitresult. Or you can delete parts of your level and anything you have spawned until the aircraft stops crashing when you roll.

nmfarras commented 2 months ago

...The line trace itself uses the aircraft transform + 200 units up and the end point always straight down. I guess I should have clarified, the line trace code is already setup to ignore anything attached to the aircraft blueprint. So it might take some more work to find out what the line trace is actually hitting. If you are not spawning any players/characters and it's just the aircraft blueprint, then maybe it's colliding with some part of the cesium system that it's not supposed to.

Thanks for the reply! I will check if deactivating Cesium might stop the issue.

Also I got new info. I check it with my college and he do it in UE5.0 but got no such a error. But i notice something interesting that in both version, sometime the fighter behave like "hitting" something when rolling, and cause the roll seems unnatural. Does line tracing cause this kind of effect as well (like hitting a wall or something) or just simply checking the distance between aircraft and nearest mesh below aircraft?

Also as in the one on UE5.0 no airplane crashed occur, does UE version might also has some factor in it as well?

nmfarras commented 2 months ago

image

image

Quick update. I already deactivate Cesium, but i guess it still happen. I also try to remove volumetric cloud in case it will affect too. But still the same i guess...

gallonmate commented 2 months ago

It looks like you have extra blueprints attached to airplane. Try flying with only the aircraft blueprint. As for the question about about hitting/bouncing off things, the landing gear and body can have contact points defined in the xml file and then UE5 uses line traces to send collision information at those locations to JSBSim. So you can bump/hit objects with different parts of the plane and not "crash" but instead bounce or lose stability.

image I suggest removing those attached objects to the plane and seeing if that helps.

Here you can see the results of contacting an object. In the last example moving the block under the aircraft's location changes the "ground level" and moving it high enough eventually "crashes" the aircraft. image

nmfarras commented 2 months ago

It looks like you have extra blueprints attached to airplane. Try flying with only the aircraft blueprint. As for the question about about hitting/bouncing off things, the landing gear and body can have contact points defined in the xml file and then UE5 uses line traces to send collision information at those locations to JSBSim. So you can bump/hit objects with different parts of the plane and not "crash" but instead bounce or lose stability.

All right i will try flying with nothing attach first. If it works, maybe the way i modelled it is the problem.

Regarding the use of UE5.0 not having crash issue that my college found, just now I also try to rebuilt from scratch while leaving the pawn having extra object (it is armament attach on Blueprint pawn), and it work though the weird hitting or maybe tapping something when rolling still exist. I will update you again if i found something else.

nmfarras commented 2 months ago

Sorry for late update. After trying, the error still persist. Just in case i try this one . As the result, the the behavior like "tapping" something when rolling and crashed on the air no longer happened. So it is indeed line tracing hitting something.

I actually want to follow second option suggested here. As i still new, can you suggest me some reference to add pawn or actor into ignore list as suggest? So far i only working with the graph side (node thingy) of unreal, therefore I'am not familiar how to check in which file my actor registered, or do they have object class relate to it that can be registered on the array?

gallonmate commented 2 months ago

If you don't know what you're colliding with, then an ignore list will not really help. And it also requires editing the plugin in c++. The person was kind enough to share the c++ code changes here if you want to try adding the change yourself: https://github.com/JSBSim-Team/jsbsim/pull/893/commits/a7e4b899aa1218c394770aa65f220c78a0ef5538

Though if you're able to change code in c++, then you should be able to debug the code and check the name of the object in HitResult. Otherwise then you're going to have to still double check everything again. Check what is different between your UE5.0 and UE5.2 projects. Or start with the sample project that comes with the plugin and slowly add your changes until the error happens again.

nmfarras commented 2 months ago

Allright maybe i will take my time for this one. For checking the HitResult does i just need to uncomment DrawDebugLine()?

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.

https://github.com/JSBSim-Team/jsbsim/blob/10ac2036d8b5ac6d840a105f41062c603e952e6a/UnrealEngine/Plugins/JSBSimFlightDynamicsModel/Source/JSBSimFlightDynamicsModel/Private/JSBSimMovementComponent.cpp#L218-L222

Originally posted by @gallonmate in https://github.com/JSBSim-Team/jsbsim/discussions/862#discussioncomment-5512289

gallonmate commented 2 months ago

That's just for visually seeing the line trace, it won't tell you what you're hitting. You can already view the HitResult without changing code.

How to debug and view the HitResult: -Open UEReferenceApp.sln with Visual Studio. -Press the Green button labeled "Local Windows Debugger" which will open UE5 with debugging ability. -After UE5 is loaded, start flying your aircraft as normal and get close to the moment that causes crashed/error but do not cause the crash/error yet. -Pause game and switch back to Visual Studio. -Open file JSBSimMovementComponent.cpp and go down to line 249. -Right click in the area left of the 249 line and Insert Conditional Breakpoint. -Where the new box says Example: x==5, write in there HAT < -3, press keyboard enter or click close button. This condition means when distance is less than -3 meters (-10 feet) it will automatically pause the program so you can inspect the data values. Here's a picture for reference. image

-Now you can switch back to UE5 and press play to continue flying. -Try rolling aircraft or however you normally can cause error/crash. -Visual studio will then pause or "break" the program when the aircraft is less than -3 meters (-10 feet). -When this happens you can now find the HitResult in the Locals tab. As seen in this picture: image

(You can also hover the mouse pointer over the variables in the code file and it will show the same current variable data if available, in a popup window you can scroll through.) image

nmfarras commented 2 months ago

That's just for visually seeing the line trace, it won't tell you what you're hitting. You can already view the HitResult without changing code.

How to debug and view the HitResult: -Open UEReferenceApp.sln with Visual Studio. -Press the Green button labeled "Local Windows Debugger" which will open UE5 with debugging ability. -After UE5 is loaded, start flying your aircraft as normal and get close to the moment that causes crashed/error but do not cause the crash/error yet. -Pause game and switch back to Visual Studio. -Open file JSBSimMovementComponent.cpp and go down to line 249. -Right click in the area left of the 249 line and Insert Conditional Breakpoint. -Where the new box says Example: x==5, write in there HAT < -3, press keyboard enter or click close button. This condition means when distance is less than -3 meters (-10 feet) it will automatically pause the program so you can inspect the data values. Here's a picture for reference. image

-Now you can switch back to UE5 and press play to continue flying. -Try rolling aircraft or however you normally can cause error/crash. -Visual studio will then pause or "break" the program when the aircraft is less than -3 meters (-10 feet). -When this happens you can now find the HitResult in the Locals tab. As seen in this picture: image

(You can also hover the mouse pointer over the variables in the code file and it will show the same current variable data if available, in a popup window you can scroll through.) image

Thank you for the guide of debugging on visual studio. It is very helpful!

nmfarras commented 2 months ago

Considering the solution, i guess it is pretty much answer what should i do to solve my problem. I guess I will close the issue for now and maybe will open it again if the I find something else aside debugging with hit result and adding the object in ignore list. Thank you for the support!