diff --git a/mission/controller/AcsController.cpp b/mission/controller/AcsController.cpp index 8a7ac78c..1a19ff87 100644 --- a/mission/controller/AcsController.cpp +++ b/mission/controller/AcsController.cpp @@ -191,7 +191,7 @@ void AcsController::performSafe() { break; case (acs::SafeModeStrategy::SAFECTRL_ECLIPSE_DAMPING): safeCtrl.safeRateDamping(mgmDataProcessed.mgmVecTot.value, gyrDataProcessed.gyrVecTot.value, - sunTargetDir, magMomMtq, errAng); + sunTargetDir, inertiaEive, magMomMtq, errAng); safeCtrlFailureFlag = false; safeCtrlFailureCounter = 0; break; diff --git a/mission/controller/acs/control/SafeCtrl.cpp b/mission/controller/acs/control/SafeCtrl.cpp index ce44dbef..0b732556 100644 --- a/mission/controller/acs/control/SafeCtrl.cpp +++ b/mission/controller/acs/control/SafeCtrl.cpp @@ -42,11 +42,11 @@ void SafeCtrl::safeMekf(const double *magFieldB, const double *satRotRateB, errorAngle = acos(dotSun); splitRotationalRate(satRotRateB, sunDirB); - calculateRotationalRateTorque(sunDirB, sunDirRefB, errorAngle, - acsParameters->safeModeControllerParameters.k_parallelMekf, - acsParameters->safeModeControllerParameters.k_orthoMekf); + calculateRotationalRateTorque( + sunDirB, sunDirRefB, errorAngle, acsParameters->safeModeControllerParameters.k_parallelMekf, + acsParameters->safeModeControllerParameters.k_orthoMekf, inertiaMatrix); calculateAngleErrorTorque(sunDirB, sunDirRefB, - acsParameters->safeModeControllerParameters.k_alignMekf, inertiaMatrix); + acsParameters->safeModeControllerParameters.k_alignMekf); // sum of all torques for (uint8_t i = 0; i < 3; i++) { @@ -70,10 +70,10 @@ void SafeCtrl::safeNonMekf(const double *magFieldB, const double *satRotRateB, splitRotationalRate(satRotRateB, sunDirB); calculateRotationalRateTorque(sunDirB, sunDirRefB, errorAngle, acsParameters->safeModeControllerParameters.k_parallelNonMekf, - acsParameters->safeModeControllerParameters.k_orthoNonMekf); + acsParameters->safeModeControllerParameters.k_orthoNonMekf, + inertiaMatrix); calculateAngleErrorTorque(sunDirB, sunDirRefB, - acsParameters->safeModeControllerParameters.k_alignNonMekf, - inertiaMatrix); + acsParameters->safeModeControllerParameters.k_alignNonMekf); // sum of all torques for (uint8_t i = 0; i < 3; i++) { @@ -84,7 +84,8 @@ void SafeCtrl::safeNonMekf(const double *magFieldB, const double *satRotRateB, } void SafeCtrl::safeRateDamping(const double *magFieldB, const double *satRotRateB, - const double *sunDirRefB, double *magMomB, double &errorAngle) { + const double *sunDirRefB, const double inertiaMatrix[3][3], + double *magMomB, double &errorAngle) { // convert magFieldB from uT to T VectorOperations::mulScalar(magFieldB, 1e-6, magFieldBT, 3); @@ -94,7 +95,8 @@ void SafeCtrl::safeRateDamping(const double *magFieldB, const double *satRotRate splitRotationalRate(satRotRateB, sunDirRefB); calculateRotationalRateTorque(sunDirRefB, sunDirRefB, errorAngle, acsParameters->safeModeControllerParameters.k_parallelNonMekf, - acsParameters->safeModeControllerParameters.k_orthoNonMekf); + acsParameters->safeModeControllerParameters.k_orthoNonMekf, + inertiaMatrix); // sum of all torques double cmdTorque[3] = {0, 0, 0}; @@ -114,21 +116,23 @@ void SafeCtrl::splitRotationalRate(const double *satRotRateB, const double *sunD void SafeCtrl::calculateRotationalRateTorque(const double *sunDirB, const double *sunDirRefB, double &errorAngle, const double gainParallel, - const double gainOrtho) { + const double gainOrtho, + const double inertiaMatrix[3][3]) { // calculate torque for parallel rotational rate VectorOperations::mulScalar(satRotRateParallelB, -gainParallel, cmdParallel, 3); // calculate torque for orthogonal rotational rate - VectorOperations::mulScalar(satRotRateOrthogonalB, -gainOrtho, cmdOrtho, 3); + double orthoFactor[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; + MatrixOperations::multiplyScalar(*inertiaMatrix, gainOrtho, *orthoFactor, 3, 3); + MatrixOperations::multiply(*orthoFactor, satRotRateOrthogonalB, cmdAlign, 3, 3, 1); } void SafeCtrl::calculateAngleErrorTorque(const double *sunDirB, const double *sunDirRefB, - const double gainAlign, const double inertiaMatrix[3][3]) { + const double gainAlign) { // calculate torque for alignment - double crossAlign[3] = {0, 0, 0}, alignFactor[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; - MatrixOperations::multiplyScalar(*inertiaMatrix, gainAlign, *alignFactor, 3, 3); + double crossAlign[3] = {0, 0, 0}; VectorOperations::cross(sunDirRefB, sunDirB, crossAlign); - MatrixOperations::multiply(*alignFactor, crossAlign, cmdAlign, 3, 3, 1); + VectorOperations::mulScalar(crossAlign, gainAlign, cmdAlign, 3); } void SafeCtrl::calculateMagneticMoment(double *magMomB) { diff --git a/mission/controller/acs/control/SafeCtrl.h b/mission/controller/acs/control/SafeCtrl.h index 108321df..f0ab8a3c 100644 --- a/mission/controller/acs/control/SafeCtrl.h +++ b/mission/controller/acs/control/SafeCtrl.h @@ -25,16 +25,16 @@ class SafeCtrl { double &errorAngle); void safeRateDamping(const double *magFieldB, const double *satRotRateB, const double *sunDirRefB, - double *magMomB, double &errorAngle); + const double inertiaMatrix[3][3], double *magMomB, double &errorAngle); void splitRotationalRate(const double *satRotRateB, const double *sunDirB); void calculateRotationalRateTorque(const double *sunDirB, const double *sunDirRefB, double &errorAngle, const double gainParallel, - const double gainOrtho); + const double gainOrtho, const double inertiaMatrix[3][3]); void calculateAngleErrorTorque(const double *sunDirB, const double *sunDirRefB, - const double gainAlign, const double inertiaMatrix[3][3]); + const double gainAlign); void calculateMagneticMoment(double *magMomB);