Skip to content

Commit ee86a88

Browse files
committed
Merge branch 'imu2' of github.com:Open-Source-Space-Foundation/proves-core-reference into lsm6dso-driver-component
2 parents bb1be34 + e44fa63 commit ee86a88

File tree

12 files changed

+237
-78
lines changed

12 files changed

+237
-78
lines changed

FprimeZephyrReference/Components/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FatalHandler")
44
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Watchdog")
55
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Imu/")
66
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/lms6dsoDriver/")
7+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Lis2mdlDriver/")

FprimeZephyrReference/Components/Imu/Imu.cpp

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ namespace Components {
1313
// Component construction and destruction
1414
// ----------------------------------------------------------------------
1515

16-
Imu ::Imu(const char* const compName) : ImuComponentBase(compName) {
17-
// Initialize the LIS2MDL sensor
18-
lis2mdl = device_get_binding("LIS2MDL");
19-
FW_ASSERT(device_is_ready(lis2mdl));
20-
21-
}
16+
Imu ::Imu(const char* const compName) : ImuComponentBase(compName) {}
2217

2318
Imu ::~Imu() {}
2419

@@ -27,35 +22,10 @@ Imu ::~Imu() {}
2722
// ----------------------------------------------------------------------
2823

2924
void Imu ::run_handler(FwIndexType portNum, U32 context) {
30-
// Fetch new data samples from the sensors
31-
sensor_sample_fetch_chan(lis2mdl, SENSOR_CHAN_MAGN_XYZ);
32-
33-
34-
// Output sensor values via telemetry
3525
this->tlmWrite_Acceleration(this->readAcceleration_out(0));
3626
this->tlmWrite_AngularVelocity(this->readAngularVelocity_out(0));
27+
this->tlmWrite_MagneticField(this->readMagneticField_out(0));
3728
this->tlmWrite_Temperature(this->readTemperature_out(0));
38-
39-
this->tlmWrite_MagneticField(this->get_magnetic_field());
40-
4129
}
4230

43-
F64 Imu ::sensor_value_to_f64(const struct sensor_value& val) {
44-
return val.val1 + val.val2 / 1000000.0f;
45-
}
46-
47-
Components::Imu_MagneticField Imu ::get_magnetic_field() {
48-
struct sensor_value x;
49-
struct sensor_value y;
50-
struct sensor_value z;
51-
52-
sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_X, &x);
53-
sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_Y, &y);
54-
sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_Z, &z);
55-
56-
return Components::Imu_MagneticField(this->sensor_value_to_f64(x), this->sensor_value_to_f64(y),
57-
this->sensor_value_to_f64(z));
58-
}
59-
60-
6131
} // namespace Components

