From: david Date: Sat, 5 Apr 2003 14:37:12 +0000 (+0000) Subject: Improved tumbling behaviour -- the AI doesn't just freeze now, but X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e4dc8fc3fd1f85fa6ffd8af84393ae3e8edbd7a9;p=flightgear.git Improved tumbling behaviour -- the AI doesn't just freeze now, but appears still to be indicating. Added a 'caged' property to the AI, for aerobatic work. Temporarily disabled tumbling due to pitch, until I can learn more about it. Publish the current amount of tumble (-1.0:1.0) under /instrumentation/attitude-indicator/tumble-norm. --- diff --git a/src/Instrumentation/attitude_indicator.cxx b/src/Instrumentation/attitude_indicator.cxx index 3badf2055..3558e6486 100644 --- a/src/Instrumentation/attitude_indicator.cxx +++ b/src/Instrumentation/attitude_indicator.cxx @@ -14,7 +14,6 @@ AttitudeIndicator::AttitudeIndicator () - : _tumble(0) { } @@ -33,6 +32,10 @@ AttitudeIndicator::init () _tumble_flag_node = fgGetNode("/instrumentation/attitude-indicator/config/tumble-flag", true); + _caged_node = + fgGetNode("/instrumentation/attitude-indicator/caged-flag", true); + _tumble_node = + fgGetNode("/instrumentation/attitude-indicator/tumble-norm", true); _pitch_out_node = fgGetNode("/instrumentation/attitude-indicator/indicated-pitch-deg", true); @@ -60,6 +63,13 @@ AttitudeIndicator::unbind () void AttitudeIndicator::update (double dt) { + // If it's caged, it doesn't indicate + if (_caged_node->getBoolValue()) { + _roll_out_node->setDoubleValue(0.0); + _pitch_out_node->setDoubleValue(0.0); + return; + } + // Get the spin from the gyro _gyro.set_power_norm(_suction_node->getDoubleValue()/5.0); _gyro.update(dt); @@ -75,29 +85,30 @@ AttitudeIndicator::update (double dt) // Calculate the tumble for the // next pass. if (_tumble_flag_node->getBoolValue()) { - if (_tumble < 1.0) { - if (fabs(roll) > 45.0) { - double target = (fabs(roll) - 45.0) / 45.0; - if (_tumble < target) - _tumble = target; - } - if (fabs(pitch) > 45.0) { - double target = (fabs(pitch) - 45.0) / 45.0; - if (_tumble < target) - _tumble = target; - } - if (_tumble > 1.0) { - _tumble = 1.0; - } + double tumble = _tumble_node->getDoubleValue(); + if (fabs(roll) > 45.0) { + double target = (fabs(roll) - 45.0) / 45.0; + target *= target; // exponential past +-45 degrees + if (roll < 0) + target = -target; + + if (fabs(target) > fabs(tumble)) + tumble = target; + + if (tumble > 1.0) + tumble = 1.0; + else if (tumble < -1.0) + tumble = -1.0; } - // Reerect in 5 minutes - _tumble -= dt/300.0; - if (_tumble < 0.0) - _tumble = 0.0; - - responsiveness *= ((1.0 - _tumble) * (1.0 - _tumble) * - (1.0 - _tumble) * (1.0 - _tumble)); - + // Reerect in 5 minutes + double step = dt/300.0; + if (tumble < -step) + tumble += step; + else if (tumble > step) + tumble -= step; + + roll += tumble * 45; + _tumble_node->setDoubleValue(tumble); } roll = fgGetLowPass(_roll_out_node->getDoubleValue(), roll, diff --git a/src/Instrumentation/attitude_indicator.hxx b/src/Instrumentation/attitude_indicator.hxx index b75ccd317..00014bcb4 100644 --- a/src/Instrumentation/attitude_indicator.hxx +++ b/src/Instrumentation/attitude_indicator.hxx @@ -26,6 +26,8 @@ * * /instrumentation/attitude-indicator/config/tumble-flag * /instrumentation/attitude-indicator/serviceable + * /instrumentation/attitude-indicator/caged-flag + * /instrumentation/attitude-indicator/tumble-norm * /orientation/pitch-deg * /orientation/roll-deg * /systems/vacuum[0]/suction-inhg @@ -34,6 +36,7 @@ * * /instrumentation/attitude-indicator/indicated-pitch-deg * /instrumentation/attitude-indicator/indicated-roll-deg + * /instrumentation/attitude-indicator/tumble-norm */ class AttitudeIndicator : public FGSubsystem { @@ -52,9 +55,9 @@ private: Gyro _gyro; - double _tumble; - SGPropertyNode_ptr _tumble_flag_node; + SGPropertyNode_ptr _caged_node; + SGPropertyNode_ptr _tumble_node; SGPropertyNode_ptr _pitch_in_node; SGPropertyNode_ptr _roll_in_node; SGPropertyNode_ptr _suction_node;