Table of Contents

G1. INTRODUCTION G-[2](#g1.-introduction)

G2. ANALYTICAL APPROACH G-[2](#g2.-analytical-approach)

G3. PC PROGRAMMING APPROACH G-[5](#g3.-pc-programming-approach)

G4. GSFC CONTACT G-[7](#g4.-gsfc-contact)

List of Tables

Table G.1 PC Program In Basic For Calculating Shuttle Body Axis Attitude
G-[8](#__RefHeading___Toc454688624)

APPENDIX G

ALGORITHMS FOR ATTITUDE CONVERSIONS SIMPLIFIED CALCULATION OF SHUTTLE
BODY AXIS ATTITUDES USING M50 QUATERNIONS

# G1. INTRODUCTION

This appendix outlines simplified equations that can be used to
calculate Shuttle body axis attitudes using M50 body quaternions in the
Shuttle downlink. Both an analytical background and a simplified set of
equations that can be used by a programmer will be provided. In
addition, a sample personnel computer (PC) program in BASIC is provided
for reference in Table G.1.

# G2. ANALYTICAL APPROACH

NOTE: This section is an excerpt from the document titled: Payloads
Mathematical Specifications, CSC/SD-85/6024, Prepared for NASA under
Contract NAS5-27888, July, 1985.

A vector in Shuttle body axis coordinates, V~by~, can be expressed as:

V~by~ = {A~s~}~M50~ V~M50~

where:

{A~s~}~M50~ = Attitude matrix relative to the Mean 2000 System (M50)

V~M50~ = Vector in M50 coordinate system

then,

V~M50~ = {A~s~}~M50~^-1^ V~by~

= {As}~M50~^T^ V~by~

NOTE: Since {A~s~}~M50~ is orthogonal, its inverse is equal to the
transpose.

The attitude matrix {As}M50 can be constructed from the Shuttle M50 body
quaternion as follows:

A11 A12 A13

{A~s~}~M50~ = A21 A22 A23

A31 A32 A33

where: A11 = q1^2^ + q2^2^ - q3^2^ - q4^2^

A12 = 2(q2q3 - q1q4)

A13 = 2(q2q4 + q1q3)

A21 = 2(q2q3 + q1q4)

A22 = q1^2^ - q2^2^ + q3^2^ - q4^2^

A23 = 2(q3q4 - q1q2)

A31 = 2(q2q4 - q1q3)

A32 = 2(q3q4 + q1q2)

A33 = q1^2^ - q2^2^ - q3^2^ + q4^2^

and (q1, q2, q3, q4) are the elements of the Shuttle M50 body
quaternion.

For the i^th^ Shuttle body axis:

(i)~M50~ = (Ali ^-1^, A2i ^-1^, A3i ^-1^)^T^~M50~

Hence (RA~i~)~M50~ = Tan^-1^ A2i^-1^

A1i-1M50

And (Dec~i~)~M50~ = Tan^-1^ A3i^-1^

(Ali^-1^)^2^ + (A2i^-1^)^2^

Where (RA^i^)~M50~ = Right Ascension of the i~th~ body axis of the
Shuttle in the

> M50 system

(Dec~i~)~M50~ = Declination of the i~th~ body axis of the Shuttle in the
M50

> system.

\* The Shuttle M50 Pitch/Roll/Yaw attitudes can easily be calculated by
forming the matrix {K} as follows:

{K} = {A~s~}~M50~ {R}^-1^

where {R} = Identity matrix

1 0 0

= 0 1 0

0 0 1

and therefore = {R}^-1^ = {R}^T^ = {R}

Hence:

{K} = {A~s~}~M50~

Then, the Pitch, Roll, and Yaw using a 2-3-1 Euler rotation can be
calculated:

Pitch~M50~ = Tan^-1^ (-K13/K11) 0≤p\<2

Roll~M50~ = Tan^-1^ (-K32/K22) 0≤R\<2

Yaw~M50~ = Sin^-1^ (K12) -π/2≤Y≤π/2

To calculate the Shuttle body axis Pitch, Roll, Yaw attitudes in the
LVLH coordinate system, one needs to form the {K} matrix as above and
repeated here again:

{K} = {A~s~}~M50~ {R^}-1^

Where {R} = a matrix formed using the Shuttle position vector (r) and
velocity

> vector (v) in the M50 coordinate system. The position and velocity
> vectors are obtained from the Shuttle ancillary downlink.

and

U~1~^T^

{R} = U~2~^T^

U~3~^T^

where

U~1~ = U~2~ X U~3~

U~2~ = [- (r X v)]{.underline}

r X v

U~3~ = - r

r

Since the {R} matrix is orthogonal, then

{R}^-1^ = {R}^T^

Hence:

{K} = {A~s~}~M50~ {R}^T^

Then, the Pitch, Roll, and Yaw body axis attitudes in the LVLH system
can be calculated using a 2-3-1 Euler rotation as follows:

Pitch~LVLH~ = Tan^-1^ (-K13/K11) 0\<P\<2

Roll~LVLH~ = Tan^-1^ (-K32/K22) 0\<R\<2

Yaw~LVLH~ = Sin^-1^ (K12) - /2\<Y\</2

# G3. PC PROGRAMMING APPROACH

Simple computer programming approach using quaternions to calculate
Shuttle attitudes in: M50 Right Ascension and Declination; M50
Pitch/Roll/Yaw; and LVLH Pitch/Roll/Yaw.

[Step 1]{.underline}

Obtain the Shuttle M50 body quaternion (Q1, Q2, Q3, Q4)

Set radians to degrees constant:

RTOD = 57.2957795

Note: If high precision is required, it is suggested that double
precision be used.

[Step 2]{.underline}

Calculate the elements of the matrix {As} as follows:

A11 = Q1\*\*2+Q2\*\*2-Q3\*\*2-Q4\*\*2

A12 = 2.\*(Q2\*Q3-Q1\*Q4)

A13 = 2.\*(Q2\*Q4+Q1\*Q3)

A21 = 2.\*(Q2\*Q3+Q1\*Q4)

A22 = Q1\*\*2-Q2\*\*2+Q3\*\*2-Q4\*\*2

A23 = 2.\*(Q3\*Q4-Q1\*Q2)

A31 = 2.\*(Q2\*Q4-Q1\*Q3)

A32 = 2.\*(Q3\*Q4+Q1\*Q2)

A33 = Q1\*\*2-Q2\*\*2-Q3\*\*2+Q4\*\*2

[Step 3]{.underline}

> Calculate RA and Dec of each Shuttle axis in degrees using the
> transpose of matrix {As} as follows:

X Shuttle M50 Body Axis (Out Nose):

RAX = ATAN2(A12/A11)\*RTOD

IF(RAX.LT.0.0)RAX=RAX+360.0

DECX=ATAN2(A13/SQRT(A11\*\*2+A12\*\*2))\*RTOD

Y Shuttle M50 Body Axis (Out Right Wing):

RAY=ATAN2(A22/A21)\*RTOD

IF (RAY.LT.0.0)RAY=RAY+360.0

DECY=ATAN2(A23/SQRT(A21\*\*2+A22\*\*2))\*RTOD

Z Shuttle M50 Body Axis (Out Bottom of Fuselage):

RAZ=ATAN2(A32/A31)\*RTOD

IF(RAZ.LT.0.0)RAZ=RAZ+360.0

DECZ=ATAN2(A33/SQRT(A31\*\*2+A32\*\*2))\*RTOD

-Z Shuttle M50 Body Axis (Up Out of Payload Bay):

RANZ=RAZ+180.0

IF(RANZ.GE.360.0)RANZ=RANZ-360.0

DECNZ=-DECZ

[Step 4]{.underline}

Calculate the M50 Pitch/Roll/Yaw using a 2-3-1 Euler rotation:

PITCH=ATAN2(-A13/A11)\*RTOD

IF(PITCH.LT.0.0)PITCH=PITCH+360.0

ROLL=ATAN2(-A32/A22)\*RTOD

IF(ROLL.LT.0.0)ROLL=ROLL+360.0

YAW=ARSIN(A12)\*RTOD

(Note: Yaw defined between -90 and +90)

[Step 5]{.underline}

> To calculate the LVLH Pitch/Roll/Yaw Shuttle body axis attitudes using
> the 2-3-1 Euler rotation, obtain the Shuttle position (R1, R2, R3) and
> velocity (V1, V2, V3) vectors in M50 from the Shuttle ancillary
> downlink.

[Step 6]{.underline}

Calculate the {R} matrix:

RMAG=SQRT(R1\*\*2+R2\*\*2+R3\*\*2)

U3X=-R1/RMAG

U3Y=-R2/RMAG

U3Z=-R3/RMAG

RXVX=R2\*V3-R3\*V2

RXVY=R3\*V1-R1\*V3

RXVZ=R1\*V2-R2\*V1

RXVMAG=SQRT(RXVX\*\*2+RXVY\*\*2+RXVZ\*\*2)

U2X=-RXVX/RXVMAG

U2Y=-RXVY/RXVMAG

U2Z=-RXVZ/RXVMAG

U1X=U2Y\*U3Z-U2Z\*U3Y

U1Y=U2Z\*U3X-U2X\*U3Z

U1Z=U2X\*U3Y-U2Y\*U3X

[Step 7]{.underline}

Using the transpose of {R}, calculate the {K} matrix where:

{K} = {As}M50 {R}T

and

U1X U2X U3X

{R}T = U1Y U2Y U3Y

U1Z U2Z U3Z

and

{As}M50 was calculated before

Hence the code to calculate {K} is:

K11=A11\*U1X+A12\*U1Y+A13\*U1Z

K12=A11\*U2X+A12\*U2Y+A13\*U2Z

K13=A11\*U3X+A12\*U3Y+A13\*U3Z

K21=A21\*U1X+A22\*U1Y+A23\*U1Z

K22=A21\*U2X+A22\*U2Y+A23\*U2Z

K23=A21\*U3X+A22\*U3Y+A23\*U3Z

K31=A31\*U1X+A32\*U1Y+A33\*U1Z

K32=A31\*U2X+A32\*U2Y+A33\*U2Z

K33=A31\*U3X+A32\*U3Y+A33\*U3Z

[Step 8]{.underline}

> Calculate the LVLH Shuttle body axis Pitch/Roll/Yaw attitudes using a
> 2-3-1 Euler rotation:

PITCH=ATAN2(-K13/K11)\*RTOD

IF(PITCH.LT.0.0)PITCH=PITCH+360.0

ROLL=ATAN2(-K32/K22)\*RTOD)

IF (ROLL.LT.0.0)ROLL=ROLL+360.0

YAW=ARSIN(K12)\*RTOD

(Note: since JSC normally represents yaw positive, then add 360 if
negative)

IF(YAW.LT.0.0)YAW=YAW+360.0

# G4. GSFC CONTACT

If there are additional questions or problems, these can be directed to:

Deputy Project Manager

NASA/GSFC, Code 870

Greenbelt, Maryland 20771

\(301\) 286-2193 (FAX 301-286-1694)

[]{#__RefHeading___Toc454688624 .anchor}Table G.1 PC Program In Basic
For Calculating Shuttle Body Axis Attitude

10 REM PROGRAM (IN BASIC) TO CALC ATTITUDE FROM

20 REM FROM M50 SHUTTLE BODY QUATERNIONS

30 RTOD#=180#/3.14159265#

40 PRINT \"INPUT Q1\"

50 INPUT Q1#

60 PRINT \"INPUT Q2\"

70 INPUT Q2#

80 PRINT \"INPUT Q3\"

90 INPUT Q3#

100 PRINT \"INPUT Q4\"

110 INPUT Q4#

120 PRINT

130 PRINT \"THE INPUT QUATERNION IS\"

140 PRINT Q1#,Q2#,Q3#,Q4#

150 REM

160 REM PART I : CALCULATE RIGHT ASCENSION AND DECLINATION IN M50

170 REM

180 PRINT

190 PRINT

200 PRINT \"THE RIGHT ASCENSION AND DECLINATION IN M50 IS\"

210 PRINT

220 PRINT

230 REM CALCULATE MATRIX A

240 A11#=Q1#\^2+Q2#\^2-Q3#\^2-Q4#\^2

250 A12#=2#\*(Q2#\*Q3#-Q1#\*Q4#)

260 A13#=2#\*(Q2#\*Q4#+Q1#\*Q3#)

270 A21#=2#\*(Q2#\*Q3#+Q1#\*Q4#)

280 A22#=Q1#\^2-Q2#\^2+Q3#\^2-Q4#\^2

290 A23#=2#\*(Q3#\*Q4#-Q1#\*Q2#)

300 A31#=2#\*(Q2#\*Q4#-Q1#\*Q3#)

310 A32#=2#\*(Q3#\*Q4#+Q1#\*Q2#)

320 A33#=Q1#\^2-Q2#\^2-Q3#\^2+Q4#\^2

330 REM THEN TRANSPOSE MATRIX A AND CALC RA+DEC FOR EACH

340 REM SHUTTLE BODY AXIS (INCLUDING X, Y, Z, AND -Z)

350 REM -Z=UP OUT OF SHUTTLE BAY

360 REM X=OUT NOSE OF SHUTTLE

370 REM Y=OUT RIGHT WING

380 REM Z=OUT THE UNDERSIDE OF SHUTTLE FUSELAGE

390 RAX#=ATN(A12#/A11#)\*RTOD#

400 IF A11#\<0 THEN RAX#=RAX#+180#

410 IF A11#\>0 AND A12#\<0 THEN RAX#=RAX#+360#

420 DECX#=ATN(A13#/SQR(A11#\^2+A12#\^2))\*RTOD#

430 PRINT \"RA +X (DEG)=\",RAX#,\"DEC +X (DEG)=\",DECX#

440 RAY#=ATN(A22#/A21#)\*RTOD#

450 IF A21#\<0 THEN RAY#=RAY#+180#

460 IF A21#\>0 AND A22#\<0 THEN RAY#=RAY#+360#

470 DECY#=ATN(A23#/SQR(A21#\^2+A22#\^2))\*RTOD#

480 PRINT \"RA +Y (DEG)=\",RAY#,\"DEC +Y (DEG)=\",DECY#

490 RAZ#=ATN(A32#/A31#)\*RTOD#

Table G.1 (Cont'd)

500 IF A31#\<0 THEN RAZ#=RAZ#+180#

510 IF A31#\>0 AND A32#\<0 THEN RAZ#=RAZ#+360#

520 DECZ#=ATN(A33#/SQR(A31#\^2+A32#\^2))\*RTOD#

530 PRINT \"RA +Z (DEG)=\",RAZ#,\"DEC +Z (DEG)=\",DECZ#

540 RANZ#=RAZ#+180#

550 IF RANZ#\>=360# THEN RANZ#=RANZ#-360#

560 DECNZ#=-DECZ#

570 PRINT \"RA -Z (DEG)=\",RANZ#,\"DEC -Z (DEG)=\",DECNZ#

580 PRINT

590 PRINT

600 REM PART II : CALCULATE M50 PITCH/ROLL/YAW USING 2-3-1 EULER SEQ

610 REM CALCULATE THE K MATRIX AS FOLLOWS:

620 REM T

630 REM K = (A) (R)

640 REM ( 1 0 0 )

650 REM R = ( 0 1 0 )

660 REM ( 0 0 1 )

670 REM T

680 REM R = (R)

690 REM SINCE R=IDENTITY MATRIX, THEREFORE MATRIX K = MATRIX A

700 REM USING A 2-3-1 ROTATION CALCULATE PITCH/ROLL/YAW (M50)

710 REM WHERE 0\<=PITCH\<360, 0\<=ROLL\<360, AND -90\<=YAW\<=90

720 REM HOWEVER, YAW IS MODIFIED TO BE BETWEEN 270 AND 90 GOING THRU 0

730 PITCH#=ATN(-A13#/A11#)\*RTOD#

740 IF A11#\<0 THEN PITCH#=PITCH#+180#

750 IF A11#\>0 AND -A13#\<0 THEN PITCH#=PITCH#+360#

760 ROLL#=ATN(-A32#/A22#)\*RTOD#

770 IF A22#\<0 THEN ROLL#=ROLL#+180#

780 IF A22#\>0 AND -A32#\<0 THEN ROLL#=ROLL#+360#

790 REM ACTUALLY YAW#=ARCSIN(A12#)\*RTOD# , BUT MY PC BASIC DOESN\'T

800 REM HAVE THE ARCSIN, HENCE THE RADICAL CALCULATION

810 YAW#=ATN(A12#/(SQR(1#-A12#\^2)))\*RTOD#

820 IF YAW#\<0 THEN YAW#=YAW#+360#

830 PRINT

840 PRINT \"SHUTTLE M50 PITCH/ROLL/YAW (2-3-1 EULER SEQ)\"

850 PRINT

860 PRINT \"PITCH (DEG)=\",PITCH#,\"ROLL (DEG)=\",ROLL#,\"YAW
(DEG)=\",YAW#

870 PRINT

880 PRINT

890 REM

900 REM PART III : CONVERT ATTITUDE TO LVLH PITCH/ROLL/YAW IN A

910 REM 2-3-1 EULER SEQUENCE

920 REM

930 REM INPUT ORBIT POSITION AND VELOCITY VECTORS(FT AND FT/SEC)

940 PRINT \"INPUT R1\"

950 INPUT R1#

960 PRINT \"INPUT R2\"

970 INPUT R2#

980 PRINT \"INPUT R3\"

Table G.1 (Cont'd)

990 INPUT R3#

1000 PRINT \"INPUT V1\"

1010 INPUT V1#

1020 PRINT \"INPUT V2\"

1030 INPUT V2#

1040 PRINT \"INPUT V3\"

1050 INPUT V3#

1060 PRINT \"THE INPUT RADIUS VECTOR (FT) IS\"

1070 PRINT R1#,R2#,R3#

1080 PRINT

1090 PRINT \"THE INPUT VELOCITY VECTOR (FT/SEC) IS\"

1100 PRINT V1#,V2#,V3#

1110 PRINT

1120 PRINT

1130 REM NOW CALCULATE THE R MATRIX USING THE R AND V VECTORS

1140 RMAG#=SQR(R1#\^2+R2#\^2+R3#\^2)

1150 U3X#=-R1#/RMAG#

1160 U3Y#=-R2#/RMAG#

1170 U3Z#=-R3#/RMAG#

1180 RXVX#=R2#\*V3#-R3#\*V2#

1190 RXVY#=R3#\*V1#-R1#\*V3#

1200 RXVZ#=R1#\*V2#-R2#\*V1#

1210 RVMAG#=SQR(RXVX#\^2+RXVY#\^2+RXVZ#\^2)

1220 U2X#=-RXVX#/RVMAG#

1230 U2Y#=-RXVY#/RVMAG#

1240 U2Z#=-RXVZ#/RVMAG#

1250 U1X#=U2Y#\*U3Z#-U2Z#\*U3Y#

1260 U1Y#=U2Z#\*U3X#-U2X#\*U3Z#

1270 U1Z#=U2X#\*U3Y#-U2Y#\*U3X#

1280 REM WE NOW HAVE R=(U1,U2,U3) MATRIX

1290 REM ( U1X# U1Y# U1Z# )

1300 REM R = ( U2X# U2Y# U2Z# )

1310 REM ( U3X# U3Y# U3Z# ) T

1320 REM NOW HOWEVER TAKE THE TRANSPOSE OF R = R

1330 REM

1340 REM T ( U1X# U2X# U3X# )

1350 REM R = ( U1Y# U2Y# U3Y# )

1360 REM ( U1Z# U2Z# U3Z# )

1370 REM T

1380 REM NOW CALCULATE THE K MATRIX = (A) (R)

1390 K11#=A11#\*U1X#+A12#\*U1Y#+A13#\*U1Z#

1400 K12#=A11#\*U2X#+A12#\*U2Y#+A13#\*U2Z#

1410 K13#=A11#\*U3X#+A12#\*U3Y#+A13#\*U3Z#

1420 K21#=A21#\*U1X#+A22#\*U1Y#+A23#\*U1Z#

1430 K22#=A21#\*U2X#+A22#\*U2Y#+A23#\*U2Z#

1440 K23#=A21#\*U3X#+A22#\*U3Y#+A23#\*U3Z#

1450 K31#=A31#\*U1X#+A32#\*U1Y#+A33#\*U1Z#

1460 K32#=A31#\*U2X#+A32#\*U2Y#+A33#\*U2Z#

1470 K33#=A31#\*U3X#+A32#\*U3Y#+A33#\*U3Z#

1480 REM IN A 2-3-1 ROTATION CALC PITCH/ROLL/YAW

Table G.1 (Cont'd)

1490 PITCH#=ATN(-K13#/K11#)\*RTOD#

1500 IF K11#\<0 THEN PITCH#=PITCH#+180#

1510 IF K11#\>0 AND -K13#\<0 THEN PITCH#=PITCH#+360#

1520 ROLL#=ATN(-K32#/K22#)\*RTOD#

1530 IF K22#\<0 THEN ROLL#=ROLL#+180#

1540 IF K22#\>0 AND -K32#\<0 THEN ROLL#=ROLL#+360#

1550 YAW#=ATN(K12#/(SQR(1#-K12#\^2)))\*RTOD#

1560 IF YAW#\<0 THEN YAW#=YAW#+360#

1570 PRINT

1580 PRINT \"SHUTTLE LVLH PITCH/ROLL/YAW (2-3-1 EULER SEQ)\"

1590 PRINT

1600 PRINT \"PITCH (DEG)=\",PITCH#,\"ROLL (DEG)=\",ROLL#,\"YAW
(DEG)=\",YAW#

1610 PRINT

1620 PRINT \"DONE\"

1630 REM TEST EXAMPLE : INPUTS ARE Q1=.2209538, Q2=.4641501,
Q3=.8537468,

1640 REM Q4=-.0828158, R1=-16732867, R2=-12040024, R3=7815002.5,

1650 REM V1=11329.191, V2=-21052.605, V3=-8160.598

1660 REM TEST EXAMPLE : RESULTS ARE RA+X=119.624,DEC+X=17.481

1670 REM RA+Y=36.305 ,DEC+Y=-20.274

1680 REM RA+Z=172.015,DEC+Z=-62.703

1690 REM RA-Z=352.015,DEC-Z=62.703

1700 REM M50 PITCH=212.502, ROLL=353.456, YAW=56.009

1710 REM LVLH PITCH=179.339, ROLL=269.727, YAW=1.739

720 END