meggert
6567fd1023
Some checks failed
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit
77 lines
2.8 KiB
C++
77 lines
2.8 KiB
C++
/*
|
|
* ActuatorCmd.cpp
|
|
*
|
|
* Created on: 4 Aug 2022
|
|
* Author: Robin Marquardt
|
|
*/
|
|
|
|
#include "ActuatorCmd.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 <cmath>
|
|
|
|
#include "util/CholeskyDecomposition.h"
|
|
#include "util/MathOperations.h"
|
|
|
|
ActuatorCmd::ActuatorCmd(AcsParameters *acsParameters_) { acsParameters = *acsParameters_; }
|
|
|
|
ActuatorCmd::~ActuatorCmd() {}
|
|
|
|
void ActuatorCmd::scalingTorqueRws(const double *rwTrq, double *rwTrqScaled) {
|
|
// Scaling the commanded torque to a maximum value
|
|
double maxTrq = acsParameters.rwHandlingParameters.maxTrq;
|
|
|
|
double maxValue = 0;
|
|
for (int i = 0; i < 4; i++) { // size of torque, always 4 ?
|
|
if (abs(rwTrq[i]) > maxValue) {
|
|
maxValue = abs(rwTrq[i]);
|
|
}
|
|
}
|
|
|
|
if (maxValue > maxTrq) {
|
|
double scalingFactor = maxTrq / maxValue;
|
|
VectorOperations<double>::mulScalar(rwTrq, scalingFactor, rwTrqScaled, 4);
|
|
}
|
|
}
|
|
|
|
void ActuatorCmd::cmdSpeedToRws(const int32_t *speedRw0, const int32_t *speedRw1,
|
|
const int32_t *speedRw2, const int32_t *speedRw3,
|
|
const double *rwTorque, double *rwCmdSpeed) {
|
|
using namespace Math;
|
|
|
|
// Calculating the commanded speed in RPM for every reaction wheel
|
|
double speedRws[4] = {(double)*speedRw0, (double)*speedRw1, (double)*speedRw2, (double)*speedRw3};
|
|
double deltaSpeed[4] = {0, 0, 0, 0};
|
|
double commandTime = acsParameters.onBoardParams.sampleTime,
|
|
inertiaWheel = acsParameters.rwHandlingParameters.inertiaWheel;
|
|
double radToRpm = 60 / (2 * PI); // factor for conversion to RPM
|
|
// W_RW = Torque_RW / I_RW * delta t [rad/s]
|
|
double factor = commandTime / inertiaWheel * radToRpm;
|
|
VectorOperations<double>::mulScalar(rwTorque, factor, deltaSpeed, 4);
|
|
VectorOperations<double>::add(speedRws, deltaSpeed, rwCmdSpeed, 4);
|
|
}
|
|
|
|
void ActuatorCmd::cmdDipolMtq(const double *dipolMoment, double *dipolMomentActuator) {
|
|
// Convert to actuator frame
|
|
MatrixOperations<double>::multiply(*acsParameters.magnetorquesParameter.inverseAlignment,
|
|
dipolMoment, dipolMomentActuator, 3, 3, 1);
|
|
// Scaling along largest element if dipol exceeds maximum
|
|
double maxDipol = acsParameters.magnetorquesParameter.DipolMax;
|
|
double maxValue = 0;
|
|
for (int i = 0; i < 3; i++) {
|
|
if (abs(dipolMomentActuator[i]) > maxDipol) {
|
|
maxValue = abs(dipolMomentActuator[i]);
|
|
}
|
|
}
|
|
if (maxValue > maxDipol) {
|
|
double scalingFactor = maxDipol / maxValue;
|
|
VectorOperations<double>::mulScalar(dipolMomentActuator, scalingFactor, dipolMomentActuator, 3);
|
|
}
|
|
// scale dipole from 1 Am^2 to 1e^-4 Am^2
|
|
VectorOperations<double>::mulScalar(dipolMomentActuator, 1e4, dipolMomentActuator, 3);
|
|
}
|