1 subroutine attdet( navblk, navctl, nad_bod, attxfm,
2 1 pos, vel, widphse1, widphfl1, widphse2, widphfl2,
3 1 sun_bod, sunbodfl, att_prev, delta_t, covar)
5 c
attdet( navblk, navctl, nad_bod, attxfm,
6 c pos, vel, widphse1, widphfl1, widphse2,
7 c widphfl2, sun_bod, sunbodfl, att_prev, delta_t, covar )
9 c purpose: perform the actual attitude determination
for one line
13 c name
Type i/o description
14 c -------- ---- --- -----------
15 c navblk struct i/o
navigation block including:
16 c in: sun_ref - sun ref in geo
coord sys
17 c lcl_vert - local vertical
18 c out: sen_frame - attitude
matrix
19 c att_ang - attitude angles in the
20 c order yaw, roll, pitch
21 c navctl struct i
navigation controls. used are:
22 c redoyaw -
# iterations to redo yaw
24 c yawtol - difference between yaw guess
26 c nad_bod r*4 i
size 3 unit nadir
vector in spacecraft frame
27 c attxfm r*4 i
size 3 by 3 attitude transform
matrix -
28 c the transform from geocentric to
30 c pos r*4 i
size 3 orbit position
vector(km)
31 c vel r*4 i
size 3 orbit velocity
vector(km/sec)
32 c widphse1 r*4 i
size 2 processed
earth width
34 c widphfl1 i*4 i flag
for earth sensor 1 - 0 = good
35 c widphse2 r*4 i
size 2 processed
earth width
37 c widphfl2 i*4 i flag
for earth sensor 2 - 0 = good
38 c sun_bod r*4 i
size 3 weighted sun vectors in spacecraft
40 c sunbodfl i*4 i flag
for sun sensor
data - 0 = good
41 c att_prev r*4 i
size 3 attitude angles from previous scan line
42 c delta_t r*4 i time difference from previous scan line
43 c(
set to 0
if first line in frame, negative
if
44 c propagating backwards in time)
45 c covar r*4 i
size 3 array of covariance
matrix diagonal
49 c by: w. robinson, gsc, 14 apr 93
51 c notes: the initial yaw used to create the nadir
vector from the
52 c
earth sensors is assumed to be the previous
value.
If the
53 c resultant yaw computed here id different from the guess by
54 c the
value yawtol,
and the redoyaw is
set, the nadir
vector
55 c will be
re-computed by calling routine
earth again. this will
56 c be repeated up to redoyaw number of times
58 c modification history:
61 c actual order
and sign of rotations implemented by osc in the acs.
62 c the order is 2-1-3 in the acs(not the spacecraft) frame. the acs
63 c axes defined as: x toward the velocity(spacecraft -y axis);
64 c y toward the negative orbit normal(spacecraft -z axis); z toward
65 c the nadir(spacecraft x axis). this is equivalent to a
67 c negative about the spacecraft z
and y axes.
68 c
f. s. patt, gsc, october 4, 1996.
70 c modified the order of operations to first transform the
matrix constructed
71 c from the reference vectors to the orbital frame,
then use that
matrix to
72 c compute the orbit-to-spacecraft
transformation. this will give the same
73 c results as before, but allows the attitude
matrix to be a small rotation.
74 c
f. s. patt, saic gsc, february 3, 1998.
76 c modified attitude angle calculation to weight the yaw angle according to
77 c the sun/nadir angle to prevent blowing up at subsolar point.
78 c
f. s. patt, saic gsc, march 9, 1998.
80 c rewrote this routine to implement attitude determination using a kalman
81 c
filter instead of the deterministic
algorithm used previously. this was
82 c done to resolve multiple issues: reduce jitter at sensor transitions,
83 c improve yaw accuracy at the subsolar point
and handle sensor gaps. the
84 c initial version uses a simple dynamics model which assumes an inertial
85 c
spin axis(not necessarily parallel to the orbit normal).
86 c all of the equations are taken from wertz, section 13.5.2, pp. 462-465.
87 c
f. s. patt, saic gsc, june 1, 1998.
89 c reduced the
state noise value(from 1.e-8 to 0.25e-8) to reduce the yaw
90 c variation in the middle of the orbit.
91 c
f. s. patt, saic gsc, june 22, 1998.
93 c corrected a(minor) error in the calculation of the partial derivatives.
94 c
f. s. patt, saic gsc, october 19, 1998.
96 c reduced the
state noise
value for roll
and yaw to 6.e-10, to constrain the
97 c yaw angle
near the subsolar point.
f. s. patt, saic gsc, november 25, 1998.
99 c added
data initialization statements
for p
and q to ensure they get saved
100 c between calls.
f. s. patt, saic gsc, april 14, 1999
102 c modifed calculation of sun
vector measurement covariance to avoid
103 c numerical round-off errors
for sun
vector very
close to -x axis.
104 c
f. s. patt, saic gsc, august 27, 1999
106 c increased
state noise
for roll
and yaw to 2.5e-9 based
on results of testing
107 c with revised horizon scanner calibration
and sun sensor alignments.
108 c
f. s. patt, saic gsc, september 20, 1999
110 c modified
state noise calculation to
use delta_t**2 (instead of
abs(delta_t))
111 c to reduce noise
for hrpt/lac,
and changed qvar(from 2.5e-9 to 4.0e-9) to
112 c offset this
for gac; this is based
on initial results of testing
for the
113 c mergered 1-km(mlac) files.
114 c
f. s. patt, saic, november 22, 2002
117 #include "nav_cnst.fin"
118 #include "navblk_s.fin"
119 #include "navctl_s.fin"
123 integer*4 widphfl1, widphfl2, sunbodfl
124 real*4 nad_bod(3), sun_bod(3), attxfm(3,3), widphse1(2),
125 1 widphse2(2), pos(3), vel(3), att_prev(3), delta_t, covar(3)
127 real*8 xk(3,6), p(3,3), r(6,6), g(6,3), xid(3,3), d(3,3), q(3,3)
128 real*8 t33(3,3), t66(6,6), t36(3,6), yg(6), gt(3,6), dt(3,3)
129 real*8 t6(6), t3(3), r33(3,3), s33(3,3), xx(6,3)
130 real*4 dmda(3,3,3), dvda(3,3), cpit, spit, crol, srol, cyaw, syaw
131 real*4 att_ap(3), apm(3,3), sunvar, earvar, qvar(3),
vmag, tv(3)
132 integer*4 nyaw, ier, i, j, nadbodfl
133 real*4 pmag, yawest, sr(3), nr(3)
134 logical recomp, update
137 data sunvar/1.e-6/, earvar/3.e-6/, qvar/2*4.0e-9,4.0e-9/
139 data xid/1.d0,3*0.d0,1.d0,3*0.d0,1.d0/
140 data d/1.d0,3*0.d0,1.d0,3*0.d0,1.d0/
141 data p/1.d0,3*0.d0,1.d0,3*0.d0,1.d0/
145 c compute
state propagation
and noise covariance matrices
146 d(2,1) = delta_t*.00106d0
149 c q(i,i) =
abs(delta_t)*qvar(i)
150 q(i,i) = delta_t*delta_t*qvar(i)
153 c
If first scan of scene(delta_t = 0),
set state covariance
and attitude
154 if (delta_t.eq.0.0)
then
164 c compute a priori attitude
and matrix based
on previous attitude
166 c
propagate attitude using simple dynamics model(wertz,
eq. 13-86)
167 c may replace this with a more sophisticated model at a later date
168 c need to
do this in-line to handle mixed precision
170 att_ap(i) = d(i,1)*att_prev(1) + d(i,2)*att_prev(2)
171 * + d(i,3)*att_prev(3)
173 call euler(att_ap, apm)
176 call dmatmp(d,p,t33,3,3,3)
178 call dmatmp(t33,dt,p,3,3,3)
181 p(i,j) = p(i,j) + q(i,j)
186 c
call matmpy(apm, attxfm, m)
188 c compute reference vectors in a prior spacecraft frame
192 c nr(i) = -nr(i)/pmag
194 c
call matvec(m, navblk%sun_ref(1), sr)
196 c compute partial derivatives of attitude
matrix with respect to angles
197 cyaw = cos(att_ap(1)/radeg)
198 syaw = sin(att_ap(1)/radeg)
199 crol = cos(att_ap(2)/radeg)
200 srol = sin(att_ap(2)/radeg)
201 cpit = cos(att_ap(3)/radeg)
202 spit = sin(att_ap(3)/radeg)
205 dmda(2,i,1) = apm(3,i)
206 dmda(3,i,1) = -apm(2,i)
207 dmda(i,1,2) = -apm(i,3)*cpit
208 dmda(i,2,2) = apm(i,3)*spit
209 dmda(i,1,3) = apm(i,2)
210 dmda(i,2,3) = -apm(i,1)
214 dmda(2,3,2) = -syaw*srol
215 dmda(3,3,2) = -cyaw*srol
225 call earth( pos, vel, widphse1, widphfl1, widphse2, widphfl2,
226 1 yawest, navctl, nad_bod, nadbodfl, navblk%sun_ref(3) )
240 c
If there is valid sun
data
241 if (sunbodfl.eq.0)
then
243 c compute partials of sun
vector with respect to attitude angles
244 call matvec(attxfm, navblk%sun_ref(1), tv)
247 call matvec(dmda(1,1,i),tv,dvda(1,i))
253 yg(i) = sun_bod(i) - sr(i)
254 r(i,i) = sunvar*(1.0001d0 - sr(i)*sr(i))
262 c
If there is valid
earth data
263 if (nadbodfl.eq.0)
then
265 c compute partials of
earth vector with respect to attitude angles
266 call matvec(attxfm, pos,tv)
271 call matvec(dmda(1,1,i),tv,dvda(1,i))
277 yg(i+3) = nad_bod(i) - nr(i)
285 c
If there are observations, correct attitude
and update covariance
286 if ( (sunbodfl.eq.0) .or. (nadbodfl.eq.0) )
then
288 c compute gain
matrix(wertz,
eq. 13-74)
290 call dmatmp(p,gt,t36,3,3,6)
291 call dmatmp(g,t36,t66,6,3,6)
293 t66(i,i) = t66(i,i) + r(i,i)
295 call invert(t66,yg,6,6,t6,ier)
296 call dmatmp(gt,t66,t36,3,6,6)
297 call dmatmp(p,t36,xk,3,3,6)
299 c compute update to attitude angles
300 call dmatmp(xk,yg,t3,3,6,1)
302 navblk%att_ang(i) = att_ap(i) + radeg*t3(i)
306 c
Else,
use propagated attitude
309 navblk%att_ang(i) = att_ap(i)
314 c
if the
re-compute yaw
value is greater than the
318 if( navctl%redoyaw .ge. nyaw .and.
319 1
abs( navblk%att_ang(1) - yawest) .gt. navctl%yawtol )
then
321 yawest = navblk%att_ang(1)
327 c update covariance
matrix(wertz,
eq. 13-76)
328 call dmatmp(xk,g,t33,3,6,3)
331 t33(i,j) = xid(i,j) - t33(i,j)
334 call dmatmp(t33,p,r33,3,3,3)
336 call dmatmp(r33,s33,p,3,3,3)
337 call dmatmp(xk,r,t36,3,6,6)
339 call dmatmp(t36,xx,t33,3,6,3)
342 p(i,j) = p(i,j) + t33(i,j)
346 if (navctl%lvdbug.gt.2)
then
347 write (66,*) ((att_ap(i) - att_prev(i)),i=1,3)
348 write (66,*) ((navblk%att_ang(i) - att_ap(i)),i=1,3)
353 t6(i) = t6(i) + g(i,j)*t3(j)
359 c add diagonal elements of covariance
matrix to output array
370 subroutine dmatmp(dm1, dm2, dm3, l, m, n)
372 c
dmatmp( dm1, dm2, dm3, l, m, n)
374 c purpose: multiply two general double-precision matrices
378 c name
Type i/o description
379 c -------- ---- --- -----------
380 c dm1 r*8 i input
matrix of
size l-by-m
381 c dm2 r*8 i input
matrix of
size m-by-n
382 c dm3 r*8 o output
matrix of
size l-by-n
383 c l i*4 i number of rows in dm1
and dm3
384 c m i*4 i number of columns in dm1
and rows in dm2
385 c n i*4 i number of columns in dm2
and dm3
387 c by:
f. s. patt, saic gsc, june 2, 1998
390 c modification history:
394 real*8 dm1(l,m),dm2(m,n),dm3(l,n)
397 c compute dm3 as dm1 x dm2
402 dm3(i,j) = dm3(i,j) + dm1(i,k)*dm2(k,j)
410 subroutine dxpose(din, dout, n, m)
412 c
dxpose( din, dout, n, m )
418 c name
Type i/o description
419 c -------- ---- --- -----------
420 c din r*8 i
size n by m input
matrix
421 c dout r*8 o
size m by n output
matrix
422 c n i*4 i number of rows in din
423 c m i*4 i number of columns in din
425 c by:
f. s. patt, saic gsc, june 2, 1998
429 c modification history:
433 real*8 din(n,m), dout(m,n)