131 if (!
fgGetBool(
"/sim/fdm-initialized",
false)) {
135 double indicated_roll = 0;
136 double indicated_pitch = 0;
137 double indicated_hdg = 0;
138 double indicated_roll_rate = 0;
139 double indicated_pitch_rate = 0;
140 double indicated_hdg_rate = 0;
142 double erect_time_factor = 1;
144 const double erect_time = 180;
145 const double max_g_error = 10.0;
148 _gyro.set_power_norm( _electrical_node->getDoubleValue()/24 );
150 double spin = _gyro.get_spin_norm();
153 if ( _electrical_node->getDoubleValue() > 0 && spin >= 0.25) {
154 _off_node->setBoolValue(
false);
156 _off_node->setBoolValue(
true);
161 if(_hdg_input_source_node->getBoolValue()){
162 hdg = _hdg_in_node->getDoubleValue();
164 hdg = _hdg_mag_in_node->getDoubleValue();
167 double roll = _roll_in_node->getDoubleValue();
168 double pitch = _pitch_in_node->getDoubleValue();
169 double g = _g_in_node->getDoubleValue();
171 double roll_rate = _yaw_rate_node->getDoubleValue();
172 double pitch_rate = _pitch_rate_node->getDoubleValue();
173 double yaw_rate = _yaw_rate_node->getDoubleValue();
176 double responsiveness = spin * spin * spin * spin * spin * spin;
177 roll =
fgGetLowPass( _last_roll, roll, responsiveness );
178 pitch =
fgGetLowPass( _last_pitch , pitch, responsiveness );
180 if ((hdg - _last_hdg) > 180)
182 if ((hdg - _last_hdg) < -180)
188 responsiveness = 0.1 / (spin * spin * spin * spin * spin * spin);
189 yaw_rate =
fgGetLowPass( _last_yaw_rate , yaw_rate, responsiveness );
197 _last_roll_rate = roll_rate;
198 _last_pitch_rate = pitch_rate;
199 _last_yaw_rate = yaw_rate;
203 if ( fabs ( yaw_rate ) <= 5
204 && g <= 1.5 && g >= -0.5){
206 if ( !_fast_erect_node->getBoolValue() ){
207 erect_time_factor = 1;
209 erect_time_factor = 2;
212 _g_error -= (max_g_error/(erect_time * 0.33)) * dt * erect_time_factor;
214 _g_error += (max_g_error /(erect_time * 0.33)) * dt * 2;
226 _g_error = SGMiscd::clip(_g_error, 0, 10);
228 indicated_roll = _last_roll + _g_error;
229 indicated_pitch = _last_pitch + _g_error;
230 indicated_hdg = _last_hdg + _g_error;
231 indicated_roll_rate = _last_roll_rate;
232 indicated_pitch_rate = _last_pitch_rate;
233 indicated_hdg_rate = _last_yaw_rate;
236 SGPropertyNode *bnode
237 =
fgGetNode(
"/autopilot/settings/heading-bug-deg",
false );
240 double diff = bnode->getDoubleValue() - indicated_hdg;
241 if ( diff < -180.0 ) { diff += 360.0; }
242 if ( diff > 180.0 ) { diff -= 360.0; }
243 _error_out_node->setDoubleValue( diff );
250 double factor = _responsiveness_node->getDoubleValue() * dt;
252 indicated_roll =
fgGetLowPass( _indicated_roll, indicated_roll, factor );
253 indicated_pitch =
fgGetLowPass( _indicated_pitch , indicated_pitch, factor );
256 indicated_roll_rate =
fgGetLowPass( _indicated_roll_rate, indicated_roll_rate, factor );
257 indicated_pitch_rate =
fgGetLowPass( _indicated_pitch_rate , indicated_pitch_rate, factor );
258 indicated_hdg_rate =
fgGetLowPass( _indicated_hdg_rate , indicated_hdg_rate, factor );
261 _indicated_roll = indicated_roll;
262 _indicated_pitch = indicated_pitch;
263 _indicated_hdg = indicated_hdg;
265 _indicated_roll_rate = indicated_roll_rate;
266 _indicated_pitch_rate = indicated_pitch_rate;
267 _indicated_hdg_rate = indicated_hdg_rate;
270 const double spin_thresh = 0.8;
271 const double max_roll_error = 40.0;
272 const double max_pitch_error = 12.0;
273 const double max_hdg_error = 140.0;
278 if ( spin <= spin_thresh ) {
279 double roll_error_factor = ( spin_thresh - spin ) / spin_thresh;
280 double pitch_error_factor = ( spin_thresh - spin ) / spin_thresh;
281 double hdg_error_factor = ( spin_thresh - spin ) / spin_thresh;
282 roll_error = roll_error_factor * roll_error_factor * max_roll_error;
283 pitch_error = pitch_error_factor * pitch_error_factor * max_pitch_error;
284 hdg_error = hdg_error_factor * hdg_error_factor * max_hdg_error;
291 _roll_out_node->setDoubleValue( _indicated_roll + roll_error );
292 _pitch_out_node->setDoubleValue( _indicated_pitch + pitch_error );
293 _hdg_out_node->setDoubleValue( _indicated_hdg + hdg_error );
294 _pitch_rate_out_node ->setDoubleValue( _indicated_pitch_rate );
295 _roll_rate_out_node ->setDoubleValue( _indicated_roll_rate );
296 _hdg_rate_out_node ->setDoubleValue( _indicated_hdg_rate );