Skip to content

Commit 59fcadb

Browse files
committed
add setDipoleMoment function
1 parent 2e45944 commit 59fcadb

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

FprimeZephyrReference/Components/DetumbleManager/DetumbleManager.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
#include <Fw/Types/Assert.hpp>
99

10+
#include <algorithm>
11+
#include <cmath>
12+
1013
namespace Components {
1114

1215
// ----------------------------------------------------------------------
@@ -48,4 +51,24 @@ bool DetumbleManager::executeControlStep() {
4851
// Then apply the dipole moment here, gonna have to figure that out.
4952
return true;
5053
}
54+
void DetumbleManager::setDipoleMoment(Drv::DipoleMoment dpMoment) {
55+
// Convert dipole moment to (unlimited) current
56+
F64 unlimited_x = dpMoment.get_x() / (this->COIL_NUM_TURNS_X_Y * this->COIL_AREA_X_Y);
57+
F64 unlimited_y = dpMoment.get_y() / (this->COIL_NUM_TURNS_X_Y * this->COIL_AREA_X_Y);
58+
F64 unlimited_z = dpMoment.get_z() / (this->COIL_NUM_TURNS_Z * this->COIL_AREA_Z);
59+
60+
// Limit current for each axis to max coil current
61+
F64 limited_x = std::min(std::fabs(unlimited_x), this->COIL_MAX_CURRENT_X_Y) * (unlimited_x >= 0 ? 1.0f : -1.0f);
62+
F64 limited_y = std::min(std::fabs(unlimited_y), this->COIL_MAX_CURRENT_X_Y) * (unlimited_y >= 0 ? 1.0f : -1.0f);
63+
F64 limited_z = std::min(std::fabs(unlimited_z), this->COIL_MAX_CURRENT_Z) * (unlimited_z >= 0 ? 1.0f : -1.0f);
64+
65+
F64 x1 = limited_x;
66+
F64 x2 = -limited_x;
67+
F64 y1 = limited_y;
68+
F64 y2 = -limited_y;
69+
F64 z1 = limited_z;
70+
71+
// Apply values to magnetorquers here
72+
}
73+
5174
} // namespace Components

FprimeZephyrReference/Components/DetumbleManager/DetumbleManager.hpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "FprimeZephyrReference/Components/DetumbleManager/DetumbleManagerComponentAc.hpp"
1010

11+
#include <cmath>
12+
1113
namespace Components {
1214

1315
class DetumbleManager final : public DetumbleManagerComponentBase {
@@ -32,14 +34,31 @@ class DetumbleManager final : public DetumbleManagerComponentBase {
3234
U32 context //!< The call order
3335
) override;
3436

35-
// Variables
37+
// Constants
3638
Drv::MagneticField EMPTY_MG_FIELD = Drv::MagneticField(0.0, 0.0, 0.0, -1);
37-
Drv::MagneticField prevMgField = Drv::MagneticField(0.0, 0.0, 0.0, -1);
38-
3939
Drv::DipoleMoment EMPTY_DP_MOMENT = Drv::DipoleMoment(0.0, 0.0, 0.0);
40+
const double PI = 3.14159265358979323846;
41+
42+
// Proves V3 Magnetorquer Information
43+
F64 COIL_VOLTAGE = 3.3;
44+
F64 COIL_NUM_TURNS_X_Y = 48;
45+
F64 COIL_LENGTH_X_Y = 0.053;
46+
F64 COIL_WIDTH_X_Y = 0.045;
47+
F64 COIL_AREA_X_Y = this->COIL_LENGTH_X_Y * this->COIL_WIDTH_X_Y;
48+
F64 COIL_RESISTANCE_X_Y = 57.2;
49+
F64 COIL_MAX_CURRENT_X_Y = this->COIL_VOLTAGE / this->COIL_RESISTANCE_X_Y;
50+
I64 COIL_NUM_TURNS_Z = 153;
51+
F64 COIL_DIAMETER_Z = 0.05755;
52+
F64 COIL_AREA_Z = this->PI * powf(this->COIL_DIAMETER_Z / 2, 2.0);
53+
F64 COIL_RESISTANCE_Z = 248.8;
54+
F64 COIL_MAX_CURRENT_Z = this->COIL_VOLTAGE / this->COIL_RESISTANCE_Z;
55+
56+
// Variables
57+
Drv::MagneticField prevMgField = Drv::MagneticField(0.0, 0.0, 0.0, -1);
4058

4159
// Functions
4260
bool executeControlStep();
61+
void setDipoleMoment(Drv::DipoleMoment dpMoment);
4362
};
4463

4564
} // namespace Components

0 commit comments

Comments
 (0)