Skip to content

Commit a8f74ae

Browse files
committed
perform same adaptations to SB2DOF effector
1 parent 1fbde11 commit a8f74ae

File tree

2 files changed

+133
-40
lines changed

2 files changed

+133
-40
lines changed

src/simulation/dynamics/spinningBodies/spinningBodiesTwoDOF/spinningBodyTwoDOFStateEffector.cpp

Lines changed: 84 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ SpinningBodyTwoDOFStateEffector::SpinningBodyTwoDOFStateEffector()
5656
this->nameOfTheta1DotState = "spinningBodyTheta1Dot" + std::to_string(SpinningBodyTwoDOFStateEffector::effectorID);
5757
this->nameOfTheta2State = "spinningBodyTheta2" + std::to_string(SpinningBodyTwoDOFStateEffector::effectorID);
5858
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);
5967
SpinningBodyTwoDOFStateEffector::effectorID++;
6068
}
6169

@@ -111,10 +119,10 @@ void SpinningBodyTwoDOFStateEffector::writeOutputStateMessages(uint64_t CurrentC
111119
configLogMsg = this->spinningBodyConfigLogOutMsgs[0]->zeroMsgPayload;
112120

113121
// 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);
118126
this->spinningBodyConfigLogOutMsgs[0]->write(&configLogMsg, this->moduleID, CurrentClock);
119127
}
120128

@@ -123,10 +131,10 @@ void SpinningBodyTwoDOFStateEffector::writeOutputStateMessages(uint64_t CurrentC
123131
configLogMsg = this->spinningBodyConfigLogOutMsgs[1]->zeroMsgPayload;
124132

125133
// 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);
130138
this->spinningBodyConfigLogOutMsgs[1]->write(&configLogMsg, this->moduleID, CurrentClock);
131139
}
132140
}
@@ -167,6 +175,35 @@ void SpinningBodyTwoDOFStateEffector::registerStates(DynParamManager& states)
167175
thetaDotInitMatrix(1,0) = this->theta2DotInit;
168176
this->theta1DotState->setState(thetaDotInitMatrix.row(0));
169177
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+
}
170207
}
171208

172209
/*! 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
271308
gLocal_N = g_N;
272309
g_B = this->dcm_BN * gLocal_N;
273310

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+
274331
// Update omega_BN_B
275332
this->omega_BN_B = omega_BN_B;
276333
this->omegaTilde_BN_B = eigenTilde(this->omega_BN_B);
@@ -334,12 +391,15 @@ void SpinningBodyTwoDOFStateEffector::updateContributions(double integTime, Back
334391
+ this->mass1 * (rTilde_Sc1S1_B * this->omegaTilde_S1B_B + this->omegaTilde_BN_B * rTilde_Sc1S1_B) * this->rPrime_Sc1S1_B
335392
+ this->mass2 * (rTilde_Sc2S1_B * this->omegaTilde_S1B_B + this->omegaTilde_BN_B * rTilde_Sc2S1_B) * this->rPrime_Sc2S1_B
336393
+ 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));
338397
CThetaStar(1, 0) = this->u2 - this->k2 * (this->theta2 - this->theta2Ref)
339398
- this->c2 * (this->theta2Dot - this->theta2DotRef) + this->s2Hat_B.transpose() * gravityTorquePntS2_B
340399
- this->s2Hat_B.transpose() * ((IPrimeS2PntS2_B + this->omegaTilde_BN_B * IS2PntS2_B) * this->omega_S2N_B
341400
+ 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);
343403

344404
// Check if any of the axis are locked and change dynamics accordingly
345405
if (this->lockFlag1 == 1 || this->lockFlag2 == 1)
@@ -373,7 +433,8 @@ void SpinningBodyTwoDOFStateEffector::updateContributions(double integTime, Back
373433
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);
374434
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);
375435
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;
377438

378439
// Rotation contributions
379440
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
386447
- this->mass2 * (this->rTilde_Sc2B_B * this->omegaTilde_S1B_B + this->omegaTilde_BN_B * this->rTilde_Sc2B_B) * this->rPrime_Sc2B_B
387448
- this->mass2 * this->rTilde_Sc2B_B * omegaTilde_S2S1_B * this->rPrime_Sc2S2_B
388449
- (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);
390454
}
391455

392456
/*! This method is used to find the derivatives for the SB stateEffector: thetaDDot and the kinematic derivative */
@@ -439,20 +503,20 @@ void SpinningBodyTwoDOFStateEffector::computeSpinningBodyInertialStates()
439503
Eigen::Matrix3d dcm_S2N;
440504
dcm_S1N = (this->dcm_BS1).transpose() * this->dcm_BN;
441505
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));
444508

445509
// 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;
448512

449513
// 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;
452516

453517
// 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;
456520
}
457521

458522
/*! This method is used so that the simulation will ask SB to update messages */

0 commit comments

Comments
 (0)