OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
APID198.py
Go to the documentation of this file.
1 import numpy as np
2 from .. PacketUtils import *
3 from .. timestamp import *
4 
5 '''
6 Tilt: APID 198
7 '''
8 
9 Fields = np.dtype([
10  ('timestamp', CCSDS_timestamp),
11  ('Padding', '>u4'), # Padding to maintain packet alignment
12  ('words', '>u2', 32), # Many words are packed bits; unpack later
13 ]) # total length = 74 bytes
14 
15 def APID198(data):
16  apid = 198
17  expected = Fields.itemsize
18  if len(data) != expected:
19  print('APID {}: expected={}, actual={}'.format(apid,expected,len(data)))
20 
21  tmp = np.frombuffer(data, dtype=Fields, count=1)
22  myDict = {}
23  myDict['timestamp'] = parse_CCSDS_timestamp(tmp['timestamp'][0])
24 
25  # unpack each 16-bit word
26  words = tmp['words'][0]
27 
28  # WORD_00
29  bits = getbits(words, 0)
30  #myDict['RSVD_00'] = as_int(bits[0:0+2]) # Reserved bits 0-1
31  myDict['MCE_REV'] = as_int(bits[2:2+2]) # MCE Revision
32  myDict['FPGA_VER'] = as_int(bits[5:5+12]) # FPGA Version
33 
34  # WORD_01: SADA state
35  bits = getbits(words, 1)
36  myDict['SADA_SPCL_LOC'] = as_int(bits[0:0+2]) # 00=Not Special Loc 01=Home 10=NEG EOT 11=POS EOT
37  #myDict['SADA_STP_ERR_FLG'] = bits[2] # NOT USED FOR PACE Step Error pace_tsade_sht_dscFlag, 00=No Error, 01=Error
38  myDict['SADA_RLY_STATUS'] = bits[3] # 0=Open Relay, 1=Closed Relay
39  myDict['SADA_STEP_PROFILE'] = as_int(bits[4:4+2]) # 00=Cardinal Stepping, 01=Smoothed Cardinal Stepping, 10=Sinusoidal
40  myDict['SADA_CUR_DIR'] = bits[6] # 0=Negative, 1=Positive
41  myDict['SADA_LAST_COMM_STATE']= as_int(bits[7:7+3]) # 001=State 1, 010=State 2, 011=State 3, 100=Sate 4, 101=State 5, 110 State 6, 000 & 111=Not Valid
42  myDict['SADA_LAST_STP_HOLD_TIME_STAT'] = bits[10] # 0=Disabled (mtr pwr on full time), 1=Enabled (mtr pwr off @ end of step)
43  myDict['SADA_H_BRIDGE_BOOST'] = bits[11] # 0=Disabled, 1=Enabled
44  myDict['SADA_PWR_LVL'] = as_int(bits[12:12+2]) # 00=50% maxV, 01=60% maxV, 10=80% maxV, 11=100% maxV
45  myDict['SADA_HOME_INIT'] = bits[14] # 0=Encoder not initialized, 1=initialized
46  myDict['SADA_CNT_ENA'] = bits[15] # Count enable
47 
48  # WORD_02 - WORD_03: Motor 0 (SADA) position
49  myDict['SADA_ENCPOS'] = words[2] # Motor 0 (SADA) reported encoder pos
50  myDict['SADA_CMDPOS'] = words[3] # Motor 0 (SADA) Commanded pos,
51  # x'3C4A'--x'7FFF' (-130 to -0.0075 degrees from home), x'8000' = home, x'8001--x'C3B6 = 0.0075 to 130
52 
53  # WORD_04 - WORD_06: Motor 0 (SADA) Pulse
54  myDict['SADA_PULSE_RATE'] = words[4] # Motor 0 (SADA) Pulse rate
55  myDict['SADA_PULSE_WIDTH'] = words[5] # Motor 0 (SADA) Pulse Width
56  myDict['SADA_LAST_STP_PULSE_LENGTH'] = words[6] # Motor 0 (SADA) Last Step Pulse Length
57  # x'0000'--x'007C' not valid, x'007D'--x'FFFF' 5msec to 2.62114 sec, # of 40usec clock cycles
58 
59  # WORD_07: Motor 0 (SADA) flags
60  bits = getbits(words, 7)
61  myDict['SADA_INDEX'] = bits[0] # Motor 0 (SADA) Index Track,
62  # D'15=Index track, D'14=Sine track, D'13=Cosine track, D'12=Hemisphere track, D'11=Almost Home track, D'10=Tavle limits track
63  myDict['SADA_SIN'] = bits[1] # Motor 0 (SADA) Sine Track
64  myDict['SADA_COS'] = bits[2] # Motor 0 (SADA) Cosine Track
65  myDict['SADA_HEMI'] = bits[3] # Motor 0 (SADA) Hemisphere Track
66  myDict['SADA_ALMOST_HOME'] = bits[4] # Motor 0 (SADA) Almost Home
67  myDict['SADA_TRVL_LIM'] = bits[5] # Motor 0 (SADA) Travel Limits
68  myDict['SADA_EOT_OVRD_STAT'] = as_int(bits[6:6+2]) # Motor 0 (SADA) EOT Override Status
69  #myDict['SADA_W7_RSVD'] = bits[8] # Motor 0 (SADA) Reserved
70  myDict['SADA_RAW_HEMI'] = bits[9] # Motor 0 (SADA) Raw Hemi
71  myDict['SADA_PROCESSED_HEMI'] = bits[10] # Motor 0 (SADA) Processed Hemi
72  myDict['SADA_INVERTED_HEMI'] = bits[11] # Motor 0 (SADA) Inverted Hemi
73  #myDict['SADA_W3_RSVD'] = bits[12] # Motor 0 (SADA) Reserved
74  myDict['SADA_LED_CMD_PWR_LVL']= as_int(bits[13:13+3]) # Motor 0 (SADA) LED Commanded Power Level, 0-011=commanded current lvl, 100-111=encoder off
75 
76  # WORD_08: SADA current
77  myDict['SADA_DRVR_CUR'] = words[8].item() # Motor 0 LED Driver Current, 1cnt=0.015259 mA
78 
79  # WORD_09: TILT state
80  bits = getbits(words, 9)
81  myDict['TILT_SPCL_LOC'] = as_int(bits[0:0+2]) # 00=Not a special location, 01=at home, 10=CW end of travel, 11, CCW end of travel
82  #myDict['TILT_STP_ERR_FLG'] = bits[2] # NOT USED FOR PACE Step Error Flag, 00=no error, 01=error
83  myDict['TILT_RLY_STATUS'] = bits[3] # 0=open (disabled), 1=closed (enabled)
84  myDict['TILT_STEP_PROFILE'] = as_int(bits[4:4+2]) # 00=cardinal step, 01=smoothed cardinal stepping, 10=Sinusoidal
85  myDict['TILT_CUR_DIR'] = bits[6] # 0=Negative, 1=Positive
86  myDict['TILT_LAST_COMM_STATE']= as_int(bits[7:7+3]) # 001=State 1, 010=State 2, 011=State 3, 100=Sate 4, 101=State 5, 110 State 6, 000 & 111=Not Valid
87  myDict['TILT_LAST_STP_HOLD_TIME_STAT'] = bits[10] # 0=Disabled (mtr pwr on full time), 1=Enabled (mtr pwr off @ end of step)
88  myDict['TILT_H_BRIDGE_BOOST'] = bits[11] # 0=Disabled, 1=Enabled
89  myDict['TILT_PWR_LVL'] = as_int(bits[12:12+2]) # 00=50% maxV, 01=60% maxV, 10=80% maxV, 11=100% maxV
90  myDict['TILT_HOME_INIT'] = bits[14] # 0=Encoder not initialized, 1=initialized
91  myDict['TILT_CNT_ENA'] = bits[15] # Count enable
92 
93  # WORD_10 - WORD_11: Motor 1 (TILT) position
94  (myDict['TILT_ENCPOS'], # Motor 1 (TILT) reported encoder pos
95  myDict['TILT_CMDPOS'], # Motor 1 (TILT) Commanded pos,
96  ) = 0.0075 * (words[10:12].astype(int) - 32768)
97  #) = (0.0075 * words[10:12]) - 245.76
98  # x'3C4A'--x'7FFF' (-130 to -0.0075 degrees from home), x'8000' = home, x'8001--x'C3B6 = 0.0075 to 130
99  # PolynomialConversion pace_tsade_enc_tilt {coefficients={-245.76 , 0.0075}}
100 
101  # WORD_12 - WORD_14: Motor 1 (TILT) Pulse
102  myDict['TILT_PULSE_RATE'] = words[12] # Motor 1 (TILT) Pulse rate
103  myDict['TILT_PULSE_WIDTH'] = words[13] # Motor 1 (TILT) Pulse Width
104  myDict['TILT_LAST_STP_PULSE_LENGTH'] = words[14] # Motor 1 (TILT) Last Step Pulse Length
105  # x'0000'--x'007C' not valid, x'007D'--x'FFFF' 5msec to 2.62114 sec, # of 40usec clock cycles
106 
107  # WORD_15: Motor 1 (TILT) flags
108  bits = getbits(words, 15)
109  myDict['TILT_INDEX'] = bits[0] # Motor 1 (TILT) Index Track,
110  # D'15=Index track, D'14=Sine track, D'13=Cosine track, D'12=Hemisphere track, D'11=Almost Home track, D'10=Tavle limits track
111  myDict['TILT_SIN'] = bits[1] # Motor 1 (TILT) Sine Track
112  myDict['TILT_COS'] = bits[2] # Motor 1 (TILT) Cosine Track
113  myDict['TILT_HEMI'] = bits[3] # Motor 1 (TILT) Hemisphere Track
114  myDict['TILT_ALMOST_HOME'] = bits[4] # Motor 1 (TILT) Almost Home
115  myDict['TILT_TRVL_LIM'] = bits[5] # Motor 1 (TILT) Travel Limits
116  myDict['TILT_EOT_OVRD_STAT'] = as_int(bits[6:6+2]) # Motor 1 (TILT) EOT Override Status
117  #myDict['TILT_W15_RSVD'] = bits[8] # Motor 1 (TILT) Reserved
118  myDict['TILT_RAW_HEMI'] = bits[9] # Motor 1 (TILT) Raw Hemi
119  myDict['TILT_PROCESSED_HEMI'] = bits[10] # Motor 1 (TILT) Processed Hemi
120  myDict['TILT_INVERTED_HEMI'] = bits[11] # Motor 1 (TILT) Inverted Hemi
121  #myDict['TILT_W3_RSVD'] = bits[12] # Motor 1 (TILT) Reserved
122  myDict['TILT_LED_CMD_PWR_LVL']= as_int(bits[13:13+3]) # Motor 1 (TILT) LED Commanded Power Level
123 
124  # WORD_16: TILT current
125  myDict['TILT_DRVR_CUR'] = words[16].item() # Motor 1 LED Driver Current, 1cnt=0.015259 mA
126 
127  # WORD_17 (First 5 bits indicate type in each CMD_ECHO. Not a mistake.)
128  bits = getbits(words, 17)
129  myDict['CMD_ECHO_TYPE'] = as_int(bits[0:0+5])
130 
131  # WORDs 17 - 25
132  (myDict['CMD_ECHO_0'],
133  # Command Echo 0, 9 CMD words from last 1553 received cmd to the MCE RT, valid and invalid cmds are echoed
134  myDict['CMD_ECHO_1'], # Command Echo 1, ...
135  myDict['CMD_ECHO_2'], # Command Echo 2, ...
136  myDict['CMD_ECHO_3'], # Command Echo 3, ...
137  myDict['CMD_ECHO_4'], # Command Echo 4, ...
138  myDict['CMD_ECHO_5'], # Command Echo 5, ...
139  myDict['CMD_ECHO_6'], # Command Echo 6, ...
140  myDict['CMD_ECHO_7'], # Command Echo 7, ...
141  myDict['CMD_ECHO_8'], # Command Echo 8, ...
142  ) = words[17:26]
143 
144  # WORD_26
145  bits = getbits(words, 26)
146  myDict['CMDS_NUMBER_SINCE_START'] = as_int(bits[0:8])
147  # Number of i cmds received by MCE, x'0000' - x'FFFF'], can be cmd type or invalid parameter, or cmd when mtr not initialized
148  myDict['CMDS_VLD_SINCE_START'] = as_int(bits[8:16]) # Number of valid cmds received by MCE, x'0000' - x'FFFF'
149 
150  # WORD_27
151  bits = getbits(words, 27)
152  #myDict['W27_RSVD'] = as_int(bits[0:0+2]) # Reserved bits 15-14
153  myDict['TILT_SADA_CURRENT_AF']= bits[2] # TILT & SADA Current action flag, if true, disables H-Bridge
154  myDict['TILT_SADA_CURRENT_AE']= bits[3] # TILT & SADA Current action enable, responds to error
155  myDict['WD_WRITE_AF'] = bits[4] # Watch Dog Write Action Flag
156  myDict['WD_READ_AF'] = bits[5] # Watch Dog Read Action Flag
157  myDict['WD_WRITE_EF'] = bits[6] # Watch Dog Write Error Flag
158  myDict['WD_READ_EF'] = bits[7] # Watch Dog Read Error Flag
159  myDict['SADA_EOT_PGM_POS_EF'] = bits[8] # SADA EOT Programable Postive Error Flag
160  myDict['SADA_EOT_PGM_NEG_EF'] = bits[9] # SADA EOT Programable Negative Error Flag
161  myDict['TILT_EOT_PGM_POS_EF'] = bits[10] # TILT EOT Programable Postive Error Flag
162  myDict['TILT_EOT_PGM_NEG_EF'] = bits[11] # TILT EOT Programable Negative Error Flag
163  myDict['TILT_ERR_FLG'] = as_int(bits[12:12+2]) # Motor 1 (TILT) error flag, 00=no error, 01=No home detected, 10=No right position
164  #myDict['W27_RSVD2'] = bits[14] # Motor 1 (TILT) time contorl, 1=time cntrl enabled, 0=time cntrl disabled
165  myDict['TILT_DIR'] = bits[15] # Motor 1 (TILT) direction, 1=CW, 0=CCW
166 
167  # WORD_28
168  bits = getbits(words, 28)
169  myDict['ERR_CTR_NO_HOME_WHEN_TILT'] = as_int(bits[0:0+4]) # Error Counter no home detected when tilt
170  myDict['ERR_CTR_NIT_NOT_INIT_POS_WHTILT'] = as_int(bits[4:4+4]) # Error Counter not init position when tilt
171  myDict['NUM_OF_TILT_FSM_CMDS_DECODED'] = as_int(bits[8:8+8]) # Number of TILT FSM Commands Decoded
172 
173  # WORD_29
174  (myDict['ABS_TILT_DELTA_ERR_POS'], # Motor 1 (TILT) absolute delta error position
175  myDict['ABS_SADA_DELTA_ERR_POS'], # Motor 0 (SADA) absolute delta error position
176  ) = words[29,np.newaxis].view(dtype='|u1')
177 
178  # WORD_30
179  (myDict['SADA_POS_ED_EF'], # SADA ED Error
180  myDict['SADA_POS_ED_ENA'],
181  myDict['TILT_SADA_CUR_EF'],
182  myDict['TILT_EOT_LED_NEG_EF'],
183  myDict['TILT_EOT_LED_POS_EF'],
184  myDict['SADA_EOT_LED_NEG_EF'],
185  myDict['SADA_EOT_LED_POS_EF'],
186  myDict['TILT_EOT_ENC_NEG_ENA'],
187  myDict['TILT_EOT_ENC_POS_ENA'],
188  myDict['SADA_EOT_ENC_NEG_ENA'],
189  myDict['SADA_EOT_ENC_POS_ENA'],
190  myDict['TILT_DELTA_ERF'],
191  myDict['TILT_TOTAL_TRAVEL_EF'],
192  myDict['TILT_CRUISE_EF'],
193  myDict['TILT_RAMP_DWN_EF'],
194  myDict['TILT_RAMP_UP_EF'],
195  ) = getbits(words, 30)
196 
197  # WORD_31
198  (myDict['SADA_POS_ED_AE'],
199  myDict['TILT_SADA_CUR_ENA'],
200  myDict['TILT_DELTA_AE'], # Motor 1 (TILT) Delta Action Enable
201  myDict['TILT_TOTAL_TIME_AE'], # Motor 1 (TILT) Total Time Action Enable
202  myDict['TILT_CRUISE_AE'], # Motor 1 (TILT) Crusie Action Enable
203  myDict['TILT_RAMPDOWN_AE'], # Motor 1 (TILT) Ramp Down Action Enable
204  myDict['TILT_RAMPUP_AE'], # Motor 1 (TILT) Ramp Up Action Enable
205  myDict['TILT_DELTA_ENA'],
206  myDict['TILT_TOT_TIME_ENA'],
207  myDict['TILT_CRUISE_ENA'],
208  myDict['TILT_RAMPDOWN_ENA'],
209  myDict['TILT_RAMPUP_ENA'],
210  myDict['WD_W_ERR_ENA'], # Enables TSADE Error Detection for write communication to 1553 Bus
211  myDict['WD_R_ERR_ENA'], # Enables TSADE Error Detection for read communication to 1553 Bus
212  myDict['WD_W_ACTION_ENA'], # Enables TSADE Action if the WD Write Error Detection is triggered
213  myDict['WD_R_ACTION_ENA'], # Enables TSADE Action if the WD Read Error Detection is triggered
214  ) = getbits(words, 31)
215 
216  return myDict
def getbits(var, i=0)
Definition: PacketUtils.py:19
def parse_CCSDS_timestamp(timestr)
Definition: timestamp.py:15
def as_int(bitlist)
Definition: PacketUtils.py:22
def APID198(data)
Definition: APID198.py:15