FprimeZephyrReference/Components/Imu/Imu.fpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,22 @@ module Components {
44
sync input port run: Svc.Sched
55

66
output port readAcceleration: AccelerationRead
7-
87
output port readAngularVelocity: AngularVelocityRead
9-
8+
output port readMagneticField: MagneticFieldRead
109
output port readTemperature: TemperatureRead
1110

12-
@ Magnetic field reading in gauss
13-
struct MagneticField {
14-
x: F64
15-
y: F64
16-
z: F64
17-
}
11+
@Telemetry channel for angular velocity
12+
telemetry AngularVelocity: AngularVelocity
13+
14+
@ Telemetry channel for Acceleration
15+
telemetry Acceleration: Acceleration
1816

1917
@ Telemetry channel for magnetic field
2018
telemetry MagneticField: MagneticField
2119

2220
@ Telemetry channel for temperature in degrees Celsius
2321
telemetry Temperature: F64
2422

25-
@Telemetry channel for angular velocity
26-
telemetry AngularVelocity: AngularVelocity
27-
28-
@ Telemetry channel for Acceleration
29-
telemetry Acceleration: Acceleration
30-
3123
###############################################################################
3224
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
3325
###############################################################################

FprimeZephyrReference/Components/Imu/Imu.hpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88

99
#include "FprimeZephyrReference/Components/Imu/ImuComponentAc.hpp"
1010

11-
#include <zephyr/device.h>
12-
#include <zephyr/drivers/sensor.h>
13-
#include <zephyr/kernel.h>
14-
1511
namespace Components {
1612

1713
class Imu final : public ImuComponentBase {
@@ -35,31 +31,6 @@ class Imu final : public ImuComponentBase {
3531
void run_handler(FwIndexType portNum, //!< The port number
3632
U32 context //!< The call order
3733
) override;
38-
39-
// ----------------------------------------------------------------------
40-
// Helper methods
41-
// ----------------------------------------------------------------------
42-
43-
//! Convert a Zephyr sensor_value to an Fprime F64
44-
F64 sensor_value_to_f64(const struct sensor_value& val);
45-
46-
// ----------------------------------------------------------------------
47-
// IMU access methods
48-
// ----------------------------------------------------------------------
49-
50-
51-
//! Get the magnetic field reading from the IMU
52-
Components::Imu_MagneticField get_magnetic_field();
53-
54-
55-
// ----------------------------------------------------------------------
56-
// Member variables
57-
// ----------------------------------------------------------------------
58-
59-
//! Zephyr device stores the initialized LIS2MDL sensor
60-
const struct device* lis2mdl;
61-
62-
6334
};
6435

6536
} // namespace Components
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}/Lis2mdlDriver.fpp"
20+
SOURCES
21+
"${CMAKE_CURRENT_LIST_DIR}/Lis2mdlDriver.cpp"
22+
# DEPENDS
23+
# MyPackage_MyOtherModule
24+
)
25+
26+
### Unit Tests ###
27+
# register_fprime_ut(
28+
# AUTOCODER_INPUTS
29+
# "${CMAKE_CURRENT_LIST_DIR}/Lis2mdlDriver.fpp"
30+
# SOURCES
31+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/Lis2mdlDriverTestMain.cpp"
32+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/Lis2mdlDriverTester.cpp"
33+
# DEPENDS
34+
# STest # For rules-based testing
35+
# UT_AUTO_HELPERS
36+
# )
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// ======================================================================
2+
// \title Lis2mdlDriver.cpp
3+
// \author aychar
4+
// \brief cpp file for Lis2mdlDriver component implementation class
5+
// ======================================================================
6+
7+
#include "FprimeZephyrReference/Components/Lis2mdlDriver/Lis2mdlDriver.hpp"
8+
9+
#include <Fw/Types/Assert.hpp>
10+
11+
namespace Components {
12+
13+
// ----------------------------------------------------------------------
14+
// Component construction and destruction
15+
// ----------------------------------------------------------------------
16+
17+
Lis2mdlDriver ::Lis2mdlDriver(const char* const compName) : Lis2mdlDriverComponentBase(compName) {
18+
lis2mdl = device_get_binding("LIS2MDL");
19+
FW_ASSERT(device_is_ready(lis2mdl));
20+
}
21+
22+
Lis2mdlDriver ::~Lis2mdlDriver() {}
23+
24+
F64 Lis2mdlDriver ::sensor_value_to_f64(const struct sensor_value& val) {
25+
return val.val1 + val.val2 / 1000000.0f;
26+
}
27+
28+
Components::MagneticField Lis2mdlDriver ::getMagneticField_handler(FwIndexType portNum) {
29+
// Fetch new data sample from sensors
30+
sensor_sample_fetch_chan(lis2mdl, SENSOR_CHAN_MAGN_XYZ);
31+
32+
struct sensor_value x;
33+
struct sensor_value y;
34+
struct sensor_value z;
35+
36+
sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_X, &x);
37+
sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_Y, &y);
38+
sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_Z, &z);
39+
40+
return Components::MagneticField(this->sensor_value_to_f64(x), this->sensor_value_to_f64(y),
41+
this->sensor_value_to_f64(z));
42+
}
43+
44+
} // namespace Components
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Components {
2+
@ Magnetic field reading in gauss
3+
struct MagneticField {
4+
x: F64
5+
y: F64
6+
z: F64
7+
}
8+
9+
# Port definitions
10+
port MagneticFieldRead -> MagneticField
11+
12+
@ Component for F Prime FSW framework.
13+
passive component Lis2mdlDriver {
14+
15+
sync input port getMagneticField: MagneticFieldRead
16+
17+
###############################################################################
18+
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
19+
###############################################################################
20+
@ Port for requesting the current time
21+
time get port timeCaller
22+
23+
}
24+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// ======================================================================
2+
// \title Lis2mdlDriver.hpp
3+
// \author aychar
4+
// \brief hpp file for Lis2mdlDriver component implementation class
5+
// ======================================================================
6+
7+
#ifndef Components_Lis2mdlDriver_HPP
8+
#define Components_Lis2mdlDriver_HPP
9+
10+
#include "FprimeZephyrReference/Components/Lis2mdlDriver/Lis2mdlDriverComponentAc.hpp"
11+
12+
#include <zephyr/device.h>
13+
#include <zephyr/drivers/sensor.h>
14+
#include <zephyr/kernel.h>
15+
16+
namespace Components {
17+
18+
class Lis2mdlDriver final : public Lis2mdlDriverComponentBase {
19+
public:
20+
// ----------------------------------------------------------------------
21+
// Component construction and destruction
22+
// ----------------------------------------------------------------------
23+
24+
//! Construct Lis2mdlDriver object
25+
Lis2mdlDriver(const char* const compName //!< The component name
26+
);
27+
28+
//! Destroy Lis2mdlDriver object
29+
~Lis2mdlDriver();
30+
31+
private:
32+
//! Handler implementation
33+
MagneticField getMagneticField_handler(FwIndexType portNum) override;
34+
35+
// ----------------------------------------------------------------------
36+
// Helper methods
37+
// ----------------------------------------------------------------------
38+
39+
//! Convert a Zephyr sensor_value to an Fprime F64
40+
F64 sensor_value_to_f64(const struct sensor_value& val);
41+
42+
// ----------------------------------------------------------------------
43+
// Member variables
44+
// ----------------------------------------------------------------------
45+
46+
//! Zephyr device stores the initialized LIS2MDL sensor
47+
const struct device* lis2mdl;
48+
};
49+
50+
} // namespace Components
51+
52+
#endif
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Components::Lis2mdlDriver
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/ReferenceDeployment/Top/ReferenceDeploymentPackets.fppi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ telemetry packets ReferenceDeploymentPackets {
4040
ReferenceDeployment.imu.MagneticField
4141
}
4242

43-
4443
} omit {
4544
CdhCore.cmdDisp.CommandErrors
4645
# Only has one library, no custom versions

0 commit comments

Comments
 (0)