Skip to content

Commit 1a42d0e

Browse files
Yumeka Naganoschaubh
authored andcommitted
Change THRSimConfig to shared pointer
1 parent 90694ab commit 1a42d0e

10 files changed

Lines changed: 119 additions & 68 deletions

File tree

examples/BskSim/models/BSK_Dynamics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def SetThrusterStateEffector(self):
192192
"""Set the 8 ACS thrusters."""
193193
# Make a fresh TH factory instance, this is critical to run multiple times
194194
thFactory = simIncludeThruster.thrusterFactory()
195+
self.thFactory = thFactory
195196

196197
# 8 thrusters are modeled that act in pairs to provide the desired torque
197198
thPos = [
@@ -221,7 +222,7 @@ def SetThrusterStateEffector(self):
221222
, dir_B
222223
)
223224
# create thruster object container and tie to spacecraft object
224-
thFactory.addToSpacecraft("ACS Thrusters",
225+
self.thFactory.addToSpacecraft("ACS Thrusters",
225226
self.thrustersDynamicEffector,
226227
self.scObject)
227228

src/simulation/dynamics/Thrusters/thrusterDynamicEffector/_UnitTest/test_ThrusterDynamicsUnit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,9 @@ def unitThrusters(testFixture, show_plots, ramp, thrustNumber, duration, long_an
419419
rampOffList.append(newElement)
420420

421421
# Set up the ramps
422-
thrusterSet.thrusterData[0].ThrusterOnRamp = \
422+
thruster1.ThrusterOnRamp = \
423423
thrusterDynamicEffector.ThrusterTimeVector(rampOnList)
424-
thrusterSet.thrusterData[0].ThrusterOffRamp = \
424+
thruster1.ThrusterOffRamp = \
425425
thrusterDynamicEffector.ThrusterTimeVector(rampOffList)
426426

427427
if rampDown == "OFF":

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

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ void ThrusterDynamicEffector::Reset(uint64_t CurrentSimNanos)
7272
void ThrusterDynamicEffector::writeOutputMessages(uint64_t CurrentClock)
7373
{
7474
int idx = 0;
75-
std::vector<THRSimConfig>::iterator it;
75+
std::vector<std::shared_ptr<THRSimConfig>>::iterator itp;
76+
std::shared_ptr<THRSimConfig> it;
7677

7778
THROutputMsgPayload tmpThruster;
78-
for (it = this->thrusterData.begin(); it != this->thrusterData.end(); ++it)
79+
for (itp = this->thrusterData.begin(); itp != this->thrusterData.end(); ++itp)
7980
{
81+
it = *itp;
8082
tmpThruster = this->thrusterOutMsgs[idx]->zeroMsgPayload;
8183
eigenVector3d2CArray(it->thrLoc_B, tmpThruster.thrusterLocation);
8284
eigenVector3d2CArray(it->thrDir_B, tmpThruster.thrusterDirection);
@@ -140,32 +142,32 @@ bool ThrusterDynamicEffector::ReadInputs()
140142
*/
141143
void ThrusterDynamicEffector::ConfigureThrustRequests(double currentTime)
142144
{
143-
std::vector<THRSimConfig>::iterator it;
144145
std::vector<double>::iterator CmdIt;
146+
size_t THIter = 0;
145147
// Iterate through the list of thruster commands that we read in.
146-
for(CmdIt = NewThrustCmds.begin(), it = this->thrusterData.begin();
147-
it != this->thrusterData.end(); it++, CmdIt++)
148+
for(CmdIt = NewThrustCmds.begin(); CmdIt != NewThrustCmds.end(); CmdIt++)
148149
{
149-
if(*CmdIt >= it->MinOnTime) // Check to see if we have met minimum for each thruster
150+
if(*CmdIt >= this->thrusterData[THIter]->MinOnTime) // Check to see if we have met minimum for each thruster
150151
{
151152
// For each case where we are above the minimum firing request, reset the thruster
152-
it->ThrustOps.ThrustOnCmd = *CmdIt;
153-
it->ThrustOps.fireCounter += it->ThrustOps.ThrustFactor > 0.0
153+
this->thrusterData[THIter]->ThrustOps.ThrustOnCmd = *CmdIt;
154+
this->thrusterData[THIter]->ThrustOps.fireCounter += this->thrusterData[THIter]->ThrustOps.ThrustFactor > 0.0
154155
? 0 : 1;
155156
}
156157
else
157158
{
158159
// Will ensure that thruster shuts down once this cmd expires
159-
it->ThrustOps.ThrustOnCmd = it->ThrustOps.ThrustFactor > 0.0
160+
this->thrusterData[THIter]->ThrustOps.ThrustOnCmd = this->thrusterData[THIter]->ThrustOps.ThrustFactor > 0.0
160161
? *CmdIt : 0.0;
161162
}
162-
it->ThrustOps.ThrusterStartTime = currentTime;
163-
it->ThrustOps.PreviousIterTime = currentTime;
164-
it->ThrustOps.ThrustOnRampTime = 0.0;
165-
it->ThrustOps.ThrustOnSteadyTime = 0.0;
166-
it->ThrustOps.ThrustOffRampTime = 0.0;
163+
this->thrusterData[THIter]->ThrustOps.ThrusterStartTime = currentTime;
164+
this->thrusterData[THIter]->ThrustOps.PreviousIterTime = currentTime;
165+
this->thrusterData[THIter]->ThrustOps.ThrustOnRampTime = 0.0;
166+
this->thrusterData[THIter]->ThrustOps.ThrustOnSteadyTime = 0.0;
167+
this->thrusterData[THIter]->ThrustOps.ThrustOffRampTime = 0.0;
167168
// After we have assigned the firing to the internal thruster, zero the command request.
168169
*CmdIt = 0.0;
170+
THIter++;
169171
}
170172

171173
}
@@ -233,7 +235,7 @@ void ThrusterDynamicEffector::linkInStates(DynParamManager& states){
233235

234236
for(const auto& thrusterConfig : this->thrusterData) {
235237
if (this->fuelMass < 0.0 &&
236-
(!thrusterConfig.thrBlowDownCoeff.empty() || !thrusterConfig.ispBlowDownCoeff.empty())) {
238+
(!thrusterConfig->thrBlowDownCoeff.empty() || !thrusterConfig->ispBlowDownCoeff.empty())) {
237239
bskLogger.bskLog(BSK_WARNING,"ThrusterDynamicEffector: blow down coefficients have been "
238240
"specified, but no fuel tank is attached.");
239241
}
@@ -274,13 +276,14 @@ void ThrusterDynamicEffector::computeForceTorque(double integTime, double timeSt
274276
axesWeightMatrix << 2, 0, 0, 0, 1, 0, 0, 0, 1;
275277

276278
// Loop variables
277-
std::vector<THRSimConfig>::iterator it;
279+
std::shared_ptr<THRSimConfig> it;
278280
THROperation* ops;
279281

280282
// Iterate through all of the thrusters to aggregate the force/torque in the system
281283
int index;
282-
for(it = this->thrusterData.begin(), index = 0; it != this->thrusterData.end(); it++, index++)
284+
for(index = 0; index < this->thrusterData.size(); ++index)
283285
{
286+
it = this->thrusterData[index];
284287
ops = &it->ThrustOps;
285288

286289
// Compute the thruster properties wrt the hub (note that B refers to the F frame when extracting from the thruster info)
@@ -289,23 +292,24 @@ void ThrusterDynamicEffector::computeForceTorque(double integTime, double timeSt
289292

290293
// If the connected fuel tank is subject to blow down effects, update them here
291294
if (this->fuelMass >= 0.0 && (!it->thrBlowDownCoeff.empty() || !it->ispBlowDownCoeff.empty())) {
292-
this->computeBlowDownDecay(&(*it));
295+
this->computeBlowDownDecay(it);
293296
}
294297

295298
// For each thruster see if the on-time is still valid and if so, call ComputeThrusterFire()
296299
if((ops->ThrustOnCmd + ops->ThrusterStartTime - integTime) >= -dt*10E-10 &&
297300
ops->ThrustOnCmd > 0.0)
298301
{
299-
ComputeThrusterFire(&(*it), integTime);
302+
ComputeThrusterFire(it, integTime);
300303
}
301304
// If we are not actively firing, continue shutdown process for active thrusters
302305
else if(ops->ThrustFactor > 0.0)
303306
{
304-
ComputeThrusterShut(&(*it), integTime);
307+
ComputeThrusterShut(it, integTime);
305308
}
306309

307310
// For each thruster, aggregate the current thrust direction into composite body force
308311
tmpThrustMag = it->MaxThrust * ops->ThrustFactor * ops->thrustBlowDownFactor;
312+
309313
// Apply dispersion to magnitude
310314
tmpThrustMag *= (1. + it->thrusterMagDisp);
311315
SingleThrusterForce = tmpThrustMag * thrustDirection_B;
@@ -351,9 +355,9 @@ void ThrusterDynamicEffector::computeForceTorque(double integTime, double timeSt
351355
352356
@param newThruster thruster sim config(s)
353357
*/
354-
void ThrusterDynamicEffector::addThruster(THRSimConfig* newThruster)
358+
void ThrusterDynamicEffector::addThruster(std::shared_ptr<THRSimConfig> newThruster)
355359
{
356-
this->thrusterData.push_back(*newThruster);
360+
this->thrusterData.push_back(newThruster);
357361

358362
// Create corresponding output message
359363
Message<THROutputMsgPayload>* msg;
@@ -377,9 +381,9 @@ void ThrusterDynamicEffector::addThruster(THRSimConfig* newThruster)
377381
@param newThruster thruster sim config(s)
378382
@param bodyStateMsg body states to which thruster(s) are attached
379383
*/
380-
void ThrusterDynamicEffector::addThruster(THRSimConfig* newThruster, Message<SCStatesMsgPayload>* bodyStateMsg)
384+
void ThrusterDynamicEffector::addThruster(std::shared_ptr<THRSimConfig> newThruster, Message<SCStatesMsgPayload>* bodyStateMsg)
381385
{
382-
this->thrusterData.push_back(*newThruster);
386+
this->thrusterData.push_back(newThruster);
383387

384388
// Create corresponding output message
385389
Message<THROutputMsgPayload>* msg;
@@ -405,7 +409,7 @@ void ThrusterDynamicEffector::addThruster(THRSimConfig* newThruster, Message<SCS
405409
* tank subject to blow down effects.
406410
407411
*/
408-
void ThrusterDynamicEffector::computeBlowDownDecay(THRSimConfig *currentThruster)
412+
void ThrusterDynamicEffector::computeBlowDownDecay(std::shared_ptr<THRSimConfig> currentThruster)
409413
{
410414
THROperation *ops = &(currentThruster->ThrustOps);
411415

@@ -435,14 +439,16 @@ void ThrusterDynamicEffector::computeBlowDownDecay(THRSimConfig *currentThruster
435439
/*! This method computes contributions to the fuel mass depletion. */
436440
void ThrusterDynamicEffector::computeStateContribution(double integTime){
437441

438-
std::vector<THRSimConfig>::iterator it;
442+
std::vector<std::shared_ptr<THRSimConfig>>::iterator itp;
443+
std::shared_ptr<THRSimConfig> it;
439444
THROperation *ops;
440445
double mDotSingle=0.0;
441446
this->mDotTotal = 0.0;
442447
this->stateDerivContribution.setZero();
443448
// Iterate through all of the thrusters to aggregate the force/torque in the system
444-
for(it = this->thrusterData.begin(); it != this->thrusterData.end(); it++)
449+
for(itp = this->thrusterData.begin(); itp != this->thrusterData.end(); itp++)
445450
{
451+
it = *itp;
446452
ops = &it->ThrustOps;
447453
mDotSingle = 0.0;
448454
if(it->steadyIsp * ops->IspFactor * ops->ispBlowDownFactor > 0.0)
@@ -464,7 +470,7 @@ void ThrusterDynamicEffector::computeStateContribution(double integTime){
464470
@param CurrentThruster Pointer to the configuration data for a given thruster
465471
@param currentTime The current simulation clock time converted to a double
466472
*/
467-
void ThrusterDynamicEffector::ComputeThrusterFire(THRSimConfig *CurrentThruster,
473+
void ThrusterDynamicEffector::ComputeThrusterFire(std::shared_ptr<THRSimConfig> CurrentThruster,
468474
double currentTime)
469475
{
470476
std::vector<THRTimePair>::iterator it;
@@ -523,7 +529,7 @@ void ThrusterDynamicEffector::ComputeThrusterFire(THRSimConfig *CurrentThruster,
523529
@param CurrentThruster Pointer to the configuration data for a given thruster
524530
@param currentTime The current simulation clock time converted to a double
525531
*/
526-
void ThrusterDynamicEffector::ComputeThrusterShut(THRSimConfig *CurrentThruster,
532+
void ThrusterDynamicEffector::ComputeThrusterShut(std::shared_ptr<THRSimConfig> CurrentThruster,
527533
double currentTime)
528534
{
529535
std::vector<THRTimePair>::iterator it;
@@ -576,7 +582,7 @@ void ThrusterDynamicEffector::ComputeThrusterShut(THRSimConfig *CurrentThruster,
576582
@param thrData The data for the thruster that we are currently firing
577583
@param thrRamp This just allows us to avoid switching to figure out which ramp
578584
*/
579-
double ThrusterDynamicEffector::thrFactorToTime(THRSimConfig *thrData,
585+
double ThrusterDynamicEffector::thrFactorToTime(std::shared_ptr<THRSimConfig> thrData,
580586
std::vector<THRTimePair> *thrRamp)
581587
{
582588
std::vector<THRTimePair>::iterator it;

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,28 @@ class ThrusterDynamicEffector: public SysModel, public DynamicEffector {
4949
void computeForceTorque(double integTime, double timeStep);
5050
void computeStateContribution(double integTime);
5151
void Reset(uint64_t CurrentSimNanos);
52-
void addThruster(THRSimConfig* newThruster);
53-
void addThruster(THRSimConfig* newThruster, Message<SCStatesMsgPayload>* bodyStateMsg);
52+
void addThruster(std::shared_ptr<THRSimConfig> newThruster);
53+
void addThruster(std::shared_ptr<THRSimConfig> newThruster, Message<SCStatesMsgPayload>* bodyStateMsg);
5454
void UpdateState(uint64_t CurrentSimNanos);
5555
void writeOutputMessages(uint64_t CurrentClock);
5656
bool ReadInputs();
5757
void ConfigureThrustRequests(double currentTime);
58-
void ComputeThrusterFire(THRSimConfig *CurrentThruster, double currentTime);
59-
void ComputeThrusterShut(THRSimConfig *CurrentThruster, double currentTime);
58+
void ComputeThrusterFire(std::shared_ptr<THRSimConfig> CurrentThruster, double currentTime);
59+
void ComputeThrusterShut(std::shared_ptr<THRSimConfig> CurrentThruster, double currentTime);
6060
void UpdateThrusterProperties();
61-
void computeBlowDownDecay(THRSimConfig *CurrentThruster);
61+
void computeBlowDownDecay(std::shared_ptr<THRSimConfig> CurrentThruster);
6262

6363
public:
6464
ReadFunctor<THRArrayOnTimeCmdMsgPayload> cmdsInMsg; //!< -- input message with thruster commands
6565
std::vector<Message<THROutputMsgPayload>*> thrusterOutMsgs; //!< -- output message vector for thruster data
6666

6767
int stepsInRamp; //!< class variable
68-
std::vector<THRSimConfig> thrusterData; //!< -- Thruster information
68+
std::vector<std::shared_ptr<THRSimConfig>> thrusterData; //!< -- Thruster information
6969
std::vector<double> NewThrustCmds; //!< -- Incoming thrust commands
7070
double mDotTotal; //!< kg/s Current mass flow rate of thrusters
7171
double fuelMass; //!< kg Current total fuel mass of connected fuel tank
7272
double prevFireTime; //!< s Previous thruster firing time
73-
double thrFactorToTime(THRSimConfig *thrData,
73+
double thrFactorToTime(std::shared_ptr<THRSimConfig> thrData,
7474
std::vector<THRTimePair> *thrRamp);
7575
StateData *hubSigma; //!< pointer to the hub attitude states
7676
StateData *hubOmega; //!< pointer to the hub angular velocity states

src/simulation/dynamics/Thrusters/thrusterDynamicEffector/thrusterDynamicEffector.i

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@ namespace std {
4343
%include "thrusterDynamicEffector.h"
4444

4545
%include "simulation/dynamics/_GeneralModuleFiles/THRTimePair.h"
46-
%include "simulation/dynamics/_GeneralModuleFiles/THRSimConfig.h"
46+
%import "simulation/dynamics/_GeneralModuleFiles/THRSimConfig.i"
4747

4848
%include "architecture/msgPayloadDefC/THRArrayOnTimeCmdMsgPayload.h"
4949
struct THRArrayOnTimeCmdMsg_C;
5050
%include "architecture/msgPayloadDefCpp/THROutputMsgPayload.h"
5151
%include "architecture/msgPayloadDefC/SCStatesMsgPayload.h"
5252
struct SCStatesMsg_C;
5353

54+
%pythoncode %{
55+
from Basilisk.simulation.THRSimConfig import THRSimConfig as THRSimConfig
56+
%}
57+
5458
%pythoncode %{
5559
import sys
5660
protectAllClasses(sys.modules[__name__])

0 commit comments

Comments
 (0)