Skip to content

Commit 674ef18

Browse files
committed
add bdotdetumble component
1 parent b9e831b commit 674ef18

File tree

6 files changed

+249
-0
lines changed

6 files changed

+249
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// ======================================================================
2+
// \title BDotDetumble.cpp
3+
// \author aychar
4+
// \brief cpp file for BDotDetumble component implementation class
5+
// ======================================================================
6+
7+
#include "FprimeZephyrReference/Components/Drv/BDotDetumble/BDotDetumble.hpp"
8+
9+
#include <cmath>
10+
11+
namespace Drv {
12+
13+
// ----------------------------------------------------------------------
14+
// Component construction and destruction
15+
// ----------------------------------------------------------------------
16+
17+
BDotDetumble ::BDotDetumble(const char* const compName) : BDotDetumbleComponentBase(compName) {}
18+
19+
BDotDetumble ::~BDotDetumble() {}
20+
21+
Drv::DipoleMoment dipoleMomentGet_handler(const FwIndexType portNum,
22+
const Drv::MagneticField currMagField,
23+
const Drv::MagneticField prevMagField) {
24+
F32 magnitude = getMagnitude(currMagField);
25+
if (magnitude < 1e-6) {
26+
return; // Figure out how I should handle the return here.
27+
}
28+
29+
if (currMagField.timestamp <= prevMagField.timestamp) {
30+
return; // Also figure out the return here.
31+
}
32+
33+
F64* dB_dtArr = dB_dt(currMagField, prevMagField);
34+
if (dB_dtArr == nullptr) {
35+
return; // Yeah just figure out how to properly raise error/return nothing.
36+
}
37+
38+
F64 moment_x = this->gain * dB_dtArr[0] / magnitude;
39+
F64 moment_y = this->gain * dB_dtArr[1] / magnitude;
40+
F64 moment_z = this->gain * dB_dtArr[2] / magnitude;
41+
42+
delete[] dB_dtArr;
43+
44+
return Drv::DipoleMoment(moment_x, moment_y, moment_z);
45+
}
46+
47+
F32 getMagnitude(const Drv::MagneticField magField) {
48+
return sqrt(f64_square(magField.x) + f64_square(magField.y) + f64_square(magField.z));
49+
}
50+
51+
F64* dB_dt(const Drv::MagneticField currMagField, const Drv::MagneticField prevMagField) {
52+
I64 dt = currMagField.timestamp - prevMagField.timestamp;
53+
if (dt < 1e-6) {
54+
return nullptr;
55+
}
56+
57+
F64 dBx_dt = (currMagField.x - prevMagField.x) / dt;
58+
F64 dBy_dt = (currMagField.y - prevMagField.y) / dt;
59+
F64 dBz_dt = (currMagField.z - prevMagField.z) / dt;
60+
61+
F64* arr = new F64[3];
62+
arr[0] = dBx_dt;
63+
arr[1] = dBy_dt;
64+
arr[2] = dBz_dt;
65+
66+
return arr;
67+
}
68+
69+
} // namespace Drv
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module Drv {
2+
port DipoleMomentGet -> DipoleMoment
3+
}
4+
5+
module Drv {
6+
@ Component for F Prime FSW framework.
7+
passive component BDotDetumble {
8+
9+
sync input port dipoleMomentGet: DipoleMomentGet
10+
11+
telemetry DipoleMoment: DipoleMoment
12+
13+
###############################################################################
14+
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
15+
###############################################################################
16+
@ Port for requesting the current time
17+
time get port timeCaller
18+
19+
@ Port for sending textual representation of events
20+
text event port logTextOut
21+
22+
@ Port for sending events to downlink
23+
event port logOut
24+
25+
@ Port for sending telemetry channels to downlink
26+
telemetry port tlmOut
27+
28+
@ Port to return the value of a parameter
29+
param get port prmGetOut
30+
31+
@Port to set the value of a parameter
32+
param set port prmSetOut
33+
34+
}
35+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// ======================================================================
2+
// \title BDotDetumble.hpp
3+
// \author aychar
4+
// \brief hpp file for BDotDetumble component implementation class
5+
// ======================================================================
6+
7+
#ifndef Drv_BDotDetumble_HPP
8+
#define Drv_BDotDetumble_HPP
9+
10+
#include "FprimeZephyrReference/Components/Drv/BDotDetumble/BDotDetumbleComponentAc.hpp"
11+
#include "FprimeZephyrReference/Components/Drv/Helpers/Helpers.hpp"
12+
13+
namespace Drv {
14+
15+
class BDotDetumble final : public BDotDetumbleComponentBase {
16+
public:
17+
// ----------------------------------------------------------------------
18+
// Component construction and destruction
19+
// ----------------------------------------------------------------------
20+
21+
//! Construct BDotDetumble object
22+
BDotDetumble(const char* const compName //!< The component name
23+
);
24+
25+
//! Destroy BDotDetumble object
26+
~BDotDetumble();
27+
28+
// Get the current dipole moment
29+
Drv::DipoleMoment dipoleMomentGet_handler(const FwIndexType portNum) override;
30+
31+
private:
32+
F64 gain = 1.0;
33+
34+
// Get magnitude
35+
F32 getMagnitude(const Drv::MagneticField magField);
36+
37+
// Get the time derivative of the magnetic field
38+
F64* dB_dt(const Drv::MagneticField currMagField, const Drv::MagneticField prevMagField);
39+
40+
} // namespace Drv
41+
42+
#endif
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
####
2+
# F Prime CMakeLists.txt:
3+
#
4+
# SOURCES: list of source files (to be compiled)
5+
# AUTOCODER_INPUTS: list of files to be passed to the autocoders
6+
# DEPENDS: list of libraries that this module depends on
7+
#
8+
# More information in the F´ CMake API documentation:
9+
# https://fprime.jpl.nasa.gov/latest/docs/reference/api/cmake/API/
10+
#
11+
####
12+
13+
# Module names are derived from the path from the nearest project/library/framework
14+
# root when not specifically overridden by the developer. i.e. The module defined by
15+
# `Ref/SignalGen/CMakeLists.txt` will be named `Ref_SignalGen`.
16+
17+
register_fprime_library(
18+
AUTOCODER_INPUTS
19+
"${CMAKE_CURRENT_LIST_DIR}/BDotDetumble.fpp"
20+
SOURCES
21+
"${CMAKE_CURRENT_LIST_DIR}/BDotDetumble.cpp"
22+
# DEPENDS
23+
# MyPackage_MyOtherModule
24+
)
25+
26+
### Unit Tests ###
27+
# register_fprime_ut(
28+
# AUTOCODER_INPUTS
29+
# "${CMAKE_CURRENT_LIST_DIR}/BDotDetumble.fpp"
30+
# SOURCES
31+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/BDotDetumbleTestMain.cpp"
32+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/BDotDetumbleTester.cpp"
33+
# DEPENDS
34+
# STest # For rules-based testing
35+
# UT_AUTO_HELPERS
36+
# )
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Drv::BDotDetumble
2+
3+
Component for F Prime FSW framework.
4+
5+
## Usage Examples
6+
Add usage examples here
7+
8+
### Diagrams
9+
Add diagrams here
10+
11+
### Typical Usage
12+
And the typical usage of the component here
13+
14+
## Class Diagram
15+
Add a class diagram here
16+
17+
## Port Descriptions
18+
| Name | Description |
19+
|---|---|
20+
|---|---|
21+
22+
## Component States
23+
Add component states in the chart below
24+
| Name | Description |
25+
|---|---|
26+
|---|---|
27+
28+
## Sequence Diagrams
29+
Add sequence diagrams here
30+
31+
## Parameters
32+
| Name | Description |
33+
|---|---|
34+
|---|---|
35+
36+
## Commands
37+
| Name | Description |
38+
|---|---|
39+
|---|---|
40+
41+
## Events
42+
| Name | Description |
43+
|---|---|
44+
|---|---|
45+
46+
## Telemetry
47+
| Name | Description |
48+
|---|---|
49+
|---|---|
50+
51+
## Unit Tests
52+
Add unit test descriptions in the chart below
53+
| Name | Description | Output | Coverage |
54+
|---|---|---|---|
55+
|---|---|---|---|
56+
57+
## Requirements
58+
Add requirements in the chart below
59+
| Name | Description | Validation |
60+
|---|---|---|
61+
|---|---|---|
62+
63+
## Change Log
64+
| Date | Description |
65+
|---|---|
66+
|---| Initial Draft |

FprimeZephyrReference/Components/Drv/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Lis2mdlManager/")
33
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Lsm6dsoManager/")
44
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/RtcManager")
55
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Types/")
6+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/BDotDetumble/")

0 commit comments

Comments
 (0)