Skip to content

Commit d199c16

Browse files
committed
Refactor test case module variable initializations
1 parent 60fb7c5 commit d199c16

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

src/fswAlgorithms/attGuidance/sunSafePoint/_UnitTest/test_sunSafePoint.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,49 @@ def test_sunSafePoint(show_plots, case):
5252
unitTestSim.AddModelToTask(unitTaskName, sun_safe_point)
5353

5454
# Initialize sunSafePoint module configuration data
55-
sHat_Cmd_B = np.array([0.0, 0.0, 1.0])
56-
if case == 5:
57-
sHat_Cmd_B = np.array([1.0, 0.0, 0.0])
58-
sun_safe_point.setSHatBdyCmd(sHat_Cmd_B)
5955
sun_safe_point.setMinUnitMag(0.1)
60-
if case == 2:
56+
sun_safe_point.setSmallAngle(0.01 * mc.D2R)
57+
58+
sHat_Cmd_B = []
59+
sunVec_B = []
60+
if case == 1: # Sun visible, vectors not aligned
61+
sHat_Cmd_B = np.array([0.0, 0.0, 1.0])
62+
sunVec_B = np.array([1.0, 1.0, 0.0])
63+
64+
if case == 2: # Sun not visible, search rate specified
65+
sHat_Cmd_B = np.array([0.0, 0.0, 1.0])
66+
sunVec_B = np.array([0.0, sun_safe_point.getMinUnitMag() / 2, 0.0])
67+
6168
omega_RN_B_Search = np.array([0.0, 0.0, 0.1])
6269
sun_safe_point.setOmega_RN_B(omega_RN_B_Search)
63-
sun_safe_point.setSmallAngle(0.01 * mc.D2R)
6470

65-
# Create sunSafePoint sun direction input messages
66-
inputSunVecData = messaging.NavAttMsgPayload()
67-
sunVec_B = np.array([1.0, 1.0, 0.0])
68-
if case == 2 or case == 6: # No sun visible, providing a near zero norm direction vector
69-
sunVec_B = [0.0, sun_safe_point.getMinUnitMag() / 2, 0.0]
70-
if case == 3:
71+
elif case == 3: # Sun visible, vectors aligned
72+
sHat_Cmd_B = np.array([0.0, 0.0, 1.0])
7173
sunVec_B = sHat_Cmd_B
72-
if case == 4 or case == 5:
74+
75+
elif case == 4: # Sun visible, vectors oppositely aligned
76+
sHat_Cmd_B = np.array([0.0, 0.0, 1.0])
77+
sunVec_B = -sHat_Cmd_B
78+
79+
elif case == 5: # Sun visible, vectors oppositely aligned, sHatCmd is along b1
80+
sHat_Cmd_B = np.array([1.0, 0.0, 0.0])
7381
sunVec_B = -sHat_Cmd_B
82+
83+
elif case == 6: # Sun not visible, no search rate specified
84+
sHat_Cmd_B = np.array([0.0, 0.0, 1.0])
85+
sunVec_B = np.array([0.0, sun_safe_point.getMinUnitMag() / 2, 0.0])
86+
87+
else: # Sun visible, spin rate about sun heading vector specified
88+
sHat_Cmd_B = np.array([0.0, 0.0, 1.0])
89+
sunVec_B = np.array([1.0, 1.0, 0.0])
90+
91+
sun_safe_point.setSunAxisSpinRate(1.5*mc.D2R)
92+
omega_RN_B_Search = sunVec_B/np.linalg.norm(sunVec_B) * sun_safe_point.getSunAxisSpinRate()
93+
94+
sun_safe_point.setSHatBdyCmd(sHat_Cmd_B)
95+
96+
# Create sunSafePoint sun direction input messages
97+
inputSunVecData = messaging.NavAttMsgPayload()
7498
inputSunVecData.vehSunPntBdy = sunVec_B
7599
sunInMsg = messaging.NavAttMsg().write(inputSunVecData)
76100

@@ -80,10 +104,6 @@ def test_sunSafePoint(show_plots, case):
80104
inputIMUData.omega_BN_B = omega_BN_B
81105
imuInMsg = messaging.NavAttMsg().write(inputIMUData)
82106

83-
if case == 7:
84-
sun_safe_point.setSunAxisSpinRate(1.5*mc.D2R)
85-
omega_RN_B_Search = sunVec_B/np.linalg.norm(sunVec_B) * sun_safe_point.getSunAxisSpinRate()
86-
87107
# Set up data logging
88108
attGuidOutMsgDataLog = sun_safe_point.attGuidanceOutMsg.recorder()
89109
unitTestSim.AddModelToTask(unitTaskName, attGuidOutMsgDataLog)

0 commit comments

Comments
 (0)