Skip to content

Commit 0027bae

Browse files
committed
Add eclipse checking in spacecraftLocation
1 parent 67f27e2 commit 0027bae

6 files changed

Lines changed: 37 additions & 8 deletions

File tree

docs/source/Support/bskReleaseNotes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Version |release|
3535
- Deprecated :ref:`SpacecraftSystem`. It was never completed and we have other ways to connect spacecraft components
3636
- Allow event conditions and effects to be defined by functions. This is preferred over the old string-based method, as it
3737
enables the use of arbitrary packages and objects in events and allows for event code to be parsed by IDE tools.
38-
- Add a sun message input and ``theta_solar`` threshold to :ref:`SpacecraftLocation`.
38+
- Add a sun message input and ``theta_solar`` threshold to :ref:`SpacecraftLocation`. Also supports including an eclipse message to determine illumination.
3939

4040

4141
Version 2.7.0 (April 20, 2025)

src/architecture/msgPayloadDefC/EclipseMsgPayload.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
//!@brief Eclipse shadow factor message definition.
2525
typedef struct {
26-
double shadowFactor; //!< Proportion of shadowing due to eclipse
26+
double shadowFactor; //!< Proportion of illumination due to eclipse. 0 = fully shadowed, 1 = fully illuminated.
2727
}EclipseMsgPayload;
2828

2929

src/simulation/environment/spacecraftLocation/spacecraftLocation.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ SpacecraftLocation::SpacecraftLocation()
3636
this->aHat_B.fill(0.0);
3737
this->theta = -1.0;
3838
this->theta_solar = -1.0;
39+
this->min_shadow_factor = -1.0;
3940

4041
this->planetState = this->planetInMsg.zeroMsgPayload;
4142
this->planetState.J20002Pfix[0][0] = 1;
@@ -85,7 +86,7 @@ SpacecraftLocation::Reset(uint64_t CurrentSimNanos)
8586
}
8687

8788
if (this->theta_solar >= 0.0) {
88-
if (this->aHat_B.norm() < 0.001){
89+
if (this->aHat_B.norm() < 0.001) {
8990
bskLogger.bskLog(BSK_ERROR, "SpacecraftLocation must set aHat_B if you specify theta_solar");
9091
}
9192
}
@@ -152,11 +153,20 @@ SpacecraftLocation::ReadMessages()
152153
sunRead = this->sunInMsg.isWritten();
153154
this->sunData = this->sunInMsg();
154155
} else {
155-
sunRead = false;
156156
this->r_HN_N.setZero();
157157
}
158158

159-
return (planetRead && scRead && sunRead);
159+
//! - Zero eclipse information
160+
this->eclipseInMsgData = eclipseInMsg.zeroMsgPayload;
161+
162+
bool eclipseRead = true;
163+
if (this->eclipseInMsg.isLinked()) {
164+
eclipseRead = this->eclipseInMsg.isWritten();
165+
this->eclipseInMsgData = this->eclipseInMsg();
166+
}
167+
168+
169+
return (planetRead && scRead && sunRead && eclipseRead);
160170
}
161171

