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

Add warning messages for inconsistent gravity settings. #318

Merged
merged 2 commits into from
Sep 7, 2020
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
28 changes: 27 additions & 1 deletion src/models/FGInertial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ bool FGInertial::Load(Element* el)

GroundCallback->SetEllipse(a, b);

// Messages to warn the user about possible inconsistencies.
if (a != b && J2 == 0.0)
cout << "Gravitational constant J2 is null for a non-spherical planet." << endl;
if (a == b && J2 != 0.0)
cout << "Gravitational constant J2 is non-zero for a spherical planet." << endl;

Debug(2);

return true;
Expand Down Expand Up @@ -217,11 +223,31 @@ void FGInertial::SetAltitudeAGL(FGLocation& location, double altitudeAGL)

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

void FGInertial::SetGravityType(int gt)
{
// Messages to warn the user about possible inconsistencies.
switch (gt)
{
case eGravType::gtStandard:
if (a != b)
cout << "Warning: Standard gravity model has been set for a non-spherical planet" << endl;
break;
case eGravType::gtWGS84:
if (J2 == 0.0)
cout << "Warning: WGS84 gravity model has been set without specifying the J2 gravitational constant." << endl;
}

gravType = gt;
}

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

void FGInertial::bind(void)
{
PropertyManager->Tie("inertial/sea-level-radius_ft", &in.Position,
&FGLocation::GetSeaLevelRadius);
PropertyManager->Tie("simulation/gravity-model", &gravType);
PropertyManager->Tie("simulation/gravity-model", this, &FGInertial::GetGravityType,
&FGInertial::SetGravityType);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
26 changes: 16 additions & 10 deletions src/models/FGInertial.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ class FGInertial : public FGModel {
*/
void SetGroundCallback(FGGroundCallback* gc) { GroundCallback.reset(gc); }

/// These define the indices use to select the gravitation models.
enum eGravType {
/// Evaluate gravity using Newton's classical formula assuming the Earth is
/// spherical
gtStandard,
/// Evaluate gravity using WGS84 formulas that take the Earth oblateness
/// into account
gtWGS84
};

/// Get the gravity type.
int GetGravityType(void) const { return gravType; }

/// Set the gravity type.
void SetGravityType(int gt);

/** Transform matrix from the local horizontal frame to earth centered.
The local frame is the NED (North-East-Down) frame. Since the Down
direction depends on the gravity so is the local frame.
Expand Down Expand Up @@ -185,16 +201,6 @@ class FGInertial : public FGModel {
bool Load(Element* el) override;

private:
/// These define the indices use to select the gravitation models.
enum eGravType {
/// Evaluate gravity using Newton's classical formula assuming the Earth is
/// spherical
gtStandard,
/// Evaluate gravity using WGS84 formulas that take the Earth oblateness
/// into account
gtWGS84
};

// Standard gravity (9.80665 m/s^2) in ft/s^2 which is the gravity at 45 deg.
// of latitude (see ISA 1976 and Steven & Lewis)
// It includes the centripetal acceleration.
Expand Down