Hold simulation, reposition the aircraft and restart #613
Replies: 12 comments 2 replies
-
Is it just a typo in terms of the latitude and longitude not being an initial condition, i.e. |
Beta Was this translation helpful? Give feedback.
-
Ok, Thanks! I will try soon. So, for reposition the aircraft I must hold the simulation: FDMExec->Hold(); Update the IC properties with FDMExec->SetPropertyValue (all of them?) Restart the simulation with FDMExec->RunIC(); I changed the topic title. Thanks. |
Beta Was this translation helpful? Give feedback.
-
Ok, First of all, the main problem was an I/O function that I use to send and receive datas from FSUIPC. So for now, I stopped its execution into the main loop to isolate the issue. Now I want to concentrate on repositioning. I've changed some code because Xplane calls "elevation" the altitude over sea level. FDMExec->Hold();
xpl_elevation = xpl_altitude - xpl_agl;
FDMExec->SetPropertyValue("ic/h-agl-ft", xpl_agl);
FDMExec->SetPropertyValue("ic/terrain-elevation-ft", xpl_elevation);
FDMExec->SetPropertyValue("ic/h-sl-ft", xpl_altitude);
FDMExec->SetPropertyValue("ic/lat-gc-deg", xpl_latitude);
FDMExec->SetPropertyValue("ic/long-gc-deg", xpl_longitude);
FDMExec->SetPropertyValue("ic/psi-true-deg",xpl_heading);
FDMExec->SetPropertyValue("ic/theta-deg", xpl_pitch);
FDMExec->RunIC(); Thanks Again |
Beta Was this translation helpful? Give feedback.
-
I'm a bit confused in terms of your overall setup, since there seem to be multiple simulation engines involved, so it's not entirely clear to me which ones are responsible for the flight dynamics, maybe some are only responsible for rendering the outside view graphics? You mention FSUIPC which is an API for dealing with Microsoft Flight Simulator or Prepar3D, then you mention XPlane another full flight simulator and then JSBSim. I have experience from my own VSS (Variable Stability System) simulator where I use JSBSim for the flight dynamics etc. and then on each time step I used the SimConnect API etc. to drive Prepar3D's external views. In my setup I also query Prepar3D for terrain elevation which I pass into JSBSim. |
Beta Was this translation helpful? Give feedback.
-
Sorry, I forgot to explain my project. To increase the transport delay, I 'm trying to integrate the fdm in the main program. I need xplane as Visual generator, but I also need to query elevation data from it to have the same elevation. |
Beta Was this translation helpful? Give feedback.
-
Okay, so I do the exact same thing in my VSS sim, I'm just using Prepar3D instead of X-Plane as the visual generator and as the source of the terrain elevation. So on each simulation time step I use the lat, lon position calculated by JSBSim to set the aircraft's position in Prepar3D, which updates the visuals, I then also receive the ground elevation for that coordinate from Prepar3D on each time step and feed that into JSBSim. // Receive ground elevation from Prepar3D
case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
{
SIMCONNECT_RECV_SIMOBJECT_DATA* pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;
if (pObjData->dwRequestID == AIRCRAFT_INFO_REQUEST)
{
AIRCRAFT_INFO_DATA* pInfoData = (AIRCRAFT_INFO_DATA*)&pObjData->dwData;
AircraftInfoData.GroundAltitude = pInfoData->GroundAltitude * 3.28083989;
void copy_to_JSBSim()
{
// Set ground altitude
std::shared_ptr<JSBSim::FGPropagate> Propagate = FDMExec->GetPropagate();
Propagate->SetTerrainElevation(AircraftInfoData.GroundAltitude);
|
Beta Was this translation helpful? Give feedback.
-
Now my situation: Unhandled exception at 0x0009CC91 in JSBTest.exe: 0xC0000091: Floating-point overflow (parameters: 0x00000000, 0x00001928). FGAtmosphere.cpp at row 127 DensityAltitude = CalculateDensityAltitude(Density, altitude); or FGQuaternion.cpp at row 202 double q0q2 = q0*q2; If I restart my exe, the situation is perfect , because JSBsim restart from the init file just generated with the correct values. How can I restart the simulation from scratch ? |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if this is the best way, but this is the way I do it in my sim. void copy_to_JSBSim()
{
// Set ground altitude
std::shared_ptr<JSBSim::FGPropagate> Propagate = FDMExec->GetPropagate();
Propagate->SetTerrainElevation(AircraftInfoData.GroundAltitude);
....
std::shared_ptr<JSBSim::FGFCS> FCS = FDMExec->GetFCS();
// DirectInput inputs
g_Joystick.Poll();
FCS->SetDeCmd(g_Joystick.Pitch);
FCS->SetDaCmd(g_Joystick.Roll);
FCS->SetDrCmd(DeadBand(g_Joystick.Rudder, 0.02));
FCS->SetThrottleCmd(-1, g_Joystick.Throttle);
FCS->SetLBrake(g_Joystick.LeftBrake);
FCS->SetRBrake(g_Joystick.RightBrake);
....
} And.. void copy_from_JSBSim()
{
....
// Pump SimConnect message pump
SimConnect_CallDispatch(hSimConnect, MyDispatchProcSD, NULL);
// Collect JSBSim data
std::shared_ptr<JSBSim::FGPropagate> Propagate = FDMExec->GetPropagate();
std::shared_ptr<JSBSim::FGAuxiliary> Auxiliary = FDMExec->GetAuxiliary();
std::shared_ptr<JSBSim::FGAtmosphere> Atmosphere = FDMExec->GetAtmosphere();
std::shared_ptr<JSBSim::FGAccelerations> Accelerations = FDMExec->GetAccelerations();
AircraftData.Altitude = Propagate->GetAltitudeASL();
AircraftData.Latitude = Propagate->GetLocation().GetLatitudeDeg();
AircraftData.Longitude = Propagate->GetLocation().GetLongitudeDeg();
AircraftData.Bank = radtodeg * Propagate->GetEuler(ePhi) * -1.0;
AircraftData.Pitch = radtodeg * Propagate->GetEuler(eTht) * -1.0;
AircraftData.Heading = radtodeg * Propagate->GetEuler(ePsi);
AircraftData.IAS = Auxiliary->GetVcalibratedKTS();
AircraftData.VSI = Propagate->GetVel(eDown) * -1.0;
AircraftData.BodyZVelocity = Propagate->GetUVW(JSBSim::FGJSBBase::eU);
AircraftData.BodyXVelocity = Propagate->GetUVW(JSBSim::FGJSBBase::eV);
AircraftData.BodyYVelocity = Propagate->GetUVW(JSBSim::FGJSBBase::eW) * -1.0;
AircraftData.WorldZVelocity = Propagate->GetVel(JSBSim::FGJSBBase::eNorth);
AircraftData.WorldXVelocity = Propagate->GetVel(JSBSim::FGJSBBase::eEast);
AircraftData.WorldYVelocity = Propagate->GetVel(JSBSim::FGJSBBase::eDown) * -1.0;
AircraftData.BodyZAcceleration = Accelerations->GetUVWdot(JSBSim::FGJSBBase::eU);
AircraftData.BodyXAcceleration = Accelerations->GetUVWdot(JSBSim::FGJSBBase::eV);
AircraftData.BodyYAcceleration = Accelerations->GetUVWdot(JSBSim::FGJSBBase::eW) * -1.0;
....
} |
Beta Was this translation helpful? Give feedback.
-
I think Lines 687 to 704 in b4ca399 It also calls Lines 641 to 674 in b4ca399 Also take a look at the following discussion with regards to resetting JSBSim for multiple runs - #455 |
Beta Was this translation helpful? Give feedback.
-
Ok Sean, Thank You. Forgive my incompetence about C++ shared pointers , but how can I create the Class constructor?
Thanks. |
Beta Was this translation helpful? Give feedback.
-
Ok , |
Beta Was this translation helpful? Give feedback.
-
Yes the master branch always consists of the latest code, releases will be older. |
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.
-
Hello,
First of all let me congratulate and thank You (The Authors, the contributors, the mantainers) for this worderful work.
I was totally invoved in You project.
I'm not a professional programmer, and I'm learning C++ thanks to Your project so please forgive me if my questions are probably stupid.
My Goal is to build a complete simulation project with JSBSim.
First of all I learned how to interact with JSBSim via UDP, and I was able to send position data to an external Visual generator (starting from P3D, then X-plane, now I'm working with RSI protocol) , then I was able to connect FCS commands to connect the hardware in the loop to fly in real time.
With UDP connection all is working.
Then I integrated all signals to an external avionics software with FSUIPC.
Now the next step is the API integration.
I compiled the static library and tried to integrate the simulation with FDMExec class.
All seems working good.
But my question is: how can I send the commands without problems?
I'm using the GetPropertyValue and SetPropertyValue functions in the loop, to read the data and write FCS commands, and all seems working well, but when I try to reposition the aircraft airborne I have an Floating-point overflow (parameters: 0x00000000, 0x00001928) during Debug.
I'm Using Visual Studio 2019, I compiled the JSBSim library in 32bit.
After many runs, MSVS C++ tells me the problem in the "FGQuaternion.cpp" line 202 " double q0q2 = q0*q2;"
Surely the problem is my fault, probably is the altitude that come from the external visual (x-plane in this case) is a float, but the values seems normal.
this is the code I use to send the data to JSBSim:
The problem could be the elevation?
I tried also to reduce the floating point precision without success.
Thanks in advance.
Carlo.
Beta Was this translation helpful? Give feedback.
All reactions