JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGWaypoint Class Reference

Detailed Description

Models a Waypoint object.

The waypoint_heading component returns the heading to a specified waypoint lat/long from another specified point. The waypoint_distance component returns the distance between

<waypoint_heading name="component_name" unit="DEG|RAD">
<target_latitude unit="DEG|RAD"> property_name </target_latitude>
<target_longitude unit="DEG|RAD"> property_name </target_longitude>
<source_latitude unit="DEG|RAD"> property_name </source_latitude>
<source_longitude unit="DEG|RAD"> property_name </source_longitude>
[<clipto>
<min> {[-]property name | value} </min>
<max> {[-]property name | value} </max>
</clipto>]
[<output> {property} </output>]
</waypoint_heading>
<waypoint_distance name="component_name" unit="FT|M">
<target_latitude unit="DEG|RAD"> property_name </target_latitude>
<target_longitude unit="DEG|RAD"> property_name </target_longitude>
<source_latitude unit="DEG|RAD"> property_name </source_latitude>
<source_longitude unit="DEG|RAD"> property_name </source_longitude>
[<radius> {value} </radius>]
[<clipto>
<min> {[-]property name | value} </min>
<max> {[-]property name | value} </max>
</clipto>]
[<output> {property} </output>]
</waypoint_distance>
Author
Jon S. Berndt

Definition at line 97 of file FGWaypoint.h.

#include <FGWaypoint.h>

+ Inheritance diagram for FGWaypoint:
+ Collaboration diagram for FGWaypoint:

Public Member Functions

 FGWaypoint (FGFCS *fcs, Element *element)
 
bool Run (void) override
 
- Public Member Functions inherited from FGFCSComponent
 FGFCSComponent (FGFCS *fcs, Element *el)
 Constructor.
 
virtual ~FGFCSComponent ()
 Destructor.
 
std::string GetName (void) const
 
double GetOutput (void) const
 
virtual double GetOutputPct (void) const
 
std::string GetType (void) const
 
virtual void ResetPastStates (void)
 
virtual void SetOutput (void)
 
- Public Member Functions inherited from FGJSBBase
 FGJSBBase ()
 Constructor for FGJSBBase.
 
virtual ~FGJSBBase ()
 Destructor for FGJSBBase.
 
void disableHighLighting (void)
 Disables highlighting in the console output.
 

Additional Inherited Members

- Public Types inherited from FGJSBBase
enum  { eL = 1 , eM , eN }
 Moments L, M, N. More...
 
enum  { eP = 1 , eQ , eR }
 Rates P, Q, R. More...
 
enum  { eU = 1 , eV , eW }
 Velocities U, V, W. More...
 
enum  { eX = 1 , eY , eZ }
 Positions X, Y, Z. More...
 
enum  { ePhi = 1 , eTht , ePsi }
 Euler angles Phi, Theta, Psi. More...
 
enum  { eDrag = 1 , eSide , eLift }
 Stability axis forces, Drag, Side force, Lift. More...
 
enum  { eRoll = 1 , ePitch , eYaw }
 Local frame orientation Roll, Pitch, Yaw. More...
 
enum  { eNorth = 1 , eEast , eDown }
 Local frame position North, East, Down. More...
 
enum  { eLat = 1 , eLong , eRad }
 Locations Radius, Latitude, Longitude. More...
 
enum  {
  inNone = 0 , inDegrees , inRadians , inMeters ,
  inFeet
}
 Conversion specifiers. More...
 
- Static Public Member Functions inherited from FGJSBBase
static const std::string & GetVersion (void)
 Returns the version number of JSBSim.
 
static constexpr double KelvinToFahrenheit (double kelvin)
 Converts from degrees Kelvin to degrees Fahrenheit.
 
static constexpr double CelsiusToRankine (double celsius)
 Converts from degrees Celsius to degrees Rankine.
 
static constexpr double RankineToCelsius (double rankine)
 Converts from degrees Rankine to degrees Celsius.
 
