combined SensorProcessing and SusConverter
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit

This commit is contained in:
Marius Eggert 2022-10-06 15:38:23 +02:00
parent 84e960a9ef
commit 3079dabc20
4 changed files with 582 additions and 668 deletions

View File

@ -6,81 +6,86 @@
*/ */
#include "SensorProcessing.h" #include "SensorProcessing.h"
#include "Igrf13Model.h"
#include "util/MathOperations.h"
#include <math.h>
#include <fsfw/globalfunctions/constants.h> #include <fsfw/globalfunctions/constants.h>
#include <fsfw/globalfunctions/math/MatrixOperations.h> #include <fsfw/globalfunctions/math/MatrixOperations.h>
#include <fsfw/globalfunctions/math/QuaternionOperations.h> #include <fsfw/globalfunctions/math/QuaternionOperations.h>
#include <fsfw/globalfunctions/math/VectorOperations.h> #include <fsfw/globalfunctions/math/VectorOperations.h>
#include <fsfw/globalfunctions/timevalOperations.h> #include <fsfw/globalfunctions/timevalOperations.h>
#include <math.h>
#include "../controllerdefinitions/AcsCtrlDefinitions.h"
#include "Igrf13Model.h"
#include "util/MathOperations.h"
using namespace Math; using namespace Math;
// Thought: Maybe separate file for transforming of sensor values // Thought: Maybe separate file for transforming of sensor values
// into geometry frame and body frame // into geometry frame and body frame
SensorProcessing::SensorProcessing(AcsParameters *acsParameters_) : SensorProcessing::SensorProcessing(AcsParameters *acsParameters_) : savedMagFieldEst{0, 0, 0} {
savedMagFieldEst { 0, 0, 0 }{
validMagField = false; validMagField = false;
validGcLatitude = false; validGcLatitude = false;
} }
SensorProcessing::~SensorProcessing() { SensorProcessing::~SensorProcessing() {}
}
bool SensorProcessing::processMgm(const float *mgm0Value, bool mgm0valid, bool SensorProcessing::processMgm(const float *mgm0Value, bool mgm0valid, const float *mgm1Value,
const float *mgm1Value, bool mgm1valid, const float *mgm2Value, bool mgm1valid, const float *mgm2Value, bool mgm2valid,
bool mgm2valid, const float *mgm3Value, bool mgm3valid, const float *mgm3Value, bool mgm3valid, const float *mgm4Value,
const float *mgm4Value, bool mgm4valid, timeval timeOfMgmMeasurement, bool mgm4valid, timeval timeOfMgmMeasurement,
const AcsParameters::MgmHandlingParameters *mgmParameters, const AcsParameters::MgmHandlingParameters *mgmParameters,
const double gpsLatitude, const double gpsLongitude, const double gpsLatitude, const double gpsLongitude,
const double gpsAltitude, bool gpsValid, double *magFieldEst, bool *outputValid, const double gpsAltitude, bool gpsValid, double *magFieldEst,
double *magFieldModel, bool*magFieldModelValid, bool *outputValid, double *magFieldModel,
double *magneticFieldVectorDerivative, bool *magneticFieldVectorDerivativeValid) { bool *magFieldModelValid, double *magneticFieldVectorDerivative,
bool *magneticFieldVectorDerivativeValid) {
if (!mgm0valid && !mgm1valid && !mgm2valid && !mgm3valid && !mgm4valid) { if (!mgm0valid && !mgm1valid && !mgm2valid && !mgm3valid && !mgm4valid) {
*outputValid = false; *outputValid = false;
validMagField = false; validMagField = false;
return false; return false;
} }
// Transforming Values to the Body Frame (actually it is the geometry frame atm) // Transforming Values to the Body Frame (actually it is the geometry frame atm)
float mgm0ValueBody[3] = {0,0,0}, mgm1ValueBody[3] = {0,0,0}, float mgm0ValueBody[3] = {0, 0, 0}, mgm1ValueBody[3] = {0, 0, 0}, mgm2ValueBody[3] = {0, 0, 0},
mgm2ValueBody[3] = {0,0,0}, mgm3ValueBody[3] = {0,0,0}, mgm3ValueBody[3] = {0, 0, 0}, mgm4ValueBody[3] = {0, 0, 0};
mgm4ValueBody[3] = {0,0,0};
bool validUnit[5] = {false, false, false, false, false}; bool validUnit[5] = {false, false, false, false, false};
uint8_t validCount = 0; uint8_t validCount = 0;
if (mgm0valid) { if (mgm0valid) {
MatrixOperations<float>::multiply(mgmParameters->mgm0orientationMatrix[0], mgm0Value, mgm0ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(mgmParameters->mgm0orientationMatrix[0], mgm0Value,
mgm0ValueBody, 3, 3, 1);
validCount += 1; validCount += 1;
validUnit[0] = true; validUnit[0] = true;
} }
if (mgm1valid) { if (mgm1valid) {
MatrixOperations<float>::multiply(mgmParameters->mgm1orientationMatrix[0], mgm1Value, mgm1ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(mgmParameters->mgm1orientationMatrix[0], mgm1Value,
mgm1ValueBody, 3, 3, 1);
validCount += 1; validCount += 1;
validUnit[1] = true; validUnit[1] = true;
} }
if (mgm2valid) { if (mgm2valid) {
MatrixOperations<float>::multiply(mgmParameters->mgm2orientationMatrix[0], mgm2Value, mgm2ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(mgmParameters->mgm2orientationMatrix[0], mgm2Value,
mgm2ValueBody, 3, 3, 1);
validCount += 1; validCount += 1;
validUnit[2] = true; validUnit[2] = true;
} }
if (mgm3valid) { if (mgm3valid) {
MatrixOperations<float>::multiply(mgmParameters->mgm3orientationMatrix[0], mgm3Value, mgm3ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(mgmParameters->mgm3orientationMatrix[0], mgm3Value,
mgm3ValueBody, 3, 3, 1);
validCount += 1; validCount += 1;
validUnit[3] = true; validUnit[3] = true;
} }
if (mgm4valid) { if (mgm4valid) {
MatrixOperations<float>::multiply(mgmParameters->mgm4orientationMatrix[0], mgm4Value, mgm4ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(mgmParameters->mgm4orientationMatrix[0], mgm4Value,
mgm4ValueBody, 3, 3, 1);
validCount += 1; validCount += 1;
validUnit[4] = true; validUnit[4] = true;
} }
/* -------- MagFieldEst: Middle Value ------- */ /* -------- MagFieldEst: Middle Value ------- */
float mgmValues[3][5] = { { mgm0ValueBody[0], mgm1ValueBody[0], mgm2ValueBody[0], float mgmValues[3][5] = {
mgm3ValueBody[0], mgm4ValueBody[0] }, { mgm0ValueBody[1], mgm1ValueBody[1], {mgm0ValueBody[0], mgm1ValueBody[0], mgm2ValueBody[0], mgm3ValueBody[0], mgm4ValueBody[0]},
mgm2ValueBody[1], mgm3ValueBody[1], mgm4ValueBody[1] }, { mgm0ValueBody[2], {mgm0ValueBody[1], mgm1ValueBody[1], mgm2ValueBody[1], mgm3ValueBody[1], mgm4ValueBody[1]},
mgm1ValueBody[2], mgm2ValueBody[2], mgm3ValueBody[2], mgm4ValueBody[2] } }; {mgm0ValueBody[2], mgm1ValueBody[2], mgm2ValueBody[2], mgm3ValueBody[2], mgm4ValueBody[2]}};
double mgmValidValues[3][validCount]; double mgmValidValues[3][validCount];
uint8_t j = 0; uint8_t j = 0;
for (uint8_t i = 0; i < validCount; i++) { for (uint8_t i = 0; i < validCount; i++) {
@ -104,8 +109,7 @@ bool SensorProcessing::processMgm(const float *mgm0Value, bool mgm0valid,
//-----------------------Mag Rate Computation --------------------------------------------------- //-----------------------Mag Rate Computation ---------------------------------------------------
double timeDiff = timevalOperations::toDouble(timeOfMgmMeasurement - timeOfSavedMagFieldEst); double timeDiff = timevalOperations::toDouble(timeOfMgmMeasurement - timeOfSavedMagFieldEst);
for (uint8_t i = 0; i < 3; i++) { for (uint8_t i = 0; i < 3; i++) {
magneticFieldVectorDerivative[i] = (magFieldEst[i] magneticFieldVectorDerivative[i] = (magFieldEst[i] - savedMagFieldEst[i]) / timeDiff;
- savedMagFieldEst[i]) / timeDiff;
savedMagFieldEst[i] = magFieldEst[i]; savedMagFieldEst[i] = magFieldEst[i];
} }
@ -119,14 +123,12 @@ bool SensorProcessing::processMgm(const float *mgm0Value, bool mgm0valid,
timeOfSavedMagFieldEst = timeOfMgmMeasurement; timeOfSavedMagFieldEst = timeOfMgmMeasurement;
*outputValid = true; *outputValid = true;
// ---------------- IGRF- 13 Implementation here ------------------------------------------------ // ---------------- IGRF- 13 Implementation here ------------------------------------------------
if (!gpsValid) { if (!gpsValid) {
*magFieldModelValid = false; *magFieldModelValid = false;
} } else {
else{
// Should be existing class object which will be called and modified here. // Should be existing class object which will be called and modified here.
Igrf13Model igrf13; Igrf13Model igrf13;
// So the line above should not be done here. Update: Can be done here as long updated coffs // So the line above should not be done here. Update: Can be done here as long updated coffs
@ -134,93 +136,155 @@ bool SensorProcessing::processMgm(const float *mgm0Value, bool mgm0valid,
igrf13.updateCoeffGH(timeOfMgmMeasurement); igrf13.updateCoeffGH(timeOfMgmMeasurement);
// maybe put a condition here, to only update after a full day, this // maybe put a condition here, to only update after a full day, this
// class function has around 700 steps to perform // class function has around 700 steps to perform
igrf13.magFieldComp(gpsLongitude, gpsLatitude, gpsAltitude, igrf13.magFieldComp(gpsLongitude, gpsLatitude, gpsAltitude, timeOfMgmMeasurement,
timeOfMgmMeasurement, magFieldModel); magFieldModel);
*magFieldModelValid = false; *magFieldModelValid = false;
} }
return true; return true;
} }
void SensorProcessing::processSus(const float sus0Value[], bool sus0valid, const float sus1Value[], bool sus1valid, void SensorProcessing::processSus(acsctrl::SusDataRaw susData, timeval timeOfSusMeasurement,
const float sus2Value[], bool sus2valid, const float sus3Value[], bool sus3valid, const AcsParameters::SusHandlingParameters *susParameters,
const float sus4Value[], bool sus4valid, const float sus5Value[], bool sus5valid, const AcsParameters::SunModelParameters *sunModelParameters,
const float sus6Value[], bool sus6valid, const float sus7Value[], bool sus7valid, double *sunDirEst, bool *sunDirEstValid,
const float sus8Value[], bool sus8valid, const float sus9Value[], bool sus9valid,
const float sus10Value[], bool sus10valid, const float sus11Value[], bool sus11valid,
timeval timeOfSusMeasurement, const AcsParameters::SusHandlingParameters *susParameters,
const AcsParameters::SunModelParameters *sunModelParameters, double *sunDirEst, bool *sunDirEstValid,
double *sunVectorInertial, bool *sunVectorInertialValid, double *sunVectorInertial, bool *sunVectorInertialValid,
double *sunVectorDerivative, bool *sunVectorDerivativeValid) { double *sunVectorDerivative, bool *sunVectorDerivativeValid) {
susData.sus0.setValid(susConverter.checkSunSensorData(susData.sus0));
susData.sus1.setValid(susConverter.checkSunSensorData(susData.sus1));
susData.sus2.setValid(susConverter.checkSunSensorData(susData.sus2));
susData.sus3.setValid(susConverter.checkSunSensorData(susData.sus3));
susData.sus4.setValid(susConverter.checkSunSensorData(susData.sus4));
susData.sus5.setValid(susConverter.checkSunSensorData(susData.sus5));
susData.sus6.setValid(susConverter.checkSunSensorData(susData.sus6));
susData.sus7.setValid(susConverter.checkSunSensorData(susData.sus7));
susData.sus8.setValid(susConverter.checkSunSensorData(susData.sus8));
susData.sus9.setValid(susConverter.checkSunSensorData(susData.sus9));
susData.sus10.setValid(susConverter.checkSunSensorData(susData.sus10));
susData.sus11.setValid(susConverter.checkSunSensorData(susData.sus11));
if(!sus0valid && !sus1valid && !sus2valid && !sus3valid && !sus4valid && !sus5valid if (!susData.sus0.isValid() && !susData.sus1.isValid() && !susData.sus2.isValid() &&
&& !sus6valid && !sus7valid && !sus8valid && !sus9valid && !sus10valid && !sus11valid){ !susData.sus3.isValid() && !susData.sus4.isValid() && !susData.sus5.isValid() &&
!susData.sus6.isValid() && !susData.sus7.isValid() && !susData.sus8.isValid() &&
!susData.sus9.isValid() && !susData.sus10.isValid() && !susData.sus11.isValid()) {
*sunDirEstValid = false; *sunDirEstValid = false;
return; return;
} } else {
else{
// WARNING: NOT TRANSFORMED IN BODY FRAME YET // WARNING: NOT TRANSFORMED IN BODY FRAME YET
// Transformation into Geomtry Frame // Transformation into Geomtry Frame
float sus0ValueBody[3] = {0,0,0}, sus1ValueBody[3] = {0,0,0}, sus2ValueBody[3] = {0,0,0}, float sus0VecBody[3] = {0, 0, 0}, sus1VecBody[3] = {0, 0, 0}, sus2VecBody[3] = {0, 0, 0},
sus3ValueBody[3] = {0,0,0}, sus4ValueBody[3] = {0,0,0}, sus5ValueBody[3] = {0,0,0}, sus3VecBody[3] = {0, 0, 0}, sus4VecBody[3] = {0, 0, 0}, sus5VecBody[3] = {0, 0, 0},
sus6ValueBody[3] = {0,0,0}, sus7ValueBody[3] = {0,0,0}, sus8ValueBody[3] = {0,0,0}, sus6VecBody[3] = {0, 0, 0}, sus7VecBody[3] = {0, 0, 0}, sus8VecBody[3] = {0, 0, 0},
sus9ValueBody[3] = {0,0,0}, sus10ValueBody[3] = {0,0,0}, sus11ValueBody[3] = {0,0,0}; sus9VecBody[3] = {0, 0, 0}, sus10VecBody[3] = {0, 0, 0}, sus11VecBody[3] = {0, 0, 0};
if (sus0valid) { if (susData.sus0.isValid()) {
MatrixOperations<float>::multiply(susParameters->sus0orientationMatrix[0], sus0Value, sus0ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(
susParameters->sus0orientationMatrix[0],
susConverter.getSunVectorSensorFrame(susData.sus0, susParameters->sus0coeffAlpha,
susParameters->sus0coeffBeta),
sus0VecBody, 3, 3, 1);
} }
if (sus1valid) { if (susData.sus1.isValid()) {
MatrixOperations<float>::multiply(susParameters->sus1orientationMatrix[0], sus1Value, sus1ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(
susParameters->sus1orientationMatrix[0],
susConverter.getSunVectorSensorFrame(susData.sus1, susParameters->sus1coeffAlpha,
susParameters->sus1coeffBeta),
sus1VecBody, 3, 3, 1);
} }
if (sus2valid) { if (susData.sus2.isValid()) {
MatrixOperations<float>::multiply(susParameters->sus2orientationMatrix[0], sus2Value, sus2ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(
susParameters->sus2orientationMatrix[0],
susConverter.getSunVectorSensorFrame(susData.sus2, susParameters->sus2coeffAlpha,
susParameters->sus2coeffBeta),
sus2VecBody, 3, 3, 1);
} }
if (sus3valid) { if (susData.sus3.isValid()) {
MatrixOperations<float>::multiply(susParameters->sus3orientationMatrix[0], sus3Value, sus3ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(
susParameters->sus3orientationMatrix[0],
susConverter.getSunVectorSensorFrame(susData.sus3, susParameters->sus3coeffAlpha,
susParameters->sus3coeffBeta),
sus3VecBody, 3, 3, 1);
} }
if (sus4valid) { if (susData.sus4.isValid()) {
MatrixOperations<float>::multiply(susParameters->sus4orientationMatrix[0], sus4Value, sus4ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(
susParameters->sus4orientationMatrix[0],
susConverter.getSunVectorSensorFrame(susData.sus4, susParameters->sus4coeffAlpha,
susParameters->sus4coeffBeta),
sus4VecBody, 3, 3, 1);
} }
if (sus5valid) { if (susData.sus5.isValid()) {
MatrixOperations<float>::multiply(susParameters->sus5orientationMatrix[0], sus5Value, sus5ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(
susParameters->sus5orientationMatrix[0],
susConverter.getSunVectorSensorFrame(susData.sus5, susParameters->sus5coeffAlpha,
susParameters->sus5coeffBeta),
sus5VecBody, 3, 3, 1);
} }
if (sus6valid) { if (susData.sus6.isValid()) {
MatrixOperations<float>::multiply(susParameters->sus6orientationMatrix[0], sus6Value, sus6ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(
susParameters->sus6orientationMatrix[0],
susConverter.getSunVectorSensorFrame(susData.sus6, susParameters->sus6coeffAlpha,
susParameters->sus6coeffBeta),
sus6VecBody, 3, 3, 1);
} }
if (sus7valid) { if (susData.sus7.isValid()) {
MatrixOperations<float>::multiply(susParameters->sus7orientationMatrix[0], sus7Value, sus7ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(
susParameters->sus7orientationMatrix[0],
susConverter.getSunVectorSensorFrame(susData.sus7, susParameters->sus7coeffAlpha,
susParameters->sus7coeffBeta),
sus7VecBody, 3, 3, 1);
} }
if (sus8valid) { if (susData.sus8.isValid()) {
MatrixOperations<float>::multiply(susParameters->sus8orientationMatrix[0], sus8Value, sus8ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(
susParameters->sus8orientationMatrix[0],
susConverter.getSunVectorSensorFrame(susData.sus8, susParameters->sus8coeffAlpha,
susParameters->sus8coeffBeta),
sus8VecBody, 3, 3, 1);
} }
if (sus9valid) { if (susData.sus9.isValid()) {
MatrixOperations<float>::multiply(susParameters->sus9orientationMatrix[0], sus9Value, sus9ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(
susParameters->sus9orientationMatrix[0],
susConverter.getSunVectorSensorFrame(susData.sus9, susParameters->sus9coeffAlpha,
susParameters->sus9coeffBeta),
sus9VecBody, 3, 3, 1);
} }
if (sus10valid) { if (susData.sus10.isValid()) {
MatrixOperations<float>::multiply(susParameters->sus10orientationMatrix[0], sus10Value, sus10ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(
susParameters->sus10orientationMatrix[0],
susConverter.getSunVectorSensorFrame(susData.sus10, susParameters->sus10coeffAlpha,
susParameters->sus10coeffBeta),
sus10VecBody, 3, 3, 1);
} }
if (sus11valid) { if (susData.sus11.isValid()) {
MatrixOperations<float>::multiply(susParameters->sus11orientationMatrix[0], sus11Value, sus11ValueBody, 3, 3, 1); MatrixOperations<float>::multiply(
susParameters->sus11orientationMatrix[0],
susConverter.getSunVectorSensorFrame(susData.sus11, susParameters->sus11coeffAlpha,
susParameters->sus11coeffBeta),
sus11VecBody, 3, 3, 1);
} }
/* ------ Mean Value: susDirEst ------ */ /* ------ Mean Value: susDirEst ------ */
// Timo already done // Timo already done
bool validIds[12] = {sus0valid, sus1valid, sus2valid, sus3valid, sus4valid, sus5valid, bool validIds[12] = {susData.sus0.isValid(), susData.sus1.isValid(), susData.sus2.isValid(),
sus6valid, sus7valid, sus8valid, sus9valid, sus10valid, sus11valid}; susData.sus3.isValid(), susData.sus4.isValid(), susData.sus5.isValid(),
float susValuesBody[3][12] = {{sus0ValueBody[0], sus1ValueBody[0], sus2ValueBody[0], sus3ValueBody[0], sus4ValueBody[0], susData.sus6.isValid(), susData.sus7.isValid(), susData.sus8.isValid(),
sus5ValueBody[0], sus6ValueBody[0], sus7ValueBody[0], sus8ValueBody[0], sus9ValueBody[0], sus10ValueBody[0], sus11ValueBody[0]}, susData.sus9.isValid(), susData.sus10.isValid(), susData.sus11.isValid()};
{sus0ValueBody[1], sus1ValueBody[1], sus2ValueBody[1], sus3ValueBody[1], sus4ValueBody[1], float susVecBody[3][12] = {{sus0VecBody[0], sus1VecBody[0], sus2VecBody[0], sus3VecBody[0],
sus5ValueBody[1], sus6ValueBody[1], sus7ValueBody[1], sus8ValueBody[1], sus9ValueBody[1], sus10ValueBody[1], sus11ValueBody[1]}, sus4VecBody[0], sus5VecBody[0], sus6VecBody[0], sus7VecBody[0],
{sus0ValueBody[2], sus1ValueBody[2], sus2ValueBody[2], sus3ValueBody[2], sus4ValueBody[2], sus8VecBody[0], sus9VecBody[0], sus10VecBody[0], sus11VecBody[0]},
sus5ValueBody[2], sus6ValueBody[2], sus7ValueBody[2], sus8ValueBody[2], sus9ValueBody[2], sus10ValueBody[2], sus11ValueBody[2]}}; {sus0VecBody[1], sus1VecBody[1], sus2VecBody[1], sus3VecBody[1],
sus4VecBody[1], sus5VecBody[1], sus6VecBody[1], sus7VecBody[1],
sus8VecBody[1], sus9VecBody[1], sus10VecBody[1], sus11VecBody[1]},
{sus0VecBody[2], sus1VecBody[2], sus2VecBody[2], sus3VecBody[2],
sus4VecBody[2], sus5VecBody[2], sus6VecBody[2], sus7VecBody[2],
sus8VecBody[2], sus9VecBody[2], sus10VecBody[2], sus11VecBody[2]}};
double susMeanValue[3] = {0, 0, 0}; double susMeanValue[3] = {0, 0, 0};
uint8_t validSusCounter = 0; uint8_t validSusCounter = 0;
for (uint8_t i = 0; i < 12; i++) { for (uint8_t i = 0; i < 12; i++) {
if (validIds[i]) { if (validIds[i]) {
susMeanValue[0]+=susValuesBody[0][i]; susMeanValue[0] += susVecBody[0][i];
susMeanValue[1]+=susValuesBody[1][i]; susMeanValue[1] += susVecBody[1][i];
susMeanValue[2]+=susValuesBody[2][i]; susMeanValue[2] += susVecBody[2][i];
validSusCounter += 1; validSusCounter += 1;
} }
} }
@ -233,8 +297,7 @@ void SensorProcessing::processSus(const float sus0Value[], bool sus0valid, const
double timeDiff = timevalOperations::toDouble(timeOfSusMeasurement - timeOfSavedSusDirEst); double timeDiff = timevalOperations::toDouble(timeOfSusMeasurement - timeOfSavedSusDirEst);
for (uint8_t i = 0; i < 3; i++) { for (uint8_t i = 0; i < 3; i++) {
sunVectorDerivative[i] = (sunDirEst[i] sunVectorDerivative[i] = (sunDirEst[i] - savedSunVector[i]) / timeDiff;
- savedSunVector[i]) / timeDiff;
savedSunVector[i] = sunDirEst[i]; savedSunVector[i] = sunDirEst[i];
} }
@ -255,63 +318,60 @@ void SensorProcessing::processSus(const float sus0Value[], bool sus0valid, const
// Julean Centuries // Julean Centuries
double JC2000 = JD2000 / 36525; double JC2000 = JD2000 / 36525;
double meanLongitude = (sunModelParameters->omega_0 + (sunModelParameters->domega) * JC2000) * PI /180; double meanLongitude =
double meanAnomaly = (sunModelParameters->m_0 (sunModelParameters->omega_0 + (sunModelParameters->domega) * JC2000) * PI / 180;
+ sunModelParameters->dm * JC2000) * PI / 180.; double meanAnomaly = (sunModelParameters->m_0 + sunModelParameters->dm * JC2000) * PI / 180.;
double eclipticLongitude = meanLongitude + sunModelParameters->p1 * sin(meanAnomaly) double eclipticLongitude = meanLongitude + sunModelParameters->p1 * sin(meanAnomaly) +
+ sunModelParameters->p2 * sin(2 * meanAnomaly); sunModelParameters->p2 * sin(2 * meanAnomaly);
double epsilon = sunModelParameters->e - (sunModelParameters->e1) * JC2000; double epsilon = sunModelParameters->e - (sunModelParameters->e1) * JC2000;
sunVectorInertial[0] = cos(eclipticLongitude); sunVectorInertial[0] = cos(eclipticLongitude);
sunVectorInertial[1] = sin(eclipticLongitude) sunVectorInertial[1] = sin(eclipticLongitude) * cos(epsilon);
* cos(epsilon); sunVectorInertial[2] = sin(eclipticLongitude) * sin(epsilon);
sunVectorInertial[2] = sin(eclipticLongitude)
* sin(epsilon);
*sunVectorInertialValid = true; *sunVectorInertialValid = true;
} }
void SensorProcessing::processRmu(const double rmu0Value[], bool rmu0valid, void SensorProcessing::processRmu(const double rmu0Value[], bool rmu0valid,
const double rmu1Value[], bool rmu1valid, const double rmu1Value[], bool rmu1valid,
const double rmu2Value[], bool rmu2valid, const double rmu2Value[], bool rmu2valid,
timeval timeOfrmuMeasurement, const AcsParameters::RmuHandlingParameters *rmuParameters, timeval timeOfrmuMeasurement,
const AcsParameters::RmuHandlingParameters *rmuParameters,
double *satRatEst, bool *satRateEstValid) { double *satRatEst, bool *satRateEstValid) {
if (!rmu0valid && !rmu1valid && !rmu2valid) { if (!rmu0valid && !rmu1valid && !rmu2valid) {
*satRateEstValid = false; *satRateEstValid = false;
return; return;
} }
// Transforming Values to the Body Frame (actually it is the geometry frame atm) // Transforming Values to the Body Frame (actually it is the geometry frame atm)
double rmu0ValueBody[3] = {0,0,0}, rmu1ValueBody[3]= {0,0,0}, double rmu0ValueBody[3] = {0, 0, 0}, rmu1ValueBody[3] = {0, 0, 0}, rmu2ValueBody[3] = {0, 0, 0};
rmu2ValueBody[3] = {0,0,0};
bool validUnit[3] = {false, false, false}; bool validUnit[3] = {false, false, false};
uint8_t validCount = 0; uint8_t validCount = 0;
if (rmu0valid) { if (rmu0valid) {
MatrixOperations<double>::multiply(rmuParameters->rmu0orientationMatrix[0], rmu0Value, rmu0ValueBody, 3, 3, 1); MatrixOperations<double>::multiply(rmuParameters->rmu0orientationMatrix[0], rmu0Value,
rmu0ValueBody, 3, 3, 1);
validCount += 1; validCount += 1;
validUnit[0] = true; validUnit[0] = true;
} }
if (rmu1valid) { if (rmu1valid) {
MatrixOperations<double>::multiply(rmuParameters->rmu1orientationMatrix[0], rmu1Value, rmu1ValueBody, 3, 3, 1); MatrixOperations<double>::multiply(rmuParameters->rmu1orientationMatrix[0], rmu1Value,
rmu1ValueBody, 3, 3, 1);
validCount += 1; validCount += 1;
validUnit[1] = true; validUnit[1] = true;
} }
if (rmu2valid) { if (rmu2valid) {
MatrixOperations<double>::multiply(rmuParameters->rmu2orientationMatrix[0], rmu2Value, rmu2ValueBody, 3, 3, 1); MatrixOperations<double>::multiply(rmuParameters->rmu2orientationMatrix[0], rmu2Value,
rmu2ValueBody, 3, 3, 1);
validCount += 1; validCount += 1;
validUnit[2] = true; validUnit[2] = true;
} }
/* -------- SatRateEst: Middle Value ------- */ /* -------- SatRateEst: Middle Value ------- */
double rmuValues[3][3] = { { rmu0ValueBody[0], rmu1ValueBody[0], rmu2ValueBody[0]}, { rmu0ValueBody[1], rmu1ValueBody[1], double rmuValues[3][3] = {{rmu0ValueBody[0], rmu1ValueBody[0], rmu2ValueBody[0]},
rmu2ValueBody[1]}, { rmu0ValueBody[2], {rmu0ValueBody[1], rmu1ValueBody[1], rmu2ValueBody[1]},
rmu1ValueBody[2], rmu2ValueBody[2]} }; {rmu0ValueBody[2], rmu1ValueBody[2], rmu2ValueBody[2]}};
double rmuValidValues[3][validCount]; double rmuValidValues[3][validCount];
uint8_t j = 0; uint8_t j = 0;
for (uint8_t i = 0; i < validCount; i++) { for (uint8_t i = 0; i < validCount; i++) {
@ -331,7 +391,6 @@ void SensorProcessing::processRmu(const double rmu0Value[], bool rmu0valid,
satRatEst[1] = rmuValidValuesSort[1][n]; satRatEst[1] = rmuValidValuesSort[1][n];
satRatEst[2] = rmuValidValuesSort[2][n]; satRatEst[2] = rmuValidValuesSort[2][n];
*satRateEstValid = true; *satRateEstValid = true;
} }
void SensorProcessing::processGps(const double gps0latitude, const double gps0longitude, void SensorProcessing::processGps(const double gps0latitude, const double gps0longitude,
@ -345,18 +404,17 @@ void SensorProcessing::processGps(const double gps0latitude, const double gps0lo
double factor = 1 - pow(eccentricityWgs84, 2); double factor = 1 - pow(eccentricityWgs84, 2);
*gcLatitude = atan(factor * tan(latitudeRad)); *gcLatitude = atan(factor * tan(latitudeRad));
validGcLatitude = true; validGcLatitude = true;
} }
} }
void SensorProcessing::process(timeval now, ACS::SensorValues *sensorValues, void SensorProcessing::process(timeval now, ACS::SensorValues *sensorValues,
ACS::OutputValues *outputValues, const AcsParameters *acsParameters) { ACS::OutputValues *outputValues,
const AcsParameters *acsParameters) {
sensorValues->update(); sensorValues->update();
processGps(sensorValues->gps0latitude, sensorValues->gps0longitude, processGps(sensorValues->gps0latitude, sensorValues->gps0longitude, sensorValues->gps0Valid,
sensorValues->gps0Valid, &outputValues->gcLatitude, &outputValues->gdLongitude); &outputValues->gcLatitude, &outputValues->gdLongitude);
outputValues->mgmUpdated = processMgm(sensorValues->mgm0, sensorValues->mgm0Valid, /*outputValues->mgmUpdated = processMgm(sensorValues->mgm0, sensorValues->mgm0Valid,
sensorValues->mgm1, sensorValues->mgm1Valid, sensorValues->mgm1, sensorValues->mgm1Valid,
sensorValues->mgm2, sensorValues->mgm2Valid, sensorValues->mgm2, sensorValues->mgm2Valid,
sensorValues->mgm3, sensorValues->mgm3Valid, sensorValues->mgm3, sensorValues->mgm3Valid,
@ -366,22 +424,23 @@ void SensorProcessing::process(timeval now, ACS::SensorValues *sensorValues,
sensorValues->gps0Valid, sensorValues->gps0Valid,
outputValues->magFieldEst, &outputValues->magFieldEstValid, outputValues->magFieldEst, &outputValues->magFieldEstValid,
outputValues->magFieldModel, &outputValues->magFieldModelValid, outputValues->magFieldModel, &outputValues->magFieldModelValid,
outputValues->magneticFieldVectorDerivative, &outputValues->magneticFieldVectorDerivativeValid); // VALID outputs- PoolVariable ? outputValues->magneticFieldVectorDerivative,
&outputValues->magneticFieldVectorDerivativeValid); // VALID outputs- PoolVariable ?
processSus(sensorValues->sus0, sensorValues->sus0Valid, sensorValues->sus1, sensorValues->sus1Valid, processSus(sensorValues->sus0, sensorValues->sus0Valid, sensorValues->sus1,
sensorValues->sus2, sensorValues->sus2Valid, sensorValues->sus3, sensorValues->sus3Valid, sensorValues->sus1Valid, sensorValues->sus2, sensorValues->sus2Valid, sensorValues->sus3,
sensorValues->sus4, sensorValues->sus4Valid, sensorValues->sus5, sensorValues->sus5Valid, sensorValues->sus3Valid, sensorValues->sus4, sensorValues->sus4Valid, sensorValues->sus5,
sensorValues->sus6, sensorValues->sus6Valid, sensorValues->sus7, sensorValues->sus7Valid, sensorValues->sus5Valid, sensorValues->sus6, sensorValues->sus6Valid, sensorValues->sus7,
sensorValues->sus8, sensorValues->sus8Valid, sensorValues->sus9, sensorValues->sus9Valid, sensorValues->sus7Valid, sensorValues->sus8, sensorValues->sus8Valid, sensorValues->sus9,
sensorValues->sus10, sensorValues->sus10Valid, sensorValues->sus11, sensorValues->sus11Valid, sensorValues->sus9Valid, sensorValues->sus10, sensorValues->sus10Valid, sensorValues->sus11,
now, &acsParameters->susHandlingParameters, &acsParameters->sunModelParameters, sensorValues->sus11Valid, now, &acsParameters->susHandlingParameters,
outputValues->sunDirEst, &outputValues->sunDirEstValid, &acsParameters->sunModelParameters, outputValues->sunDirEst, &outputValues->sunDirEstValid,
outputValues->sunDirModel, &outputValues->sunDirModelValid, outputValues->sunDirModel, &outputValues->sunDirModelValid,
outputValues->sunVectorDerivative, &outputValues->sunVectorDerivativeValid); // VALID outputs ? outputValues->sunVectorDerivative, &outputValues->sunVectorDerivativeValid); //
VALID outputs ?
processRmu(sensorValues->rmu0, sensorValues->rmu0Valid, sensorValues->rmu1, sensorValues->rmu1Valid, */
sensorValues->rmu2, sensorValues->rmu2Valid, now, &acsParameters->rmuHandlingParameters, processRmu(sensorValues->rmu0, sensorValues->rmu0Valid, sensorValues->rmu1,
outputValues->satRateEst, &outputValues->satRateEstValid); sensorValues->rmu1Valid, sensorValues->rmu2, sensorValues->rmu2Valid, now,
&acsParameters->rmuHandlingParameters, outputValues->satRateEst,
&outputValues->satRateEstValid);
} }

View File

@ -5,14 +5,16 @@
#ifndef SENSORPROCESSING_H_ #ifndef SENSORPROCESSING_H_
#define SENSORPROCESSING_H_ #define SENSORPROCESSING_H_
#include "AcsParameters.h" #include <fsfw/returnvalues/returnvalue.h>
#include "SensorValues.h"
#include "OutputValues.h"
#include "config/classIds.h"
#include <stdint.h> //uint8_t #include <stdint.h> //uint8_t
#include <time.h> /*purpose, timeval ?*/ #include <time.h> /*purpose, timeval ?*/
#include <fsfw/returnvalues/returnvalue.h>
#include "SusConverter.h"
#include "../controllerdefinitions/AcsCtrlDefinitions.h"
#include "AcsParameters.h"
#include "OutputValues.h"
#include "SensorValues.h"
#include "config/classIds.h"
/*Planned: /*Planned:
* - Fusion of Sensor Measurements - * - Fusion of Sensor Measurements -
@ -28,7 +30,6 @@
class SensorProcessing { class SensorProcessing {
public: public:
void reset(); void reset();
SensorProcessing(AcsParameters *acsParameters_); SensorProcessing(AcsParameters *acsParameters_);
@ -37,44 +38,33 @@ public:
void process(timeval now, ACS::SensorValues *sensorValues, ACS::OutputValues *outputValues, void process(timeval now, ACS::SensorValues *sensorValues, ACS::OutputValues *outputValues,
const AcsParameters *acsParameters); // Will call protected functions const AcsParameters *acsParameters); // Will call protected functions
private: private:
protected: protected:
// short description needed for every function // short description needed for every function
bool processMgm(const float *mgm0Value, bool mgm0valid, bool processMgm(const float *mgm0Value, bool mgm0valid, const float *mgm1Value, bool mgm1valid,
const float *mgm1Value, bool mgm1valid, const float *mgm2Value, bool mgm2valid, const float *mgm3Value, bool mgm3valid,
const float *mgm2Value, bool mgm2valid, const float *mgm4Value, bool mgm4valid, timeval timeOfMgmMeasurement,
const float *mgm3Value, bool mgm3valid,
const float *mgm4Value, bool mgm4valid,
timeval timeOfMgmMeasurement,
const AcsParameters::MgmHandlingParameters *mgmParameters, const AcsParameters::MgmHandlingParameters *mgmParameters,
const double gpsLatitude, const double gpsLongitude, const double gpsLatitude, const double gpsLongitude, const double gpsAltitude,
const double gpsAltitude, bool gpsValid, bool gpsValid, double *magFieldEst, bool *outputValid, double *magFieldModel,
double *magFieldEst, bool *outputValid, bool *magFieldModelValid, double *magneticFieldVectorDerivative,
double *magFieldModel, bool*magFieldModelValid, bool *magneticFieldVectorDerivativeValid); // Output
double *magneticFieldVectorDerivative, bool *magneticFieldVectorDerivativeValid); //Output
void processSus(const float sus0Value[], bool sus0valid, const float sus1Value[], bool sus1valid, void processSus(acsctrl::SusDataRaw susData, timeval timeOfSusMeasurement,
const float sus2Value[], bool sus2valid, const float sus3Value[], bool sus3valid, const AcsParameters::SusHandlingParameters *susParameters,
const float sus4Value[], bool sus4valid, const float sus5Value[], bool sus5valid, const AcsParameters::SunModelParameters *sunModelParameters, double *sunDirEst,
const float sus6Value[], bool sus6valid, const float sus7Value[], bool sus7valid, bool *sunDirEstValid, double *sunVectorInertial, bool *sunVectorInertialValid,
const float sus8Value[], bool sus8valid, const float sus9Value[], bool sus9valid,
const float sus10Value[], bool sus10valid, const float sus11Value[], bool sus11valid,
timeval timeOfSusMeasurement, const AcsParameters::SusHandlingParameters *susParameters,
const AcsParameters::SunModelParameters *sunModelParameters, double *sunDirEst, bool *sunDirEstValid,
double *sunVectorModel, bool *sunVectorModelValid,
double *sunVectorDerivative, bool *sunVectorDerivativeValid); double *sunVectorDerivative, bool *sunVectorDerivativeValid);
void processRmu(const double rmu0Value[], bool rmu0valid, // processRmu void processRmu(const double rmu0Value[], bool rmu0valid, // processRmu
const double rmu1Value[], bool rmu1valid, const double rmu1Value[], bool rmu1valid, const double rmu2Value[],
const double rmu2Value[], bool rmu2valid, bool rmu2valid, timeval timeOfrmuMeasurement,
timeval timeOfrmuMeasurement, const AcsParameters::RmuHandlingParameters *rmuParameters, const AcsParameters::RmuHandlingParameters *rmuParameters, double *satRatEst,
double *satRatEst, bool *satRateEstValid); bool *satRateEstValid);
void processStr(); void processStr();
void processGps(const double gps0latitude, const double gps0longitude, void processGps(const double gps0latitude, const double gps0longitude, const bool validGps,
const bool validGps, double *gcLatitude, double *gdLongitude); double *gcLatitude, double *gdLongitude);
double savedMagFieldEst[3]; double savedMagFieldEst[3];
timeval timeOfSavedMagFieldEst; timeval timeOfSavedMagFieldEst;
@ -83,8 +73,8 @@ protected:
bool validMagField; bool validMagField;
bool validGcLatitude; bool validGcLatitude;
SusConverter susConverter;
AcsParameters acsParameters;
}; };
#endif /*SENSORPROCESSING_H_*/ #endif /*SENSORPROCESSING_H_*/

View File

@ -6,191 +6,68 @@
*/ */
#include "SusConverter.h" #include "SusConverter.h"
#include <math.h> //for atan2
#include <iostream>
#include <fsfw/globalfunctions/math/VectorOperations.h>
#include <fsfw/datapoollocal/LocalPoolVariable.h> #include <fsfw/datapoollocal/LocalPoolVariable.h>
#include <fsfw/datapoollocal/LocalPoolVector.h> #include <fsfw/datapoollocal/LocalPoolVector.h>
#include <fsfw/globalfunctions/math/VectorOperations.h>
#include <math.h> //for atan2
#include <iostream>
void SunSensor::checkSunSensorData(uint8_t susNumber) { bool SusConverter::checkSunSensorData(lp_vec_t<uint16_t, 6> susChannel) {
uint16_t channelValueSum; if (susChannel.value[0] <= susChannelValueCheckLow ||
susChannel.value[0] > susChannelValueCheckHigh ||
// Check individual channel values susChannel.value[0] > susChannel.value[GNDREF]) {
for (int k = 0; k < 4; k++) { // iteration above all photodiode quarters return false;
}
if (susChannelValues[susNumber][k] <= channelValueCheckLow || if (susChannel.value[1] <= susChannelValueCheckLow ||
susChannelValues[susNumber][k] > channelValueCheckHigh) { // Channel values out of range for 12 bit SUS susChannel.value[1] > susChannelValueCheckHigh ||
// channel measurement range? susChannel.value[1] > susChannel.value[GNDREF]) {
validFlag[susNumber] = returnvalue::FAILED; return false;
/*printf(
"The value of channel %i from sun sensor %i is not inside the borders of valid data with "
"a value of %i \n",
k, susNumber, ChannelValue[k]);*/
} else if (susChannelValues[susNumber][k] >
susChannelValues[susNumber][4]) { // Channel values higher than zero current threshold GNDREF?
validFlag[susNumber] = returnvalue::FAILED;
/*printf(
"The value of channel %i from sun sensor %i is higher than the zero current threshold "
"GNDREF\n",
k, susNumber);*/
}; };
if (susChannel.value[2] <= susChannelValueCheckLow ||
susChannel.value[2] > susChannelValueCheckHigh ||
susChannel.value[2] > susChannel.value[GNDREF]) {
return false;
};
if (susChannel.value[3] <= susChannelValueCheckLow ||
susChannel.value[3] > susChannelValueCheckHigh ||
susChannel.value[3] > susChannel.value[GNDREF]) {
return false;
}; };
// check sum of all channel values to check if sun sensor is illuminated by the sun (sum is susChannelValueSum = 4 * susChannel.value[GNDREF] - (susChannel.value[0] + susChannel.value[1] +
// smaller than a treshold --> sun sensor is not illuminated by the sun, but by the moon susChannel.value[2] + susChannel.value[3]);
// reflection or earth albedo) if ((susChannelValueSum < susChannelValueSumHigh) &&
channelValueSum = (susChannelValueSum > susChannelValueSumLow)) {
4 * susChannelValues[susNumber][4] - (susChannelValues[susNumber][0] + return false;
susChannelValues[susNumber][1] + susChannelValues[susNumber][2] +
susChannelValues[susNumber][3]);
if ((channelValueSum < channelValueSumHigh) && (channelValueSum > channelValueSumLow)) {
validFlag[susNumber] = returnvalue::FAILED;
//printf("Sun sensor %i is not illuminated by the sun\n", susNumber);
}; };
return true;
} }
void SunSensor::calcAngle(uint8_t susNumber) { void SusConverter::calcAngle(lp_vec_t<uint16_t, 6> susChannel) {
float xout, yout; float xout, yout;
float s = 0.03; // s=[mm] gap between diodes float s = 0.03; // s=[mm] gap between diodes
uint8_t d = 5; // d=[mm] edge length of the quadratic aperture uint8_t d = 5; // d=[mm] edge length of the quadratic aperture
uint8_t h = 1; // h=[mm] distance between diodes and aperture uint8_t h = 1; // h=[mm] distance between diodes and aperture
int ch0, ch1, ch2, ch3; int ch0, ch1, ch2, ch3;
// Substract measurement values from GNDREF zero current threshold // Substract measurement values from GNDREF zero current threshold
ch0 = susChannelValues[susNumber][4] - susChannelValues[susNumber][0]; ch0 = susChannel.value[GNDREF] - susChannel.value[0];
ch1 = susChannelValues[susNumber][4] - susChannelValues[susNumber][1]; ch1 = susChannel.value[GNDREF] - susChannel.value[1];
ch2 = susChannelValues[susNumber][4] - susChannelValues[susNumber][2]; ch2 = susChannel.value[GNDREF] - susChannel.value[2];
ch3 = susChannelValues[susNumber][4] - susChannelValues[susNumber][3]; ch3 = susChannel.value[GNDREF] - susChannel.value[3];
// Calculation of x and y // Calculation of x and y
xout = ((d - s) / 2) * (ch2 - ch3 - ch0 + ch1) / (ch0 + ch1 + ch2 + ch3); //[mm] xout = ((d - s) / 2) * (ch2 - ch3 - ch0 + ch1) / (ch0 + ch1 + ch2 + ch3); //[mm]
yout = ((d - s) / 2) * (ch2 + ch3 - ch0 - ch1) / (ch0 + ch1 + ch2 + ch3); //[mm] yout = ((d - s) / 2) * (ch2 + ch3 - ch0 - ch1) / (ch0 + ch1 + ch2 + ch3); //[mm]
// Calculation of the angles // Calculation of the angles
alphaBetaRaw[susNumber][0] = atan2(xout, h) * (180 / M_PI); //[°] alphaBetaRaw[0] = atan2(xout, h) * (180 / M_PI); //[°]
alphaBetaRaw[susNumber][1] = atan2(yout, h) * (180 / M_PI); //[°] alphaBetaRaw[1] = atan2(yout, h) * (180 / M_PI); //[°]
} }
void SunSensor::setCalibrationCoefficients(uint8_t susNumber) { void SusConverter::calibration(const float coeffAlpha[9][10], const float coeffBeta[9][10]) {
switch (susNumber) { // search for the correct calibration coefficients for each SUS uint8_t index, k, l;
case 0:
for (uint8_t row = 0; row < 9;
row++) { // save the correct coefficients in the right SUS class
for (uint8_t column = 0; column < 10; column++) {
coeffAlpha[susNumber][row][column] = acsParameters.susHandlingParameters.sus0coeffAlpha[row][column];
coeffBeta[susNumber][row][column] = acsParameters.susHandlingParameters.sus0coeffBeta[row][column];
}
}
break;
case 1:
for (uint8_t row = 0; row < 9; row++) {
for (uint8_t column = 0; column < 10; column++) {
coeffAlpha[susNumber][row][column] = acsParameters.susHandlingParameters.sus1coeffAlpha[row][column];
coeffBeta[susNumber][row][column] = acsParameters.susHandlingParameters.sus1coeffBeta[row][column];
}
}
break;
case 2:
for (uint8_t row = 0; row < 9; row++) {
for (uint8_t column = 0; column < 10; column++) {
coeffAlpha[susNumber][row][column] = acsParameters.susHandlingParameters.sus2coeffAlpha[row][column];
coeffBeta[susNumber][row][column] = acsParameters.susHandlingParameters.sus2coeffBeta[row][column];
}
}
break;
case 3:
for (uint8_t row = 0; row < 9; row++) {
for (uint8_t column = 0; column < 10; column++) {
coeffAlpha[susNumber][row][column] = acsParameters.susHandlingParameters.sus3coeffAlpha[row][column];
coeffBeta[susNumber][row][column] = acsParameters.susHandlingParameters.sus3coeffBeta[row][column];
}
}
break;
case 4:
for (uint8_t row = 0; row < 9; row++) {
for (uint8_t column = 0; column < 10; column++) {
coeffAlpha[susNumber][row][column] = acsParameters.susHandlingParameters.sus4coeffAlpha[row][column];
coeffBeta[susNumber][row][column] = acsParameters.susHandlingParameters.sus4coeffBeta[row][column];
}
}
break;
case 5:
for (uint8_t row = 0; row < 9; row++) {
for (uint8_t column = 0; column < 10; column++) {
coeffAlpha[susNumber][row][column] = acsParameters.susHandlingParameters.sus5coeffAlpha[row][column];
coeffBeta[susNumber][row][column] = acsParameters.susHandlingParameters.sus5coeffBeta[row][column];
}
}
break;
case 6:
for (uint8_t row = 0; row < 9; row++) {
for (uint8_t column = 0; column < 10; column++) {
coeffAlpha[susNumber][row][column] = acsParameters.susHandlingParameters.sus6coeffAlpha[row][column];
coeffBeta[susNumber][row][column] = acsParameters.susHandlingParameters.sus6coeffBeta[row][column];
}
}
break;
case 7:
for (uint8_t row = 0; row < 9; row++) {
for (uint8_t column = 0; column < 10; column++) {
coeffAlpha[susNumber][row][column] = acsParameters.susHandlingParameters.sus7coeffAlpha[row][column];
coeffBeta[susNumber][row][column] = acsParameters.susHandlingParameters.sus7coeffBeta[row][column];
}
}
break;
case 8:
for (uint8_t row = 0; row < 9; row++) {
for (uint8_t column = 0; column < 10; column++) {
coeffAlpha[susNumber][row][column] = acsParameters.susHandlingParameters.sus8coeffAlpha[row][column];
coeffBeta[susNumber][row][column] = acsParameters.susHandlingParameters.sus8coeffBeta[row][column];
}
}
break;
case 9:
for (uint8_t row = 0; row < 9; row++) {
for (uint8_t column = 0; column < 10; column++) {
coeffAlpha[susNumber][row][column] = acsParameters.susHandlingParameters.sus9coeffAlpha[row][column];
coeffBeta[susNumber][row][column] = acsParameters.susHandlingParameters.sus9coeffBeta[row][column];
}
}
break;
case 10:
for (uint8_t row = 0; row < 9; row++) {
for (uint8_t column = 0; column < 10; column++) {
coeffAlpha[susNumber][row][column] = acsParameters.susHandlingParameters.sus10coeffAlpha[row][column];
coeffBeta[susNumber][row][column] = acsParameters.susHandlingParameters.sus10coeffBeta[row][column];
}
}
break;
case 11:
for (uint8_t row = 0; row < 9; row++) {
for (uint8_t column = 0; column < 10; column++) {
coeffAlpha[susNumber][row][column] = acsParameters.susHandlingParameters.sus11coeffAlpha[row][column];
coeffBeta[susNumber][row][column] = acsParameters.susHandlingParameters.sus11coeffBeta[row][column];
}
}
break;
}
}
void SunSensor::Calibration(uint8_t susNumber) {
float alpha_m, beta_m, alpha_calibrated, beta_calibrated, k, l;
uint8_t index;
alpha_m = alphaBetaRaw[susNumber][0]; //[°]
beta_m = alphaBetaRaw[susNumber][1]; //[°]
// while loop iterates above all calibration cells to use the different calibration functions in // while loop iterates above all calibration cells to use the different calibration functions in
// each cell // each cell
@ -201,68 +78,62 @@ void SunSensor::Calibration(uint8_t susNumber) {
while (l < 3) { while (l < 3) {
l = l + 1; l = l + 1;
// if-condition to check in which cell the data point has to be // if-condition to check in which cell the data point has to be
if ((alpha_m > ((completeCellWidth * ((k - 1) / 3)) - halfCellWidth) && if ((alphaBetaRaw[0] > ((completeCellWidth * ((k - 1) / 3)) - halfCellWidth) &&
alpha_m < ((completeCellWidth * (k / 3)) - halfCellWidth)) && alphaBetaRaw[0] < ((completeCellWidth * (k / 3)) - halfCellWidth)) &&
(beta_m > ((completeCellWidth * ((l - 1) / 3)) - halfCellWidth) && (alphaBetaRaw[1] > ((completeCellWidth * ((l - 1) / 3)) - halfCellWidth) &&
beta_m < ((completeCellWidth * (l / 3)) - halfCellWidth))) { alphaBetaRaw[1] < ((completeCellWidth * (l / 3)) - halfCellWidth))) {
index = (3 * (k - 1) + l) - 1; // calculate the index of the datapoint for the right cell index = (3 * (k - 1) + l) - 1; // calculate the index of the datapoint for the right cell
// -> first cell has number 0 alphaBetaCalibrated[0] =
alphaBetaCalibrated[susNumber][0] = coeffAlpha[index][0] + coeffAlpha[index][1] * alphaBetaRaw[0] +
coeffAlpha[susNumber][index][0] + coeffAlpha[susNumber][index][1] * alpha_m + coeffAlpha[susNumber][index][2] * beta_m + coeffAlpha[index][2] * alphaBetaRaw[1] +
coeffAlpha[susNumber][index][3] * alpha_m * alpha_m + coeffAlpha[susNumber][index][4] * alpha_m * beta_m + coeffAlpha[index][3] * alphaBetaRaw[0] * alphaBetaRaw[0] +
coeffAlpha[susNumber][index][5] * beta_m * beta_m + coeffAlpha[index][4] * alphaBetaRaw[0] * alphaBetaRaw[1] +
coeffAlpha[susNumber][index][6] * alpha_m * alpha_m * alpha_m + coeffAlpha[index][5] * alphaBetaRaw[1] * alphaBetaRaw[1] +
coeffAlpha[susNumber][index][7] * alpha_m * alpha_m * beta_m + coeffAlpha[index][6] * alphaBetaRaw[0] * alphaBetaRaw[0] * alphaBetaRaw[0] +
coeffAlpha[susNumber][index][8] * alpha_m * beta_m * beta_m + coeffAlpha[index][7] * alphaBetaRaw[0] * alphaBetaRaw[0] * alphaBetaRaw[1] +
coeffAlpha[susNumber][index][9] * beta_m * beta_m * beta_m; //[°] coeffAlpha[index][8] * alphaBetaRaw[0] * alphaBetaRaw[1] * alphaBetaRaw[1] +
alphaBetaCalibrated[susNumber][1] = coeffAlpha[index][9] * alphaBetaRaw[1] * alphaBetaRaw[1] * alphaBetaRaw[1]; //[°]
coeffBeta[susNumber][index][0] + coeffBeta[susNumber][index][1] * alpha_m + alphaBetaCalibrated[1] =
coeffBeta[susNumber][index][2] * beta_m + coeffBeta[susNumber][index][3] * alpha_m * alpha_m + coeffBeta[index][0] + coeffBeta[index][1] * alphaBetaRaw[0] +
coeffBeta[susNumber][index][4] * alpha_m * beta_m + coeffBeta[index][2] * alphaBetaRaw[1] +
coeffBeta[susNumber][index][5] * beta_m * beta_m + coeffBeta[index][3] * alphaBetaRaw[0] * alphaBetaRaw[0] +
coeffBeta[susNumber][index][6] * alpha_m * alpha_m * alpha_m + coeffBeta[index][4] * alphaBetaRaw[0] * alphaBetaRaw[1] +
coeffBeta[susNumber][index][7] * alpha_m * alpha_m * beta_m + coeffBeta[index][5] * alphaBetaRaw[1] * alphaBetaRaw[1] +
coeffBeta[susNumber][index][8] * alpha_m * beta_m * beta_m + coeffBeta[index][6] * alphaBetaRaw[0] * alphaBetaRaw[0] * alphaBetaRaw[0] +
coeffBeta[susNumber][index][9] * beta_m * beta_m * beta_m; //[°] coeffBeta[index][7] * alphaBetaRaw[0] * alphaBetaRaw[0] * alphaBetaRaw[1] +
coeffBeta[index][8] * alphaBetaRaw[0] * alphaBetaRaw[1] * alphaBetaRaw[1] +
coeffBeta[index][9] * alphaBetaRaw[1] * alphaBetaRaw[1] * alphaBetaRaw[1]; //[°]
} }
} }
} }
} }
void SunSensor::CalculateSunVector(uint8_t susNumber) { float* SusConverter::calculateSunVector() {
float alpha, beta;
alpha = alphaBetaCalibrated[susNumber][0]; //[°]
beta = alphaBetaCalibrated[susNumber][1]; //[°]
// Calculate the normalized Sun Vector // Calculate the normalized Sun Vector
sunVectorBodyFrame[susNumber][0] = sunVectorBodyFrame[0] = (tan(alphaBetaCalibrated[0] * (M_PI / 180)) /
(tan(alpha * (M_PI / 180)) / (sqrt((powf(tan(alphaBetaCalibrated[0] * (M_PI / 180)), 2)) +
(sqrt((powf(tan(alpha * (M_PI / 180)), 2)) + powf(tan((beta * (M_PI / 180))), 2) + (1)))); powf(tan((alphaBetaCalibrated[1] * (M_PI / 180))), 2) + (1))));
sunVectorBodyFrame[susNumber][1] = sunVectorBodyFrame[1] = (tan(alphaBetaCalibrated[1] * (M_PI / 180)) /
(tan(beta * (M_PI / 180)) / (sqrt(powf((tan(alphaBetaCalibrated[0] * (M_PI / 180))), 2) +
(sqrt(powf((tan(alpha * (M_PI / 180))), 2) + powf(tan((beta * (M_PI / 180))), 2) + (1)))); powf(tan((alphaBetaCalibrated[1] * (M_PI / 180))), 2) + (1))));
sunVectorBodyFrame[susNumber][2] = sunVectorBodyFrame[2] =
(-1 / (-1 / (sqrt(powf((tan(alphaBetaCalibrated[0] * (M_PI / 180))), 2) +
(sqrt(powf((tan(alpha * (M_PI / 180))), 2) + powf((tan(beta * (M_PI / 180))), 2) + (1)))); powf((tan(alphaBetaCalibrated[1] * (M_PI / 180))), 2) + (1))));
return sunVectorBodyFrame;
} }
float* SunSensor::getSunVectorBodyFrame(uint8_t susNumber) { float* SusConverter::getSunVectorSensorFrame(lp_vec_t<uint16_t, 6> susChannel,
// return function for the sun vector in the body frame const float coeffAlpha[9][10],
float* SunVectorBodyFrameReturn = 0; const float coeffBeta[9][10]) {
SunVectorBodyFrameReturn = new float[3]; calcAngle(susChannel);
calibration(coeffAlpha, coeffBeta);
SunVectorBodyFrameReturn[0] = sunVectorBodyFrame[susNumber][0]; return calculateSunVector();
SunVectorBodyFrameReturn[1] = sunVectorBodyFrame[susNumber][1];
SunVectorBodyFrameReturn[2] = sunVectorBodyFrame[susNumber][2];
return SunVectorBodyFrameReturn;
} }
bool SunSensor::getValidFlag(uint8_t susNumber) { bool SusConverter::getValidFlag(uint8_t susNumber) { return validFlag[susNumber]; }
return validFlag[susNumber];
}
float* SunSensor::TransferSunVector() { float* SusConverter::TransferSunVector() {
float* sunVectorEIVE = 0; float* sunVectorEIVE = 0;
sunVectorEIVE = new float[3]; sunVectorEIVE = new float[3];
@ -288,42 +159,53 @@ float* SunSensor::TransferSunVector() {
for (uint8_t c1 = 0; c1 < 3; c1++) { for (uint8_t c1 = 0; c1 < 3; c1++) {
for (uint8_t c2 = 0; c2 < 3; c2++) { for (uint8_t c2 = 0; c2 < 3; c2++) {
switch (susNumber) { switch (susNumber) {
case 0: case 0:
basisMatrixUse[c1][c2] = acsParameters.susHandlingParameters.sus0orientationMatrix[c1][c2]; basisMatrixUse[c1][c2] =
acsParameters.susHandlingParameters.sus0orientationMatrix[c1][c2];
break; break;
case 1: case 1:
basisMatrixUse[c1][c2] = acsParameters.susHandlingParameters.sus1orientationMatrix[c1][c2]; basisMatrixUse[c1][c2] =
acsParameters.susHandlingParameters.sus1orientationMatrix[c1][c2];
break; break;
case 2: case 2:
basisMatrixUse[c1][c2] = acsParameters.susHandlingParameters.sus2orientationMatrix[c1][c2]; basisMatrixUse[c1][c2] =
acsParameters.susHandlingParameters.sus2orientationMatrix[c1][c2];
break; break;
case 3: case 3:
basisMatrixUse[c1][c2] = acsParameters.susHandlingParameters.sus3orientationMatrix[c1][c2]; basisMatrixUse[c1][c2] =
acsParameters.susHandlingParameters.sus3orientationMatrix[c1][c2];
break; break;
case 4: case 4:
basisMatrixUse[c1][c2] = acsParameters.susHandlingParameters.sus4orientationMatrix[c1][c2]; basisMatrixUse[c1][c2] =
acsParameters.susHandlingParameters.sus4orientationMatrix[c1][c2];
break; break;
case 5: case 5:
basisMatrixUse[c1][c2] = acsParameters.susHandlingParameters.sus5orientationMatrix[c1][c2]; basisMatrixUse[c1][c2] =
acsParameters.susHandlingParameters.sus5orientationMatrix[c1][c2];
break; break;
case 6: case 6:
basisMatrixUse[c1][c2] = acsParameters.susHandlingParameters.sus6orientationMatrix[c1][c2]; basisMatrixUse[c1][c2] =
acsParameters.susHandlingParameters.sus6orientationMatrix[c1][c2];
break; break;
case 7: case 7:
basisMatrixUse[c1][c2] = acsParameters.susHandlingParameters.sus7orientationMatrix[c1][c2]; basisMatrixUse[c1][c2] =
acsParameters.susHandlingParameters.sus7orientationMatrix[c1][c2];
break; break;
case 8: case 8:
basisMatrixUse[c1][c2] = acsParameters.susHandlingParameters.sus8orientationMatrix[c1][c2]; basisMatrixUse[c1][c2] =
acsParameters.susHandlingParameters.sus8orientationMatrix[c1][c2];
break; break;
case 9: case 9:
basisMatrixUse[c1][c2] = acsParameters.susHandlingParameters.sus9orientationMatrix[c1][c2]; basisMatrixUse[c1][c2] =
acsParameters.susHandlingParameters.sus9orientationMatrix[c1][c2];
break; break;
case 10: case 10:
basisMatrixUse[c1][c2] = acsParameters.susHandlingParameters.sus10orientationMatrix[c1][c2]; basisMatrixUse[c1][c2] =
acsParameters.susHandlingParameters.sus10orientationMatrix[c1][c2];
break; break;
case 11: case 11:
basisMatrixUse[c1][c2] = acsParameters.susHandlingParameters.sus11orientationMatrix[c1][c2]; basisMatrixUse[c1][c2] =
acsParameters.susHandlingParameters.sus11orientationMatrix[c1][c2];
break; break;
} }
} }
@ -359,5 +241,3 @@ float* SunSensor::TransferSunVector() {
return sunVectorEIVE; return sunVectorEIVE;
} }

View File

@ -8,69 +8,54 @@
#ifndef MISSION_CONTROLLER_ACS_SUSCONVERTER_H_ #ifndef MISSION_CONTROLLER_ACS_SUSCONVERTER_H_
#define MISSION_CONTROLLER_ACS_SUSCONVERTER_H_ #define MISSION_CONTROLLER_ACS_SUSCONVERTER_H_
#include "AcsParameters.h" #include <fsfw/datapoollocal/LocalPoolVector.h>
#include <stdint.h> #include <stdint.h>
class SunSensor { #include "AcsParameters.h"
public:
SunSensor() {}
void checkSunSensorData(uint8_t susNumber); class SusConverter {
void calcAngle(uint8_t susNumber); public:
void setCalibrationCoefficients(uint8_t susNumber); SusConverter() {}
void Calibration(uint8_t susNumber);
void CalculateSunVector(uint8_t susNumber); bool checkSunSensorData(lp_vec_t<uint16_t, 6> susChannel);
void calcAngle(lp_vec_t<uint16_t, 6> susChannel);
void calibration(const float coeffAlpha[9][10], const float coeffBeta[9][10]);
float* calculateSunVector();
bool getValidFlag(uint8_t susNumber); bool getValidFlag(uint8_t susNumber);
float* getSunVectorBodyFrame(uint8_t susNumber); float* getSunVectorSensorFrame(lp_vec_t<uint16_t, 6> susChannel, const float coeffAlpha[9][10],
const float coeffBeta[9][10]);
float* TransferSunVector(); float* TransferSunVector();
private: private:
// ToDo: remove statics and replace with actual data float alphaBetaRaw[2]; //[°]
uint16_t susChannelValues[12][4] = { // float coeffAlpha[9][10];
{3913, 3912, 3799, 4056}, // float coeffBeta[9][10];
{3913, 3912, 3799, 4056}, float alphaBetaCalibrated[2]; //[°]
{3913, 3912, 3799, 4056}, float sunVectorBodyFrame[3]; //[-]
{3913, 3912, 3799, 4056},
{3913, 3912, 3799, 4056},
{3913, 3912, 3799, 4056},
{3913, 3912, 3799, 4056},
{3913, 3912, 3799, 4056},
{3913, 3912, 3799, 4056},
{3913, 3912, 3799, 4056},
{3913, 3912, 3799, 4056},
{3913, 3912, 3799, 4056}}; //[Bit]
float alphaBetaRaw[12][2]; //[°]
float alphaBetaCalibrated[12][2]; //[°]
float sunVectorBodyFrame[12][3]; //[-]
bool validFlag[12] = {returnvalue::OK, bool validFlag[12] = {returnvalue::OK, returnvalue::OK, returnvalue::OK, returnvalue::OK,
returnvalue::OK,returnvalue::OK, returnvalue::OK, returnvalue::OK, returnvalue::OK, returnvalue::OK,
returnvalue::OK,returnvalue::OK, returnvalue::OK, returnvalue::OK, returnvalue::OK, returnvalue::OK};
returnvalue::OK,returnvalue::OK,
returnvalue::OK,returnvalue::OK,
returnvalue::OK,returnvalue::OK,
returnvalue::OK};
uint16_t channelValueCheckHigh = static const uint8_t GNDREF = 4;
uint16_t susChannelValueCheckHigh =
4096; //=2^12[Bit]high borderline for the channel values of one sun sensor for validity Check 4096; //=2^12[Bit]high borderline for the channel values of one sun sensor for validity Check
uint8_t channelValueCheckLow = uint8_t susChannelValueCheckLow =
0; //[Bit]low borderline for the channel values of one sun sensor for validity Check 0; //[Bit]low borderline for the channel values of one sun sensor for validity Check
uint16_t channelValueSumHigh = uint16_t susChannelValueSumHigh =
100; // 4096[Bit]high borderline for check if the sun sensor is illuminated by the sun or by 100; // 4096[Bit]high borderline for check if the sun sensor is illuminated by the sun or by
// the reflection of sunlight from the moon/earth // the reflection of sunlight from the moon/earth
uint8_t channelValueSumLow = uint8_t susChannelValueSumLow =
0; //[Bit]low borderline for check if the sun sensor is illuminated 0; //[Bit]low borderline for check if the sun sensor is illuminated
// by the sun or by the reflection of sunlight from the moon/earth // by the sun or by the reflection of sunlight from the moon/earth
uint8_t completeCellWidth = 140, uint8_t completeCellWidth = 140,
halfCellWidth = 70; //[°] Width of the calibration cells --> necessary for checking in halfCellWidth = 70; //[°] Width of the calibration cells --> necessary for checking in
// which cell a data point should be // which cell a data point should be
uint16_t susChannelValueSum = 0;
float coeffAlpha[12][9][10];
float coeffBeta[12][9][10];
AcsParameters acsParameters; AcsParameters acsParameters;
}; };
#endif /* MISSION_CONTROLLER_ACS_SUSCONVERTER_H_ */ #endif /* MISSION_CONTROLLER_ACS_SUSCONVERTER_H_ */