1 // FGAIShip - FGAIBase-derived class creates an AI ship
3 // Written by David Culp, started October 2003.
4 // with major amendments and additions by Vivian Meazza, 2004 - 2007
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 # define finite _finite
27 #elif defined(__sun) || defined(sgi)
33 #include <simgear/sg_inlines.h>
34 #include <simgear/math/sg_geodesy.hxx>
35 #include <simgear/timing/sg_time.hxx>
36 #include <simgear/math/sg_random.h>
37 #include <simgear/scene/util/SGNodeMasks.hxx>
42 FGAIShip::FGAIShip(object_type ot) :
49 FGAIShip::~FGAIShip() {
52 void FGAIShip::readFromScenario(SGPropertyNode* scFileNode) {
57 FGAIBase::readFromScenario(scFileNode);
59 setRudder(scFileNode->getFloatValue("rudder", 0.0));
60 setName(scFileNode->getStringValue("name", "Titanic"));
61 setRadius(scFileNode->getDoubleValue("turn-radius-ft", 2000));
62 std::string flightplan = scFileNode->getStringValue("flightplan");
63 setRepeat(scFileNode->getBoolValue("repeat", false));
64 setStartTime(scFileNode->getStringValue("time", ""));
66 if (!flightplan.empty()) {
67 FGAIFlightPlan* fp = new FGAIFlightPlan(flightplan);
73 bool FGAIShip::init(bool search_in_AI_path) {
74 prev = 0; // the one behind you
75 curr = 0; // the one ahead
76 next = 0; // the next plus 1
80 props->setStringValue("name", _name.c_str());
81 props->setStringValue("position/waypoint-name-prev", _prev_name.c_str());
82 props->setStringValue("position/waypoint-name-curr", _curr_name.c_str());
83 props->setStringValue("position/waypoint-name-next", _next_name.c_str());
84 props->setStringValue("submodels/path", _path.c_str());
85 props->setStringValue("position/waypoint-start-time", _start_time.c_str());
86 props->setStringValue("position/waypoint-wait-until-time", _until_time.c_str());
92 _rudder_constant = 0.5;
93 _roll_constant = 0.001;
94 _speed_constant = 0.05;
96 _roll_factor = -0.0083335;
98 _rd_turn_radius_ft = _sp_turn_radius_ft = turn_radius_ft;
103 _new_waypoint = true;
107 _missed_time_sec = 30;
112 _wp_range = _old_range = 0;
116 _fp_init = initFlightPlan();
118 return FGAIBase::init(search_in_AI_path);
121 void FGAIShip::initModel(osg::Node *node) {
122 FGAIBase::initModel(node);
123 model->setNodeMask(model->getNodeMask() | SG_NODEMASK_TERRAIN_BIT);
126 void FGAIShip::bind() {
129 props->tie("surface-positions/rudder-pos-deg",
130 SGRawValuePointer<float>(&_rudder));
131 props->tie("controls/heading-lock",
132 SGRawValuePointer<bool>(&_hdg_lock));
133 props->tie("controls/tgt-speed-kts",
134 SGRawValuePointer<double>(&tgt_speed));
135 props->tie("controls/tgt-heading-degs",
136 SGRawValuePointer<double>(&tgt_heading));
137 props->tie("controls/constants/rudder",
138 SGRawValuePointer<double>(&_rudder_constant));
139 props->tie("controls/constants/roll-factor",
140 SGRawValuePointer<double>(&_roll_factor));
141 props->tie("controls/constants/roll",
142 SGRawValuePointer<double>(&_roll_constant));
143 props->tie("controls/constants/rudder",
144 SGRawValuePointer<double>(&_rudder_constant));
145 props->tie("controls/constants/speed",
146 SGRawValuePointer<double>(&_speed_constant));
147 props->tie("position/waypoint-range-nm",
148 SGRawValuePointer<double>(&_wp_range));
149 props->tie("position/waypoint-range-old-nm",
150 SGRawValuePointer<double>(&_old_range));
151 props->tie("position/waypoint-range-rate-nm-sec",
152 SGRawValuePointer<double>(&_range_rate));
153 props->tie("position/waypoint-new",
154 SGRawValuePointer<bool>(&_new_waypoint));
155 props->tie("position/waypoint-missed",
156 SGRawValuePointer<bool>(&_missed));
157 props->tie("position/waypoint-missed-count",
158 SGRawValuePointer<double>(&_missed_count));
159 props->tie("position/waypoint-missed-time-sec",
160 SGRawValuePointer<double>(&_missed_time_sec));
161 props->tie("position/waypoint-wait-count",
162 SGRawValuePointer<double>(&_wait_count));
163 props->tie("position/waypoint-waiting",
164 SGRawValuePointer<bool>(&_waiting));
165 props->tie("submodels/serviceable",
166 SGRawValuePointer<bool>(&_serviceable));
167 props->tie("controls/turn-radius-ft",
168 SGRawValuePointer<double>(&turn_radius_ft));
171 void FGAIShip::unbind() {
173 props->untie("surface-positions/rudder-pos-deg");
174 props->untie("controls/heading-lock");
175 props->untie("controls/tgt-speed-kts");
176 props->untie("controls/tgt-heading-degs");
177 props->untie("controls/constants/roll");
178 props->untie("controls/constants/rudder");
179 props->untie("controls/constants/roll-factor");
180 props->untie("controls/constants/speed");
181 props->untie("position/waypoint-range-nm");
182 props->untie("position/waypoint-range-old-nm");
183 props->untie("position/waypoint-range-rate-nm-sec");
184 props->untie("position/waypoint-new");
185 props->untie("position/waypoint-missed");
186 props->untie("position/waypoint-missed-count");
187 props->untie("position/waypoint-missed-time-sec");
188 props->untie("position/waypoint-wait-count");
189 props->untie("position/waypoint-waiting");
190 props->untie("submodels/serviceable");
191 props->untie("controls/turn-radius-ft");
194 void FGAIShip::update(double dt) {
195 // For computation of rotation speeds we just use finite differences here.
196 // That is perfectly valid since this thing is not driven by accelerations
197 // but by just apply discrete changes at its velocity variables.
198 // Update the velocity information stored in those nodes.
199 // Transform that one to the horizontal local coordinate system.
200 SGQuatd ec2hl = SGQuatd::fromLonLat(pos);
201 // The orientation of the carrier wrt the horizontal local frame
202 SGQuatd hl2body = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
203 // and postrotate the orientation of the AIModel wrt the horizontal
205 SGQuatd ec2body = ec2hl*hl2body;
206 // The cartesian position of the carrier in the wgs84 world
207 SGVec3d cartPos = SGVec3d::fromGeod(pos);
209 // The simulation time this transform is meant for
210 aip.setReferenceTime(globals->get_sim_time_sec());
212 // Compute the velocity in m/s in the body frame
213 aip.setBodyLinearVelocity(SGVec3d(0.51444444*speed, 0, 0));
215 FGAIBase::update(dt);
219 // Only change these values if we are able to compute them safely
220 if (SGLimits<double>::min() < dt) {
221 // Now here is the finite difference ...
223 // Transform that one to the horizontal local coordinate system.
224 SGQuatd ec2hlNew = SGQuatd::fromLonLat(pos);
225 // compute the new orientation
226 SGQuatd hl2bodyNew = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
227 // The rotation difference
228 SGQuatd dOr = inverse(ec2body)*ec2hlNew*hl2bodyNew;
229 SGVec3d dOrAngleAxis;
230 dOr.getAngleAxis(dOrAngleAxis);
231 // divided by the time difference provides a rotation speed vector
234 aip.setBodyAngularVelocity(dOrAngleAxis);
238 void FGAIShip::Run(double dt) {
239 //cout << _name << " init: " << _fp_init << endl;
241 ProcessFlightPlan(dt);
243 // double speed_north_deg_sec;
244 // double speed_east_deg_sec;
250 double speed_diff = tgt_speed - speed;
252 if (fabs(speed_diff) > 0.1) {
254 if (speed_diff > 0.0)
255 speed += _speed_constant * dt;
257 if (speed_diff < 0.0)
258 speed -= _speed_constant * dt;
262 // do not allow unreasonable ship speeds
266 // convert speed to degrees per second
267 speed_north_deg_sec = cos(hdg / SGD_RADIANS_TO_DEGREES)
268 * speed * 1.686 / ft_per_deg_lat;
269 speed_east_deg_sec = sin(hdg / SGD_RADIANS_TO_DEGREES)
270 * speed * 1.686 / ft_per_deg_lon;
273 pos.setLatitudeDeg(pos.getLatitudeDeg() + speed_north_deg_sec * dt);
274 pos.setLongitudeDeg(pos.getLongitudeDeg() + speed_east_deg_sec * dt);
276 // adjust heading based on current _rudder angle
277 if (turn_radius_ft <= 0)
278 turn_radius_ft = 0; // don't allow nonsense values
286 //we assume that at slow speed ships will manoeuvre using engines/bow thruster
288 _sp_turn_radius_ft = 500;
290 // adjust turn radius for speed. The equation is very approximate.
291 // we need to allow for negative speeds
292 _sp_turn_radius_ft = 10 * pow ((fabs(speed) - 15), 2) + turn_radius_ft;
294 if (_rudder <= -0.25 || _rudder >= 0.25) {
295 // adjust turn radius for _rudder angle. The equation is even more approximate.
300 _rd_turn_radius_ft = (a * exp(b * fabs(_rudder)) + c) * _sp_turn_radius_ft;
302 // calculate the angle, alpha, subtended by the arc traversed in time dt
303 alpha = ((speed * 1.686 * dt) / _rd_turn_radius_ft) * SG_RADIANS_TO_DEGREES;
305 // make sure that alpha is applied in the right direction
306 hdg += alpha * sign(_rudder);
308 SG_NORMALIZE_RANGE(hdg, 0.0, 360.0);
310 //adjust roll for rudder angle and speed. Another bit of voodoo
311 raw_roll = _roll_factor * speed * _rudder;
313 // _rudder angle is 0
321 roll = (raw_roll * _roll_constant) + (roll * (1 - _roll_constant));
323 // adjust target _rudder angle if heading lock engaged
324 double rudder_diff = 0.0;
326 double rudder_sense = 0.0;
327 double diff = fabs(hdg - tgt_heading);
328 //cout << "_rudder diff" << diff << endl;
330 diff = fabs(diff - 360);
332 double sum = hdg + diff;
337 if (fabs(sum - tgt_heading)< 1.0)
343 rudder_sense = -rudder_sense;
346 _tgt_rudder = diff * rudder_sense;
348 _tgt_rudder = 45 * rudder_sense;
350 rudder_diff = _tgt_rudder - _rudder;
353 // set the _rudder limit by speed
355 rudder_limit = (-0.825 * speed) + 35;
359 if (fabs(rudder_diff)> 0.1) { // apply dead zone
361 if (rudder_diff > 0.0) {
362 _rudder += _rudder_constant * dt;
364 if (_rudder > rudder_limit) // apply the _rudder limit
365 _rudder = rudder_limit;
367 } else if (rudder_diff < 0.0) {
368 _rudder -= _rudder_constant * dt;
370 if (_rudder < -rudder_limit)
371 _rudder = -rudder_limit;
375 // do calculations for radar
376 UpdateRadar(manager);
380 void FGAIShip::AccelTo(double speed) {
384 void FGAIShip::PitchTo(double angle) {
388 void FGAIShip::RollTo(double angle) {
392 void FGAIShip::YawTo(double angle) {
395 void FGAIShip::ClimbTo(double altitude) {
399 void FGAIShip::TurnTo(double heading) {
400 tgt_heading = heading;
404 double FGAIShip::sign(double x) {
411 void FGAIShip::setFlightPlan(FGAIFlightPlan* f) {
415 void FGAIShip::setName(const string& n) {
419 void FGAIShip::setStartTime(const string& st) {
423 void FGAIShip::setUntilTime(const string& ut) {
425 props->setStringValue("position/waypoint-wait-until-time", _until_time.c_str());
428 void FGAIShip::setCurrName(const string& c) {
430 props->setStringValue("position/waypoint-name-curr", _curr_name.c_str());
433 void FGAIShip::setNextName(const string& n) {
435 props->setStringValue("position/waypoint-name-next", _next_name.c_str());
438 void FGAIShip::setPrevName(const string& p) {
440 props->setStringValue("position/waypoint-name-prev", _prev_name.c_str());
443 void FGAIShip::setRepeat(bool r) {
447 void FGAIShip::setMissed(bool m) {
449 props->setBoolValue("position/waypoint-missed", _missed);
452 void FGAIShip::setRudder(float r) {
456 void FGAIShip::setRoll(double rl) {
460 void FGAIShip::setWPNames() {
463 setPrevName(prev->name);
467 setCurrName(curr->name);
470 setNextName(next->name);
474 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: prev wp name " << prev->name);
475 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: current wp name " << curr->name);
476 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: next wp name " << next->name);
480 double FGAIShip::getRange(double lat, double lon, double lat2, double lon2) const {
482 double course, distance, az2;
484 //calculate the bearing and range of the second pos from the first
485 geo_inverse_wgs_84(lat, lon, lat2, lon2, &course, &az2, &distance);
486 distance *= SG_METER_TO_NM;
490 double FGAIShip::getCourse(double lat, double lon, double lat2, double lon2) const {
492 double course, distance, recip;
494 //calculate the bearing and range of the second pos from the first
495 geo_inverse_wgs_84(lat, lon, lat2, lon2, &course, &recip, &distance);
496 if (tgt_speed >= 0) {
503 void FGAIShip::ProcessFlightPlan(double dt) {
505 double time_sec = getDaySeconds();
506 double until_time_sec = 0;
511 ///////////////////////////////////////////////////////////////////////////
512 // Check Execution time (currently once every 1 sec)
513 // Add a bit of randomization to prevent the execution of all flight plans
514 // in synchrony, which can add significant periodic framerate flutter.
515 ///////////////////////////////////////////////////////////////////////////
517 //cout << "_start_sec " << _start_sec << " time_sec " << time_sec << endl;
518 if (_dt_count < _next_run && _start_sec < time_sec)
521 _next_run = 1.0 + (0.5 * sg_random());
523 // check to see if we've reached the point for our next turn
524 // if the range to the waypoint is less than the calculated turn
525 // radius we can start the turn to the next leg
526 _wp_range = getRange(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->latitude, curr->longitude);
527 _range_rate = (_wp_range - _old_range) / _dt_count;
528 double sp_turn_radius_nm = _sp_turn_radius_ft / 6076.1155;
530 // we need to try to identify a _missed waypoint
532 // calculate the time needed to turn through an arc of 90 degrees, and allow an error of 30 secs
534 _missed_time_sec = 30 + ((SGD_PI * sp_turn_radius_nm * 60 * 60) / (2 * fabs(speed)));
536 _missed_time_sec = 30;
538 if ((_range_rate > 0) && (_wp_range < 3 * sp_turn_radius_nm) && !_new_waypoint)
539 _missed_count += _dt_count;
541 if (_missed_count >= _missed_time_sec) {
547 _old_range = _wp_range;
550 if ((_wp_range < sp_turn_radius_nm) || _missed || _waiting && !_new_waypoint) {
552 if (_next_name == "END") {
555 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: Flightplan restarting ");
558 curr = fp->getCurrentWaypoint();
559 next = fp->getNextWaypoint();
561 _wp_range = getRange(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->latitude, curr->longitude);
562 _old_range = _wp_range;
564 _new_waypoint = true;
566 AccelTo(prev->speed);
568 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: Flightplan dieing ");
574 } else if (_next_name == "WAIT") {
576 if (_wait_count < next->time_sec) {
577 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " waiting ");
580 _wait_count += _dt_count;
584 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name
585 << " wait done: getting new waypoints ");
588 fp->IncrementWaypoint(false);
589 next = fp->getNextWaypoint();
591 if (next->name == "WAITUNTIL" || next->name == "WAIT"
592 || next->name == "END")
596 fp->IncrementWaypoint(false);
597 curr = fp->getCurrentWaypoint();
598 next = fp->getNextWaypoint();
601 } else if (_next_name == "WAITUNTIL") {
602 time_sec = getDaySeconds();
603 until_time_sec = processTimeString(next->time);
604 _until_time = next->time;
605 setUntilTime(next->time);
606 if (until_time_sec > time_sec) {
607 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " waiting until: "
608 << _until_time << " " << until_time_sec << " now " << time_sec );
613 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: "
614 << _name << " wait until done: getting new waypoints ");
616 fp->IncrementWaypoint(false);
618 while (next->name == "WAITUNTIL") {
619 fp->IncrementWaypoint(false);
620 next = fp->getNextWaypoint();
623 if (next->name == "WAIT")
627 fp->IncrementWaypoint(false);
628 curr = fp->getCurrentWaypoint();
629 next = fp->getNextWaypoint();
634 //now reorganise the waypoints, so that next becomes current and so on
635 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " getting new waypoints ");
636 fp->IncrementWaypoint(false);
637 prev = fp->getPreviousWaypoint(); //first waypoint
638 curr = fp->getCurrentWaypoint(); //second waypoint
639 next = fp->getNextWaypoint(); //third waypoint (might not exist!)
643 _new_waypoint = true;
646 _wp_range = getRange(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->latitude, curr->longitude);
647 _old_range = _wp_range;
648 AccelTo(prev->speed);
650 _new_waypoint = false;
653 // now revise the required course for the next way point
654 double course = getCourse(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->latitude, curr->longitude);
659 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: Bearing or Range is not a finite number");
662 } // end Processing FlightPlan
664 bool FGAIShip::initFlightPlan() {
666 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " initializing waypoints ");
673 fp->IncrementWaypoint(false);
675 prev = fp->getPreviousWaypoint(); //first waypoint
676 curr = fp->getCurrentWaypoint(); //second waypoint
677 next = fp->getNextWaypoint(); //third waypoint (might not exist!)
679 while (curr->name == "WAIT" || curr->name == "WAITUNTIL") { // don't wait when initialising
680 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " re-initializing waypoints ");
681 fp->IncrementWaypoint(false);
682 curr = fp->getCurrentWaypoint();
683 next = fp->getNextWaypoint();
686 if (!_start_time.empty()){
687 _start_sec = processTimeString(_start_time);
688 double day_sec = getDaySeconds();
690 if (_start_sec < day_sec){
691 //cout << "flight plan has already started " << _start_time << endl;
692 init = advanceFlightPlan(_start_sec, day_sec);
694 } else if (_start_sec > day_sec && _repeat) {
695 //cout << "flight plan has not started, " << _start_time;
696 //cout << "offsetting start time by -24 hrs" << endl;
698 init = advanceFlightPlan(_start_sec, day_sec);
702 _start_sec = 0; // set to zero for an immediate start of the Flight Plan
705 fp->IncrementWaypoint(false);
706 prev = fp->getPreviousWaypoint();
707 curr = fp->getCurrentWaypoint();
708 next = fp->getNextWaypoint();
713 setLatitude(prev->latitude);
714 setLongitude(prev->longitude);
715 setSpeed(prev->speed);
719 setHeading(getCourse(prev->latitude, prev->longitude, curr->latitude, curr->longitude));
720 _wp_range = getRange(prev->latitude, prev->longitude, curr->latitude, curr->longitude);
721 _old_range = _wp_range;
726 _new_waypoint = true;
728 SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " done initialising waypoints ");
737 } // end of initialization
740 double FGAIShip::processTimeString(const string& theTime) {
746 // first split theTime string into
747 // hour, minute, second and convert to int;
748 Hour = atoi(theTime.substr(0,2).c_str());
749 Minute = atoi(theTime.substr(3,5).c_str());
750 Second = atoi(theTime.substr(6,8).c_str());
752 // offset by a day-sec to allow for starting a day earlier
753 double time_seconds = Hour * 3600
760 double FGAIShip::getDaySeconds () {
762 struct tm *t = globals->get_time_params()->getGmt();
764 double day_seconds = t->tm_hour * 3600
771 bool FGAIShip::advanceFlightPlan (double start_sec, double day_sec) {
773 double elapsed_sec = start_sec;
774 double distance_nm = 0;
776 //cout << "advancing flight plan start_sec: " << start_sec << " " << day_sec << endl;
778 while ( elapsed_sec < day_sec ) {
780 if (next->name == "END") {
783 //cout << _name << ": " << "restarting flightplan" << endl;
785 curr = fp->getCurrentWaypoint();
786 next = fp->getNextWaypoint();
788 //cout << _name << ": " << "ending flightplan" << endl;
793 } else if (next->name == "WAIT") {
794 //cout << _name << ": begin WAIT: " << prev->name << " ";
795 //cout << curr->name << " " << next->name << endl;
797 elapsed_sec += next->time_sec;
799 if ( elapsed_sec >= day_sec)
802 fp->IncrementWaypoint(false);
803 next = fp->getNextWaypoint();
805 if (next->name != "WAITUNTIL" && next->name != "WAIT"
806 && next->name != "END") {
808 fp->IncrementWaypoint(false);
809 curr = fp->getCurrentWaypoint();
810 next = fp->getNextWaypoint();
813 } else if (next->name == "WAITUNTIL") {
814 double until_sec = processTimeString(next->time);
816 if (until_sec > _start_sec && start_sec < 0)
819 if (elapsed_sec < until_sec)
820 elapsed_sec = until_sec;
822 if (elapsed_sec >= day_sec )
825 fp->IncrementWaypoint(false);
826 next = fp->getNextWaypoint();
828 if (next->name != "WAITUNTIL" && next->name != "WAIT") {
830 fp->IncrementWaypoint(false);
831 curr = fp->getCurrentWaypoint();
832 next = fp->getNextWaypoint();
835 //cout << _name << ": end WAITUNTIL: ";
836 //cout << prev->name << " " << curr->name << " " << next->name << endl;
839 distance_nm = getRange(prev->latitude, prev->longitude, curr->latitude, curr->longitude);
840 elapsed_sec += distance_nm * 60 * 60 / prev->speed;
842 if (elapsed_sec >= day_sec)
845 fp->IncrementWaypoint(false);
846 prev = fp->getPreviousWaypoint();
847 curr = fp->getCurrentWaypoint();
848 next = fp->getNextWaypoint();
853 // the required position lies between the previous and current waypoints
854 // so we will calculate the distance back up the track from the current waypoint
855 // then calculate the lat and lon.
856 /*cout << "advancing flight plan done elapsed_sec: " << elapsed_sec
857 << " " << day_sec << endl;*/
859 double time_diff = elapsed_sec - day_sec;
860 double lat, lon, recip;
862 //cout << " time diff " << time_diff << endl;
864 if (next->name == "WAIT" ){
866 lat = curr->latitude;
867 lon = curr->longitude;
868 _wait_count= time_diff;
870 } else if (next->name == "WAITUNTIL") {
872 lat = curr->latitude;
873 lon = curr->longitude;
876 setSpeed(prev->speed);
877 distance_nm = speed * time_diff / (60 * 60);
878 double brg = getCourse(curr->latitude, curr->longitude, prev->latitude, prev->longitude);
880 //cout << " brg " << brg << " from " << curr->name << " to " << prev->name << " "
881 // << " lat " << curr->latitude << " lon " << curr->longitude
882 // << " distance m " << distance_nm * SG_NM_TO_METER << endl;
884 lat = geo_direct_wgs_84 (curr->latitude, curr->longitude, brg,
885 distance_nm * SG_NM_TO_METER, &lat, &lon, &recip );
886 lon = geo_direct_wgs_84 (curr->latitude, curr->longitude, brg,
887 distance_nm * SG_NM_TO_METER, &lat, &lon, &recip );
888 recip = geo_direct_wgs_84 (curr->latitude, curr->longitude, brg,
889 distance_nm * SG_NM_TO_METER, &lat, &lon, &recip );
892 //cout << "Pos " << lat << ", " << lon << " recip " << recip << endl;