setFixedTurnRadius(scFileNode->getDoubleValue("fixed-turn-radius-ft", 500));
setSpeedConstant(scFileNode->getDoubleValue("speed-constant", 0.5));
setSMPath(scFileNode->getStringValue("submodel-path", ""));
+ setRollFactor(scFileNode->getDoubleValue("roll-factor", 1));
if (!flightplan.empty()) {
- SG_LOG(SG_GENERAL, SG_ALERT, "getting flightplan: " << _name );
+ SG_LOG(SG_AI, SG_ALERT, "getting flightplan: " << _name );
FGAIFlightPlan* fp = new FGAIFlightPlan(flightplan);
setFlightPlan(fp);
}
bool FGAIShip::init(bool search_in_AI_path) {
+ reinit();
+ return FGAIBase::init(search_in_AI_path);
+}
+
+void FGAIShip::reinit()
+{
prev = 0; // the one behind you
curr = 0; // the one ahead
next = 0; // the next plus 1
if (fp)
_fp_init = initFlightPlan();
- return FGAIBase::init(search_in_AI_path);
+ FGAIBase::reinit();
}
void FGAIShip::bind() {
FGAIBase::bind();
- props->tie("surface-positions/rudder-pos-deg",
+ tie("surface-positions/rudder-pos-deg",
SGRawValuePointer<float>(&_rudder));
- props->tie("controls/heading-lock",
+ tie("controls/heading-lock",
SGRawValuePointer<bool>(&_hdg_lock));
- props->tie("controls/tgt-speed-kts",
+ tie("controls/tgt-speed-kts",
SGRawValuePointer<double>(&tgt_speed));
- props->tie("controls/tgt-heading-degs",
+ tie("controls/tgt-heading-degs",
SGRawValuePointer<double>(&tgt_heading));
- props->tie("controls/constants/rudder",
+ tie("controls/constants/rudder",
SGRawValuePointer<double>(&_rudder_constant));
- props->tie("controls/constants/roll-factor",
+ tie("controls/constants/roll-factor",
SGRawValuePointer<double>(&_roll_factor));
- props->tie("controls/constants/roll",
+ tie("controls/constants/roll",
SGRawValuePointer<double>(&_roll_constant));
- props->tie("controls/constants/rudder",
+ tie("controls/constants/rudder",
SGRawValuePointer<double>(&_rudder_constant));
- props->tie("controls/constants/speed",
+ tie("controls/constants/speed",
SGRawValuePointer<double>(&_speed_constant));
- props->tie("waypoint/range-nm",
+ tie("waypoint/range-nm",
SGRawValuePointer<double>(&_wp_range));
- props->tie("waypoint/brg-deg",
+ tie("waypoint/brg-deg",
SGRawValuePointer<double>(&_course));
- props->tie("waypoint/rangerate-nm-sec",
+ tie("waypoint/rangerate-nm-sec",
SGRawValuePointer<double>(&_range_rate));
- props->tie("waypoint/new",
+ tie("waypoint/new",
SGRawValuePointer<bool>(&_new_waypoint));
- props->tie("waypoint/missed",
+ tie("waypoint/missed",
SGRawValuePointer<bool>(&_missed));
- props->tie("waypoint/missed-count-sec",
+ tie("waypoint/missed-count-sec",
SGRawValuePointer<double>(&_missed_count));
- props->tie("waypoint/missed-range-nm",
+ tie("waypoint/missed-range-nm",
SGRawValuePointer<double>(&_missed_range));
- props->tie("waypoint/missed-time-sec",
+ tie("waypoint/missed-time-sec",
SGRawValuePointer<double>(&_missed_time_sec));
- props->tie("waypoint/wait-count-sec",
+ tie("waypoint/wait-count-sec",
SGRawValuePointer<double>(&_wait_count));
- props->tie("waypoint/xtrack-error-ft",
+ tie("waypoint/xtrack-error-ft",
SGRawValuePointer<double>(&_xtrack_error));
- props->tie("waypoint/waiting",
+ tie("waypoint/waiting",
SGRawValuePointer<bool>(&_waiting));
- props->tie("waypoint/lead-angle-deg",
+ tie("waypoint/lead-angle-deg",
SGRawValuePointer<double>(&_lead_angle));
- props->tie("waypoint/tunnel",
+ tie("waypoint/tunnel",
SGRawValuePointer<bool>(&_tunnel));
- props->tie("waypoint/alt-curr-m",
+ tie("waypoint/alt-curr-m",
SGRawValuePointer<double>(&_curr_alt));
- props->tie("waypoint/alt-prev-m",
+ tie("waypoint/alt-prev-m",
SGRawValuePointer<double>(&_prev_alt));
- props->tie("submodels/serviceable",
+ tie("submodels/serviceable",
SGRawValuePointer<bool>(&_serviceable));
- props->tie("controls/turn-radius-ft",
+ tie("controls/turn-radius-ft",
SGRawValuePointer<double>(&turn_radius_ft));
- props->tie("controls/turn-radius-corrected-ft",
+ tie("controls/turn-radius-corrected-ft",
SGRawValuePointer<double>(&_rd_turn_radius_ft));
- props->tie("controls/constants/lead-angle/gain",
+ tie("controls/constants/lead-angle/gain",
SGRawValuePointer<double>(&_lead_angle_gain));
- props->tie("controls/constants/lead-angle/limit-deg",
+ tie("controls/constants/lead-angle/limit-deg",
SGRawValuePointer<double>(&_lead_angle_limit));
- props->tie("controls/constants/lead-angle/proportion",
+ tie("controls/constants/lead-angle/proportion",
SGRawValuePointer<double>(&_proportion));
- props->tie("controls/fixed-turn-radius-ft",
+ tie("controls/fixed-turn-radius-ft",
SGRawValuePointer<double>(&_fixed_turn_radius));
- props->tie("controls/restart",
+ tie("controls/restart",
SGRawValuePointer<bool>(&_restart));
- props->tie("velocities/speed-kts",
- SGRawValuePointer<double>(&speed));
+ tie("velocities/speed-kts",
+ SGRawValuePointer<double>(&speed));
}
-void FGAIShip::unbind() {
- FGAIBase::unbind();
- props->untie("surface-positions/rudder-pos-deg");
- props->untie("controls/heading-lock");
- props->untie("controls/tgt-speed-kts");
- props->untie("controls/tgt-heading-degs");
- props->untie("controls/constants/roll");
- props->untie("controls/constants/rudder");
- props->untie("controls/constants/roll-factor");
- props->untie("controls/constants/speed");
- props->untie("waypoint/range-nm");
- props->untie("waypoint/range-brg-deg");
- props->untie("waypoint/rangerate-nm-sec");
- props->untie("waypoint/new");
- props->untie("waypoint/missed");
- props->untie("waypoint/missed-count-sec");
- props->untie("waypoint/missed-time-sec");
- props->untie("waypoint/missed-range");
- props->untie("waypoint/wait-count-sec");
- props->untie("waypoint/lead-angle-deg");
- props->untie("waypoint/xtrack-error-ft");
- props->untie("waypoint/waiting");
- props->untie("waypoint/tunnel");
- props->untie("waypoint/alt-curr-m");
- props->untie("waypoint/alt-prev-m");
- props->untie("submodels/serviceable");
- props->untie("controls/turn-radius-ft");
- props->untie("controls/turn-radius-corrected-ft");
- props->untie("controls/constants/lead-angle/gain");
- props->untie("controls/constants/lead-angle/limit-deg");
- props->untie("controls/constants/lead-angle/proportion");
- props->untie("controls/fixed-turn-radius-ft");
- props->untie("controls/constants/speed");
- props->untie("controls/restart");
- props->untie("velocities/speed-kts");
-
-}
void FGAIShip::update(double dt) {
- //SG_LOG(SG_GENERAL, SG_ALERT, "updating Ship: " << _name <<hdg<<pitch<<roll);
+ //SG_LOG(SG_AI, SG_ALERT, "updating Ship: " << _name <<hdg<<pitch<<roll);
// For computation of rotation speeds we just use finite differences here.
// That is perfectly valid since this thing is not driven by accelerations
// but by just apply discrete changes at its velocity variables.
// local frame
SGQuatd ec2body = ec2hl*hl2body;
// The cartesian position of the ship in the wgs84 world
- SGVec3d cartPos = SGVec3d::fromGeod(pos);
+ //SGVec3d cartPos = SGVec3d::fromGeod(pos);
// The simulation time this transform is meant for
aip.setReferenceTime(globals->get_sim_time_sec());
_fixed_turn_radius = ftr;
}
+void FGAIShip::setRollFactor(double rf) {
+ _roll_factor = rf * -0.0083335;
+}
+
void FGAIShip::setInitialTunnel(bool t) {
_initial_tunnel = t;
setTunnel(_initial_tunnel);
setCurrName(curr->getName());
else{
setCurrName("");
- SG_LOG(SG_GENERAL, SG_ALERT, "AIShip: current wp name error" );
+ SG_LOG(SG_AI, SG_ALERT, "AIShip: current wp name error" );
}
if (next != 0)
else
setNextName("");
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: prev wp name " << prev->getName());
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: current wp name " << curr->getName());
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: next wp name " << next->getName());
+ SG_LOG(SG_AI, SG_DEBUG, "AIShip: prev wp name " << prev->getName());
+ SG_LOG(SG_AI, SG_DEBUG, "AIShip: current wp name " << curr->getName());
+ SG_LOG(SG_AI, SG_DEBUG, "AIShip: next wp name " << next->getName());
}
geo_inverse_wgs_84(lat, lon, lat2, lon2, &course, &recip, &distance);
if (tgt_speed >= 0) {
return course;
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: course " << course);
+ SG_LOG(SG_AI, SG_DEBUG, "AIShip: course " << course);
} else {
return recip;
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: recip " << recip);
+ SG_LOG(SG_AI, SG_DEBUG, "AIShip: recip " << recip);
}
}
if (_next_name == "TUNNEL"){
_tunnel = !_tunnel;
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " " << sp_turn_radius_nm );
+ SG_LOG(SG_AI, SG_DEBUG, "AIShip: " << _name << " " << sp_turn_radius_nm );
fp->IncrementWaypoint(false);
next = fp->getNextWaypoint();
}else if(_next_name == "END" || fp->getNextWaypoint() == 0) {
if (_repeat) {
- SG_LOG(SG_GENERAL, SG_INFO, "AIShip: "<< _name << " Flightplan repeating ");
+ SG_LOG(SG_AI, SG_INFO, "AIShip: "<< _name << " Flightplan repeating ");
fp->restart();
prev = curr;
curr = fp->getCurrentWaypoint();
_lead_angle = 0;
AccelTo(prev->getSpeed());
} else if (_restart){
- SG_LOG(SG_GENERAL, SG_INFO, "AIShip: " << _name << " Flightplan restarting ");
+ SG_LOG(SG_AI, SG_INFO, "AIShip: " << _name << " Flightplan restarting ");
_missed_count = 0;
initFlightPlan();
} else {
- SG_LOG(SG_GENERAL, SG_ALERT, "AIShip: " << _name << " Flightplan dying ");
+ SG_LOG(SG_AI, SG_ALERT, "AIShip: " << _name << " Flightplan dying ");
setDie(true);
_dt_count = 0;
return;
} else if (_next_name == "WAIT") {
if (_wait_count < next->getTime_sec()) {
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " waiting ");
+ SG_LOG(SG_AI, SG_DEBUG, "AIShip: " << _name << " waiting ");
setSpeed(0);
_waiting = true;
_wait_count += _dt_count;
_lead_angle = 0;
return;
} else {
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name
+ SG_LOG(SG_AI, SG_DEBUG, "AIShip: " << _name
<< " wait done: getting new waypoints ");
_waiting = false;
_wait_count = 0;
_until_time = next->getTime();
setUntilTime(next->getTime());
if (until_time_sec > time_sec) {
- SG_LOG(SG_GENERAL, SG_INFO, "AIShip: " << _name << " "
+ SG_LOG(SG_AI, SG_INFO, "AIShip: " << _name << " "
<< curr->getName() << " waiting until: "
<< _until_time << " " << until_time_sec << " now " << time_sec );
setSpeed(0);
_waiting = true;
return;
} else {
- SG_LOG(SG_GENERAL, SG_INFO, "AIShip: "
+ SG_LOG(SG_AI, SG_INFO, "AIShip: "
<< _name << " wait until done: getting new waypoints ");
setUntilTime("");
fp->IncrementWaypoint(false);
} else {
//now reorganise the waypoints, so that next becomes current and so on
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " getting new waypoints ");
+ SG_LOG(SG_AI, SG_DEBUG, "AIShip: " << _name << " getting new waypoints ");
fp->IncrementWaypoint(false);
prev = fp->getPreviousWaypoint(); //first waypoint
curr = fp->getCurrentWaypoint(); //second waypoint
if (finite(_course))
TurnTo(_course);
else
- SG_LOG(SG_GENERAL, SG_ALERT, "AIShip: Bearing or Range is not a finite number");
+ SG_LOG(SG_AI, SG_ALERT, "AIShip: Bearing or Range is not a finite number");
_dt_count = 0;
} // end Processing FlightPlan
bool FGAIShip::initFlightPlan() {
- SG_LOG(SG_GENERAL, SG_ALERT, "AIShip: " << _name << " initializing waypoints ");
+ SG_LOG(SG_AI, SG_ALERT, "AIShip: " << _name << " initializing waypoints ");
bool init = false;
_start_sec = 0;
next = fp->getNextWaypoint(); //third waypoint (might not exist!)
while (curr->getName() == "WAIT" || curr->getName() == "WAITUNTIL") { // don't wait when initialising
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " re-initializing waypoints ");
+ SG_LOG(SG_AI, SG_DEBUG, "AIShip: " << _name << " re-initializing waypoints ");
fp->IncrementWaypoint(false);
curr = fp->getCurrentWaypoint();
next = fp->getNextWaypoint();
_missed_count = 0;
_new_waypoint = true;
- SG_LOG(SG_GENERAL, SG_ALERT, "AIShip: " << _name << " done initialising waypoints " << _tunnel);
+ SG_LOG(SG_AI, SG_ALERT, "AIShip: " << _name << " done initialising waypoints " << _tunnel);
if (prev)
init = true;
if (curr->getOn_ground()){
if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(wppos, 3000),
- elevation_m, &_material, 0)){
+ elevation_m, NULL, 0)){
wppos.setElevationM(elevation_m);
}