1
0
Fork 0

Merge commit 'refs/merge-requests/13' of git://gitorious.org/fg/flightgear into next

This commit is contained in:
Csaba Halasz 2010-11-30 00:26:22 +01:00
commit 674a295896
5 changed files with 227 additions and 201 deletions

View file

@ -152,11 +152,11 @@ bool FGAIBallistic::init(bool search_in_AI_path) {
props->setStringValue("contents/path", _contents_path.c_str());
}
if(_parent != ""){
setParentNode();
}
//if(_parent != ""){
// setParentNode();
//}
setParentNodes(_selected_ac);
//setParentNodes(_selected_ac);
//props->setStringValue("vector/path", _vector_path.c_str());
@ -168,7 +168,11 @@ bool FGAIBallistic::init(bool search_in_AI_path) {
Transform();
//cout << _name << " speed init: " << speed << endl;
if(_parent != ""){
setParentNode();
}
setParentNodes(_selected_ac);
return true;
}

View file

@ -215,13 +215,14 @@ bool FGAIWingman::init(bool search_in_AI_path) {
roll = _rotation;
_ht_agl_ft = 1e10;
props->setStringValue("submodels/path", _path.c_str());
if(_parent != ""){
setParentNode();
}
setParentNodes(_selected_ac);
props->setStringValue("submodels/path", _path.c_str());
user_WoW_node = fgGetNode("gear/gear[1]/wow", true);
return true;
}
@ -277,7 +278,7 @@ double FGAIWingman::calcAngle(double range, SGGeod pos1, SGGeod pos2){
void FGAIWingman::formateToAC(double dt){
double p_hdg, p_pch, p_rll, p_agl, p_ht = 0;
double p_hdg, p_pch, p_rll, p_agl, p_ht, p_wow = 0;
setTgtOffsets(dt, 25);
@ -312,8 +313,9 @@ void FGAIWingman::formateToAC(double dt){
double h_feet = 3 * factor;
p_agl = manager->get_user_agl();
p_wow = user_WoW_node->getDoubleValue();
if(p_agl <= 10) {
if(p_agl <= 10 || p_wow == 1) {
_height = p_ht;
//cout << "ht case1 " ;
} else if (p_agl > 10 && p_agl <= 150 ) {
@ -332,7 +334,8 @@ void FGAIWingman::formateToAC(double dt){
pos.setLongitudeDeg(_offsetpos.getLongitudeDeg());
// these calculations are unreliable at slow speeds
if(speed >= 10) {
// and we don't want random movement on the ground
if(speed >= 10 && p_wow != 1) {
setHdg(p_hdg + h_angle, dt, 0.9);
setPch(p_pch + p_angle + _pitch_offset, dt, 0.9);

View file

@ -67,7 +67,7 @@ private:
double _coeff_bnk; //dimensionless coefficient
double _coeff_spd; //dimensionless coefficient
SGPropertyNode_ptr user_WoW_node;
inline void setFormate(bool f);
inline void setTgtHdg(double hdg);

View file

@ -20,10 +20,11 @@
#include "mrg.hxx"
const double MasterReferenceGyro::gravity = -32.1740485564;
MasterReferenceGyro::MasterReferenceGyro ( SGPropertyNode *node ) :
_name(node->getStringValue("name", "master-reference-gyro")),
_num(node->getIntValue("number", 0))
_name(node->getStringValue("name", "master-reference-gyro")),
_num(node->getIntValue("number", 0))
{
}
@ -43,7 +44,9 @@ MasterReferenceGyro::init ()
_indicated_hdg_rate = 0;
_indicated_roll_rate = 0;
_indicated_pitch_rate = 0;
_erect_time = 0;
_erect_time = 180;
_last_g = 1;
_g_error = 10;
string branch;
branch = "/instrumentation/" + _name;
@ -55,6 +58,7 @@ MasterReferenceGyro::init ()
_pitch_rate_node = fgGetNode("/orientation/pitch-rate-degps", true);
_roll_rate_node = fgGetNode("/orientation/roll-rate-degps", true);
_yaw_rate_node = fgGetNode("/orientation/yaw-rate-degps", true);
//_g_in_node = fgGetNode("/accelerations/pilot/z-accel-fps_sec", true);
_g_in_node = fgGetNode("/accelerations/pilot-g", true);
_electrical_node = fgGetNode("/systems/electrical/outputs/MRG", true);
_hdg_mag_in_node = fgGetNode("/orientation/heading-magnetic-deg", true);
@ -78,6 +82,7 @@ MasterReferenceGyro::init ()
_off_node->setBoolValue(false);
_hdg_input_source_node->setBoolValue(false);
_fast_erect_node->setBoolValue(false);
_g_in_node->setDoubleValue(1);
}
void
@ -109,14 +114,24 @@ MasterReferenceGyro::unbind ()
void
MasterReferenceGyro::update (double dt)
{
//sanity check
if (!fgGetBool("/sim/fdm-initialized", false)) {
return;
}
double indicated_roll = 0;
double indicated_pitch = 0;
double indicated_hdg = 0;
double indicated_roll_rate = 0;
double indicated_pitch_rate = 0;
double indicated_hdg_rate = 0;
double hdg = 0;
double erect_time_factor = 1;
// Get the spin from the gyro
const double erect_time = 180;
const double max_g_error = 10.0;
//Get the spin from the gyro
_gyro.set_power_norm( _electrical_node->getDoubleValue()/24 );
_gyro.update(dt);
double spin = _gyro.get_spin_norm();
@ -130,18 +145,19 @@ MasterReferenceGyro::update (double dt)
}
// Get the input values
double hdg = _hdg_mag_in_node->getDoubleValue();
if(_hdg_input_source_node->getBoolValue())
if(_hdg_input_source_node->getBoolValue()){
hdg = _hdg_in_node->getDoubleValue();
} else {
hdg = _hdg_mag_in_node->getDoubleValue();
}
double roll = _roll_in_node->getDoubleValue();
double pitch = _pitch_in_node->getDoubleValue();
double g = _g_in_node->getDoubleValue()/* / gravity*/;
double roll_rate = _yaw_rate_node->getDoubleValue();
double pitch_rate = _yaw_rate_node->getDoubleValue();
double pitch_rate = _pitch_rate_node->getDoubleValue();
double yaw_rate = _yaw_rate_node->getDoubleValue();
double g = _g_in_node->getDoubleValue();
//modulate the input by the spin rate
double responsiveness = spin * spin * spin * spin * spin * spin;
@ -158,7 +174,7 @@ MasterReferenceGyro::update (double dt)
//but we need to filter the hdg and yaw_rate as well - yuk!
responsiveness = 0.1 / (spin * spin * spin * spin * spin * spin);
yaw_rate = fgGetLowPass( _last_yaw_rate , yaw_rate, responsiveness );
g = fgGetLowPass( _last_g , g, 0.015 );
g = fgGetLowPass( _last_g , g, 1.5);
// store the new values
@ -170,38 +186,38 @@ MasterReferenceGyro::update (double dt)
_last_yaw_rate = yaw_rate;
_last_g = g;
if (_erect_time > 0){
//the gyro only erects inside limits
if ( fabs ( yaw_rate ) <= 5
&& g <= 1.5 && g >= -0.5){
if ( !_fast_erect_node->getBoolValue() )
_erect_time -= dt;
else
_erect_time -= 2 * dt;
if ( !_fast_erect_node->getBoolValue() ){
erect_time_factor = 1;
} else {
erect_time_factor = 2;
}
_g_error -= (max_g_error/(erect_time * 0.33)) * dt * erect_time_factor;
} else {
_g_error += (max_g_error /(erect_time * 0.33)) * dt * 2;
//SG_LOG(SG_GENERAL, SG_ALERT,_num <<
// " g input " << _g_in_node->getDoubleValue() * gravity
// <<" _erect_time " << _erect_time
// << " yaw " << yaw_rate
// << " pitch " << _pitch_rate_node->getDoubleValue()
// << " roll " << _roll_rate_node->getDoubleValue());
}
//SG_LOG(SG_GENERAL, SG_ALERT,
// "g input " << g <<" _erect_time " << _erect_time << " spin " << spin);
//the gyro only erects inside limits
if ( fabs ( yaw_rate ) <= 5
&& ( g <= 1.5 || g >= -0.5)
&& _erect_time <=0 ) {
indicated_roll = _last_roll;
indicated_pitch = _last_pitch;
indicated_hdg = _last_hdg;
//cout << "_g_error "<< _g_error << endl;
_g_error = SGMiscd::clip(_g_error, 0, 10);
// cout << "_g_error clip "<< _g_error << endl;
indicated_roll = _last_roll + _g_error;
indicated_pitch = _last_pitch + _g_error;
indicated_hdg = _last_hdg + _g_error;
indicated_roll_rate = _last_roll_rate;
indicated_pitch_rate = _last_pitch_rate;
indicated_hdg_rate = _last_yaw_rate;
} else {
indicated_roll_rate = 0;
indicated_pitch_rate = 0;
indicated_hdg_rate = 0;
if (_erect_time <= 0 )
_erect_time = 34;
}
// calculate the difference between the indicated heading
// and the selected heading for use with an autopilot
static SGPropertyNode *bnode

View file

@ -49,6 +49,8 @@ public:
private:
static const double gravity; //conversion factor
string _name;
int _num;
@ -66,6 +68,7 @@ private:
double _last_yaw_rate;
double _last_g;
double _erect_time;
double _g_error;
Gyro _gyro;