static constexpr double KelvinToRankine (double kelvin)
 Converts from degrees Kelvin to degrees Rankine.
 
static constexpr double RankineToKelvin (double rankine)
 Converts from degrees Rankine to degrees Kelvin.
 
static constexpr double FahrenheitToCelsius (double fahrenheit)
 Converts from degrees Fahrenheit to degrees Celsius.
 
static constexpr double CelsiusToFahrenheit (double celsius)
 Converts from degrees Celsius to degrees Fahrenheit.
 
static constexpr double CelsiusToKelvin (double celsius)
 Converts from degrees Celsius to degrees Kelvin.
 
static constexpr double KelvinToCelsius (double kelvin)
 Converts from degrees Kelvin to degrees Celsius.
 
static constexpr double FeetToMeters (double measure)
 Converts from feet to meters.
 
static bool EqualToRoundoff (double a, double b)
 Finite precision comparison.
 
static bool EqualToRoundoff (float a, float b)
 Finite precision comparison.
 
static bool EqualToRoundoff (float a, double b)
 Finite precision comparison.
 
static bool EqualToRoundoff (double a, float b)
 Finite precision comparison.
 
static constexpr double Constrain (double min, double value, double max)
 Constrain a value between a minimum and a maximum value.
 
static constexpr double sign (double num)
 
- Static Public Attributes inherited from FGJSBBase
static char highint [5] = {27, '[', '1', 'm', '\0' }
 highlights text
 
static char halfint [5] = {27, '[', '2', 'm', '\0' }
 low intensity text
 
static char normint [6] = {27, '[', '2', '2', 'm', '\0' }
 normal intensity text
 
static char reset [5] = {27, '[', '0', 'm', '\0' }
 resets text properties
 
static char underon [5] = {27, '[', '4', 'm', '\0' }
 underlines text
 
static char underoff [6] = {27, '[', '2', '4', 'm', '\0' }
 underline off
 
static char fgblue [6] = {27, '[', '3', '4', 'm', '\0' }
 blue text
 
static char fgcyan [6] = {27, '[', '3', '6', 'm', '\0' }
 cyan text
 
static char fgred [6] = {27, '[', '3', '1', 'm', '\0' }
 red text
 
static char fggreen [6] = {27, '[', '3', '2', 'm', '\0' }
 green text
 
static char fgdef [6] = {27, '[', '3', '9', 'm', '\0' }
 default text
 
static short debug_lvl = 1
 
- Protected Member Functions inherited from FGFCSComponent
virtual void bind (Element *el, FGPropertyManager *pm)
 
void CheckInputNodes (size_t MinNodes, size_t MaxNodes, Element *el)
 
void Clip (void)
 
void Delay (void)
 
- Static Protected Member Functions inherited from FGJSBBase
static std::string CreateIndexedPropertyName (const std::string &Property, int index)
 
- Protected Attributes inherited from FGFCSComponent
bool clip
 
FGParameter_ptr ClipMax
 
FGParameter_ptr ClipMin
 
bool cyclic_clip
 
unsigned int delay
 
double delay_time
 
double dt
 
FGFCSfcs
 
int index
 
std::vector< FGPropertyValue_ptr > InitNodes
 
double Input
 
std::vector< FGPropertyValue_ptr > InputNodes
 
std::string Name
 
double Output
 
std::vector< double > output_array
 
std::vector< SGPropertyNode_ptr > OutputNodes
 
std::string Type
 
- Static Protected Attributes inherited from FGJSBBase
static constexpr double radtodeg = 180. / M_PI
 
static constexpr double degtorad = M_PI / 180.
 
static constexpr double hptoftlbssec = 550.0
 
static constexpr double psftoinhg = 0.014138
 
static constexpr double psftopa = 47.88
 
static constexpr double fttom = 0.3048
 
static constexpr double ktstofps = 1852./(3600*fttom)
 
