Skip to content

Commit b0fd33e

Browse files
nateinactionhrfarmerCopilotasiemsenineskhou
authored
Introduce ImuManager, Lis2mdlDriver & Lsm6dsoDriver Components (#11)
* Use custom board definition * Initial IMU component generation lastFile:FprimeZephyrReference/Components/Imu/Imu.fpp * Initial imu data pull * Reading magnetic field data * Add new telemetry for accel and angvel * Acceleration and AngularVelocity telemetry working * Add temp * Improve documentation * Update FprimeZephyrReference/Components/Imu/docs/sdd.md Co-authored-by: Copilot <[email protected]> * Add LIS2MDL driver & implement in Imu component (#16) * add lis2mdl driver and implement in imu component * fix formatting * Create lsm6dso driver component & implementation (#17) * Update README.md * Create lmsd6dsoDriver component * create ports for sensor reading output * fix port naming issue * Use custom board definition * Remove commented config * Moving prj.conf sensors to board definition * Add d board * Try referencing c definitions in d board * Making a common v5 board definition * Fix readme * Minor Makefile, Readme and cmake presets fixes * change lsm6dso internal structs to carry F64 and added output ports to imu * removed lmsdso init from imu constructor * remove old sensor reading from imu * add lms6dso driver to topology * change base id to allow for lis2mdl driver * remove line endings * add channel retrieval during sensor data * Ensure submodules are downloaded before venv is created * Fix infinit submodule make target recursion... --------- Co-authored-by: ineskhou <[email protected]> Co-authored-by: Nate Gay <[email protected]> Co-authored-by: Nate Gay <[email protected]> Co-authored-by: Saidi Adams <[email protected]> Co-authored-by: Michael Pham <[email protected]> * Spit out common helpers and types from drivers, standardize port name schema, update SDDs * Remove unnecessary board files * remove fpp helper file * finished renaming to build * add parentheses for clearer intentions * remove FW_ASSERTs * clear throttle after successful device ready check * adding telemetry to lis2mdlManager * fix fprime files to match new names & telemetry structure * edit cpp implementation files to output telemetry * formatting * clear throttle, configure lsm6 sensor, read->get * Add IMU tests * Add type hinting * Comment fix --------- Co-authored-by: aychar <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Aaron Siemsen <[email protected]> Co-authored-by: ineskhou <[email protected]> Co-authored-by: Saidi Adams <[email protected]> Co-authored-by: Michael Pham <[email protected]> Co-authored-by: asiemsen <[email protected]>
1 parent db9d018 commit b0fd33e

27 files changed

+1033
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Include project-wide components here
22

3+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Drv/")
34
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FatalHandler")
5+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ImuManager/")
46
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Watchdog")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Include project-wide components here
2+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Helpers/")
3+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Lis2mdlManager/")
4+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Lsm6dsoManager/")
5+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Types/")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
SOURCES
19+
"${CMAKE_CURRENT_LIST_DIR}/Helpers.cpp"
20+
DEPENDS
21+
Fw_Types
22+
)
23+
24+
### Unit Tests ###
25+
# register_fprime_ut(
26+
# AUTOCODER_INPUTS
27+
# "${CMAKE_CURRENT_LIST_DIR}/Helpers.fpp"
28+
# SOURCES
29+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/HelpersTestMain.cpp"
30+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/HelpersTester.cpp"
31+
# DEPENDS
32+
# STest # For rules-based testing
33+
# UT_AUTO_HELPERS
34+
# )
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// ======================================================================
2+
// \title Helpers.cpp
3+
// \brief cpp file for Helpers component implementation class
4+
// ======================================================================
5+
6+
#include "FprimeZephyrReference/Components/Drv/Helpers/Helpers.hpp"
7+
8+
#include <Fw/Types/Assert.hpp>
9+
10+
namespace Drv {
11+
12+
F64 sensor_value_to_f64(const struct sensor_value& val) {
13+
return val.val1 + (val.val2 / 1000000.0f);
14+
}
15+
16+
} // namespace Drv
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// ======================================================================
2+
// \title Helpers.hpp
3+
// \brief hpp file for Helpers component implementation class
4+
// ======================================================================
5+
6+
#ifndef Components_Helpers_HPP
7+
#define Components_Helpers_HPP
8+
9+
#include <Fw/Types/BasicTypes.h>
10+
#include <zephyr/drivers/sensor.h>
11+
12+
namespace Drv {
13+
14+
//! Convert a Zephyr sensor_value to an Fprime F64
15+
F64 sensor_value_to_f64(const struct sensor_value& val);
16+
17+
} // namespace Drv
18+
19+
#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}/Lis2mdlManager.fpp"
20+
SOURCES
21+
"${CMAKE_CURRENT_LIST_DIR}/Lis2mdlManager.cpp"
22+
DEPENDS
23+
FprimeZephyrReference_Components_Drv_Helpers
24+
)
25+
26+
### Unit Tests ###
27+
# register_fprime_ut(
28+
# AUTOCODER_INPUTS
29+
# "${CMAKE_CURRENT_LIST_DIR}/Lis2mdlManager.fpp"
30+
# SOURCES
31+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/Lis2mdlManagerTestMain.cpp"
32+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/Lis2mdlManagerTester.cpp"
33+
# DEPENDS
34+
# STest # For rules-based testing
35+
# UT_AUTO_HELPERS
36+
# )
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// ======================================================================
2+
// \title Lis2mdlManager.cpp
3+
// \brief cpp file for Lis2mdlManager component implementation class
4+
// ======================================================================
5+
6+
#include "FprimeZephyrReference/Components/Drv/Lis2mdlManager/Lis2mdlManager.hpp"
7+
8+
#include <Fw/Types/Assert.hpp>
9+
10+
namespace Drv {
11+
12+
// ----------------------------------------------------------------------
13+
// Component construction and destruction
14+
// ----------------------------------------------------------------------
15+
16+
Lis2mdlManager ::Lis2mdlManager(const char* const compName) : Lis2mdlManagerComponentBase(compName) {
17+
dev = device_get_binding("LIS2MDL");
18+
}
19+
20+
Lis2mdlManager ::~Lis2mdlManager() {}
21+
22+
// ----------------------------------------------------------------------
23+
// Handler implementations for typed input ports
24+
// ----------------------------------------------------------------------
25+
26+
Drv::MagneticField Lis2mdlManager ::magneticFieldGet_handler(FwIndexType portNum) {
27+
if (!device_is_ready(dev)) {
28+
this->log_WARNING_HI_DeviceNotReady();
29+
return Drv::MagneticField(0.0, 0.0, 0.0);
30+
}
31+
this->log_WARNING_HI_DeviceNotReady_ThrottleClear();
32+
33+
struct sensor_value x;
34+
struct sensor_value y;
35+
struct sensor_value z;
36+
37+
sensor_sample_fetch_chan(dev, SENSOR_CHAN_MAGN_XYZ);
38+
39+
sensor_channel_get(dev, SENSOR_CHAN_MAGN_X, &x);
40+
sensor_channel_get(dev, SENSOR_CHAN_MAGN_Y, &y);
41+
sensor_channel_get(dev, SENSOR_CHAN_MAGN_Z, &z);
42+
43+
Drv::MagneticField magnetic_readings =
44+
Drv::MagneticField(Drv::sensor_value_to_f64(x), Drv::sensor_value_to_f64(y), Drv::sensor_value_to_f64(z));
45+
46+
this->tlmWrite_MagneticField(magnetic_readings);
47+
48+
return magnetic_readings;
49+
}
50+
51+
} // namespace Drv
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Port definition
2+
module Drv {
3+
port MagneticFieldGet -> MagneticField
4+
}
5+
6+
# Component definition
7+
module Drv {
8+
@ LIS2MDL Manager Component for F Prime FSW framework.
9+
passive component Lis2mdlManager {
10+
@ Port to read the current magnetic field in gauss.
11+
sync input port magneticFieldGet: MagneticFieldGet
12+
13+
@ Event for reporting LSM6DSO not ready error
14+
event DeviceNotReady() severity warning high format "LIS2MDL device not ready" throttle 5
15+
16+
@ Telemetry channel for magnetic field in gauss
17+
telemetry MagneticField: MagneticField
18+
19+
20+
###############################################################################
21+
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
22+
###############################################################################
23+
@ Port for requesting the current time
24+
time get port timeCaller
25+
26+
@ Port for sending textual representation of events
27+
text event port logTextOut
28+
29+
@ Port for sending events to downlink
30+
event port logOut
31+
32+
@ Port for sending telemetry channels to downlink
33+
telemetry port tlmOut
34+
}
35+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// ======================================================================
2+
// \title Lis2mdlManager.hpp
3+
// \brief hpp file for Lis2mdlManager component implementation class
4+
// ======================================================================
5+
6+
#ifndef Components_Lis2mdlManager_HPP
7+
#define Components_Lis2mdlManager_HPP
8+
9+
// clang-format off
10+
// Keep the includes in this order
11+
#include "FprimeZephyrReference/Components/Drv/Lis2mdlManager/Lis2mdlManagerComponentAc.hpp"
12+
#include "FprimeZephyrReference/Components/Drv/Helpers/Helpers.hpp"
13+
// clang-format on
14+
15+
#include <zephyr/device.h>
16+
#include <zephyr/drivers/sensor.h>
17+
#include <zephyr/kernel.h>
18+
19+
namespace Drv {
20+
21+
class Lis2mdlManager final : public Lis2mdlManagerComponentBase {
22+
public:
23+
// ----------------------------------------------------------------------
24+
// Component construction and destruction
25+
// ----------------------------------------------------------------------
26+
27+
//! Construct Lis2mdlManager object
28+
Lis2mdlManager(const char* const compName);
29+
30+
//! Destroy Lis2mdlManager object
31+
~Lis2mdlManager();
32+
33+
private:
34+
// ----------------------------------------------------------------------
35+
// Handler implementations for typed input ports
36+
// ----------------------------------------------------------------------
37+
38+
//! Get the magnetic field reading from the LIS2MDL sensor
39+
Drv::MagneticField magneticFieldGet_handler(const FwIndexType portNum //!< The port number
40+
) override;
41+
42+
// ----------------------------------------------------------------------
43+
// Member variables
44+
// ----------------------------------------------------------------------
45+
46+
//! Zephyr device stores the initialized LIS2MDL sensor
47+
const struct device* dev;
48+
};
49+
50+
} // namespace Drv
51+
52+
#endif
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Drv::Lis2mdlManager
2+
3+
The LIS2MDL Manager component interfaces with the LIS2MDL magnetometer to provide magnetic field measurements.
4+
5+
## Usage Examples
6+
7+
The LIS2MDL Manager component is designed to be called periodically to collect and return sensor data. It operates as a passive component that responds to manager calls.
8+
9+
### Typical Usage
10+
11+
1. The component is instantiated and initialized during system startup
12+
2. A manager calls the `MagneticFieldGet` port
13+
3. On each call, the component:
14+
- Fetches fresh sensor samples from the sensor
15+
- Converts sensor data to F Prime data structures
16+
- Writes telemetry data
17+
- Returns data in SI units
18+
19+
## Class Diagram
20+
21+
```mermaid
22+
classDiagram
23+
namespace Drv {
24+
class Lis2mdlManagerComponentBase {
25+
<<Auto-generated>>
26+
}
27+
class Lis2mdlManager {
28+
- lis2mdl: const struct device*
29+
+ Lis2mdlManager(const char* compName)
30+
+ ~Lis2mdlManager()
31+
- magneticFieldGet_handler(const FwIndexType portNum): Drv::MagneticField
32+
}
33+
}
34+
Lis2mdlManagerComponentBase <|-- Lis2mdlManager : inherits
35+
```
36+
37+
## Port Descriptions
38+
| Name | Type | Description |
39+
|---|---|---|
40+
| MagneticFieldGet | sync input | Triggers magnetic field data collection and returns a MagneticField struct |
41+
42+
## Sequence Diagrams
43+
44+
```mermaid
45+
sequenceDiagram
46+
participant Manager
47+
participant LIS2MDL Manager
48+
participant Zephyr Sensor API
49+
participant LIS2MDL Sensor
50+
51+
Manager-->>LIS2MDL Manager: Call MagneticFieldGet synchronous input port
52+
LIS2MDL Manager->>Zephyr Sensor API: Fetch sensor data
53+
Zephyr Sensor API->>LIS2MDL Sensor: Read sensor
54+
LIS2MDL Sensor->>Zephyr Sensor API: Return sensor data
55+
Zephyr Sensor API->>LIS2MDL Manager: Return x, y, z sensor_value structs
56+
LIS2MDL Manager->>LIS2MDL Manager: Write telemetry
57+
LIS2MDL Manager-->>Manager: Return MagneticField struct
58+
```
59+
60+
## Requirements
61+
Add requirements in the chart below
62+
| Name | Description | Validation |
63+
|---|---|---|
64+
| MagneticFieldGet Port | The component shall provide access magnetic field sensor data and return in MagneticField struct, readings will be in gauss | Verify output matches expected values from sensor datasheet |
65+
66+
## Change Log
67+
| Date | Description |
68+
|---|---|
69+
| 2025-9-15 | Initial LIS2MDL Manager component |

0 commit comments

Comments
 (0)