dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
OPPlots.m
Go to the documentation of this file.
1 function OPPlots()
2  [FileName,PathName,FilterIndex] = uigetfile('*.mat');
3  matfile = strcat(PathName,FileName);
4  load(matfile);
5 
6  %load('specificfilename')
7 
8  TimeVA = [VelocityActual.timestamp]/1000;
9  VA = [[VelocityActual.North]
10  [VelocityActual.East]
11  [VelocityActual.Down]]/100;
12 
13  TimeGPSPos = [GPSPosition.timestamp]/1000;
14  Vgps=[[GPSPosition.Groundspeed].*cos([GPSPosition.Heading]*pi/180)
15  [GPSPosition.Groundspeed].*sin([GPSPosition.Heading]*pi/180)];
16 
17  figure(1);
18  plot(TimeVA,VA(1,:),TimeVA,VA(2,:),TimeGPSPos,Vgps(1,:),TimeGPSPos,Vgps(2,:));
19  s1='Velocity Actual North';
20  s2='Velocity Actual East';
21  s3='GPS Velocity North';
22  s4='GPS Velocity East';
23  legend(s1,s2,s3,s4);
24  xlabel('Time (sec)');
25  ylabel('Velocity (m/s)');
26 
27 
28  TimePA = [PositionActual.timestamp]/1000;
29  PA = [[PositionActual.North]
30  [PositionActual.East]
31  [PositionActual.Down]]/100;
32 
33  TimeGPSPos = [GPSPosition.timestamp]/1000;
34  LLA=[[GPSPosition.Latitude]*1e-7;
35  [GPSPosition.Longitude]*1e-7;
36  [GPSPosition.Altitude]+[GPSPosition.GeoidSeparation]];
37  BaseECEF = LLA2ECEF([HomeLocation.Latitude*1e-7, HomeLocation.Longitude*1e-7, HomeLocation.Altitude]');
38  Rne = RneFromLLA([HomeLocation.Latitude*1e-7, HomeLocation.Longitude*1e-7, HomeLocation.Altitude]');
39  GPSPos=LLA2Base(LLA,BaseECEF,Rne);
40 
41  figure(2);
42  plot(TimePA,PA(1,:),TimePA,PA(2,:),TimeGPSPos,GPSPos(1,:),TimeGPSPos,GPSPos(2,:));
43  s1='Position Actual North';
44  s2='Position Actual East';
45  s3='GPS Position North';
46  s4='GPS Position East';
47  legend(s1,s2,s3,s4);
48  xlabel('Time (sec)');
49  ylabel('Position (m)');
50 
51  figure(3);
52  plot3(PA(2,:),PA(1,:),PA(3,:),GPSPos(2,:),GPSPos(1,:),GPSPos(3,:));
53  s1='Pos Actual';
54  s2='GPS Pos';
55  legend(s1,s2);
56  xlabel('East (m)');
57  ylabel('North(m)');
58  zlabel('Up (m)');
59  axis equal
60 
61 end
62 
63 function NED = LLA2Base(LLA,BaseECEF,Rne)
64  n = size(LLA,2);
65 
66  ECEF = LLA2ECEF(LLA);
67 
68  diff = ECEF - repmat(BaseECEF,1,n);
69 
70  NED = Rne*diff;
71 end
72 
73 function LLA = Base2LLA(NED,BaseECEF,Rne)
74  n = size(NED,2);
75 
76  diff=Rne'*NED;
77  ECEF=diff + repmat(BaseECEF,1,n) ;
78 
79  LLA=ECEF2LLA(ECEF);
80 end
81 
82 
83 % // ****** convert ECEF to Lat,Lon,Alt (ITERATIVE!) *********
84 function LLA=ECEF2LLA(ECEF, Alt)
85 %
94  if nargin==1
95  Alt=0;
96  end
97 
98  a = 6378137.0; %// Equatorial Radius
99  e = 8.1819190842622e-2;%; // Eccentricity
100  x = ECEF(1);
101  y = ECEF(2);
102  z = ECEF(3);
103 
104  MAX_ITER =10; %// should not take more than 5 for valid coordinates
105  ACCURACY= 1.0e-11;% // used to be e-14, but we don't need sub micrometer exact calculations
106  RAD2DEG=180/pi;
108 
109  LLA(2) = RAD2DEG * atan2(y, x);
110  Lat = DEG2RAD * LLA(1);
111  esLat = e * sin(Lat);
112  N = a / sqrt(1 - esLat * esLat);
113  NplusH = N+Alt;
114  delta = 1;
115  iter = 0;
116 
117  while (((delta > ACCURACY) || (delta < -ACCURACY)) && (iter < MAX_ITER))
118  delta = Lat - atan(z / (sqrt(x * x + y * y) * (1 - (N * e * e / NplusH))));
119  Lat = Lat - delta;
120  esLat = e * sin(Lat);
121  N = a / sqrt(1 - esLat * esLat);
122  NplusH = sqrt(x * x + y * y) / cos(Lat);
123  iter = iter+1;
124  end
125 
126  LLA(1) = RAD2DEG * Lat;
127  LLA(3) = NplusH - N;
128 
129 
130 end
131 
132 function ECEF = LLA2ECEF(LLA)
133 
134  a = 6378137.0; % Equatorial Radius
135  e = 8.1819190842622e-2; % Eccentricity
136 
137  n = size(LLA,2);
138  ECEF = zeros(3,n);
139 
140  for i=1:n
141  sinLat = sin(pi*LLA(1,i)/180);
142  sinLon = sin(pi*LLA(2,i)/180);
143  cosLat = cos(pi*LLA(1,i)/180);
144  cosLon = cos(pi*LLA(2,i)/180);
145 
146  N = a / sqrt(1.0 - e * e * sinLat * sinLat); %prime vertical radius of curvature
147 
148  ECEF(1,i) = (N + LLA(3,i)) * cosLat * cosLon;
149  ECEF(2,i) = (N + LLA(3,i)) * cosLat * sinLon;
150  ECEF(3,i) = ((1 - e * e) * N + LLA(3,i)) * sinLat;
151  end
152 end
153 
154 % // ****** find ECEF to NED rotation matrix ********
155 function Rne=RneFromLLA(LLA)
156  RAD2DEG=180/pi;
157  DEG2RAD=1/RAD2DEG;
158 
159  sinLat = sin(DEG2RAD * LLA(1));
160  sinLon = sin(DEG2RAD * LLA(2));
161  cosLat = cos(DEG2RAD * LLA(1));
162  cosLon = cos(DEG2RAD * LLA(2));
163 
164  Rne(1,1) = -sinLat * cosLon;
165  Rne(1,2) = -sinLat * sinLon;
166  Rne(1,3) = cosLat;
167  Rne(2,1) = -sinLon;
168  Rne(2,2) = cosLon;
169  Rne(2,3) = 0;
170  Rne(3,1) = -cosLat * cosLon;
171  Rne(3,2) = -cosLat * sinLon;
172  Rne(3,3) = -sinLat;
173 end
174 
legend(s1, s2, s3, s4)
s1
Definition: OPPlots.m:19
iter
Definition: OPPlots.m:115
function[]
BaseECEF
Definition: OPPlots.m:37
cosLat
Definition: OPPlots.m:143
while(((delta > ACCURACY)||(delta< -ACCURACY))&&(iter< MAX_ITER)) delta
function OPPlots()[FileName
DEG2RAD
Definition: OPPlots.m:107
diff
Definition: OPPlots.m:68
Rne
Definition: OPPlots.m:38
cosLon
Definition: OPPlots.m:144
sinLon
Definition: OPPlots.m:142
matfile
Definition: OPPlots.m:3
axis equal end function NED
Definition: OPPlots.m:63
VA
Definition: OPPlots.m:9
for i
Definition: OPPlots.m:140
ylabel('Velocity(m/s)')
TimeGPSPos
Definition: OPPlots.m:13
xlabel('Time(sec)')
s4
Definition: OPPlots.m:22
end a
Definition: OPPlots.m:98
MAX_ITER
Definition: OPPlots.m:104
figure(1)
Vgps
Definition: OPPlots.m:14
Lat
Definition: OPPlots.m:110
function PathName
Definition: OPPlots.m:2
end(INSTANTIATIONCODE) fid
NplusH
Definition: OPPlots.m:113
TimePA
Definition: OPPlots.m:28
Eccentricity n
Definition: OPPlots.m:137
z
Definition: OPPlots.m:102
PA
Definition: OPPlots.m:29
load(matfile)
s2
Definition: OPPlots.m:20
sinLat
Definition: OPPlots.m:159
RAD2DEG
Definition: OPPlots.m:106
delta
Definition: OPPlots.m:114
s3
Definition: OPPlots.m:21
GPSPos
Definition: OPPlots.m:39
LLA
Definition: OPPlots.m:34
ACCURACY
Definition: OPPlots.m:105
x
Definition: OPPlots.m:100
ECEF
Definition: OPPlots.m:66
plot3(PA(2,:), PA(1,:), PA(3,:), GPSPos(2,:), GPSPos(1,:), GPSPos(3,:))
if nargin
N
Definition: OPPlots.m:112
zlabel('Up(m)')
esLat
Definition: OPPlots.m:111
e
Definition: OPPlots.m:99
y
Definition: OPPlots.m:101
plot(TimeVA, VA(1,:), TimeVA, VA(2,:), TimeGPSPos, Vgps(1,:), TimeGPSPos, Vgps(2,:))