1
0
Fork 0

Expose the vertical flight path as a property

write the vertical flight path to /orientation/path-deg
zero means level flight, positive angles climb

Also use SGD_DEGREES_TO_RADIANS (and vice versa) for double computations
instead of the float constants
This commit is contained in:
Torsten Dreyer 2014-08-19 00:01:08 +02:00
parent d1638932b3
commit a4b0be3d8a
2 changed files with 22 additions and 10 deletions

View file

@ -297,6 +297,8 @@ FGInterface::bind ()
fgSetArchivable("/orientation/heading-deg"); fgSetArchivable("/orientation/heading-deg");
_tiedProperties.Tie("/orientation/track-deg", this, _tiedProperties.Tie("/orientation/track-deg", this,
&FGInterface::get_Track); // read-only &FGInterface::get_Track); // read-only
_tiedProperties.Tie("/orientation/path-deg", this,
&FGInterface::get_Path); // read-only
// Body-axis "euler rates" (rotation speed, but in a funny // Body-axis "euler rates" (rotation speed, but in a funny
// representation). // representation).
@ -481,7 +483,7 @@ bool FGInterface::writeState(SGIOChannel* io)
void FGInterface::_updatePositionM(const SGVec3d& cartPos) void FGInterface::_updatePositionM(const SGVec3d& cartPos)
{ {
TrackComputer tracker( _state.track, _state.geodetic_position_v ); TrackComputer tracker( _state.track, _state.path, _state.geodetic_position_v );
_state.cartesian_position_v = cartPos; _state.cartesian_position_v = cartPos;
_state.geodetic_position_v = SGGeod::fromCart(_state.cartesian_position_v); _state.geodetic_position_v = SGGeod::fromCart(_state.cartesian_position_v);
_state.geocentric_position_v = SGGeoc::fromCart(_state.cartesian_position_v); _state.geocentric_position_v = SGGeoc::fromCart(_state.cartesian_position_v);
@ -492,7 +494,7 @@ void FGInterface::_updatePositionM(const SGVec3d& cartPos)
void FGInterface::_updatePosition(const SGGeod& geod) void FGInterface::_updatePosition(const SGGeod& geod)
{ {
TrackComputer tracker( _state.track, _state.geodetic_position_v ); TrackComputer tracker( _state.track, _state.path, _state.geodetic_position_v );
_state.geodetic_position_v = geod; _state.geodetic_position_v = geod;
_state.cartesian_position_v = SGVec3d::fromGeod(_state.geodetic_position_v); _state.cartesian_position_v = SGVec3d::fromGeod(_state.geodetic_position_v);
_state.geocentric_position_v = SGGeoc::fromCart(_state.cartesian_position_v); _state.geocentric_position_v = SGGeoc::fromCart(_state.cartesian_position_v);
@ -504,7 +506,7 @@ void FGInterface::_updatePosition(const SGGeod& geod)
void FGInterface::_updatePosition(const SGGeoc& geoc) void FGInterface::_updatePosition(const SGGeoc& geoc)
{ {
TrackComputer tracker( _state.track, _state.geodetic_position_v ); TrackComputer tracker( _state.track, _state.path, _state.geodetic_position_v );
_state.geocentric_position_v = geoc; _state.geocentric_position_v = geoc;
_state.cartesian_position_v = SGVec3d::fromGeoc(_state.geocentric_position_v); _state.cartesian_position_v = SGVec3d::fromGeoc(_state.geocentric_position_v);
_state.geodetic_position_v = SGGeod::fromCart(_state.cartesian_position_v); _state.geodetic_position_v = SGGeod::fromCart(_state.cartesian_position_v);

View file

@ -99,18 +99,26 @@ class SGIOChannel;
*/ */
class TrackComputer { class TrackComputer {
public: public:
inline TrackComputer( double & track, const SGGeod & position ) : inline TrackComputer( double & track, double & path, const SGGeod & position ) :
_track( track ), _track( track ),
_path( path ),
_position( position ), _position( position ),
_prevPosition( position ) { _prevPosition( position ) {
} }
inline ~TrackComputer() { inline ~TrackComputer() {
if( _prevPosition == _position ) return; if( _prevPosition == _position ) return;
_track = SGGeodesy::courseDeg( _prevPosition, _position ); // _track = SGGeodesy::courseDeg( _prevPosition, _position );
double d = .0;
double distance = .0;
if( SGGeodesy::inverse( _prevPosition, _position, _track, d, distance ) ) {
d = _position.getElevationM() - _prevPosition.getElevationM();
_path = atan2( d, distance ) * SGD_RADIANS_TO_DEGREES;
}
} }
private: private:
double & _track; double & _track;
double & _path;
const SGGeod & _position; const SGGeod & _position;
const SGGeod _prevPosition; const SGGeod _prevPosition;
}; };
@ -194,6 +202,7 @@ private:
double climb_rate; // in feet per second double climb_rate; // in feet per second
double altitude_agl; double altitude_agl;
double track; double track;
double path;
}; };
FlightState _state; FlightState _state;
@ -306,17 +315,17 @@ public:
void set_Phi_dot_degps(double x) void set_Phi_dot_degps(double x)
{ {
_state.euler_rates_v[0] = x * SG_DEGREES_TO_RADIANS; _state.euler_rates_v[0] = x * SGD_DEGREES_TO_RADIANS;
} }
void set_Theta_dot_degps(double x) void set_Theta_dot_degps(double x)
{ {
_state.euler_rates_v[1] = x * SG_DEGREES_TO_RADIANS; _state.euler_rates_v[1] = x * SGD_DEGREES_TO_RADIANS;
} }
void set_Psi_dot_degps(double x) void set_Psi_dot_degps(double x)
{ {
_state.euler_rates_v[2] = x * SG_DEGREES_TO_RADIANS; _state.euler_rates_v[2] = x * SGD_DEGREES_TO_RADIANS;
} }
inline void _set_Geocentric_Rates( double lat, double lon, double rad ) { inline void _set_Geocentric_Rates( double lat, double lon, double rad ) {
@ -349,7 +358,7 @@ public:
_set_Geodetic_Position( lat, lon, _state.geodetic_position_v.getElevationFt()); _set_Geodetic_Position( lat, lon, _state.geodetic_position_v.getElevationFt());
} }
inline void _set_Geodetic_Position( double lat, double lon, double alt ) { inline void _set_Geodetic_Position( double lat, double lon, double alt ) {
TrackComputer tracker( _state.track, _state.geodetic_position_v ); TrackComputer tracker( _state.track, _state.path, _state.geodetic_position_v );
_state.geodetic_position_v.setLatitudeRad(lat); _state.geodetic_position_v.setLatitudeRad(lat);
_state.geodetic_position_v.setLongitudeRad(lon); _state.geodetic_position_v.setLongitudeRad(lon);
_state.geodetic_position_v.setElevationFt(alt); _state.geodetic_position_v.setElevationFt(alt);
@ -364,7 +373,7 @@ public:
inline void _set_Alpha( double a ) { _state.alpha = a; } inline void _set_Alpha( double a ) { _state.alpha = a; }
inline void _set_Beta( double b ) { _state.beta = b; } inline void _set_Beta( double b ) { _state.beta = b; }
inline void set_Alpha_deg( double a ) { _state.alpha = a * SG_DEGREES_TO_RADIANS; } inline void set_Alpha_deg( double a ) { _state.alpha = a * SGD_DEGREES_TO_RADIANS; }
inline void _set_Gamma_vert_rad( double gv ) { _state.gamma_vert_rad = gv; } inline void _set_Gamma_vert_rad( double gv ) { _state.gamma_vert_rad = gv; }
inline void _set_Density( double d ) { _state.density = d; } inline void _set_Density( double d ) { _state.density = d; }
@ -617,6 +626,7 @@ public:
} }
inline double get_Altitude_AGL(void) const { return _state.altitude_agl; } inline double get_Altitude_AGL(void) const { return _state.altitude_agl; }
inline double get_Track(void) const { return _state.track; } inline double get_Track(void) const { return _state.track; }
inline double get_Path(void) const { return _state.path; }
inline double get_Latitude_deg () const { inline double get_Latitude_deg () const {
return _state.geodetic_position_v.getLatitudeDeg(); return _state.geodetic_position_v.getLatitudeDeg();