1
0
Fork 0

Sync.with JSBSim CVS

This commit is contained in:
ehofman 2008-10-23 19:04:45 +00:00
parent ee8f603969
commit 6d95ade940
9 changed files with 131 additions and 28 deletions

View file

@ -248,6 +248,8 @@ FGJSBsim::FGJSBsim( double dt )
speedbrake_pos_pct
=fgGetNode("/surface-positions/speedbrake-pos-norm",true);
spoilers_pos_pct=fgGetNode("/surface-positions/spoilers-pos-norm",true);
tailhook_pos_pct=fgGetNode("/gear/tailhook/position-norm",true);
wing_fold_pos_pct=fgGetNode("surface-positions/wing-fold-pos-norm",true);
elevator_pos_pct->setDoubleValue(0);
left_aileron_pos_pct->setDoubleValue(0);
@ -279,6 +281,8 @@ FGJSBsim::FGJSBsim( double dt )
fgGetDouble("/fdm/jsbsim/systems/hook/tailhook-offset-x-in", 196),
fgGetDouble("/fdm/jsbsim/systems/hook/tailhook-offset-y-in", 0),
fgGetDouble("/fdm/jsbsim/systems/hook/tailhook-offset-z-in", -16));
crashed = false;
}
/******************************************************************************/
@ -398,6 +402,12 @@ void FGJSBsim::init()
void FGJSBsim::update( double dt )
{
if(crashed) {
if(!fgGetBool("/sim/crashed"))
fgSetBool("/sim/crashed", true);
return;
}
if (is_suspended())
return;
@ -480,6 +490,8 @@ void FGJSBsim::update( double dt )
msg = fdmex->ProcessMessage();
switch (msg->type) {
case FGJSBBase::Message::eText:
if (msg->text == "Crash Detected: Simulation FREEZE.")
crashed = true;
SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text );
break;
case FGJSBBase::Message::eBool:
@ -862,12 +874,13 @@ bool FGJSBsim::copy_from_JSBsim()
flap_pos_pct->setDoubleValue( FCS->GetDfPos(ofNorm) );
speedbrake_pos_pct->setDoubleValue( FCS->GetDsbPos(ofNorm) );
spoilers_pos_pct->setDoubleValue( FCS->GetDspPos(ofNorm) );
tailhook_pos_pct->setDoubleValue( FCS->GetTailhookPos() );
wing_fold_pos_pct->setDoubleValue( FCS->GetWingFoldPos() );
// force a sim reset if crashed (altitude AGL < 0)
// force a sim crashed if crashed (altitude AGL < 0)
if (get_Altitude_AGL() < -100.0) {
fgSetBool("/sim/crashed", true);
SGPropertyNode* node = fgGetNode("/sim/presets", true);
globals->get_commands()->execute("old-reinit-dialog", node);
State->SuspendIntegration();
crashed = true;
}
return true;
@ -1073,6 +1086,7 @@ void FGJSBsim::init_gear(void )
node->setDoubleValue("position-norm", gear->GetGearUnitPos());
node->setDoubleValue("tire-pressure-norm", gear->GetTirePressure());
node->setDoubleValue("compression-norm", gear->GetCompLen());
node->setDoubleValue("compression-ft", gear->GetCompLen());
if ( gear->GetSteerable() )
node->setDoubleValue("steering-norm", gear->GetSteerNorm());
}
@ -1089,6 +1103,7 @@ void FGJSBsim::update_gear(void)
node->getChild("position-norm", 0, true)->setDoubleValue(gear->GetGearUnitPos());
gear->SetTirePressure(node->getDoubleValue("tire-pressure-norm"));
node->setDoubleValue("compression-norm", gear->GetCompLen());
node->setDoubleValue("compression-ft", gear->GetCompLen());
if ( gear->GetSteerable() )
node->setDoubleValue("steering-norm", gear->GetSteerNorm());
}

View file

@ -252,6 +252,8 @@ private:
SGPropertyNode_ptr spoilers_pos_pct;
SGPropertyNode_ptr gear_pos_pct;
SGPropertyNode_ptr wing_fold_pos_pct;
SGPropertyNode_ptr tailhook_pos_pct;
SGPropertyNode_ptr temperature;
SGPropertyNode_ptr pressure;
@ -271,6 +273,8 @@ private:
double hook_length;
bool got_wire;
bool crashed;
void init_gear(void);
void update_gear(void);

View file

