61 lines
1.9 KiB
C++
61 lines
1.9 KiB
C++
|
|
/*
|
|
* Detumble.cpp
|
|
*
|
|
* Created on: 17 Aug 2022
|
|
* Author: Robin Marquardt
|
|
*/
|
|
|
|
#include "Detumble.h"
|
|
|
|
#include <fsfw/globalfunctions/constants.h>
|
|
#include <fsfw/globalfunctions/math/MatrixOperations.h>
|
|
#include <fsfw/globalfunctions/math/QuaternionOperations.h>
|
|
#include <fsfw/globalfunctions/math/VectorOperations.h>
|
|
#include <fsfw/globalfunctions/sign.h>
|
|
#include <math.h>
|
|
|
|
#include "../util/MathOperations.h"
|
|
|
|
Detumble::Detumble() {}
|
|
|
|
Detumble::~Detumble() {}
|
|
|
|
ReturnValue_t Detumble::bDotLaw(const double *magRate, const bool magRateValid,
|
|
const double *magField, const bool magFieldValid, double *magMom,
|
|
double gain) {
|
|
if (!magRateValid || !magFieldValid) {
|
|
return DETUMBLE_NO_SENSORDATA;
|
|
}
|
|
double factor = -gain / pow(VectorOperations<double>::norm(magField, 3), 2);
|
|
VectorOperations<double>::mulScalar(magRate, factor, magMom, 3);
|
|
return returnvalue::OK;
|
|
}
|
|
|
|
ReturnValue_t Detumble::bangbangLaw(const double *magRate, const bool magRateValid, double *magMom,
|
|
double dipolMax) {
|
|
if (!magRateValid) {
|
|
return DETUMBLE_NO_SENSORDATA;
|
|
}
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
magMom[i] = -dipolMax * sign(magRate[i]);
|
|
}
|
|
|
|
return returnvalue::OK;
|
|
}
|
|
|
|
ReturnValue_t Detumble::bDotLawFull(const double *satRate, const bool *satRateValid,
|
|
const double *magField, const bool *magFieldValid,
|
|
double *magMom, double gain) {
|
|
if (!satRateValid || !magFieldValid) {
|
|
return DETUMBLE_NO_SENSORDATA;
|
|
}
|
|
double factor = gain / pow(VectorOperations<double>::norm(magField, 3), 2);
|
|
double magFieldNormed[3] = {0, 0, 0}, crossProduct[3] = {0, 0, 0};
|
|
VectorOperations<double>::normalize(magField, magFieldNormed, 3);
|
|
VectorOperations<double>::cross(satRate, magFieldNormed, crossProduct);
|
|
VectorOperations<double>::mulScalar(crossProduct, factor, magMom, 3);
|
|
return returnvalue::OK;
|
|
}
|