OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
APID108.py
Go to the documentation of this file.
1 import numpy as np
2 from .. PacketUtils import *
3 from .. timestamp import *
4 
5 '''
6 Attitude: APID 108
7 AC_AttFilterOut_tlm_msg packet (section 7.2)
8 '''
9 
10 Fields = np.dtype([
11  ('timestamp', CCSDS_timestamp),
12  ('Padding', '>u4'), # Padding to maintain packet alignment
13 
14  ('Est_Time', '>f8'), # estimate TAI timestamp
15  ('q_EciToBrf_Est', '>f8', (4,)), # attitude estimate
16  ('b_gyro_Brf_Est', '>f8', (3,)), # gyro bias estimate
17  ('w_EciToBrf_Brf_Est','>f8', (3,)), # angular rate estimate
18  ('Covar', '>f8', (6,6)),
19  ('Covar_eigs', '>f8', (6,)), # covariance matrix eigenvalues
20  ('Covar_cond', '>f8'), # covariance matrix condition number
21  ('underweight', '>f8'), # meas underweight param
22  ('gyro_sig_w', '>f8'), # ARW related noise param (sig_v)
23  ('gyro_sig_b', '>f8'), # Bias drift noise param (sig_u)
24 
25  ('Covar_St1', '>f8', (3,3)),
26  ('Covar_St2', '>f8', (3,3)),
27  ('Covar_St3', '>f8', (3,3)),
28 
29  ('att_uncert_thresh', '>f8', (3,)), # attitude estimate uncertainty max threshold
30  ('gyro_bias_uncert_thresh', '>f8', (3,)), # gyro bias estimate uncertainty max threshold
31  ('gyro_bias_est_mag_thresh', '>f8'), # gyro bias estimate magnitude max threshold
32  ('st1_innov_thresh', '>f8'), # ST1 innov threshold (Mahalanobis^2)
33  ('st2_innov_thresh', '>f8'), # ST2 innov threshold (Mahalanobis^2)
34  ('st3_innov_thresh', '>f8'), # ST3 innov threshold (Mahalanobis^2)
35  ('att_corr_thresh', '>f8'), # attitude correction threshold
36  ('gyro_bias_corr_thresh', '>f8'), # gyro bias correction threshold
37 
38  ('st1_latest_accept_time', '>f8'), # timestamp of most recent ST1 accepted
39  ('st1_latest_innov', '>f8', (6,)), # innov of most recent ST1 accepted
40  ('st1_latest_mahalanobis', '>f8'), # (Mahalanobis)^2 of most recent ST1 accepted
41  ('st1_latest_reject_time', '>f8'), # timestamp of most recent ST1 rejected
42 
43  ('st2_latest_accept_time', '>f8'), # timestamp of most recent ST2 accepted
44  ('st2_latest_innov', '>f8', (6,)), # innov of most recent ST2 accepted
45  ('st2_latest_mahalanobis', '>f8'), # (Mahalanobis)^2 of most recent ST2 accepted
46  ('st2_latest_reject_time', '>f8'), # timestamp of most recent ST2 rejected
47 
48  ('st3_latest_accept_time', '>f8'), # timestamp of most recent ST3 accepted
49  ('st3_latest_innov', '>f8', (6,)), # innov of most recent ST3 accepted
50  ('st3_latest_mahalanobis', '>f8'), # (Mahalanobis)^2 of most recent ST3 accepted
51  ('st3_latest_reject_time', '>f8'), # timestamp of most recent ST3 rejected
52 
53  ('enable_ST3', '|u1'), # ST3 processing enabled flag
54  ('gyro_bias_est_enable', '|u1'), # gyro bias estimation enabled flag
55  ('aif_st1', '|u1'), # ST1 Auto/Inhibit/Force flag
56  ('aif_st2', '|u1'), # ST2 Auto/Inhibit/Force flag
57  ('aif_st3', '|u1'), # ST3 Auto/Inhibit/Force flag
58 
59  ('packed_bits', '|u1', (3,)), # to unpack later
60 
61  ('st1_latest_reject_code', '|u1'), # most recent ST1 reject code
62  ('st2_latest_reject_code', '|u1'), # most recent ST2 reject code
63  ('st3_latest_reject_code', '|u1'), # most recent ST3 reject code
64  ('st1_mekf_disagree', '|u1'), # ST1 meas disagree with MEKF est
65  ('st2_mekf_disagree', '|u1'), # ST2 meas disagree with MEKF est
66  ('att_corr_excessive', '|u1'), # 1 if attitude correction excessive
67  ('gyro_bias_corr_excessive', '|u1'), # 1 if gyro bias correction excessive
68  ('gyro_bias_mag_excessive', '|u1'), # 1 if gyro bias magnitude excessive
69  ('gyro_meas_missing', '|u1'), # number of gyro meas missing from GyroBuffer
70  ('filter_is_init', '|u1'), # filter is initialized flag
71 
72  ('gyro_buff_is_init', '|u1'), # GyroBuffer is initialized flag
73  ('gyro_buff_idx_new', '|u1'), # GyroBuffer most recent entry index
74  ('gyro_buff_idx_old', '|u1'), # GyroBuffer oldest entry index
75  ('Padding2', '|u1', (3,)),
76 
77 ]) # total length = 1018 bytes
78 
79 
80 def APID108(data):
81  apid = 108
82  expected = Fields.itemsize
83  if len(data) != expected:
84  print('APID {}: expected={}, actual={}'.format(apid,expected,len(data)))
85 
86  tmp = np.frombuffer(data, dtype=Fields, count=1)
87  myDict = getDict(tmp)
88  myDict['timestamp'] = parse_CCSDS_timestamp(myDict['timestamp'])
89 
90  # unpack bit fields
91  (
92  myDict['excessive_gyro_meas_missing'], # 1 if excessive gyro missing
93  myDict['invalid_covar_eigenvalues'], # 1 if covariance eigenvalues too small
94  myDict['excessive_covar_condition'], # 1 if covariance condition number too big
95  spare, # ignore
96  myDict['filter_initialized'], # 1 if filter not init
97  myDict['gyro_buffer_initialized'], # 1 if gyro buffer not init
98  myDict['excessive_att_uncert'], # 1 if attitude estimate uncertainty excessive
99  myDict['excessive_bias_uncert'], # 1 if gyro bias estimate uncertainty excessive
100  ) = np.unpackbits(myDict['packed_bits'][0])
101 
102  (
103  myDict['att_X_uncert'], # 1 if att X estimate uncertainty excessive
104  myDict['att_Y_uncert'], # 1 if att Y estimate uncertainty excessive
105  myDict['att_Z_uncert'], # 1 if att Z estimate uncertainty excessive
106  ) = np.unpackbits(myDict['packed_bits'][1])[:3] # ignore last 5 bits
107 
108  (
109  myDict['bias_X_uncert'], # 1 if gyro X bias estimate uncertainty excessive
110  myDict['bias_Y_uncert'], # 1 if gyro Y bias estimate uncertainty excessive
111  myDict['bias_Z_uncert'], # 1 if gyro Z bias estimate uncertainty excessive
112  ) = np.unpackbits(myDict['packed_bits'][2])[:3] # ignore last 5 bits
113 
114  del myDict['packed_bits']
115 
116  return myDict
def getDict(structured_array)
Definition: PacketUtils.py:4
def parse_CCSDS_timestamp(timestr)
Definition: timestamp.py:15
def APID108(data)
Definition: APID108.py:80