#include <simgear/math/sg_random.h>
#include <simgear/route/route.hxx>
-#include <Cockpit/steam.hxx>
#include <Cockpit/radiostack.hxx>
#include <Controls/controls.hxx>
#include <FDM/flight.hxx>
altitude_agl_node = fgGetNode("/position/altitude-agl-ft", true);
vertical_speed_node = fgGetNode("/velocities/vertical-speed-fps", true);
heading_node = fgGetNode("/orientation/heading-deg", true);
+ dg_heading_node
+ = fgGetNode("/instrumentation/heading-indicator/indicated-heading-deg",
+ true);
roll_node = fgGetNode("/orientation/roll-deg", true);
pitch_node = fgGetNode("/orientation/pitch-deg", true);
+
+
// bind config property nodes...
TargetClimbRate
= fgGetNode("/autopilot/config/target-climb-rate-fpm", true);
= fgGetNode("/autopilot/config/zero-pitch-throttle", true);
zero_pitch_trim_full_throttle
= fgGetNode("/autopilot/config/zero-pitch-trim-full-throttle", true);
+ max_aileron_node = fgGetNode("/autopilot/config/max-aileron", true);
+ max_roll_node = fgGetNode("/autopilot/config/max-roll-deg", true);
+ roll_out_node = fgGetNode("/autopilot/config/roll-out-deg", true);
+ roll_out_smooth_node = fgGetNode("/autopilot/config/roll-out-smooth-deg", true);
+
current_throttle = fgGetNode("/controls/throttle");
// initialize config properties with defaults (in case config isn't there)
fgSetFloat( "/autopilot/config/zero-pitch-throttle", 0.60 );
if ( zero_pitch_trim_full_throttle->getFloatValue() < 0.0000001 )
fgSetFloat( "/autopilot/config/zero-pitch-trim-full-throttle", 0.15 );
+ if ( max_aileron_node->getFloatValue() < 0.0000001 )
+ fgSetFloat( "/autopilot/config/max-aileron", 0.2 );
+ if ( max_roll_node->getFloatValue() < 0.0000001 )
+ fgSetFloat( "/autopilot/config/max-roll-deg", 20 );
+ if ( roll_out_node->getFloatValue() < 0.0000001 )
+ fgSetFloat( "/autopilot/config/roll-out-deg", 20 );
+ if ( roll_out_smooth_node->getFloatValue() < 0.0000001 )
+ fgSetFloat( "/autopilot/config/roll-out-smooth-deg", 10 );
/* set defaults */
heading_hold = false ; // turn the heading hold off
altitude_hold = false ; // turn the altitude hold off
auto_throttle = false ; // turn the auto throttle off
heading_mode = DEFAULT_AP_HEADING_LOCK;
+ altitude_mode = DEFAULT_AP_ALTITUDE_LOCK;
DGTargetHeading = fgGetDouble("/autopilot/settings/heading-bug-deg");
TargetHeading = fgGetDouble("/autopilot/settings/heading-bug-deg");
// the deg from heading to start rolling out at, in Deg
RollOut = 20;
- // how far can I move the aleron from center.
- MaxAileron = .2;
-
// Smoothing distance for alerion control
RollOutSmooth = 10;
// 25% max control variablilty 0.5 / 2.0
disengage_threshold = 1.0;
+ // set default aileron max deflection
+ MaxAileron = 0.5;
+
#if !defined( USING_SLIDER_CLASS )
MaxRollAdjust = 2 * MaxRoll;
RollOutAdjust = 2 * RollOut;
- MaxAileronAdjust = 2 * MaxAileron;
+ //MaxAileronAdjust = 2 * MaxAileron;
RollOutSmoothAdjust = 2 * RollOutSmooth;
#endif // !defined( USING_SLIDER_CLASS )
update_old_control_values();
- sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id") );
+ sprintf( NewTgtAirportId, "%s", fgGetString("/sim/presets/airport-id") );
MakeTargetLatLonStr( get_TargetLatitude(), get_TargetLongitude() );
}
void
-FGAutopilot::update (int dt)
+FGAutopilot::update (double dt)
{
// Remove the following lines when the calling funcitons start
// passing in the data pointer
double lon = longitude_node->getDoubleValue();
double alt = altitude_node->getDoubleValue() * SG_FEET_TO_METER;
+ // get config settings
+ MaxAileron = max_aileron_node->getDoubleValue();
+ MaxRoll = max_roll_node->getDoubleValue();
+ RollOut = roll_out_node->getDoubleValue();
+ RollOutSmooth = roll_out_smooth_node->getDoubleValue();
+
SG_LOG( SG_ALL, SG_DEBUG, "FGAutopilot::run() lat = " << lat <<
" lon = " << lon << " alt = " << alt );
// heading hold
if ( heading_hold == true ) {
if ( heading_mode == FG_DG_HEADING_LOCK ) {
- TargetHeading = DGTargetHeading + FGSteam::get_DG_err();
+ double dg_error = heading_node->getDoubleValue()
+ - dg_heading_node->getDoubleValue();
+ TargetHeading = DGTargetHeading + dg_error;
+ // cout << "dg_error = " << dg_error << endl;
while ( TargetHeading < 0.0 ) { TargetHeading += 360.0; }
while ( TargetHeading > 360.0 ) { TargetHeading -= 360.0; }
MakeTargetHeadingStr( TargetHeading );
// determine our current radial position relative to the
// navaid in "true" heading.
- double cur_radial = current_radiostack->get_nav1_heading();
- if ( current_radiostack->get_nav1_loc() ) {
+ double cur_radial = current_radiostack->get_navcom1()->get_nav_heading();
+ if ( current_radiostack->get_navcom1()->get_nav_loc() ) {
// ILS localizers radials are already "true" in our
// database
} else {
- cur_radial += current_radiostack->get_nav1_magvar();
+ cur_radial += current_radiostack->get_navcom1()->get_nav_magvar();
}
- if ( current_radiostack->get_nav1_from_flag() ) {
+ if ( current_radiostack->get_navcom1()->get_nav_from_flag() ) {
cur_radial += 180.0;
while ( cur_radial >= 360.0 ) { cur_radial -= 360.0; }
}
// determine the target radial in "true" heading
- double tgt_radial = current_radiostack->get_nav1_radial();
- if ( current_radiostack->get_nav1_loc() ) {
+ double tgt_radial = current_radiostack->get_navcom1()->get_nav_radial();
+ if ( current_radiostack->get_navcom1()->get_nav_loc() ) {
// ILS localizers radials are already "true" in our
// database
} else {
// VOR radials need to have that vor's offset added in
- tgt_radial += current_radiostack->get_nav1_magvar();
+ tgt_radial += current_radiostack->get_navcom1()->get_nav_magvar();
}
// determine the heading adjustment needed.
double adjustment =
- current_radiostack->get_nav1_heading_needle_deflection()
- * (current_radiostack->get_nav1_loc_dist() * SG_METER_TO_NM);
+ current_radiostack->get_navcom1()->get_nav_heading_needle_deflection()
+ * (current_radiostack->get_navcom1()->get_nav_loc_dist() * SG_METER_TO_NM);
SG_CLAMP_RANGE( adjustment, -30.0, 30.0 );
+ // clamp closer when inside cone when beyond 5km...
+ if (current_radiostack->get_navcom1()->get_nav_loc_dist() > 5000) {
+ double clamp_angle = fabs(current_radiostack->get_navcom1()->get_nav_heading_needle_deflection()) * 3;
+ if (clamp_angle < 30)
+ SG_CLAMP_RANGE( adjustment, -clamp_angle, clamp_angle);
+ }
+
// determine the target heading to fly to intercept the
// tgt_radial
TargetHeading = tgt_radial + adjustment;
set_HeadingMode( FG_HEADING_WAYPOINT );
} else {
// end of the line
- heading_mode = FG_TRUE_HEADING_LOCK;
+ heading_mode = DEFAULT_AP_HEADING_LOCK;
// use current heading
TargetHeading = heading_node->getDoubleValue();
}
if ( heading_mode == FG_TC_HEADING_LOCK ) {
// drive the turn coordinator to zero
- double turn = FGSteam::get_TC_std();
+ double turn =
+ fgGetDouble("/instrumentation/turn-indicator/indicated-turn-rate");
double AileronSet = -turn / 2.0;
SG_CLAMP_RANGE( AileronSet, -1.0, 1.0 );
globals->get_controls()->set_aileron( AileronSet );
// figure out how far off we are from desired heading
// Now it is time to deterime how far we should be rolled.
- SG_LOG( SG_AUTOPILOT, SG_DEBUG, "RelHeading: " << RelHeading );
-
+ SG_LOG( SG_AUTOPILOT, SG_DEBUG,
+ "Heading = " << heading_node->getDoubleValue() <<
+ " TargetHeading = " << TargetHeading <<
+ " RelHeading = " << RelHeading );
// Check if we are further from heading than the roll out point
if ( fabs( RelHeading ) > RollOut ) {
if ( altitude_mode == FG_ALTITUDE_LOCK ) {
climb_rate =
- ( TargetAltitude - FGSteam::get_ALT_ft() * SG_FEET_TO_METER ) * 8.0;
+ ( TargetAltitude -
+ fgGetDouble("/instrumentation/altimeter/indicated-altitude-ft") * SG_FEET_TO_METER ) * 8.0;
+ } else if ( altitude_mode == FG_TRUE_ALTITUDE_LOCK ) {
+ climb_rate = ( TargetAltitude - alt ) * 8.0;
} else if ( altitude_mode == FG_ALTITUDE_GS1 ) {
- double x = current_radiostack->get_nav1_gs_dist();
+ double x = current_radiostack->get_navcom1()->get_nav_gs_dist();
double y = (altitude_node->getDoubleValue()
- - current_radiostack->get_nav1_elev()) * SG_FEET_TO_METER;
+ - current_radiostack->get_navcom1()->get_nav_elev()) * SG_FEET_TO_METER;
double current_angle = atan2( y, x ) * SGD_RADIANS_TO_DEGREES;
- double target_angle = current_radiostack->get_nav1_target_gs();
+ double target_angle = current_radiostack->get_navcom1()->get_nav_target_gs();
double gs_diff = target_angle - current_angle;
// calculate integral error, and adjustment amount
int_error = alt_error_accum;
// printf("error = %.2f int_error = %.2f\n", error, int_error);
- int_adj = int_error / elevator_adj_factor->getFloatValue();
+
+ // scale elev_adj_factor by speed of aircraft in relation to min climb
+ double elev_adj_factor = elevator_adj_factor->getFloatValue();
+ elev_adj_factor *=
+ pow(float(speed / min_climb->getFloatValue()), 3.0f);
+
+ int_adj = int_error / elev_adj_factor;
// caclulate proportional error
prop_error = error;
- prop_adj = prop_error / elevator_adj_factor->getDoubleValue();
+ prop_adj = prop_error / elev_adj_factor;
total_adj = ((double) 1.0 - (double) integral_contrib->getFloatValue()) * prop_adj
+ (double) integral_contrib->getFloatValue() * int_adj;
heading_mode = mode;
if ( heading_mode == FG_DG_HEADING_LOCK ) {
- // set heading hold to current heading (as read from DG)
- // ... no, leave target heading along ... just use the current
- // heading bug value
- // DGTargetHeading = FGSteam::get_DG_deg();
+ // use current heading bug value
} else if ( heading_mode == FG_TC_HEADING_LOCK ) {
// set autopilot to hold a zero turn (as reported by the TC)
} else if ( heading_mode == FG_TRUE_HEADING_LOCK ) {
if ( waypoint.get_target_alt() > 0.0 ) {
TargetAltitude = waypoint.get_target_alt();
- altitude_mode = FG_ALTITUDE_LOCK;
+ altitude_mode = DEFAULT_AP_ALTITUDE_LOCK;
set_AltitudeEnabled( true );
MakeTargetAltitudeStr( TargetAltitude * SG_METER_TO_FEET );
}
alt_error_accum = 0.0;
- if ( altitude_mode == FG_ALTITUDE_LOCK ) {
+ if ( altitude_mode == DEFAULT_AP_ALTITUDE_LOCK ) {
if ( TargetAltitude < altitude_agl_node->getDoubleValue()
* SG_FEET_TO_METER ) {
}
- if ( !strcmp("/sim/startup/units", "feet") ) {
+ if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
MakeTargetAltitudeStr( TargetAltitude * SG_METER_TO_FEET );
} else {
MakeTargetAltitudeStr( TargetAltitude * SG_METER_TO_FEET );
} else if ( altitude_mode == FG_ALTITUDE_TERRAIN ) {
TargetAGL = altitude_agl_node->getDoubleValue() * SG_FEET_TO_METER;
- if ( !strcmp("/sim/startup/units", "feet") ) {
+ if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
MakeTargetAltitudeStr( TargetAGL * SG_METER_TO_FEET );
} else {
MakeTargetAltitudeStr( TargetAGL * SG_METER_TO_FEET );
void FGAutopilot::AltitudeSet( double new_altitude ) {
double target_alt = new_altitude;
+ altitude_mode = DEFAULT_AP_ALTITUDE_LOCK;
- if ( !strcmp("/sim/startup/units", "feet") ) {
+ if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
target_alt = new_altitude * SG_FEET_TO_METER;
}
- if( target_alt < scenery.get_cur_elev() ) {
- target_alt = scenery.get_cur_elev();
+ if( target_alt < globals->get_scenery()->get_cur_elev() ) {
+ target_alt = globals->get_scenery()->get_cur_elev();
}
TargetAltitude = target_alt;
- altitude_mode = FG_ALTITUDE_LOCK;
- if ( !strcmp("/sim/startup/units", "feet") ) {
+ if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
target_alt *= SG_METER_TO_FEET;
}
// ApAltitudeDialogInput->setValue((float)target_alt);
{
double target_alt, target_agl;
- if ( !strcmp("/sim/startup/units", "feet") ) {
+ if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
target_alt = TargetAltitude * SG_METER_TO_FEET;
target_agl = TargetAGL * SG_METER_TO_FEET;
} else {
target_agl = ( int ) ( target_agl / inc ) * inc + inc;
}
- if ( !strcmp("/sim/startup/units", "feet") ) {
+ if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
target_alt *= SG_FEET_TO_METER;
target_agl *= SG_FEET_TO_METER;
}
TargetAltitude = target_alt;
TargetAGL = target_agl;
- if ( !strcmp("/sim/startup/units", "feet") )
+ if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
target_alt *= SG_METER_TO_FEET;
- if ( !strcmp("/sim/startup/units", "feet") )
+ if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
target_agl *= SG_METER_TO_FEET;
- if ( altitude_mode == FG_ALTITUDE_LOCK ) {
+ if ( altitude_mode == DEFAULT_AP_ALTITUDE_LOCK ) {
MakeTargetAltitudeStr( target_alt );
} else if ( altitude_mode == FG_ALTITUDE_TERRAIN ) {
MakeTargetAltitudeStr( target_agl );
if ( heading_mode != FG_DG_HEADING_LOCK
&& heading_mode != FG_TRUE_HEADING_LOCK )
{
- heading_mode = FG_DG_HEADING_LOCK;
+ heading_mode = DEFAULT_AP_HEADING_LOCK;
}
if ( heading_mode == FG_DG_HEADING_LOCK ) {
void FGAutopilot::HeadingSet( double new_heading ) {
+ heading_mode = DEFAULT_AP_HEADING_LOCK;
if( heading_mode == FG_TRUE_HEADING_LOCK ) {
new_heading = NormalizeDegrees( new_heading );
TargetHeading = new_heading;
{
return (get_AltitudeEnabled() &&
get_AltitudeMode()
- == FGAutopilot::FG_ALTITUDE_LOCK);
+ == DEFAULT_AP_ALTITUDE_LOCK);
}
FGAutopilot::setAPAltitudeLock (bool lock)
{
if (lock)
- set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
- if (get_AltitudeMode() == FGAutopilot::FG_ALTITUDE_LOCK)
+ set_AltitudeMode(DEFAULT_AP_ALTITUDE_LOCK);
+ if (get_AltitudeMode() == DEFAULT_AP_ALTITUDE_LOCK)
set_AltitudeEnabled(lock);
}
}
// end of newauto.cxx
+