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

Linearization from console executable and xml script #991

Merged
merged 6 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions scripts/737_cruise_steady_turn_linearize.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="http://jsbsim.sf.net/JSBSimScript.xsl"?>
<runscript xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://jsbsim.sf.net/JSBSimScript.xsd"
name="Cruise flight with steady turn in 737.">

<description>
This is a very simple script that trims the aircraft with running
engines, exports linearized equations, and runs out to 10 seconds.
</description>

<use aircraft="737" initialize="cruise_steady_turn_init"/>

<run start="0" end="10" dt="0.008333">

<property value="0"> simulation/notify-time-trigger </property>

<event name="Set engines running">
<condition> simulation/sim-time-sec le 0.1 </condition>
<set name="propulsion/engine[0]/set-running" value="1"/>
<set name="propulsion/engine[1]/set-running" value="1"/>
<notify/>
</event>

<!--
For "do_simple_trim" (Classic trim):
0: Longitudinal
1: Full
2: Ground
3: Pullup
4: Custom
5: Turn
6: None
-->

<event name="Trim and linearize">
<condition>
simulation/sim-time-sec gt 0.1
</condition>
<set name="simulation/do_simple_trim" value="5"/>
<set name="simulation/do_linearization" value="0"/>
</event>

<event name="Repeating Notify" persistent="true">
<description>Output message at 5 second intervals</description>
<notify>
<property>propulsion/engine[0]/n2</property>
<property>propulsion/engine[1]/n2</property>
<property>propulsion/engine[0]/thrust-lbs</property>
<property>propulsion/engine[1]/thrust-lbs</property>
<property>position/h-agl-ft</property>
<property>velocities/vc-kts</property>
<property>velocities/vc-fps</property>
<property>velocities/vt-fps</property>
<property>attitude/phi-rad</property>
<property>attitude/theta-rad</property>
<property>attitude/psi-rad</property>
</notify>
<condition> simulation/sim-time-sec >= simulation/notify-time-trigger </condition>
<set name="simulation/notify-time-trigger" value="5" type="FG_DELTA"/>
</event>

</run>

</runscript>
12 changes: 12 additions & 0 deletions src/FGFDMExec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "models/FGAuxiliary.h"
#include "models/FGInput.h"
#include "initialization/FGTrim.h"
#include "initialization/FGLinearization.h"
#include "input_output/FGScript.h"
#include "input_output/FGXMLFileRead.h"
#include "initialization/FGInitialCondition.h"
Expand Down Expand Up @@ -158,6 +159,7 @@
Constructing = true;
typedef int (FGFDMExec::*iPMF)(void) const;
instance->Tie("simulation/do_simple_trim", this, (iPMF)0, &FGFDMExec::DoTrim);
instance->Tie("simulation/do_linearization", this, (iPMF)0, &FGFDMExec::DoLinearization);
instance->Tie("simulation/reset", this, (iPMF)0, &FGFDMExec::ResetToInitialConditions);
instance->Tie("simulation/disperse", this, &FGFDMExec::GetDisperse);
instance->Tie("simulation/randomseed", this, (iPMF)&FGFDMExec::SRand, &FGFDMExec::SRand);
Expand Down Expand Up @@ -1315,6 +1317,16 @@

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void FGFDMExec::DoLinearization(int)

Check warning on line 1320 in src/FGFDMExec.cpp

View check run for this annotation

Codecov / codecov/patch

src/FGFDMExec.cpp#L1320

Added line #L1320 was not covered by tests
{
double dt0 = this->GetDeltaT();
FGLinearization lin(this);
lin.WriteScicoslab();
this->Setdt(dt0);
}

Check warning on line 1326 in src/FGFDMExec.cpp

View check run for this annotation

Codecov / codecov/patch

src/FGFDMExec.cpp#L1322-L1326

Added lines #L1322 - L1326 were not covered by tests

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void FGFDMExec::SRand(int sr)
{
RandomSeed = sr;
Expand Down
5 changes: 5 additions & 0 deletions src/FGFDMExec.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,11 @@ class JSBSIM_API FGFDMExec : public FGJSBBase
* - tNone */
void DoTrim(int mode);

/** Executes linearization with state-space output
* You must trim first to get an accurate state-space model
*/
void DoLinearization(int);

/// Disables data logging to all outputs.
void DisableOutput(void) { Output->Disable(); }
/// Enables data logging to all outputs.
Expand Down
7 changes: 5 additions & 2 deletions src/initialization/FGLinearization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@
}

void FGLinearization::WriteScicoslab(std::string& path) const {
int width=10;
int width=20;
int precision=10;

Check warning on line 91 in src/initialization/FGLinearization.cpp

View check run for this annotation

Codecov / codecov/patch

src/initialization/FGLinearization.cpp#L90-L91

Added lines #L90 - L91 were not covered by tests
std::ofstream scicos(path.c_str());
scicos.precision(10);
scicos.precision(precision);

Check warning on line 93 in src/initialization/FGLinearization.cpp

View check run for this annotation

Codecov / codecov/patch

src/initialization/FGLinearization.cpp#L93

Added line #L93 was not covered by tests
width=20;
scicos << std::scientific
<< aircraft_name << ".x0=..\n" << std::setw(width) << x0 << ";\n"
Expand All @@ -101,6 +102,8 @@
<< std::setw(width) << D << ");\n"
<< aircraft_name << ".tfm = ss2tf(" << aircraft_name << ".sys);\n"
<< std::endl;
scicos.close();

Check warning on line 105 in src/initialization/FGLinearization.cpp

View check run for this annotation

Codecov / codecov/patch

src/initialization/FGLinearization.cpp#L105

Added line #L105 was not covered by tests

}

} // JSBSim
Expand Down