00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <string>
00019 #include <fstream>
00020 #include <vector>
00021 #include <cmath>
00022 #include <boost/numeric/ublas/vector.hpp>
00023 #include <boost/numeric/ublas/vector_sparse.hpp>
00024 #include <boost/numeric/ublas/io.hpp>
00025 #include "uvsim/guidance/Guide.h"
00026 #include "uvsim/guidance/FlightPlan.h"
00027 #include "uvsim/guidance/GeoCoord.h"
00028
00029 namespace uvsim
00030 {
00031 Guide::Guide()
00032 {
00033 }
00034
00035 Guide::Guide(GeoCoord & pos)
00036 {
00037 setPosition(pos);
00038 }
00039
00040 Guide::~Guide()
00041 {
00042 }
00043
00044 FlightPlan* Guide::getFlightPlan()
00045 {
00046 return &flightplan;
00047 }
00048
00049 void Guide::computeCrossTrack()
00050 {
00051 GeoCoord tempWaypoint;
00052 GeoCoord currentWaypoint;
00053 vector<double> previousWaypoint (3);
00054 vector<double> nextWaypoint (3);
00055 vector<double> currentPosition (3);
00056 vector<double> tempPosition (3);
00057 vector<double> deltaXHat (3);
00058 GeoCoord m_currentPosition(40.430925,-86.9163194,190);
00059 int counter = 0;
00060 double deltaX;
00061 double deltaY;
00062 double delta = 0.1;
00063
00064
00065
00066
00067
00068
00069 currentPosition[0] = m_currentPosition.m_Latitude;
00070 currentPosition[1] = m_currentPosition.m_Longitude;
00071 currentPosition[2] = m_currentPosition.m_Altitude;
00072
00073
00074 currentWaypoint.setGeoCoord(currentPosition[0], currentPosition[1], currentPosition[2]);
00075
00076
00077 currentPosition = currentWaypoint.getCartesian();
00078
00079
00080 previousWaypoint = flightplan[counter].getCartesian();
00081 nextWaypoint = flightplan[counter + 1].getCartesian();
00082
00083 std::cout << "Previous Waypoint in Cartesian: (" <<previousWaypoint[0]
00084 << ", " << previousWaypoint[1] << ", " << previousWaypoint[2] << ")\n";
00085 std::cout << "Next Waypoint in Cartesian: (" <<nextWaypoint[0]
00086 << ", " << nextWaypoint[1] << ", " << nextWaypoint[2] << ")\n";
00087
00088
00089 deltaXHat = (previousWaypoint - nextWaypoint) / norm_2(previousWaypoint - nextWaypoint);
00090 deltaX = inner_prod((currentPosition - nextWaypoint), deltaXHat);
00091
00092
00093 tempPosition = nextWaypoint + deltaX * deltaXHat;
00094 tempWaypoint.getGeoCoord(tempPosition[0], tempPosition[1], tempPosition[2]);
00095
00096
00097 deltaY = norm_2(currentPosition - tempPosition);
00098
00099 std::cout << "Current Position in Cartesian: (" << currentPosition[0] << ", "
00100 << currentPosition[1] << ", " << currentPosition[2] << ")\n";
00101 std::cout << "Temporary Waypoint Position in Cartesian: (" << tempPosition[0]
00102 << ", " << tempPosition[1] << ", " << tempPosition[2] << ")\n";
00103 std::cout << "DeltaX (c1) = " << deltaX << "\tDeltaY (c2) = " << deltaY << "\n";
00104
00105 if (fabs(deltaX) < delta)
00106 {
00107
00108 counter++;
00109 }
00110 else if (fabs(deltaY) > delta)
00111 {
00112
00113
00114 flightplan.insert(flightplan.begin() + counter + 1, m_currentPosition);
00115 flightplan.insert(flightplan.begin() + counter + 2, tempWaypoint);
00116 counter++;
00117 }
00118
00119 }
00120
00121 void Guide::setPosition(GeoCoord & pos)
00122 {
00123 m_currentPosition = pos;
00124 }
00125 }
00126