@ -60,7 +60,7 @@ FGColumnVector3::FGColumnVector3(void)
string FGColumnVector3::Dump(string delimeter) const
{
char buffer[256];
sprintf(buffer, "%f%s%f%s%f", Entry(1), delimeter.c_str(), Entry(2), delimeter.c_str(), Entry(3));
sprintf(buffer, "%10.3e%s%10.3e%s%10.3e", Entry(1), delimeter.c_str(), Entry(2), delimeter.c_str(), Entry(3));
return string(buffer);
}

View file

@ -76,6 +76,7 @@ FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
PTrimCmd = YTrimCmd = RTrimCmd = 0.0;
GearCmd = GearPos = 1; // default to gear down
LeftBrake = RightBrake = CenterBrake = 0.0;
TailhookPos = WingFoldPos = 0.0;
bind();
for (i=0;i<NForms;i++) {
@ -134,6 +135,7 @@ bool FGFCS::InitModel(void)
DaCmd = DeCmd = DrCmd = DsCmd = DfCmd = DsbCmd = DspCmd = 0;
PTrimCmd = YTrimCmd = RTrimCmd = 0.0;
TailhookPos = WingFoldPos = 0.0;
for (i=0;i<NForms;i++) {
DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0;
@ -486,7 +488,7 @@ void FGFCS::SetPropFeather(int engineNum, bool setting)
bool FGFCS::Load(Element* el, SystemType systype)
{
string name, file, fname, interface_property_string, parent_name;
string name, file, fname="", interface_property_string, parent_name;
vector <FGFCSComponent*> *Components;
Element *component_element, *property_element, *sensor_element;
Element *channel_element;
@ -505,7 +507,7 @@ bool FGFCS::Load(Element* el, SystemType systype)
if (systype == stSystem) {
file = FindSystemFullPathname(fname);
} else {
file = FDMExec->GetFullAircraftPath() + separator + fname + ".xml";
file = FDMExec->GetFullAircraftPath() + separator + fname + ".xml";
}
if (fname.empty()) {
cerr << "FCS, Autopilot, or system does not appear to be defined inline nor in a file" << endl;
@ -530,18 +532,13 @@ bool FGFCS::Load(Element* el, SystemType systype)
}
Debug(2);
// ToDo: How do these get untied?
// ToDo: Consider having INPUT and OUTPUT interface properties. Would then
// have to duplicate this block of code after channel read code.
// Input properties could be write only (nah), and output could be read
// only.
if (document->GetName() == "flight_control") bindModel();
// Interface properties from any autopilot, flight control, or other system are
// all stored in the interface properties array.
property_element = document->FindElement("property");
if (property_element) cout << endl << " Declared properties" << endl << endl;
while (property_element) {
double value=0.0;
if ( ! property_element->GetAttributeValue("value").empty())
@ -549,9 +546,41 @@ bool FGFCS::Load(Element* el, SystemType systype)
interface_properties.push_back(new double(value));
interface_property_string = property_element->GetDataLine();
PropertyManager->Tie(interface_property_string, interface_properties.back());
cout << " " << interface_property_string << " (initial value: " << value << ")" << endl;
property_element = document->FindNextElement("property");
}
// After reading interface properties in a file, read properties in the local
// flight_control, autopiot, or system element. This allows general-purpose
// systems to be defined in a file, with overrides or initial loaded constants
// supplied in the relevant element of the aircraft configuration file.
if (!fname.empty()) {
property_element = el->FindElement("property");
if (property_element) cout << endl << " Declared properties" << endl << endl;
while (property_element) {
double value=0.0;
if ( ! property_element->GetAttributeValue("value").empty())
value = property_element->GetAttributeValueAsNumber("value");
interface_property_string = property_element->GetDataLine();
FGPropertyManager* node = PropertyManager->GetNode(interface_property_string);
if (node) {
cout << " " << "Overriding value for property " << interface_property_string
<< " (old value: " << node->getDoubleValue() << " new value: " << value << ")" << endl;
node->setDoubleValue(value);
} else {
interface_properties.push_back(new double(value));
PropertyManager->Tie(interface_property_string, interface_properties.back());
cout << " " << interface_property_string << " (initial value: " << value << ")" << endl;
}
property_element = el->FindNextElement("property");
}
}
// Any sensor elements that are outside of a channel (in either the autopilot
// or the flight_control, or even any possible "system") are placed into the global
// "sensors" array, and are executed prior to any autopilot, flight control, or
@ -570,6 +599,10 @@ bool FGFCS::Load(Element* el, SystemType systype)
channel_element = document->FindElement("channel");
while (channel_element) {
cout << endl << highint << fgblue << " Channel "
<< normint << channel_element->GetAttributeValue("name") << reset << endl;
component_element = channel_element->GetElement();
while (component_element) {
try {
@ -732,7 +765,7 @@ string FGFCS::GetComponentValues(string delimeter)
{
unsigned int comp;
string CompValues = "";
char buffer[20];
char buffer[100];
bool firstime = true;
int total_count=0;
@ -740,7 +773,7 @@ string FGFCS::GetComponentValues(string delimeter)
if (firstime) firstime = false;
else CompValues += delimeter;
sprintf(buffer, "%9.6f", Systems[i]->GetOutput());
snprintf(buffer, 100, "%9.6f", Systems[i]->GetOutput());
CompValues += string(buffer);
total_count++;
}
@ -852,6 +885,9 @@ void FGFCS::bind(void)
PropertyManager->Tie("fcs/right-brake-cmd-norm", this, &FGFCS::GetRBrake, &FGFCS::SetRBrake);
PropertyManager->Tie("fcs/center-brake-cmd-norm", this, &FGFCS::GetCBrake, &FGFCS::SetCBrake);
PropertyManager->Tie("fcs/steer-cmd-norm", this, &FGFCS::GetDsCmd, &FGFCS::SetDsCmd);
PropertyManager->Tie("gear/tailhook-pos-norm", this, &FGFCS::GetTailhookPos, &FGFCS::SetTailhookPos);
PropertyManager->Tie("fcs/wing-fold-pos-norm", this, &FGFCS::GetWingFoldPos, &FGFCS::SetWingFoldPos);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View file

@ -162,7 +162,9 @@ CLASS DOCUMENTATION
@property fcs/spoiler-pos-deg
@property fcs/spoiler-pos-norm
@property fcs/mag-spoiler-pos-rad
@property fcs/wing-fold-pos-norm
@property gear/gear-pos-norm
@property gear/tailhook-pos-norm
@author Jon S. Berndt
@version $Revision$
@ -325,6 +327,14 @@ public:
@return gear position (0 up, 1 down) */
inline double GetGearPos(void) const { return GearPos; }
/** Gets the tailhook position (0 up, 1 down)
@return tailhook position (0 up, 1 down) */
inline double GetTailhookPos(void) const { return TailhookPos; }
/** Gets the wing fold position (0 unfolded, 1 folded)
@return wing fold position (0 unfolded, 1 folded) */
inline double GetWingFoldPos(void) const { return WingFoldPos; }
/** Gets the prop pitch position.
@param engine engine ID number
@return prop pitch position for the given engine in range from 0 - 1.0 */
@ -467,6 +477,13 @@ public:
@param gear position 0 up, 1 down */
void SetGearPos(double gearpos) { GearPos = gearpos; }
/** Set the tailhook position
@param tailhook position 0 up, 1 down */
void SetTailhookPos(double hookpos) { TailhookPos = hookpos; }
/** Set the wing fold position
@param wing fold position 0 unfolded, 1 folded */
void SetWingFoldPos(double foldpos) { WingFoldPos = foldpos; }
/** Sets the actual prop pitch setting for the specified engine
@param engine engine ID number
@ -545,6 +562,7 @@ private:
vector <double> SteerPosDeg;
double LeftBrake, RightBrake, CenterBrake; // Brake settings
double GearCmd,GearPos;
double TailhookPos, WingFoldPos;
typedef vector <FGFCSComponent*> FCSCompVec;
FCSCompVec Systems;

View file

@ -130,6 +130,11 @@ bool FGMassBalance::Load(Element* el)
element = el->FindNextElement("pointmass");
}
Weight = EmptyWeight + Propulsion->GetTanksWeight() + GetPointMassWeight()
+ BuoyantForces->GetGasMass()*slugtolb;
Mass = lbtoslug*Weight;
Debug(2);
return true;
}

View file

@ -319,6 +319,7 @@ bool FGPropagate::Run(void)
last2_vLocationDot = last_vLocationDot;
last_vLocationDot = vLocationDot;
Debug(2);
return false;
}
@ -580,6 +581,20 @@ void FGPropagate::Debug(int from)
if (debug_lvl & 8 ) { // Runtime state variables
}
if (debug_lvl & 16) { // Sanity checking
if (from == 2) { // State sanity checking
if (fabs(VState.vPQR.Magnitude()) > 1000.0) {
cerr << endl << "Vehicle rotation rate is excessive (>1000 rad/sec): " << VState.vPQR.Magnitude() << endl;
exit(-1);
}
if (fabs(VState.vUVW.Magnitude()) > 1.0e10) {
cerr << endl << "Vehicle velocity is excessive (>1e10 ft/sec): " << VState.vUVW.Magnitude() << endl;
exit(-1);
}
if (fabs(GetDistanceAGL()) > 1e10) {
cerr << endl << "Vehicle altitude is excessive (>1e10 ft): " << GetDistanceAGL() << endl;
exit(-1);
}
}
}
if (debug_lvl & 64) {
if (from == 0) { // Constructor

View file

@ -304,8 +304,6 @@ Manifold_Pressure_Lookup = new
FGPiston::~FGPiston()
{
char property_name[80];
delete Lookup_Combustion_Efficiency;
delete Power_Mixture_Correlation;
delete Mixture_Efficiency_Correlation;
@ -630,18 +628,18 @@ void FGPiston::doEnginePower(void)
double T_amb_sea_lev_degF = KelvinToFahrenheit(288);
// FIXME: this needs to be generalized
double ME, friction, percent_RPM; // Convienience term for use in the calculations
double ME, friction, percent_RPM, power; // Convienience term for use in the calculations
ME = Mixture_Efficiency_Correlation->GetValue(m_dot_fuel/m_dot_air);
percent_RPM = RPM/MaxRPM;
friction = 1 - (percent_RPM * percent_RPM * percent_RPM * percent_RPM/10);
if (friction < 0 ) friction = 0;
Percentage_Power = friction;
power = friction;
if ( Magnetos != 3 ) Percentage_Power *= SparkFailDrop;
if ( Magnetos != 3 ) power *= SparkFailDrop;
HP = (FuelFlow_gph * 6.0 / BSFC )* ME * suction_loss * Percentage_Power;
HP = (FuelFlow_gph * 6.0 / BSFC )* ME * suction_loss * power;
} else {
@ -663,6 +661,7 @@ void FGPiston::doEnginePower(void)
HP = 0.0;
}
}
Percentage_Power = HP / MaxHP ;
// cout << "Power = " << HP << " RPM = " << RPM << " Running = " << Running << " Cranking = " << Cranking << endl;
}
@ -790,7 +789,7 @@ void FGPiston::doOilPressure(void)
OilPressure_psi = Oil_Press_Relief_Valve;
}
OilPressure_psi += (Design_Oil_Temp - OilTemp_degK) * Oil_Viscosity_Index;
OilPressure_psi += (Design_Oil_Temp - OilTemp_degK) * Oil_Viscosity_Index * OilPressure_psi / Oil_Press_Relief_Valve;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View file

@ -1,11 +1,22 @@
noinst_LIBRARIES = libPropulsion.a
includedir = @includedir@/JSBSim/models/propulsion
libPropulsion_a_SOURCES = FGElectric.cpp FGEngine.cpp FGForce.cpp FGNozzle.cpp \
FGPiston.cpp FGPropeller.cpp FGRocket.cpp FGRotor.cpp \
LIBRARY_SOURCES = FGElectric.cpp FGEngine.cpp FGForce.cpp FGNozzle.cpp \
FGPiston.cpp FGPropeller.cpp FGRocket.cpp \
FGTank.cpp FGThruster.cpp FGTurbine.cpp FGTurboProp.cpp
noinst_HEADERS = FGElectric.h FGEngine.h FGForce.h FGNozzle.h FGPiston.h \
FGPropeller.h FGRocket.h FGRotor.h FGTank.h FGThruster.h \
LIBRARY_INCLUDES = FGElectric.h FGEngine.h FGForce.h FGNozzle.h FGPiston.h \
FGPropeller.h FGRocket.h FGTank.h FGThruster.h \
FGTurbine.h FGTurboProp.h
INCLUDES = -I$(top_srcdir)/src/FDM/JSBSim
if BUILD_LIBRARIES
noinst_LTLIBRARIES = libPropulsion.la
include_HEADERS = $(LIBRARY_INCLUDES)
libPropulsion_la_SOURCES = $(LIBRARY_SOURCES)
libPropulsion_la_CXXFLAGS = $(AM_CXXFLAGS)
else
noinst_LIBRARIES = libPropulsion.a
noinst_HEADERS = $(LIBRARY_INCLUDES)
libPropulsion_a_SOURCES = $(LIBRARY_SOURCES)
endif
INCLUDES = -I$(top_srcdir)/src -I../../