Skip to content

Commit 4d19378

Browse files
committed
add branching capabilities to thrusterDynamicEffector
1 parent a8f74ae commit 4d19378

File tree

3 files changed

+67
-9
lines changed

3 files changed

+67
-9
lines changed

src/simulation/dynamics/Thrusters/thrusterDynamicEffector/thrusterDynamicEffector.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,19 @@ void ThrusterDynamicEffector::ConfigureThrustRequests(double currentTime)
180180
void ThrusterDynamicEffector::UpdateThrusterProperties()
181181
{
182182
// Save hub variables
183-
Eigen::Vector3d r_BN_N = (Eigen::Vector3d)*this->inertialPositionProperty;
184-
Eigen::Vector3d omega_BN_B = this->hubOmega->getState();
185183
Eigen::MRPd sigma_BN;
186-
sigma_BN = (Eigen::Vector3d)this->hubSigma->getState();
184+
Eigen::Vector3d omega_BN_B;
185+
if (!this->stateNameOfSigma.empty()) {
186+
omega_BN_B = this->hubOmega->getState();
187+
sigma_BN = (Eigen::Vector3d)this->hubSigma->getState();
188+
}
189+
else {
190+
omega_BN_B = *this->inertialAngVelocityProperty;
191+
sigma_BN = (Eigen::Vector3d)*this->inertialAttitudeProperty;
192+
}
193+
187194
Eigen::Matrix3d dcm_BN = (sigma_BN.toRotationMatrix()).transpose();
195+
Eigen::Vector3d r_BN_N = (Eigen::Vector3d)*this->inertialPositionProperty;
188196

189197
// Define the variables related to which body the thruster is attached to. The F frame represents the platform body where the thruster attaches to
190198
Eigen::MRPd sigma_FN;
@@ -242,6 +250,16 @@ void ThrusterDynamicEffector::linkInStates(DynParamManager& states){
242250
}
243251
}
244252

253+
/*! This method is used to link properties to the thrusters
254+
@return void
255+
@param properties The parameter manager to collect from
256+
*/
257+
void ThrusterDynamicEffector::linkInProperties(DynParamManager& properties){
258+
this->inertialAttitudeProperty = properties.getPropertyReference(this->propName_inertialAttitude);
259+
this->inertialAngVelocityProperty = properties.getPropertyReference(this->propName_inertialAngVelocity);
260+
this->inertialPositionProperty = properties.getPropertyReference(this->propName_inertialPosition);
261+
}
262+
245263
/*! This method computes the Forces on Torque on the Spacecraft Body.
246264
247265
@param integTime Integration time
@@ -250,7 +268,13 @@ void ThrusterDynamicEffector::linkInStates(DynParamManager& states){
250268
void ThrusterDynamicEffector::computeForceTorque(double integTime, double timeStep)
251269
{
252270
// Save omega_BN_B
253-
Eigen::Vector3d omegaLocal_BN_B = this->hubOmega->getState();
271+
Eigen::Vector3d omegaLocal_BN_B;
272+
if (!this->stateNameOfSigma.empty()) {
273+
omegaLocal_BN_B = this->hubOmega->getState();
274+
}
275+
else {
276+
omegaLocal_BN_B = *this->inertialAngVelocityProperty;
277+
}
254278

255279
// Force and torque variables
256280
Eigen::Vector3d SingleThrusterForce;

src/simulation/dynamics/Thrusters/thrusterDynamicEffector/thrusterDynamicEffector.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ class ThrusterDynamicEffector: public SysModel, public DynamicEffector {
4545
public:
4646
ThrusterDynamicEffector();
4747
~ThrusterDynamicEffector();
48-
void linkInStates(DynParamManager& states);
49-
void computeForceTorque(double integTime, double timeStep);
50-
void computeStateContribution(double integTime);
51-
void Reset(uint64_t CurrentSimNanos);
48+
void linkInStates(DynParamManager& states) override;
49+
void linkInProperties(DynParamManager& properties) override;
50+
void computeForceTorque(double integTime, double timeStep) override;
51+
void computeStateContribution(double integTime) override;
52+
void Reset(uint64_t CurrentSimNanos) override;
5253
void addThruster(std::shared_ptr<THRSimConfig> newThruster);
5354
void addThruster(std::shared_ptr<THRSimConfig> newThruster, Message<SCStatesMsgPayload>* bodyStateMsg);
54-
void UpdateState(uint64_t CurrentSimNanos);
55+
void UpdateState(uint64_t CurrentSimNanos) override;
5556
void writeOutputMessages(uint64_t CurrentClock);
5657
bool ReadInputs();
5758
void ConfigureThrustRequests(double currentTime);
@@ -75,6 +76,8 @@ class ThrusterDynamicEffector: public SysModel, public DynamicEffector {
7576
StateData *hubSigma; //!< pointer to the hub attitude states
7677
StateData *hubOmega; //!< pointer to the hub angular velocity states
7778
Eigen::MatrixXd* inertialPositionProperty; //!< [m] r_N inertial position relative to system spice zeroBase/refBase
79+
Eigen::MatrixXd* inertialAttitudeProperty; //!< attitude relative to inertial frame
80+
Eigen::MatrixXd* inertialAngVelocityProperty; //!< [rad/s] inertial angular velocity relative to inertial frame
7881

7982
BSKLogger bskLogger; //!< -- BSK Logging
8083

src/utilities/simIncludeThruster.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,37 @@ def addToSpacecraft(self, modelTag, thEffector, sc):
236236

237237
return
238238

239+
def addToSpacecraftSubcomponent(self, modelTag, thEffector, baseEffector, segment=0):
240+
"""
241+
This function is for adding a thruster cluster to intermediate bodies
242+
243+
Parameters
244+
----------
245+
modelTag: string
246+
module model tag string
247+
thEffector: thrusterEffector
248+
thruster effector handle
249+
baseEffector: intermediate body to be attached to, see table for compatibility guide
250+
segment: if subcomponent is multi-body, designate which integer segment
251+
default segment to base segment
252+
"""
253+
254+
thEffector.ModelTag = modelTag
255+
256+
for key, th in list(self.thrusterList.items()):
257+
thEffector.addThruster(th)
258+
259+
# Check the type of thruster effector
260+
thrusterType = str(type(thEffector))
261+
if 'ThrusterDynamicEffector' in thrusterType:
262+
baseEffector.addDynamicEffector(thEffector, segment)
263+
elif 'ThrusterStateEffector' in thrusterType:
264+
baseEffector.addStateEffector(thEffector, segment)
265+
else:
266+
print("This isn't a thruster effector. You did something wrong.")
267+
268+
return
269+
239270
def getNumOfDevices(self):
240271
"""
241272
Returns the number of RW devices setup.

0 commit comments

Comments
 (0)