@@ -56,6 +56,14 @@ SpinningBodyTwoDOFStateEffector::SpinningBodyTwoDOFStateEffector()
56
56
this ->nameOfTheta1DotState = " spinningBodyTheta1Dot" + std::to_string (SpinningBodyTwoDOFStateEffector::effectorID);
57
57
this ->nameOfTheta2State = " spinningBodyTheta2" + std::to_string (SpinningBodyTwoDOFStateEffector::effectorID);
58
58
this ->nameOfTheta2DotState = " spinningBodyTheta2Dot" + std::to_string (SpinningBodyTwoDOFStateEffector::effectorID);
59
+ this ->nameOfInertialPositionProperty1 = " spinningBodyInertialPosition1" + std::to_string (SpinningBodyTwoDOFStateEffector::effectorID);
60
+ this ->nameOfInertialVelocityProperty1 = " spinningBodyInertialVelocity1" + std::to_string (SpinningBodyTwoDOFStateEffector::effectorID);
61
+ this ->nameOfInertialAttitudeProperty1 = " spinningBodyInertialAttitude1" + std::to_string (SpinningBodyTwoDOFStateEffector::effectorID);
62
+ this ->nameOfInertialAngVelocityProperty1 = " spinningBodyInertialAngVelocity1" + std::to_string (SpinningBodyTwoDOFStateEffector::effectorID);
63
+ this ->nameOfInertialPositionProperty2 = " spinningBodyInertialPosition2" + std::to_string (SpinningBodyTwoDOFStateEffector::effectorID);
64
+ this ->nameOfInertialVelocityProperty2 = " spinningBodyInertialVelocity2" + std::to_string (SpinningBodyTwoDOFStateEffector::effectorID);
65
+ this ->nameOfInertialAttitudeProperty2 = " spinningBodyInertialAttitude2" + std::to_string (SpinningBodyTwoDOFStateEffector::effectorID);
66
+ this ->nameOfInertialAngVelocityProperty2 = " spinningBodyInertialAngVelocity2" + std::to_string (SpinningBodyTwoDOFStateEffector::effectorID);
59
67
SpinningBodyTwoDOFStateEffector::effectorID++;
60
68
}
61
69
@@ -111,10 +119,10 @@ void SpinningBodyTwoDOFStateEffector::writeOutputStateMessages(uint64_t CurrentC
111
119
configLogMsg = this ->spinningBodyConfigLogOutMsgs [0 ]->zeroMsgPayload ;
112
120
113
121
// Logging the S frame is the body frame B of that object
114
- eigenVector3d2CArray ( this ->r_Sc1N_N , configLogMsg.r_BN_N );
115
- eigenVector3d2CArray ( this ->v_Sc1N_N , configLogMsg.v_BN_N );
116
- eigenVector3d2CArray ( this ->sigma_S1N , configLogMsg.sigma_BN );
117
- eigenVector3d2CArray ( this ->omega_S1N_S1 , configLogMsg.omega_BN_B );
122
+ eigenMatrixXd2CArray ((* this ->r_Sc1N_N ) , configLogMsg.r_BN_N );
123
+ eigenMatrixXd2CArray ((* this ->v_Sc1N_N ) , configLogMsg.v_BN_N );
124
+ eigenMatrixXd2CArray ((* this ->sigma_S1N ) , configLogMsg.sigma_BN );
125
+ eigenMatrixXd2CArray ((* this ->omega_S1N_S1 ) , configLogMsg.omega_BN_B );
118
126
this ->spinningBodyConfigLogOutMsgs [0 ]->write (&configLogMsg, this ->moduleID , CurrentClock);
119
127
}
120
128
@@ -123,10 +131,10 @@ void SpinningBodyTwoDOFStateEffector::writeOutputStateMessages(uint64_t CurrentC
123
131
configLogMsg = this ->spinningBodyConfigLogOutMsgs [1 ]->zeroMsgPayload ;
124
132
125
133
// Logging the S frame is the body frame B of that object
126
- eigenVector3d2CArray ( this ->r_Sc2N_N , configLogMsg.r_BN_N );
127
- eigenVector3d2CArray ( this ->v_Sc2N_N , configLogMsg.v_BN_N );
128
- eigenVector3d2CArray ( this ->sigma_S2N , configLogMsg.sigma_BN );
129
- eigenVector3d2CArray ( this ->omega_S2N_S2 , configLogMsg.omega_BN_B );
134
+ eigenMatrixXd2CArray (* this ->r_Sc2N_N , configLogMsg.r_BN_N );
135
+ eigenMatrixXd2CArray (* this ->v_Sc2N_N , configLogMsg.v_BN_N );
136
+ eigenMatrixXd2CArray (* this ->sigma_S2N , configLogMsg.sigma_BN );
137
+ eigenMatrixXd2CArray (* this ->omega_S2N_S2 , configLogMsg.omega_BN_B );
130
138
this ->spinningBodyConfigLogOutMsgs [1 ]->write (&configLogMsg, this ->moduleID , CurrentClock);
131
139
}
132
140
}
@@ -167,6 +175,35 @@ void SpinningBodyTwoDOFStateEffector::registerStates(DynParamManager& states)
167
175
thetaDotInitMatrix (1 ,0 ) = this ->theta2DotInit ;
168
176
this ->theta1DotState ->setState (thetaDotInitMatrix.row (0 ));
169
177
this ->theta2DotState ->setState (thetaDotInitMatrix.row (1 ));
178
+
179
+ registerProperties (states);
180
+ }
181
+
182
+ void SpinningBodyTwoDOFStateEffector::addDynamicEffector (DynamicEffector *newDynamicEffector, int segment)
183
+ {
184
+ this ->assignStateParamNames <DynamicEffector *>(newDynamicEffector, segment);
185
+
186
+ this ->dynEffectors .push_back (newDynamicEffector);
187
+ }
188
+
189
+ void SpinningBodyTwoDOFStateEffector::registerProperties (DynParamManager& states)
190
+ {
191
+ Eigen::Vector3d stateInit = Eigen::Vector3d::Zero ();
192
+ this ->r_Sc1N_N = states.createProperty (this ->nameOfInertialPositionProperty1 , stateInit);
193
+ this ->v_Sc1N_N = states.createProperty (this ->nameOfInertialVelocityProperty1 , stateInit);
194
+ this ->sigma_S1N = states.createProperty (this ->nameOfInertialAttitudeProperty1 , stateInit);
195
+ this ->omega_S1N_S1 = states.createProperty (this ->nameOfInertialAngVelocityProperty1 , stateInit);
196
+
197
+ this ->r_Sc2N_N = states.createProperty (this ->nameOfInertialPositionProperty2 , stateInit);
198
+ this ->v_Sc2N_N = states.createProperty (this ->nameOfInertialVelocityProperty2 , stateInit);
199
+ this ->sigma_S2N = states.createProperty (this ->nameOfInertialAttitudeProperty2 , stateInit);
200
+ this ->omega_S2N_S2 = states.createProperty (this ->nameOfInertialAngVelocityProperty2 , stateInit);
201
+
202
+ std::vector<DynamicEffector*>::iterator dynIt;
203
+ for (dynIt = this ->dynEffectors .begin (); dynIt != this ->dynEffectors .end (); dynIt++)
204
+ {
205
+ (*dynIt)->linkInProperties (states);
206
+ }
170
207
}
171
208
172
209
/* ! This method allows the SB state effector to provide its contributions to the mass props and mass prop rates of the
@@ -271,6 +308,26 @@ void SpinningBodyTwoDOFStateEffector::updateContributions(double integTime, Back
271
308
gLocal_N = g_N;
272
309
g_B = this ->dcm_BN * gLocal_N ;
273
310
311
+ // Loop through to collect forces and torques from any connected dynamic effectors
312
+ Eigen::Vector3d attBodyForce_S1 = Eigen::Vector3d::Zero ();
313
+ Eigen::Vector3d attBodyTorquePntS1_S1 = Eigen::Vector3d::Zero ();
314
+ Eigen::Vector3d attBodyForce_S2 = Eigen::Vector3d::Zero ();
315
+ Eigen::Vector3d attBodyTorquePntS2_S2 = Eigen::Vector3d::Zero ();
316
+ std::vector<DynamicEffector*>::iterator dynIt;
317
+ for (dynIt = this ->dynEffectors .begin (); dynIt != this ->dynEffectors .end (); dynIt++)
318
+ {
319
+ // - Compute the force and torque contributions from the dynamicEffectors
320
+ (*dynIt)->computeForceTorque (integTime, double (0.0 ));
321
+ if ((*dynIt)->getPropName_inertialPosition () == this ->nameOfInertialPositionProperty1 ) {
322
+ attBodyForce_S1 += (*dynIt)->forceExternal_B ;
323
+ attBodyTorquePntS1_S1 += (*dynIt)->torqueExternalPntB_B ;
324
+ }
325
+ else if ((*dynIt)->getPropName_inertialPosition () == this ->nameOfInertialPositionProperty2 ) {
326
+ attBodyForce_S2 += (*dynIt)->forceExternal_B ;
327
+ attBodyTorquePntS2_S2 += (*dynIt)->torqueExternalPntB_B ;
328
+ }
329
+ }
330
+
274
331
// Update omega_BN_B
275
332
this ->omega_BN_B = omega_BN_B;
276
333
this ->omegaTilde_BN_B = eigenTilde (this ->omega_BN_B );
@@ -334,12 +391,15 @@ void SpinningBodyTwoDOFStateEffector::updateContributions(double integTime, Back
334
391
+ this ->mass1 * (rTilde_Sc1S1_B * this ->omegaTilde_S1B_B + this ->omegaTilde_BN_B * rTilde_Sc1S1_B) * this ->rPrime_Sc1S1_B
335
392
+ this ->mass2 * (rTilde_Sc2S1_B * this ->omegaTilde_S1B_B + this ->omegaTilde_BN_B * rTilde_Sc2S1_B) * this ->rPrime_Sc2S1_B
336
393
+ this ->mass2 * rTilde_Sc2S1_B * omegaTilde_S2S1_B * this ->rPrime_Sc2S2_B
337
- + this ->mass * rTilde_ScS1_B * this ->omegaTilde_BN_B * rDot_S1B_B);
394
+ + this ->mass * rTilde_ScS1_B * this ->omegaTilde_BN_B * rDot_S1B_B
395
+ - this ->dcm_BS1 * attBodyTorquePntS1_S1 + this ->dcm_BS2 * attBodyTorquePntS2_S2
396
+ - eigenTilde (this ->r_S2S1_B ) * (this ->dcm_BS2 * attBodyForce_S2));
338
397
CThetaStar (1 , 0 ) = this ->u2 - this ->k2 * (this ->theta2 - this ->theta2Ref )
339
398
- this ->c2 * (this ->theta2Dot - this ->theta2DotRef ) + this ->s2Hat_B .transpose () * gravityTorquePntS2_B
340
399
- this ->s2Hat_B .transpose () * ((IPrimeS2PntS2_B + this ->omegaTilde_BN_B * IS2PntS2_B) * this ->omega_S2N_B
341
400
+ IS2PntS2_B * this ->omegaTilde_S1B_B * this ->omega_S2S1_B + this ->mass2 * rTilde_Sc2S2_B * omegaTilde_S1N_B * this ->rPrime_S2S1_B
342
- + this ->mass2 * rTilde_Sc2S2_B * this ->omegaTilde_BN_B * (rDot_S2S1_B + rDot_S1B_B));
401
+ + this ->mass2 * rTilde_Sc2S2_B * this ->omegaTilde_BN_B * (rDot_S2S1_B + rDot_S1B_B)
402
+ - this ->dcm_BS2 * attBodyTorquePntS2_S2);
343
403
344
404
// Check if any of the axis are locked and change dynamics accordingly
345
405
if (this ->lockFlag1 == 1 || this ->lockFlag2 == 1 )
@@ -373,7 +433,8 @@ void SpinningBodyTwoDOFStateEffector::updateContributions(double integTime, Back
373
433
backSubContr.matrixA = - this ->mass * rTilde_ScS1_B * this ->s1Hat_B * this ->ATheta .row (0 ) - this ->mass2 * rTilde_Sc2S2_B * this ->s2Hat_B * this ->ATheta .row (1 );
374
434
backSubContr.matrixB = - this ->mass * rTilde_ScS1_B * this ->s1Hat_B * this ->BTheta .row (0 ) - this ->mass2 * rTilde_Sc2S2_B * this ->s2Hat_B * this ->BTheta .row (1 );
375
435
backSubContr.vecTrans = - this ->mass * this ->omegaTilde_S1B_B * this ->rPrime_ScB_B - this ->mass2 * (omegaTilde_S2S1_B * this ->rPrime_Sc2S2_B - rTilde_Sc2S2_B * this ->omegaTilde_S1B_B * this ->omega_S2S1_B )
376
- + this ->mass * rTilde_ScS1_B * this ->s1Hat_B * this ->CTheta .row (0 ) + this ->mass2 * rTilde_Sc2S2_B * this ->s2Hat_B * this ->CTheta .row (1 );
436
+ + this ->mass * rTilde_ScS1_B * this ->s1Hat_B * this ->CTheta .row (0 ) + this ->mass2 * rTilde_Sc2S2_B * this ->s2Hat_B * this ->CTheta .row (1 )
437
+ + this ->dcm_BS1 * attBodyForce_S1 + this ->dcm_BS2 * attBodyForce_S2;
377
438
378
439
// Rotation contributions
379
440
backSubContr.matrixC = (this ->IS1PntSc1_B + this ->IS2PntSc2_B - this ->mass1 * this ->rTilde_Sc1B_B * rTilde_Sc1S1_B - this ->mass2 * this ->rTilde_Sc2B_B * rTilde_Sc2S1_B) * this ->s1Hat_B * this ->ATheta .row (0 )
@@ -386,7 +447,10 @@ void SpinningBodyTwoDOFStateEffector::updateContributions(double integTime, Back
386
447
- this ->mass2 * (this ->rTilde_Sc2B_B * this ->omegaTilde_S1B_B + this ->omegaTilde_BN_B * this ->rTilde_Sc2B_B ) * this ->rPrime_Sc2B_B
387
448
- this ->mass2 * this ->rTilde_Sc2B_B * omegaTilde_S2S1_B * this ->rPrime_Sc2S2_B
388
449
- (this ->IS1PntSc1_B + this ->IS2PntSc2_B - this ->mass1 * this ->rTilde_Sc1B_B * rTilde_Sc1S1_B - this ->mass2 * this ->rTilde_Sc2B_B * rTilde_Sc2S1_B) * this ->s1Hat_B * this ->CTheta .row (0 )
389
- - (this ->IS2PntSc2_B - this ->mass2 * this ->rTilde_Sc2B_B * rTilde_Sc2S2_B) * this ->s2Hat_B * this ->CTheta .row (1 );
450
+ - (this ->IS2PntSc2_B - this ->mass2 * this ->rTilde_Sc2B_B * rTilde_Sc2S2_B) * this ->s2Hat_B * this ->CTheta .row (1 )
451
+ + this ->dcm_BS1 * attBodyTorquePntS1_S1 + this ->dcm_BS2 * attBodyTorquePntS2_S2
452
+ + eigenTilde (this ->r_S1B_B ) * (this ->dcm_BS1 * attBodyForce_S1)
453
+ + eigenTilde (this ->r_S2S1_B + this ->r_S1B_B ) * (this ->dcm_BS2 * attBodyForce_S2);
390
454
}
391
455
392
456
/* ! This method is used to find the derivatives for the SB stateEffector: thetaDDot and the kinematic derivative */
@@ -439,20 +503,20 @@ void SpinningBodyTwoDOFStateEffector::computeSpinningBodyInertialStates()
439
503
Eigen::Matrix3d dcm_S2N;
440
504
dcm_S1N = (this ->dcm_BS1 ).transpose () * this ->dcm_BN ;
441
505
dcm_S2N = (this ->dcm_BS2 ).transpose () * this ->dcm_BN ;
442
- this ->sigma_S1N = eigenMRPd2Vector3d (eigenC2MRP (dcm_S1N));
443
- this ->sigma_S2N = eigenMRPd2Vector3d (eigenC2MRP (dcm_S2N));
506
+ * this ->sigma_S1N = eigenMRPd2Vector3d (eigenC2MRP (dcm_S1N));
507
+ * this ->sigma_S2N = eigenMRPd2Vector3d (eigenC2MRP (dcm_S2N));
444
508
445
509
// Convert the angular velocity to the corresponding frame
446
- this ->omega_S1N_S1 = dcm_BS1.transpose () * this ->omega_S1N_B ;
447
- this ->omega_S2N_S2 = dcm_BS2.transpose () * this ->omega_S2N_B ;
510
+ * this ->omega_S1N_S1 = dcm_BS1.transpose () * this ->omega_S1N_B ;
511
+ * this ->omega_S2N_S2 = dcm_BS2.transpose () * this ->omega_S2N_B ;
448
512
449
513
// Compute the inertial position vector
450
- this ->r_Sc1N_N = (Eigen::Vector3d)(*this ->inertialPositionProperty ) + this ->dcm_BN .transpose () * this ->r_Sc1B_B ;
451
- this ->r_Sc2N_N = (Eigen::Vector3d)(*this ->inertialPositionProperty ) + this ->dcm_BN .transpose () * this ->r_Sc2B_B ;
514
+ * this ->r_Sc1N_N = (Eigen::Vector3d)(*this ->inertialPositionProperty ) + this ->dcm_BN .transpose () * this ->r_Sc1B_B ;
515
+ * this ->r_Sc2N_N = (Eigen::Vector3d)(*this ->inertialPositionProperty ) + this ->dcm_BN .transpose () * this ->r_Sc2B_B ;
452
516
453
517
// Compute the inertial velocity vector
454
- this ->v_Sc1N_N = (Eigen::Vector3d)(*this ->inertialVelocityProperty ) + this ->dcm_BN .transpose () * this ->rDot_Sc1B_B ;
455
- this ->v_Sc2N_N = (Eigen::Vector3d)(*this ->inertialVelocityProperty ) + this ->dcm_BN .transpose () * this ->rDot_Sc2B_B ;
518
+ * this ->v_Sc1N_N = (Eigen::Vector3d)(*this ->inertialVelocityProperty ) + this ->dcm_BN .transpose () * this ->rDot_Sc1B_B ;
519
+ * this ->v_Sc2N_N = (Eigen::Vector3d)(*this ->inertialVelocityProperty ) + this ->dcm_BN .transpose () * this ->rDot_Sc2B_B ;
456
520
}
457
521
458
522
/* ! This method is used so that the simulation will ask SB to update messages */
0 commit comments