2023-07-19 16:25:03 +02:00
|
|
|
#include "FusedRotationEstimation.h"
|
|
|
|
|
|
|
|
FusedRotationEstimation::FusedRotationEstimation(AcsParameters *acsParameters_) {
|
|
|
|
acsParameters = acsParameters_;
|
|
|
|
}
|
|
|
|
|
2023-11-14 13:22:35 +01:00
|
|
|
void FusedRotationEstimation::estimateFusedRotationRate(
|
|
|
|
acsctrl::SusDataProcessed *susDataProcessed, acsctrl::MgmDataProcessed *mgmDataProcessed,
|
|
|
|
acsctrl::GyrDataProcessed *gyrDataProcessed, ACS::SensorValues *sensorValues,
|
|
|
|
acsctrl::FusedRotRateData *fusedRotRateData) {
|
|
|
|
if (sensorValues->strSet.caliQw.isValid() and sensorValues->strSet.caliQx.isValid() and
|
|
|
|
sensorValues->strSet.caliQy.isValid() and sensorValues->strSet.caliQz.isValid()) {
|
|
|
|
double quatNew[4] = {sensorValues->strSet.caliQx.value, sensorValues->strSet.caliQy.value,
|
|
|
|
sensorValues->strSet.caliQz.value, sensorValues->strSet.caliQw.value};
|
|
|
|
if (VectorOperations<double>::norm(quatOld, 4) != 0) {
|
|
|
|
estimateFusedRotationRateStr(quatNew, fusedRotRateData);
|
|
|
|
} else {
|
|
|
|
estimateFusedRotationRateSafe(susDataProcessed, mgmDataProcessed, gyrDataProcessed,
|
|
|
|
fusedRotRateData);
|
|
|
|
}
|
|
|
|
std::memcpy(quatOld, quatNew, sizeof(quatOld));
|
|
|
|
} else {
|
|
|
|
std::memcpy(quatOld, ZERO_VEC4, sizeof(quatOld));
|
|
|
|
estimateFusedRotationRateSafe(susDataProcessed, mgmDataProcessed, gyrDataProcessed,
|
|
|
|
fusedRotRateData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FusedRotationEstimation::estimateFusedRotationRateStr(
|
|
|
|
double *quatNew, acsctrl::FusedRotRateData *fusedRotRateData) {}
|
|
|
|
|
2023-07-19 16:25:03 +02:00
|
|
|
void FusedRotationEstimation::estimateFusedRotationRateSafe(
|
2023-07-20 11:09:34 +02:00
|
|
|
acsctrl::SusDataProcessed *susDataProcessed, acsctrl::MgmDataProcessed *mgmDataProcessed,
|
|
|
|
acsctrl::GyrDataProcessed *gyrDataProcessed, acsctrl::FusedRotRateData *fusedRotRateData) {
|
2023-07-20 14:22:24 +02:00
|
|
|
if ((not mgmDataProcessed->mgmVecTot.isValid() and not susDataProcessed->susVecTot.isValid() and
|
2023-07-20 13:09:49 +02:00
|
|
|
not fusedRotRateData->rotRateTotal.isValid()) or
|
|
|
|
(not susDataProcessed->susVecTotDerivative.isValid() and
|
|
|
|
not mgmDataProcessed->mgmVecTotDerivative.isValid())) {
|
2023-07-20 11:09:34 +02:00
|
|
|
{
|
|
|
|
PoolReadGuard pg(fusedRotRateData);
|
2023-11-14 13:22:35 +01:00
|
|
|
std::memcpy(fusedRotRateData->rotRateOrthogonal.value, ZERO_VEC3, 3 * sizeof(double));
|
|
|
|
std::memcpy(fusedRotRateData->rotRateParallel.value, ZERO_VEC3, 3 * sizeof(double));
|
|
|
|
std::memcpy(fusedRotRateData->rotRateTotal.value, ZERO_VEC3, 3 * sizeof(double));
|
2023-07-20 11:09:34 +02:00
|
|
|
fusedRotRateData->setValidity(false, true);
|
|
|
|
}
|
2023-08-03 11:32:08 +02:00
|
|
|
// store for calculation of angular acceleration
|
|
|
|
if (gyrDataProcessed->gyrVecTot.isValid()) {
|
|
|
|
std::memcpy(rotRateOldB, gyrDataProcessed->gyrVecTot.value, 3 * sizeof(double));
|
|
|
|
}
|
2023-07-19 16:25:03 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-07-20 11:09:34 +02:00
|
|
|
if (not susDataProcessed->susVecTot.isValid()) {
|
|
|
|
estimateFusedRotationRateEclipse(gyrDataProcessed, fusedRotRateData);
|
2023-08-02 16:26:57 +02:00
|
|
|
// store for calculation of angular acceleration
|
|
|
|
if (gyrDataProcessed->gyrVecTot.isValid()) {
|
|
|
|
std::memcpy(rotRateOldB, gyrDataProcessed->gyrVecTot.value, 3 * sizeof(double));
|
|
|
|
}
|
2023-07-19 16:25:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate rotation around the sun
|
|
|
|
double magSunCross[3] = {0, 0, 0};
|
|
|
|
|
2023-07-20 11:09:34 +02:00
|
|
|
VectorOperations<double>::cross(mgmDataProcessed->mgmVecTot.value,
|
|
|
|
susDataProcessed->susVecTot.value, magSunCross);
|
2023-07-19 16:25:03 +02:00
|
|
|
double magSunCrossNorm = VectorOperations<double>::norm(magSunCross, 3);
|
2023-07-20 11:09:34 +02:00
|
|
|
double magNorm = VectorOperations<double>::norm(mgmDataProcessed->mgmVecTot.value, 3);
|
|
|
|
double fusedRotRateParallel[3] = {0, 0, 0};
|
2023-07-19 16:25:03 +02:00
|
|
|
if (magSunCrossNorm >
|
|
|
|
(acsParameters->safeModeControllerParameters.sineLimitSunRotRate * magNorm)) {
|
|
|
|
double omegaParallel =
|
2023-07-20 11:09:34 +02:00
|
|
|
VectorOperations<double>::dot(mgmDataProcessed->mgmVecTotDerivative.value, magSunCross) *
|
|
|
|
pow(magSunCrossNorm, -2);
|
|
|
|
VectorOperations<double>::mulScalar(susDataProcessed->susVecTot.value, omegaParallel,
|
|
|
|
fusedRotRateParallel, 3);
|
2023-07-19 16:25:03 +02:00
|
|
|
} else {
|
2023-07-20 11:09:34 +02:00
|
|
|
estimateFusedRotationRateEclipse(gyrDataProcessed, fusedRotRateData);
|
2023-08-02 16:26:57 +02:00
|
|
|
// store for calculation of angular acceleration
|
|
|
|
if (gyrDataProcessed->gyrVecTot.isValid()) {
|
|
|
|
std::memcpy(rotRateOldB, gyrDataProcessed->gyrVecTot.value, 3 * sizeof(double));
|
|
|
|
}
|
2023-07-19 16:25:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate rotation orthogonal to the sun
|
2023-07-20 11:09:34 +02:00
|
|
|
double fusedRotRateOrthogonal[3] = {0, 0, 0};
|
|
|
|
VectorOperations<double>::cross(susDataProcessed->susVecTotDerivative.value,
|
|
|
|
susDataProcessed->susVecTot.value, fusedRotRateOrthogonal);
|
|
|
|
VectorOperations<double>::mulScalar(
|
|
|
|
fusedRotRateOrthogonal,
|
2023-07-21 11:10:09 +02:00
|
|
|
pow(VectorOperations<double>::norm(susDataProcessed->susVecTot.value, 3), -2),
|
2023-07-20 11:09:34 +02:00
|
|
|
fusedRotRateOrthogonal, 3);
|
2023-07-19 16:25:03 +02:00
|
|
|
|
|
|
|
// calculate total rotation rate
|
2023-07-20 11:09:34 +02:00
|
|
|
double fusedRotRateTotal[3] = {0, 0, 0};
|
|
|
|
VectorOperations<double>::add(fusedRotRateParallel, fusedRotRateOrthogonal, fusedRotRateTotal);
|
2023-07-19 16:25:03 +02:00
|
|
|
|
2023-07-20 11:09:34 +02:00
|
|
|
{
|
|
|
|
PoolReadGuard pg(fusedRotRateData);
|
|
|
|
std::memcpy(fusedRotRateData->rotRateOrthogonal.value, fusedRotRateOrthogonal,
|
|
|
|
3 * sizeof(double));
|
|
|
|
std::memcpy(fusedRotRateData->rotRateParallel.value, fusedRotRateParallel, 3 * sizeof(double));
|
|
|
|
std::memcpy(fusedRotRateData->rotRateTotal.value, fusedRotRateTotal, 3 * sizeof(double));
|
|
|
|
fusedRotRateData->setValidity(true, true);
|
2023-07-19 16:25:03 +02:00
|
|
|
}
|
2023-08-03 11:34:29 +02:00
|
|
|
|
|
|
|
// store for calculation of angular acceleration
|
|
|
|
if (gyrDataProcessed->gyrVecTot.isValid()) {
|
|
|
|
std::memcpy(rotRateOldB, gyrDataProcessed->gyrVecTot.value, 3 * sizeof(double));
|
|
|
|
}
|
2023-07-19 16:25:03 +02:00
|
|
|
}
|
|
|
|
|
2023-07-20 11:09:34 +02:00
|
|
|
void FusedRotationEstimation::estimateFusedRotationRateEclipse(
|
|
|
|
acsctrl::GyrDataProcessed *gyrDataProcessed, acsctrl::FusedRotRateData *fusedRotRateData) {
|
2023-08-03 10:09:43 +02:00
|
|
|
if (not acsParameters->onBoardParams.fusedRateSafeDuringEclipse or
|
|
|
|
not gyrDataProcessed->gyrVecTot.isValid() or
|
2023-07-20 11:09:34 +02:00
|
|
|
VectorOperations<double>::norm(fusedRotRateData->rotRateTotal.value, 3) == 0) {
|
|
|
|
{
|
|
|
|
PoolReadGuard pg(fusedRotRateData);
|
2023-11-14 13:22:35 +01:00
|
|
|
std::memcpy(fusedRotRateData->rotRateOrthogonal.value, ZERO_VEC3, 3 * sizeof(double));
|
|
|
|
std::memcpy(fusedRotRateData->rotRateParallel.value, ZERO_VEC3, 3 * sizeof(double));
|
|
|
|
std::memcpy(fusedRotRateData->rotRateTotal.value, ZERO_VEC3, 3 * sizeof(double));
|
2023-07-20 11:09:34 +02:00
|
|
|
fusedRotRateData->setValidity(false, true);
|
|
|
|
}
|
2023-07-19 16:25:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
double angAccelB[3] = {0, 0, 0};
|
2023-07-20 11:09:34 +02:00
|
|
|
VectorOperations<double>::subtract(gyrDataProcessed->gyrVecTot.value, rotRateOldB, angAccelB, 3);
|
|
|
|
double fusedRotRateTotal[3] = {0, 0, 0};
|
|
|
|
VectorOperations<double>::add(fusedRotRateData->rotRateTotal.value, angAccelB, fusedRotRateTotal,
|
|
|
|
3);
|
|
|
|
{
|
|
|
|
PoolReadGuard pg(fusedRotRateData);
|
2023-11-14 13:22:35 +01:00
|
|
|
std::memcpy(fusedRotRateData->rotRateOrthogonal.value, ZERO_VEC3, 3 * sizeof(double));
|
2023-07-20 11:09:34 +02:00
|
|
|
fusedRotRateData->rotRateOrthogonal.setValid(false);
|
2023-11-14 13:22:35 +01:00
|
|
|
std::memcpy(fusedRotRateData->rotRateParallel.value, ZERO_VEC3, 3 * sizeof(double));
|
2023-07-20 11:09:34 +02:00
|
|
|
fusedRotRateData->rotRateParallel.setValid(false);
|
|
|
|
std::memcpy(fusedRotRateData->rotRateTotal.value, fusedRotRateTotal, 3 * sizeof(double));
|
|
|
|
fusedRotRateData->rotRateTotal.setValid(true);
|
|
|
|
}
|
2023-07-19 16:25:03 +02:00
|
|
|
}
|