1
+ function [L_b ,lambda_b ,h_b ,v_eb_n ,C_b_n ,C_e_n ,omega_en ,C_ni ] = ECEF_to_NED(r_eb_e ,v_eb_e ,C_b_e ,t )
2
+ % ECEF_to_NED - Converts Cartesian to curvilinear position, velocity
3
+ % resolving axes from ECEF to NED and attitude from ECEF- to NED-referenced
4
+ %
5
+ % Software for use with "Principles of GNSS, Inertial, and Multisensor
6
+ % Integrated Navigation Systems," Second Edition.
7
+ %
8
+ % This function created 2/4/2012 by Paul Groves
9
+ %
10
+ % Inputs:
11
+ % r_eb_e Cartesian position of body frame w.r.t. ECEF frame, resolved
12
+ % along ECEF-frame axes (m)
13
+ % v_eb_e velocity of body frame w.r.t. ECEF frame, resolved along
14
+ % ECEF-frame axes (m/s)
15
+ % C_b_e body-to-ECEF-frame coordinate transformation matrix
16
+ %
17
+ % Outputs:
18
+ % L_b latitude (rad)
19
+ % lambda_b longitude (rad)
20
+ % h_b height (m)
21
+ % v_eb_n velocity of body frame w.r.t. ECEF frame, resolved along
22
+ % north, east, and down (m/s)
23
+ % C_b_n body-to-NED coordinate transformation matrix
24
+
25
+ % Parameters
26
+ R_0 = 6378137 ; % WGS84 Equatorial radius in meters
27
+ e = 0.0818191908425 ; % WGS84 eccentricity
28
+
29
+ % Copyright 2012, Paul Groves
30
+ % License: BSD; see license.txt for details
31
+
32
+ % Begins
33
+
34
+ % Convert position using Borkowski closed-form exact solution
35
+ % From (2.113)
36
+ lambda_b = atan2(r_eb_e(2 ),r_eb_e(1 ));
37
+
38
+ % From (C.29) and (C.30)
39
+ k1 = sqrt(1 - e ^ 2 ) * abs (r_eb_e(3 ));
40
+ k2 = e ^ 2 * R_0 ;
41
+ beta = sqrt(r_eb_e(1 )^2 + r_eb_e(2 )^2 );
42
+ E = (k1 - k2 ) / beta ;
43
+ F = (k1 + k2 ) / beta ;
44
+
45
+ % From (C.31)
46
+ P = 4 / 3 * (E * F + 1 );
47
+
48
+ % From (C.32)
49
+ Q = 2 * (E ^ 2 - F ^ 2 );
50
+
51
+ % From (C.33)
52
+ D = P ^ 3 + Q ^ 2 ;
53
+
54
+ % From (C.34)
55
+ V = (sqrt(D ) - Q )^(1 / 3 ) - (sqrt(D ) + Q )^(1 / 3 );
56
+
57
+ % From (C.35)
58
+ G = 0.5 * (sqrt(E ^ 2 + V ) + E );
59
+
60
+ % From (C.36)
61
+ T = sqrt(G ^ 2 + (F - V * G ) / (2 * G - E )) - G ;
62
+
63
+ % From (C.37)
64
+ L_b = sign(r_eb_e(3 )) * atan((1 - T ^ 2 ) / (2 * T * sqrt (1 - e ^ 2 )));
65
+
66
+ % From (C.38)
67
+ h_b = (beta - R_0 * T ) * cos(L_b ) + ...
68
+ (r_eb_e(3 ) - sign(r_eb_e(3 )) * R_0 * sqrt(1 - e ^ 2 )) * sin (L_b );
69
+
70
+ % Calculate ECEF to NED coordinate transformation matrix using (2.150)
71
+ cos_lat = cos(L_b );
72
+ sin_lat = sin(L_b );
73
+ cos_long = cos(lambda_b );
74
+ sin_long = sin(lambda_b );
75
+ C_e_n = [-sin_lat * cos_long , - sin_lat * sin_long , cos_lat ;...
76
+ - sin_long , cos_long , 0 ;...
77
+ - cos_lat * cos_long , - cos_lat * sin_long , - sin_lat ];
78
+
79
+ % Transform velocity using (2.73)
80
+ v_eb_n = C_e_n * v_eb_e ;
81
+
82
+ % Transform attitude using (2.15)
83
+ C_b_n = C_e_n * C_b_e ;
84
+
85
+ % Add stuff for angular velocity calculations
86
+ % Angular velocity of NED frame with respect to ECEF frame
87
+ R_N = (R_0 *(1 - e ^ 2 ))/((1 -(e ^ 2 )*sin(L_b )^2 )^(3 / 2 ));
88
+ R_E = R_0 /(sqrt(1 -(e ^ 2 )*sin(L_b )^2 ));
89
+
90
+ omega_en = [v_eb_n(2 )/(R_E + h_b );...
91
+ - v_eb_n(1 )/(R_N + h_b );...
92
+ (-v_eb_n(2 )*tan(L_b ))/(R_E + h_b )]; % Eq 5.44
93
+
94
+ % Compute rotation matrix forom Inertial frame ECI to NED
95
+ omega_ie = 7.292115E-5 ; % Earth rotation rate (rad/s)
96
+ C_ni = [-sin(L_b )*cos(lambda_b + omega_ie * t ), - sin(L_b )*sin(lambda_b + omega_ie * t ), cos(L_b );...
97
+ - sin(lambda_b + omega_ie * t ), cos(lambda_b + omega_ie * t ),0 ;...
98
+ - cos(L_b )*cos(lambda_b + omega_ie * t ), - cos(L_b )*sin(lambda_b + omega_ie * t ), - sin(L_b )];
99
+
100
+ % Ends
0 commit comments