static constexpr double fpstokts = 1.0 / ktstofps
 
static constexpr double inchtoft = 1.0/12.0
 
static constexpr double m3toft3 = 1.0/(fttom*fttom*fttom)
 
static constexpr double in3tom3 = inchtoft*inchtoft*inchtoft/m3toft3
 
static constexpr double inhgtopa = 3386.38
 
static constexpr double slugtolb = 32.174049
 Note that definition of lbtoslug by the inverse of slugtolb and not to a different constant you can also get from some tables will make lbtoslug*slugtolb == 1 up to the magnitude of roundoff.
 
static constexpr double lbtoslug = 1.0/slugtolb
 
static constexpr double kgtolb = 2.20462
 
static constexpr double kgtoslug = 0.06852168
 
static const std::string needed_cfg_version = "2.0"
 
static const std::string JSBSim_version = JSBSIM_VERSION " " __DATE__ " " __TIME__
 

Constructor & Destructor Documentation

◆ FGWaypoint()

FGWaypoint ( FGFCS fcs,
Element element 
)

Definition at line 58 of file FGWaypoint.cpp.

59 : FGFCSComponent(fcs, element)
60{
61 if (Type == "WAYPOINT_HEADING") WaypointType = eHeading;
62 else if (Type == "WAYPOINT_DISTANCE") WaypointType = eDistance;
63
64 target_latitude_unit = 1.0;
65 target_longitude_unit = 1.0;
66 source_latitude_unit = 1.0;
67 source_longitude_unit = 1.0;
68 source = fcs->GetExec()->GetIC()->GetPosition();
69
70 auto PropertyManager = fcs->GetPropertyManager();
71
72 if (element->FindElement("target_latitude") ) {
73 target_latitude = std::make_unique<FGPropertyValue>(element->FindElementValue("target_latitude"),
74 PropertyManager, element);
75 if (element->FindElement("target_latitude")->HasAttribute("unit")) {
76 if (element->FindElement("target_latitude")->GetAttributeValue("unit") == "DEG") {
77 target_latitude_unit = 0.017453293;
78 }
79 }
80 } else {
81 XMLLogException err(element);
82 err << "Target latitude is required for waypoint component: " << Name << "\n";
83 throw err;
84 }
85
86 if (element->FindElement("target_longitude") ) {
87 target_longitude = std::make_unique<FGPropertyValue>(element->FindElementValue("target_longitude"),
88 PropertyManager, element);
89 if (element->FindElement("target_longitude")->HasAttribute("unit")) {
90 if (element->FindElement("target_longitude")->GetAttributeValue("unit") == "DEG") {
91 target_longitude_unit = 0.017453293;
92 }
93 }
94 } else {
95 XMLLogException err(element);
96 err << "Target longitude is required for waypoint component: " << Name << "\n";
97 throw err;
98 }
99
100 if (element->FindElement("source_latitude") ) {
101 source_latitude = std::make_unique<FGPropertyValue>(element->FindElementValue("source_latitude"),
102 PropertyManager, element);
103 if (element->FindElement("source_latitude")->HasAttribute("unit")) {
104 if (element->FindElement("source_latitude")->GetAttributeValue("unit") == "DEG") {
105 source_latitude_unit = 0.017453293;
106 }
107 }
108 } else {
109 XMLLogException err(element);
110 err << "Source latitude is required for waypoint component: " << Name << "\n";
111 throw err;
112 }
113
114 if (element->FindElement("source_longitude") ) {
115 source_longitude = std::make_unique<FGPropertyValue>(element->FindElementValue("source_longitude"),
116 PropertyManager, element);
117 if (element->FindElement("source_longitude")->HasAttribute("unit")) {
118 if (element->FindElement("source_longitude")->GetAttributeValue("unit") == "DEG") {
119 source_longitude_unit = 0.017453293;
120 }
121 }
122 } else {
123 XMLLogException err(element);
124 err << "Source longitude is required for waypoint component: " << Name << "\n";
125 throw err;
126 }
127
128 unit = element->GetAttributeValue("unit");
129 if (WaypointType == eHeading) {
130 if (!unit.empty()) {
131 if (unit == "DEG") eUnit = eDeg;
132 else if (unit == "RAD") eUnit = eRad;
133 else {
134 XMLLogException err(element);
135 err << "Unknown unit " << unit << " in HEADING waypoint component, " << "\n";
136 throw err;
137 }
138 } else {
139 eUnit = eRad; // Default is radians if unspecified
140 }
141 } else {
142 if (!unit.empty()) {
143 if (unit == "FT") eUnit = eFeet;
144 else if (unit == "M") eUnit = eMeters;
145 else {
146 XMLLogException err(element);
147 err << "Unknown unit " << unit << " in DISTANCE waypoint component, "
148 << Name << "\n";
149 throw err;
150 }
151 } else {
152 eUnit = eFeet; // Default is feet if unspecified
153 }
154 }
155
156 bind(element, PropertyManager.get());
157 Debug(0);
158}
FGFCSComponent(FGFCS *fcs, Element *el)
Constructor.
std::shared_ptr< FGInitialCondition > GetIC(void) const
Returns a pointer to the FGInitialCondition object.
Definition FGFDMExec.h:390