162172
/*! write module messages
@@ -269,6 +279,14 @@ SpacecraftLocation::computeAccess()
269279
this->accessMsgBuffer.at(c).hasIllumination = 0;
270280
}
271281
}
282+
283+
// Check if eclipse is valid
284+
if (this->eclipseInMsg.isLinked() and this->min_shadow_factor > 0.0) {
285+
if (eclipseInMsgData.shadowFactor < this->min_shadow_factor) {
286+
this->accessMsgBuffer.at(c).hasAccess = 0;
287+
this->accessMsgBuffer.at(c).hasIllumination = 0;
288+
}
289+
}
272290
}
273291
}
274292
}

src/simulation/environment/spacecraftLocation/spacecraftLocation.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "architecture/messaging/messaging.h"
2929
#include "architecture/msgPayloadDefC/AccessMsgPayload.h"
30+
#include "architecture/msgPayloadDefC/EclipseMsgPayload.h"
3031
#include "architecture/msgPayloadDefC/SCStatesMsgPayload.h"
3132
#include "architecture/msgPayloadDefC/SpicePlanetStateMsgPayload.h"
3233

@@ -55,10 +56,12 @@ class SpacecraftLocation : public SysModel
5556
Eigen::Vector3d aHat_B; //!< [] (optional) unit direction vector of the sensor/communication boresight axis
5657
double theta; //!< [r] (optional) sensor/communication half-cone angle, must be set if shat_B is specified
5758
double theta_solar; //!< [r] (optional) illumination half-cone angle, treating aHat_B as the surface normal
59+
double min_shadow_factor; //!< [] (optional) minimum amount of illumination due to eclipse necessary to observe
5860

5961
ReadFunctor<SCStatesMsgPayload> primaryScStateInMsg; //!< primary spacecraft input message
60-
ReadFunctor<SpicePlanetStateMsgPayload> planetInMsg; //!< planet state input message
61-
ReadFunctor<SpicePlanetStateMsgPayload> sunInMsg; //!< [-] sun data input message
62+
ReadFunctor<SpicePlanetStateMsgPayload> planetInMsg; //!< (optional) planet state input message
63+
ReadFunctor<SpicePlanetStateMsgPayload> sunInMsg; //!< (optional) sun data input message
64+
ReadFunctor<EclipseMsgPayload> eclipseInMsg; //!< (optional) eclipse input message
6265
std::vector<Message<AccessMsgPayload>*> accessOutMsgs; //!< vector of ground location access messages
6366
std::vector<ReadFunctor<SCStatesMsgPayload>> scStateInMsgs; //!< vector of other sc state input messages
6467
Eigen::Vector3d
@@ -72,6 +75,7 @@ class SpacecraftLocation : public SysModel
7275
SCStatesMsgPayload primaryScStatesBuffer; //!< buffer of primary spacecraft states
7376
SpicePlanetStateMsgPayload planetState; //!< buffer of planet data
7477
SpicePlanetStateMsgPayload sunData; //!< buffer of sun data
78+
EclipseMsgPayload eclipseInMsgData; //!< buffer of eclipse data
7579

7680
Eigen::Matrix3d dcm_PN; //!< Rotation matrix from inertial frame N to planet-centered to planet-fixed frame P
7781
Eigen::Vector3d r_PN_N; //!< [m] Planet to inertial frame origin vector.

src/simulation/environment/spacecraftLocation/spacecraftLocation.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ struct SpicePlanetStateMsg_C;
4040
struct SCStatesMsg_C;
4141
%include "architecture/msgPayloadDefC/AccessMsgPayload.h"
4242
struct AccessMsg_C;
43+
%include "architecture/msgPayloadDefC/EclipseMsgPayload.h"
44+
struct EclipseMsg_C;
4345

4446
%pythoncode %{
4547
import sys

src/simulation/environment/spacecraftLocation/spacecraftLocation.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ provides information on what this message is used for.
3838
- vector of other spacecraft state input messages. These are set through ``addSpacecraftToModel()``
3939
* - sunInMsg
4040
- :ref:`SpicePlanetStateMsgPayload`
41-
- (optional) sun state input message. Used for illumination checking if the message is connected and `theta_solar` is set.
41+
- (optional) sun state input message. Used for illumination checking if the message is connected and ``theta_solar`` is set.
42+
* - eclipseInMsg
43+
- :ref:`EclipseMsgPayload`
44+
- (optional) eclipse input message. Used for illumination checking if the message is connected and ``min_shadow_factor`` is set.
4245
* - accessOutMsgs
4346
- :ref:`AccessMsgPayload`
4447
- output vector of ground location access messages
@@ -120,6 +123,8 @@ If the ``sunInMsg`` is connected and :math:`\theta_{\text{solar,max}}` is set, t
120123
.. math::
121124
\arccos \left( \hat{\bf a} \cdot \hat{\bf s} \right) = \theta_{\text{solar}} \le \theta_{\text{solar,max}}
122125
126+
If an eclipse message is connected and ``min_shadow_factor`` is set, the module will also check that the shadow factor is above this threshold.
127+
123128
User Guide
124129
----------
125130
A new instance of ``spacecraftLocation``, alongside necessary user-supplied parameters, can be created by calling:

0 commit comments

Comments
 (0)