+ // Calculate the tumble for the
+ // next pass.
+ if (_tumble_flag_node->getBoolValue()) {
+ 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
+ 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_int_node->getDoubleValue(), roll,
+ responsiveness);
+ pitch = fgGetLowPass(_pitch_int_node->getDoubleValue(), pitch,
+ responsiveness);
+
+ // Assign the new values
+ _roll_int_node->setDoubleValue(roll);
+ _pitch_int_node->setDoubleValue(pitch);
+
+ // add in a gyro underspin "error" if gyro is spinning too slowly
+ double roll_error;
+ double pitch_error;
+ if ( spin <= spin_thresh ) {
+ double roll_error_factor = (spin_thresh - spin) / spin_thresh;
+ double pitch_error_factor = (spin_thresh - spin) / spin_thresh;
+ roll_error = roll_error_factor * roll_error_factor * max_roll_error;
+ pitch_error = pitch_error_factor * pitch_error_factor * max_pitch_error;
+ } else {
+ roll_error = 0.0;
+ pitch_error = 0.0;
+ }
+
+ _roll_out_node->setDoubleValue(roll + roll_error);
+ _pitch_out_node->setDoubleValue(pitch + pitch_error);