-
Notifications
You must be signed in to change notification settings - Fork 4
Introduce ImuManager, Lis2mdlDriver & Lsm6dsoDriver Components #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
5cfb45d
Use custom board definition
nateinaction 74bf7a6
Initial IMU component generation
hrfarmer b4203c9
Initial imu data pull
nateinaction f110ce2
Reading magnetic field data
nateinaction 8e30497
Add new telemetry for accel and angvel
nateinaction f4c903f
Acceleration and AngularVelocity telemetry working
nateinaction 4caa93c
Add temp
nateinaction 55eeb0a
Improve documentation
nateinaction 981de3e
Update FprimeZephyrReference/Components/Imu/docs/sdd.md
nateinaction e44fa63
Add LIS2MDL driver & implement in Imu component (#16)
hrfarmer 8478ca1
Create lsm6dso driver component & implementation (#17)
asiemsen d064a09
Spit out common helpers and types from drivers, standardize port name…
nateinaction 4e3cb5b
Merge branch 'main' of github.com:Open-Source-Space-Foundation/proves…
nateinaction c0424fb
Merge branch 'main' of github.com:Open-Source-Space-Foundation/proves…
nateinaction d66c949
Remove unnecessary board files
nateinaction 4ad69fc
remove fpp helper file
asiemsen 36d5278
finished renaming to build
asiemsen d8fce1f
add parentheses for clearer intentions
asiemsen 516d730
remove FW_ASSERTs
asiemsen 8e4e8d2
clear throttle after successful device ready check
asiemsen 991b010
adding telemetry to lis2mdlManager
asiemsen b73dec0
Merge branch 'main' into imu2_PR_changes_saidi
hrfarmer cac1bfc
fix fprime files to match new names & telemetry structure
hrfarmer 8a395c2
edit cpp implementation files to output telemetry
hrfarmer ac7fd7b
formatting
hrfarmer f1e5405
Merge pull request #27 from Open-Source-Space-Foundation/imu2_PR_chan…
nateinaction 8fed4e3
clear throttle, configure lsm6 sensor, read->get
nateinaction adf6b8e
Add IMU tests
nateinaction 19042fb
Add type hinting
nateinaction 5b41b97
Comment fix
nateinaction File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| # Include project-wide components here | ||
|
|
||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Drv/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FatalHandler") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ImuManager/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Watchdog") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Include project-wide components here | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Helpers/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Lis2mdlManager/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Lsm6dsoManager/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Types/") |
34 changes: 34 additions & 0 deletions
34
FprimeZephyrReference/Components/Drv/Helpers/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #### | ||
| # F Prime CMakeLists.txt: | ||
| # | ||
| # SOURCES: list of source files (to be compiled) | ||
| # AUTOCODER_INPUTS: list of files to be passed to the autocoders | ||
| # DEPENDS: list of libraries that this module depends on | ||
| # | ||
| # More information in the F´ CMake API documentation: | ||
| # https://fprime.jpl.nasa.gov/latest/docs/reference/api/cmake/API/ | ||
| # | ||
| #### | ||
|
|
||
| # Module names are derived from the path from the nearest project/library/framework | ||
| # root when not specifically overridden by the developer. i.e. The module defined by | ||
| # `Ref/SignalGen/CMakeLists.txt` will be named `Ref_SignalGen`. | ||
|
|
||
| register_fprime_library( | ||
| SOURCES | ||
| "${CMAKE_CURRENT_LIST_DIR}/Helpers.cpp" | ||
| DEPENDS | ||
| Fw_Types | ||
| ) | ||
|
|
||
| ### Unit Tests ### | ||
| # register_fprime_ut( | ||
| # AUTOCODER_INPUTS | ||
| # "${CMAKE_CURRENT_LIST_DIR}/Helpers.fpp" | ||
| # SOURCES | ||
| # "${CMAKE_CURRENT_LIST_DIR}/test/ut/HelpersTestMain.cpp" | ||
| # "${CMAKE_CURRENT_LIST_DIR}/test/ut/HelpersTester.cpp" | ||
| # DEPENDS | ||
| # STest # For rules-based testing | ||
| # UT_AUTO_HELPERS | ||
| # ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // ====================================================================== | ||
| // \title Helpers.cpp | ||
| // \brief cpp file for Helpers component implementation class | ||
| // ====================================================================== | ||
|
|
||
| #include "FprimeZephyrReference/Components/Drv/Helpers/Helpers.hpp" | ||
|
|
||
| #include <Fw/Types/Assert.hpp> | ||
|
|
||
| namespace Drv { | ||
|
|
||
| F64 sensor_value_to_f64(const struct sensor_value& val) { | ||
| return val.val1 + (val.val2 / 1000000.0f); | ||
| } | ||
|
|
||
| } // namespace Drv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // ====================================================================== | ||
| // \title Helpers.hpp | ||
| // \brief hpp file for Helpers component implementation class | ||
| // ====================================================================== | ||
|
|
||
| #ifndef Components_Helpers_HPP | ||
| #define Components_Helpers_HPP | ||
|
|
||
| #include <Fw/Types/BasicTypes.h> | ||
| #include <zephyr/drivers/sensor.h> | ||
|
|
||
| namespace Drv { | ||
|
|
||
| //! Convert a Zephyr sensor_value to an Fprime F64 | ||
| F64 sensor_value_to_f64(const struct sensor_value& val); | ||
|
|
||
| } // namespace Drv | ||
|
|
||
| #endif |
36 changes: 36 additions & 0 deletions
36
FprimeZephyrReference/Components/Drv/Lis2mdlManager/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #### | ||
| # F Prime CMakeLists.txt: | ||
| # | ||
| # SOURCES: list of source files (to be compiled) | ||
| # AUTOCODER_INPUTS: list of files to be passed to the autocoders | ||
| # DEPENDS: list of libraries that this module depends on | ||
| # | ||
| # More information in the F´ CMake API documentation: | ||
| # https://fprime.jpl.nasa.gov/latest/docs/reference/api/cmake/API/ | ||
| # | ||
| #### | ||
|
|
||
| # Module names are derived from the path from the nearest project/library/framework | ||
| # root when not specifically overridden by the developer. i.e. The module defined by | ||
| # `Ref/SignalGen/CMakeLists.txt` will be named `Ref_SignalGen`. | ||
|
|
||
| register_fprime_library( | ||
| AUTOCODER_INPUTS | ||
| "${CMAKE_CURRENT_LIST_DIR}/Lis2mdlManager.fpp" | ||
| SOURCES | ||
| "${CMAKE_CURRENT_LIST_DIR}/Lis2mdlManager.cpp" | ||
| DEPENDS | ||
| FprimeZephyrReference_Components_Drv_Helpers | ||
| ) | ||
|
|
||
| ### Unit Tests ### | ||
| # register_fprime_ut( | ||
| # AUTOCODER_INPUTS | ||
| # "${CMAKE_CURRENT_LIST_DIR}/Lis2mdlManager.fpp" | ||
| # SOURCES | ||
| # "${CMAKE_CURRENT_LIST_DIR}/test/ut/Lis2mdlManagerTestMain.cpp" | ||
| # "${CMAKE_CURRENT_LIST_DIR}/test/ut/Lis2mdlManagerTester.cpp" | ||
| # DEPENDS | ||
| # STest # For rules-based testing | ||
| # UT_AUTO_HELPERS | ||
| # ) |
51 changes: 51 additions & 0 deletions
51
FprimeZephyrReference/Components/Drv/Lis2mdlManager/Lis2mdlManager.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // ====================================================================== | ||
| // \title Lis2mdlManager.cpp | ||
| // \brief cpp file for Lis2mdlManager component implementation class | ||
| // ====================================================================== | ||
|
|
||
| #include "FprimeZephyrReference/Components/Drv/Lis2mdlManager/Lis2mdlManager.hpp" | ||
|
|
||
| #include <Fw/Types/Assert.hpp> | ||
|
|
||
| namespace Drv { | ||
|
|
||
| // ---------------------------------------------------------------------- | ||
| // Component construction and destruction | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| Lis2mdlManager ::Lis2mdlManager(const char* const compName) : Lis2mdlManagerComponentBase(compName) { | ||
| dev = device_get_binding("LIS2MDL"); | ||
| } | ||
|
|
||
| Lis2mdlManager ::~Lis2mdlManager() {} | ||
|
|
||
| // ---------------------------------------------------------------------- | ||
| // Handler implementations for typed input ports | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| Drv::MagneticField Lis2mdlManager ::magneticFieldGet_handler(FwIndexType portNum) { | ||
| if (!device_is_ready(dev)) { | ||
| this->log_WARNING_HI_DeviceNotReady(); | ||
| return Drv::MagneticField(0.0, 0.0, 0.0); | ||
| } | ||
| this->log_WARNING_HI_DeviceNotReady_ThrottleClear(); | ||
|
|
||
nateinaction marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| struct sensor_value x; | ||
| struct sensor_value y; | ||
| struct sensor_value z; | ||
|
|
||
| sensor_sample_fetch_chan(dev, SENSOR_CHAN_MAGN_XYZ); | ||
|
|
||
| sensor_channel_get(dev, SENSOR_CHAN_MAGN_X, &x); | ||
| sensor_channel_get(dev, SENSOR_CHAN_MAGN_Y, &y); | ||
| sensor_channel_get(dev, SENSOR_CHAN_MAGN_Z, &z); | ||
|
|
||
| Drv::MagneticField magnetic_readings = | ||
| Drv::MagneticField(Drv::sensor_value_to_f64(x), Drv::sensor_value_to_f64(y), Drv::sensor_value_to_f64(z)); | ||
|
|
||
| this->tlmWrite_MagneticField(magnetic_readings); | ||
|
|
||
| return magnetic_readings; | ||
| } | ||
|
|
||
| } // namespace Drv | ||
35 changes: 35 additions & 0 deletions
35
FprimeZephyrReference/Components/Drv/Lis2mdlManager/Lis2mdlManager.fpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Port definition | ||
| module Drv { | ||
| port MagneticFieldGet -> MagneticField | ||
| } | ||
|
|
||
| # Component definition | ||
| module Drv { | ||
| @ LIS2MDL Manager Component for F Prime FSW framework. | ||
| passive component Lis2mdlManager { | ||
| @ Port to read the current magnetic field in gauss. | ||
| sync input port magneticFieldGet: MagneticFieldGet | ||
|
|
||
| @ Event for reporting LSM6DSO not ready error | ||
| event DeviceNotReady() severity warning high format "LIS2MDL device not ready" throttle 5 | ||
|
|
||
| @ Telemetry channel for magnetic field in gauss | ||
| telemetry MagneticField: MagneticField | ||
|
|
||
|
|
||
| ############################################################################### | ||
| # Standard AC Ports: Required for Channels, Events, Commands, and Parameters # | ||
| ############################################################################### | ||
| @ Port for requesting the current time | ||
| time get port timeCaller | ||
|
|
||
| @ Port for sending textual representation of events | ||
| text event port logTextOut | ||
|
|
||
| @ Port for sending events to downlink | ||
| event port logOut | ||
|
|
||
| @ Port for sending telemetry channels to downlink | ||
| telemetry port tlmOut | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
FprimeZephyrReference/Components/Drv/Lis2mdlManager/Lis2mdlManager.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // ====================================================================== | ||
| // \title Lis2mdlManager.hpp | ||
| // \brief hpp file for Lis2mdlManager component implementation class | ||
| // ====================================================================== | ||
|
|
||
| #ifndef Components_Lis2mdlManager_HPP | ||
| #define Components_Lis2mdlManager_HPP | ||
|
|
||
| // clang-format off | ||
| // Keep the includes in this order | ||
| #include "FprimeZephyrReference/Components/Drv/Lis2mdlManager/Lis2mdlManagerComponentAc.hpp" | ||
| #include "FprimeZephyrReference/Components/Drv/Helpers/Helpers.hpp" | ||
| // clang-format on | ||
|
|
||
| #include <zephyr/device.h> | ||
| #include <zephyr/drivers/sensor.h> | ||
| #include <zephyr/kernel.h> | ||
|
|
||
| namespace Drv { | ||
|
|
||
| class Lis2mdlManager final : public Lis2mdlManagerComponentBase { | ||
| public: | ||
| // ---------------------------------------------------------------------- | ||
| // Component construction and destruction | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| //! Construct Lis2mdlManager object | ||
| Lis2mdlManager(const char* const compName); | ||
|
|
||
| //! Destroy Lis2mdlManager object | ||
| ~Lis2mdlManager(); | ||
|
|
||
| private: | ||
| // ---------------------------------------------------------------------- | ||
| // Handler implementations for typed input ports | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| //! Get the magnetic field reading from the LIS2MDL sensor | ||
| Drv::MagneticField magneticFieldGet_handler(const FwIndexType portNum //!< The port number | ||
| ) override; | ||
|
|
||
| // ---------------------------------------------------------------------- | ||
| // Member variables | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| //! Zephyr device stores the initialized LIS2MDL sensor | ||
| const struct device* dev; | ||
| }; | ||
|
|
||
| } // namespace Drv | ||
|
|
||
| #endif |
69 changes: 69 additions & 0 deletions
69
FprimeZephyrReference/Components/Drv/Lis2mdlManager/docs/sdd.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # Drv::Lis2mdlManager | ||
|
|
||
| The LIS2MDL Manager component interfaces with the LIS2MDL magnetometer to provide magnetic field measurements. | ||
|
|
||
| ## Usage Examples | ||
|
|
||
| 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. | ||
|
|
||
| ### Typical Usage | ||
|
|
||
| 1. The component is instantiated and initialized during system startup | ||
| 2. A manager calls the `MagneticFieldGet` port | ||
| 3. On each call, the component: | ||
| - Fetches fresh sensor samples from the sensor | ||
| - Converts sensor data to F Prime data structures | ||
| - Writes telemetry data | ||
| - Returns data in SI units | ||
|
|
||
| ## Class Diagram | ||
|
|
||
| ```mermaid | ||
| classDiagram | ||
| namespace Drv { | ||
| class Lis2mdlManagerComponentBase { | ||
| <<Auto-generated>> | ||
| } | ||
| class Lis2mdlManager { | ||
| - lis2mdl: const struct device* | ||
| + Lis2mdlManager(const char* compName) | ||
| + ~Lis2mdlManager() | ||
| - magneticFieldGet_handler(const FwIndexType portNum): Drv::MagneticField | ||
| } | ||
| } | ||
| Lis2mdlManagerComponentBase <|-- Lis2mdlManager : inherits | ||
| ``` | ||
|
|
||
| ## Port Descriptions | ||
| | Name | Type | Description | | ||
| |---|---|---| | ||
| | MagneticFieldGet | sync input | Triggers magnetic field data collection and returns a MagneticField struct | | ||
|
|
||
| ## Sequence Diagrams | ||
|
|
||
| ```mermaid | ||
| sequenceDiagram | ||
| participant Manager | ||
| participant LIS2MDL Manager | ||
| participant Zephyr Sensor API | ||
| participant LIS2MDL Sensor | ||
|
|
||
| Manager-->>LIS2MDL Manager: Call MagneticFieldGet synchronous input port | ||
| LIS2MDL Manager->>Zephyr Sensor API: Fetch sensor data | ||
| Zephyr Sensor API->>LIS2MDL Sensor: Read sensor | ||
| LIS2MDL Sensor->>Zephyr Sensor API: Return sensor data | ||
| Zephyr Sensor API->>LIS2MDL Manager: Return x, y, z sensor_value structs | ||
| LIS2MDL Manager->>LIS2MDL Manager: Write telemetry | ||
| LIS2MDL Manager-->>Manager: Return MagneticField struct | ||
| ``` | ||
|
|
||
| ## Requirements | ||
| Add requirements in the chart below | ||
| | Name | Description | Validation | | ||
| |---|---|---| | ||
| | 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 | | ||
|
|
||
| ## Change Log | ||
| | Date | Description | | ||
| |---|---| | ||
| | 2025-9-15 | Initial LIS2MDL Manager component | |
36 changes: 36 additions & 0 deletions
36
FprimeZephyrReference/Components/Drv/Lsm6dsoManager/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #### | ||
| # F Prime CMakeLists.txt: | ||
| # | ||
| # SOURCES: list of source files (to be compiled) | ||
| # AUTOCODER_INPUTS: list of files to be passed to the autocoders | ||
| # DEPENDS: list of libraries that this module depends on | ||
| # | ||
| # More information in the F´ CMake API documentation: | ||
| # https://fprime.jpl.nasa.gov/latest/docs/reference/api/cmake/API/ | ||
| # | ||
| #### | ||
|
|
||
| # Module names are derived from the path from the nearest project/library/framework | ||
| # root when not specifically overridden by the developer. i.e. The module defined by | ||
| # `Ref/SignalGen/CMakeLists.txt` will be named `Ref_SignalGen`. | ||
|
|
||
| register_fprime_library( | ||
| AUTOCODER_INPUTS | ||
| "${CMAKE_CURRENT_LIST_DIR}/Lsm6dsoManager.fpp" | ||
| SOURCES | ||
| "${CMAKE_CURRENT_LIST_DIR}/Lsm6dsoManager.cpp" | ||
| DEPENDS | ||
| FprimeZephyrReference_Components_Drv_Helpers | ||
| ) | ||
|
|
||
| ### Unit Tests ### | ||
| # register_fprime_ut( | ||
| # AUTOCODER_INPUTS | ||
| # "${CMAKE_CURRENT_LIST_DIR}/Lsm6dsoManager.fpp" | ||
| # SOURCES | ||
| # "${CMAKE_CURRENT_LIST_DIR}/test/ut/Lsm6dsoManagerTestMain.cpp" | ||
| # "${CMAKE_CURRENT_LIST_DIR}/test/ut/Lsm6dsoManagerTester.cpp" | ||
| # DEPENDS | ||
| # STest # For rules-based testing | ||
| # UT_AUTO_HELPERS | ||
| # ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to Lis2mdlManager but leave in Drv folder and namespace