@@ -39,30 +39,28 @@ def mapState(state, input_camera):
39
39
Kinv = np .linalg .inv (K )
40
40
41
41
rHat_BN_C = Kinv @ np .array ([state [0 ], state [1 ], 1 ])
42
+ norm_COB_vector = np .linalg .norm (rHat_BN_C )
42
43
rHat_BN_C = - rHat_BN_C / np .linalg .norm (rHat_BN_C )
43
44
44
- return rHat_BN_C
45
+ return rHat_BN_C , norm_COB_vector
45
46
46
47
47
- def mapCovar (pixels , input_camera ):
48
+ def mapCovar (pixels , input_camera , norm_COB_vector ):
48
49
"""Secondary method to map the covariance in pixel space to position"""
49
50
K = compute_camera_calibration_matrix (input_camera )
50
51
d_x = K [0 , 0 ]
51
52
d_y = K [1 , 1 ]
52
53
X = 1 / d_x
53
54
Y = 1 / d_y
54
55
55
- if pixels > 0 :
56
- scale_factor = np .sqrt (pixels ) / (2 * np .pi )
57
- else :
58
- scale_factor = 1 # prevent division by zero
56
+ scale_factor = np .sqrt (pixels / (4 * np .pi )) / (norm_COB_vector ** 2 )
59
57
60
58
covar = np .zeros ([3 , 3 ])
61
59
covar [0 , 0 ] = X ** 2
62
60
covar [1 , 1 ] = Y ** 2
63
61
covar [2 , 2 ] = 1
64
62
65
- return 1 / scale_factor * covar
63
+ return scale_factor * covar
66
64
67
65
68
66
def compute_camera_calibration_matrix (input_camera ):
@@ -121,7 +119,10 @@ def cob_converter_test_function(show_plots, cameraResolution, sigma_CB, sigma_BN
121
119
testProc = unitTestSim .CreateNewProcess (unitProcessName )
122
120
testProc .addTask (unitTestSim .CreateNewTask (unitTaskName , testProcessRate ))
123
121
R_object = 25. * 1e3
122
+ att_sigma = 0.001
123
+ covar_att_B = np .diag ([att_sigma ** 2 , (0.9 * att_sigma )** 2 , (0.95 * att_sigma )** 2 ])
124
124
module = cobConverter .CobConverter (method , R_object )
125
+ module .setAttitudeCovariance (covar_att_B )
125
126
unitTestSim .AddModelToTask (unitTaskName , module , module )
126
127
127
128
# Create the input messages.
@@ -183,13 +184,16 @@ def cob_converter_test_function(show_plots, cameraResolution, sigma_CB, sigma_BN
183
184
dcm_NC = np .dot (dcm_CB , dcm_BN ).T
184
185
185
186
# Center of Brightness Unit Vector
186
- rhat_COB_C_true = mapState (cob_true , inputCamera )
187
- covar_COB_C_true = mapCovar (num_pixels , inputCamera )
187
+ [ rhat_COB_C_true , norm_COB_vector ] = mapState (cob_true , inputCamera )
188
+ covar_COB_C_true = mapCovar (num_pixels , inputCamera , norm_COB_vector )
188
189
rhat_COB_N_true = np .dot (dcm_NC , rhat_COB_C_true ) * valid_COB_true # multiple by validity to get zero vector if bad
189
- covar_COB_N_true = np .dot (dcm_NC , np .dot (covar_COB_C_true , dcm_NC .T )).flatten () * valid_COB_true
190
190
timeTag_true_ns = inputCob .timeTag * valid_COB_true
191
191
timeTag_true = timeTag_true_ns * macros .NANO2SEC
192
192
193
+ covar_COB_B_true = np .dot (dcm_CB .T , np .dot (covar_COB_C_true , dcm_CB ))
194
+ covar_B_true = covar_COB_B_true + covar_att_B
195
+ covar_N_true = np .dot (dcm_BN .T , np .dot (covar_B_true , dcm_BN )).flatten () * valid_COB_true
196
+
193
197
# Center of Mass Message and Unit Vector
194
198
alpha = np .arccos (np .dot (r_BdyZero_N .T / np .linalg .norm (r_BdyZero_N ), vehSunPntN )) # phase angle
195
199
gamma = phase_angle_correction (alpha , method ) # COB/COM offset factor
@@ -202,7 +206,7 @@ def cob_converter_test_function(show_plots, cameraResolution, sigma_CB, sigma_BN
202
206
com_true = [None ] * 2 # COM location in image
203
207
com_true [0 ] = cob_true [0 ] - gamma * Rc * np .cos (phi ) * valid_COB_true
204
208
com_true [1 ] = cob_true [1 ] - gamma * Rc * np .sin (phi ) * valid_COB_true
205
- rhat_COM_C_true = mapState (com_true , inputCamera )
209
+ [ rhat_COM_C_true , norm_COM_vector ] = mapState (com_true , inputCamera )
206
210
if valid_COB_true and (method == binary or method == lambertian ):
207
211
valid_COM_true = True
208
212
rhat_COM_N_true = np .dot (dcm_NC , rhat_COM_C_true )
@@ -212,7 +216,7 @@ def cob_converter_test_function(show_plots, cameraResolution, sigma_CB, sigma_BN
212
216
213
217
# module output
214
218
rhat_COB_N = dataLogUnitVecCOB .rhat_BN_N [0 ]
215
- covar_COB_N = dataLogUnitVecCOB .covar_N [0 ]
219
+ covar_N = dataLogUnitVecCOB .covar_N [0 ]
216
220
time_COB = dataLogUnitVecCOB .timeTag [0 ]
217
221
com = dataLogCOM .centerOfMass [0 ]
218
222
time_COM_ns = dataLogCOM .timeTag [0 ]
@@ -228,11 +232,11 @@ def cob_converter_test_function(show_plots, cameraResolution, sigma_CB, sigma_BN
228
232
err_msg = 'Variable: rhat_COB_N' ,
229
233
verbose = True )
230
234
231
- np .testing .assert_allclose (covar_COB_N ,
232
- covar_COB_N_true ,
235
+ np .testing .assert_allclose (covar_N ,
236
+ covar_N_true ,
233
237
rtol = 0 ,
234
238
atol = tolerance ,
235
- err_msg = 'Variable: covar_COB_N ' ,
239
+ err_msg = 'Variable: covar_N ' ,
236
240
verbose = True )
237
241
238
242
np .testing .assert_allclose (time_COB ,
0 commit comments