◆ ~FGWaypoint()

~FGWaypoint ( )

Definition at line 162 of file FGWaypoint.cpp.

163{
164 Debug(1);
165}

Member Function Documentation

◆ Run()

bool Run ( void  )
overridevirtual

Reimplemented from FGFCSComponent.

Definition at line 169 of file FGWaypoint.cpp.

170{
171 double source_latitude_rad = source_latitude->GetValue() * source_latitude_unit;
172 double source_longitude_rad = source_longitude->GetValue() * source_longitude_unit;
173 double target_latitude_rad = target_latitude->GetValue() * target_latitude_unit;
174 double target_longitude_rad = target_longitude->GetValue() * target_longitude_unit;
175 source.SetPositionGeodetic(source_longitude_rad, source_latitude_rad, 0.0);
176
177 if (fabs(target_latitude_rad) > M_PI/2.0) {
178 LogException err;
179 err << "\nTarget latitude in waypoint \"" << Name
180 << "\" must be less than or equal to 90 degrees.\n"
181 << "(is longitude being mistakenly supplied?)\n\n";
182 throw err;
183 }
184
185 if (fabs(source_latitude_rad) > M_PI/2.0) {
186 LogException err;
187 err << "\nSource latitude in waypoint \"" << Name
188 << "\" must be less than or equal to 90 degrees.\n"
189 << "(is longitude being mistakenly supplied?)\n\n";
190 throw err;
191 }
192
193 if (WaypointType == eHeading) { // Calculate Heading
194
195 double heading_to_waypoint_rad = source.GetHeadingTo(target_longitude_rad,
196 target_latitude_rad);
197
198 if (eUnit == eDeg) Output = heading_to_waypoint_rad * radtodeg;
199 else Output = heading_to_waypoint_rad;
200
201 } else { // Calculate Distance
202
203 double wp_distance = source.GetDistanceTo(target_longitude_rad,
204 target_latitude_rad);
205 if (eUnit == eMeters) Output = FeetToMeters(wp_distance);
206 else Output = wp_distance;
207
208 }
209
210 Clip();
211 SetOutput();
212
213 return true;
214}
static constexpr double FeetToMeters(double measure)
Converts from feet to meters.
Definition FGJSBBase.h:249
double GetHeadingTo(double target_longitude, double target_latitude) const
Get the heading that should be followed from the current location to a given location along the short...
void SetPositionGeodetic(double lon, double lat, double height)
Sets the longitude, latitude and the distance above the reference spheroid.
double GetDistanceTo(double target_longitude, double target_latitude) const
Get the geodetic distance between the current location and a given location.

The documentation for this class was generated from the following files: