Skip to content

Commit 8b21bc6

Browse files
committed
[#1332] Add eclipse message to facetedSRPEffector
1 parent 2dc4479 commit 8b21bc6

5 files changed

Lines changed: 47 additions & 12 deletions

File tree

src/simulation/dynamics/facetedSRPEffector/_UnitTest/test_facetedSRPEffector.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@
5959
np.array([0.05, -0.05, -0.05]),
6060
]
6161
)
62+
@pytest.mark.parametrize("illumination_factor", [1.0, 0.5, 0.0]) # [-]
63+
6264
def test_facetedSRPEffector(show_plots,
6365
r_BN_N_init,
6466
r_SN_N_init,
6567
sigma_BN_init,
66-
omega_BN_B_init):
68+
omega_BN_B_init,
69+
illumination_factor):
6770
r"""
6871
**Verification Test Description**
6972
@@ -82,8 +85,9 @@ def test_facetedSRPEffector(show_plots,
8285
8386
This test sets up a simulation with a faceted spacecraft modeled as a cubic hub with two attached circular solar
8487
arrays. Six square facets represent the cubic hub and four circular facets represent the two solar arrays.
85-
The test varies the initial state information of both the spacecraft and the Sun. The test checks that the computed
86-
SRP forces and torques at each timestep match the values output from the module.
88+
The test varies the initial state information of the spacecraft, the initial state information of the Sun, and the
89+
Sun illumination factor. The test checks that the computed SRP forces and torques at each timestep match the
90+
values output from the module.
8791
8892
**Test Parameters**
8993
@@ -92,6 +96,7 @@ def test_facetedSRPEffector(show_plots,
9296
r_SN_N_init (np.ndarray): [m] shape (3,) Initial Sun inertial position
9397
sigma_BN_init (np.ndarray): [-] shape (3,) Initial spacecraft inertial attitude
9498
omega_BN_B_init (np.ndarray): [rad/s] shape (3,) Initial spacecraft inertial angular velocity
99+
illumination_factor (float): [-] Sun visibility factor (0 = full shadow, 1 = full sunlight)
95100
96101
**Description of Variables Being Tested**
97102
@@ -192,6 +197,11 @@ def test_facetedSRPEffector(show_plots,
192197
faceted_sc_projected_area.spacecraftStateInMsg.subscribeTo(sc_object.scStateOutMsg)
193198
test_sim.AddModelToTask(task_name, faceted_sc_projected_area)
194199

200+
# Create the eclipse message
201+
eclipse_msg_data = messaging.EclipseMsgPayload()
202+
eclipse_msg_data.illuminationFactor = illumination_factor
203+
eclipse_msg = messaging.EclipseMsg().write(eclipse_msg_data)
204+
195205
# Create the faceted SRP effector module
196206
faceted_srp_effector = facetedSRPEffector.FacetedSRPEffector()
197207
faceted_srp_effector.ModelTag = "facetedSRPEffector"
@@ -200,6 +210,7 @@ def test_facetedSRPEffector(show_plots,
200210
faceted_srp_effector.facetElementBodyInMsgs[idx].subscribeTo(facet_element_message_list[idx])
201211
faceted_srp_effector.facetProjectedAreaInMsgs[idx].subscribeTo(faceted_sc_projected_area.facetProjectedAreaOutMsgs[idx])
202212
faceted_srp_effector.sunStateInMsg.subscribeTo(sun_state_message)
213+
faceted_srp_effector.sunEclipseInMsg.subscribeTo(eclipse_msg)
203214
sc_object.addDynamicEffector(faceted_srp_effector)
204215
test_sim.AddModelToTask(task_name, faceted_srp_effector)
205216
test_sim.AddModelToTask(task_name, sc_object)
@@ -244,7 +255,8 @@ def test_facetedSRPEffector(show_plots,
244255
sigma_BN,
245256
r_BN_N,
246257
r_SN_N,
247-
facet_element_projected_area_list_sim)
258+
facet_element_projected_area_list_sim,
259+
illumination_factor)
248260

249261
# Check the simulated srp force and torque values match the computed truth values
250262
for idx in range(len(timespan)):
@@ -267,7 +279,8 @@ def compute_srp_force_torque(num_facets,
267279
sigma_BN,
268280
r_BN_N,
269281
r_SN_N,
270-
facet_element_projected_area_list_sim):
282+
facet_element_projected_area_list_sim,
283+
illumination_factor):
271284

272285
srp_force_B_list_truth = [] # [N]
273286
srp_torque_B_list_truth = [] # [Nm]
@@ -302,8 +315,8 @@ def compute_srp_force_torque(num_facets,
302315
srp_force_B += facet_force # [N]
303316
srp_torque_B += np.cross(facet_r_CopB_B_list[facet_idx], facet_force) # [Nm]
304317

305-
srp_force_B_list_truth.append(srp_force_B)
306-
srp_torque_B_list_truth.append(srp_torque_B)
318+
srp_force_B_list_truth.append(illumination_factor * srp_force_B)
319+
srp_torque_B_list_truth.append(illumination_factor * srp_torque_B)
307320

308321
return np.array(srp_force_B_list_truth), np.array(srp_torque_B_list_truth)
309322

@@ -314,5 +327,6 @@ def compute_srp_force_torque(num_facets,
314327
np.array([-4020338.690396649, 7490566.741852513, 5248299.211589362]), # [m] r_BN_N_init
315328
np.array([0.0, 0.0, 0.0]), # [m] r_SN_N_init
316329
np.array([0.0, 0.0, 0.0]), # [-] sigma_BN_init
317-
np.array([0.0, 0.0, 0.0]) # [rad/s] omega_BN_B_init
330+
np.array([0.0, 0.0, 0.0]), # [rad/s] omega_BN_B_init,
331+
1.0 # [-] illumination_factor
318332
)

src/simulation/dynamics/facetedSRPEffector/facetedSRPEffector.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ void FacetedSRPEffector::computeForceTorque(double callTime, double timeStep) {
105105
return;
106106
}
107107

108+
// Read optional sun eclipse message
109+
this->sunVisibilityFactor = 1.0;
110+
if (this->sunEclipseInMsg.isLinked() && this->sunEclipseInMsg.isWritten()) {
111+
EclipseMsgPayload sunEclipseIn = this->sunEclipseInMsg();
112+
this->sunVisibilityFactor = sunEclipseIn.illuminationFactor;
113+
}
114+
108115
// Compute the sun direction unit vector in spacecraft body frame components
109116
Eigen::MRPd sigma_BN;
110117
sigma_BN = (Eigen::Vector3d)this->hubSigma->getState();
@@ -173,8 +180,8 @@ void FacetedSRPEffector::computeForceTorque(double callTime, double timeStep) {
173180
}
174181

175182
// Update the force and torque vectors in the dynamic effector base class
176-
this->forceExternal_B = totalSRPForcePntB_B;
177-
this->torqueExternalPntB_B = totalSRPTorquePntB_B;
183+
this->forceExternal_B = this->sunVisibilityFactor * totalSRPForcePntB_B;
184+
this->torqueExternalPntB_B = this->sunVisibilityFactor * totalSRPTorquePntB_B;
178185
}
179186

180187
/*! Setter method for the total number of spacecraft facets.

src/simulation/dynamics/facetedSRPEffector/facetedSRPEffector.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "architecture/_GeneralModuleFiles/sys_model.h"
2727
#include "architecture/utilities/bskLogging.h"
2828
#include "architecture/messaging/messaging.h"
29+
#include "architecture/msgPayloadDefC/EclipseMsgPayload.h"
2930
#include "architecture/msgPayloadDefC/FacetElementBodyMsgPayload.h"
3031
#include "architecture/msgPayloadDefC/ProjectedAreaMsgPayload.h"
3132
#include "architecture/msgPayloadDefC/SpicePlanetStateMsgPayload.h"
@@ -45,6 +46,7 @@ class FacetedSRPEffector: public SysModel, public DynamicEffector {
4546
std::vector<ReadFunctor<FacetElementBodyMsgPayload>> facetElementBodyInMsgs; //!< List of facet geometry input data (Expressed in hub B frame)
4647
std::vector<ReadFunctor<ProjectedAreaMsgPayload>> facetProjectedAreaInMsgs; //!< List of facet projected area input messages
4748
ReadFunctor<SpicePlanetStateMsgPayload> sunStateInMsg; //!< Sun spice ephemeris input message
49+
ReadFunctor<EclipseMsgPayload> sunEclipseInMsg; //!< (optional) Sun eclipse input message
4850

4951
private:
5052
/* Facet input message data */
@@ -58,6 +60,7 @@ class FacetedSRPEffector: public SysModel, public DynamicEffector {
5860
uint64_t numFacets{}; //!< Number of spacecraft facets
5961
StateData *hubPosition = nullptr; //!< [m] Hub inertial position vector
6062
StateData *hubSigma = nullptr; //!< Hub MRP inertial attitude
63+
double sunVisibilityFactor = 1.0; //!< Sun visibility factor (0 = full shadow, 1 = full sunlight)
6164
};
6265

6366
#endif

src/simulation/dynamics/facetedSRPEffector/facetedSRPEffector.i

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ struct ProjectedAreaMsg_C;
4848
%include "architecture/msgPayloadDefC/SpicePlanetStateMsgPayload.h"
4949
struct SpicePlanetStateMsg_C;
5050

51+
%include "architecture/msgPayloadDefC/EclipseMsgPayload.h"
52+
struct EclipseMsg_C;
53+
5154
%pythoncode %{
5255
import sys
5356
protectAllClasses(sys.modules[__name__])

src/simulation/dynamics/facetedSRPEffector/facetedSRPEffector.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ provides information on what each message is used for.
4848
* - facetProjectedAreaInMsgs
4949
- :ref:`ProjectedAreaMsgPayload`
5050
- Input message vector containing pre-computed per-facet projected areas
51+
* - sunEclipseInMsg
52+
- :ref:`EclipseMsgPayload`
53+
- (Optional) Input msg for the Sun eclipse data. If connected, the SRP force and torque are scaled by the illumination factor (0 = full shadow, 1 = full sunlight)
5154

5255

5356
Module Functions
@@ -77,13 +80,14 @@ The unit test for this module is located in :ref:`test_facetedSRPEffector`. The
7780
correctly computes the aggregate SRP force and torque acting on the spacecraft due to impinging photons
7881
from the Sun. The test sets up a simulation with a faceted spacecraft modeled as a cubic hub with two attached
7982
circular solar arrays. Six square facets represent the cubic hub and four circular facets represent the two solar
80-
arrays. The test varies the initial state information of both the spacecraft and the Sun. Specifically, the test
81-
parameterizes:
83+
arrays. The test varies the initial state information of the spacecraft, the initial state information of the Sun,
84+
and the Sun illumination factor. Specifically, the test parameterizes:
8285

8386
- Spacecraft initial inertial position
8487
- Sun inertial position
8588
- Spacecraft initial attitude
8689
- Spacecraft initial angular velocity
90+
- Sun visibility (illumination) factor
8791

8892
The test checks that the computed SRP forces and torques at each timestep match the values output from the module.
8993

@@ -193,6 +197,10 @@ The following steps are required to set up the ``facetedSRPEffector`` module in
193197
faceted_sc_projected_area.sunStateInMsg.subscribeTo(sun_state_message)
194198
faceted_sc_projected_area.spacecraftStateInMsg.subscribeTo(sc_object.scStateOutMsg)
195199

200+
#. Optionally, connect an eclipse message to account for shadow conditions. If connected, the computed SRP force and torque are scaled by the illumination factor (0.0 = full shadow, 1.0 = full sunlight)::
201+
202+
faceted_srp_effector.sunEclipseInMsg.subscribeTo(eclipse_msg)
203+
196204
#. Add the SRP effector to the spacecraft::
197205

198206
sc_object.addDynamicEffector(faceted_srp_effector)

0 commit comments

Comments
 (0)