-
Notifications
You must be signed in to change notification settings - Fork 3
Power monitor #76
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
Merged
Power monitor #76
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
f96677b
create Ina219 manager and driver components (not impl)
asiemsen 14819e2
Add Ina219 Driver to CMAKE
nateinaction 700544e
fixing power monitor generations
asiemsen 2fa08f7
Merge branch 'power-monitor' of https://github.com/Open-Source-Space-…
asiemsen 56fdece
Impl PowerMonitor
nateinaction 0c5314b
implemented ina219 manager cpp
asiemsen 313debc
add run handler function
asiemsen 31ab047
Add comments
nateinaction bd118fd
add powermonitorManager and inu219Manager to topology
asiemsen 3d00b38
fix typo
asiemsen 84d8e66
Override min number of rate group ports
nateinaction bdb101e
add helper function for power monitor device configure and add solar …
asiemsen 6413cd8
fixed instances
asiemsen bc2a83e
change member variable naming
asiemsen 816d1e3
fix build errors
asiemsen 1a81717
fixing build errors
asiemsen 1e51e8c
Update Device Tree
Mikefly123 8df88e4
Fixed Pin Names
Mikefly123 51a9a31
Added Bus Voltage Range
Mikefly123 cad87d7
Fixed Telem Writes
Mikefly123 2fe4c95
Feedback
nateinaction fe27a58
Unify power monitor
nateinaction 7121696
Fill out power monitor sdd
nateinaction cc753a4
Initial power monitor test
nateinaction 98dc73c
Test passing
nateinaction 7252219
More Device Tree Tweaks!
Mikefly123 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,12 +1,13 @@ | ||
| # Include project-wide components here | ||
|
|
||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Drv/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/AntennaDeployer/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/BootloaderTrigger/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Burnwire/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ComDelay/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Drv/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FatalHandler") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FsSpace/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ImuManager/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/NullPrmDb/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/PowerMonitor/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Watchdog") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Burnwire/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/BootloaderTrigger/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/AntennaDeployer/") | ||
| add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FsSpace/") |
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
36 changes: 36 additions & 0 deletions
36
FprimeZephyrReference/Components/Drv/Ina219Manager/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}/Ina219Manager.fpp" | ||
| SOURCES | ||
| "${CMAKE_CURRENT_LIST_DIR}/Ina219Manager.cpp" | ||
| # DEPENDS | ||
| # MyPackage_MyOtherModule | ||
| ) | ||
|
|
||
| ### Unit Tests ### | ||
| # register_fprime_ut( | ||
| # AUTOCODER_INPUTS | ||
| # "${CMAKE_CURRENT_LIST_DIR}/Ina219Manager.fpp" | ||
| # SOURCES | ||
| # "${CMAKE_CURRENT_LIST_DIR}/test/ut/Ina219ManagerTestMain.cpp" | ||
| # "${CMAKE_CURRENT_LIST_DIR}/test/ut/Ina219ManagerTester.cpp" | ||
| # DEPENDS | ||
| # STest # For rules-based testing | ||
| # UT_AUTO_HELPERS | ||
| # ) |
85 changes: 85 additions & 0 deletions
85
FprimeZephyrReference/Components/Drv/Ina219Manager/Ina219Manager.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,85 @@ | ||
| // ====================================================================== | ||
| // \title Ina219Manager.cpp | ||
| // \brief cpp file for Ina219Manager component implementation class | ||
| // ====================================================================== | ||
|
|
||
| #include "FprimeZephyrReference/Components/Drv/Ina219Manager/Ina219Manager.hpp" | ||
| #include <Fw/Types/Assert.hpp> | ||
|
|
||
| namespace Drv { | ||
|
|
||
| // ---------------------------------------------------------------------- | ||
| // Component construction and destruction | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| Ina219Manager ::Ina219Manager(const char* const compName) : Ina219ManagerComponentBase(compName) {} | ||
|
|
||
| Ina219Manager ::~Ina219Manager() {} | ||
|
|
||
| // ---------------------------------------------------------------------- | ||
| // Helper methods | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| void Ina219Manager::configure(const struct device* dev) { | ||
| this->m_dev = dev; | ||
| } | ||
|
|
||
| // ---------------------------------------------------------------------- | ||
| // Handler implementations for typed input ports | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| F64 Ina219Manager ::currentGet_handler(FwIndexType portNum) { | ||
| if (!device_is_ready(this->m_dev)) { | ||
| this->log_WARNING_HI_DeviceNotReady(); | ||
| return 0; | ||
| } | ||
| this->log_WARNING_HI_DeviceNotReady_ThrottleClear(); | ||
|
|
||
| struct sensor_value current; | ||
|
|
||
| sensor_sample_fetch_chan(this->m_dev, SENSOR_CHAN_CURRENT); | ||
|
|
||
| sensor_channel_get(this->m_dev, SENSOR_CHAN_CURRENT, ¤t); | ||
|
|
||
| this->tlmWrite_Current(sensor_value_to_double(¤t)); | ||
|
|
||
| return sensor_value_to_double(¤t); | ||
| } | ||
|
|
||
| F64 Ina219Manager ::powerGet_handler(FwIndexType portNum) { | ||
| if (!device_is_ready(this->m_dev)) { | ||
| this->log_WARNING_HI_DeviceNotReady(); | ||
| return 0; | ||
| } | ||
| this->log_WARNING_HI_DeviceNotReady_ThrottleClear(); | ||
|
|
||
| struct sensor_value power; | ||
|
|
||
| sensor_sample_fetch_chan(this->m_dev, SENSOR_CHAN_POWER); | ||
|
|
||
| sensor_channel_get(this->m_dev, SENSOR_CHAN_POWER, &power); | ||
|
|
||
| this->tlmWrite_Power(sensor_value_to_double(&power)); | ||
|
|
||
| return sensor_value_to_double(&power); | ||
| } | ||
|
|
||
| F64 Ina219Manager ::voltageGet_handler(FwIndexType portNum) { | ||
| if (!device_is_ready(this->m_dev)) { | ||
| this->log_WARNING_HI_DeviceNotReady(); | ||
| return 0; | ||
| } | ||
| this->log_WARNING_HI_DeviceNotReady_ThrottleClear(); | ||
|
|
||
| struct sensor_value voltage; | ||
|
|
||
| sensor_sample_fetch_chan(this->m_dev, SENSOR_CHAN_VOLTAGE); | ||
|
|
||
| sensor_channel_get(this->m_dev, SENSOR_CHAN_VOLTAGE, &voltage); | ||
|
|
||
| this->tlmWrite_Voltage(sensor_value_to_double(&voltage)); | ||
|
|
||
| return sensor_value_to_double(&voltage); | ||
| } | ||
|
|
||
| } // namespace Drv |
50 changes: 50 additions & 0 deletions
50
FprimeZephyrReference/Components/Drv/Ina219Manager/Ina219Manager.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,50 @@ | ||
| module Drv { | ||
| port VoltageGet -> F64 | ||
| port CurrentGet -> F64 | ||
| port PowerGet -> F64 | ||
| } | ||
|
|
||
| module Drv { | ||
| @ Manager for Ina219 device | ||
| passive component Ina219Manager { | ||
| # Ports | ||
| @ Port to read the voltage in volts | ||
| sync input port voltageGet: VoltageGet | ||
|
|
||
| @ Port to read the current in amps | ||
| sync input port currentGet: CurrentGet | ||
|
|
||
| @ Port to read the power in watts | ||
| sync input port powerGet: PowerGet | ||
|
|
||
| # Telemetry channels | ||
|
|
||
| @ Telemetry channel for voltage in volts | ||
| telemetry Voltage: F64 | ||
|
|
||
| @ Telemetry channel for current in amps | ||
| telemetry Current: F64 | ||
|
|
||
| @ Telemetry channel for power in watts | ||
| telemetry Power: F64 | ||
|
|
||
| @ Event for reporting INA219 not ready error | ||
| event DeviceNotReady() severity warning high format "INA219 device not ready" throttle 5 | ||
|
|
||
| ############################################################################### | ||
| # 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 | ||
|
|
||
| } | ||
| } |
70 changes: 70 additions & 0 deletions
70
FprimeZephyrReference/Components/Drv/Ina219Manager/Ina219Manager.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,70 @@ | ||
| // ====================================================================== | ||
| // \title Ina219Manager.hpp | ||
| // \brief hpp file for Ina219Manager component implementation class | ||
| // ====================================================================== | ||
|
|
||
| #ifndef Drv_Ina219Manager_HPP | ||
| #define Drv_Ina219Manager_HPP | ||
|
|
||
| #include "FprimeZephyrReference/Components/Drv/Ina219Manager/Ina219ManagerComponentAc.hpp" | ||
|
|
||
| #include <zephyr/device.h> | ||
| #include <zephyr/drivers/sensor.h> | ||
| #include <zephyr/kernel.h> | ||
| namespace Drv { | ||
|
|
||
| class Ina219Manager final : public Ina219ManagerComponentBase { | ||
| public: | ||
| // ---------------------------------------------------------------------- | ||
| // Component construction and destruction | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| //! Construct Ina219Manager object | ||
| Ina219Manager(const char* const compName //!< The component name | ||
| ); | ||
|
|
||
| //! Destroy Ina219Manager object | ||
| ~Ina219Manager(); | ||
|
|
||
| public: | ||
| // ---------------------------------------------------------------------- | ||
| // Helper methods | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| //! Configure the INA219 device | ||
| void configure(const struct device* dev); | ||
|
|
||
| private: | ||
| // ---------------------------------------------------------------------- | ||
| // Handler implementations for typed input ports | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| //! Handler implementation for currentGet | ||
| //! | ||
| //! Port to read the current in amps | ||
| F64 currentGet_handler(FwIndexType portNum //!< The port number | ||
| ) override; | ||
|
|
||
| //! Handler implementation for powerGet | ||
| //! | ||
| //! Port to read the power in watts | ||
| F64 powerGet_handler(FwIndexType portNum //!< The port number | ||
| ) override; | ||
|
|
||
| //! Handler implementation for voltageGet | ||
| //! | ||
| //! Port to read the voltage in volts | ||
| F64 voltageGet_handler(FwIndexType portNum //!< The port number | ||
| ) override; | ||
|
|
||
| // ---------------------------------------------------------------------- | ||
| // Member variables | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| //! Zephyr device stores the initialized LIS2MDL sensor | ||
| const struct device* m_dev; | ||
| }; | ||
|
|
||
| } // namespace Drv | ||
|
|
||
| #endif |
111 changes: 111 additions & 0 deletions
111
FprimeZephyrReference/Components/Drv/Ina219Manager/docs/sdd.md
nateinaction marked this conversation as resolved.
Show resolved
Hide resolved
|
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,111 @@ | ||
| # Drv::Ina219Manager | ||
|
|
||
| The INA219 Manager component interfaces with the INA219 current/power monitor to provide voltage, current, and power measurements. | ||
|
|
||
| ## Usage Examples | ||
|
|
||
| The INA219 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 any of the input ports: `VoltageGet`, `CurrentGet`, or `PowerGet` | ||
| 3. On each call, the component: | ||
| - Fetches fresh sensor samples from the sensor | ||
| - Converts sensor data to double precision floating point | ||
| - Writes telemetry data | ||
| - Returns data in SI units | ||
|
|
||
| ## Class Diagram | ||
|
|
||
| ```mermaid | ||
| classDiagram | ||
| namespace Drv { | ||
| class Ina219ManagerComponentBase { | ||
| <<Auto-generated>> | ||
| } | ||
| class Ina219Manager { | ||
| - m_dev: const struct device* | ||
| + Ina219Manager(const char* compName) | ||
| + ~Ina219Manager() | ||
| + configure(const struct device* dev) | ||
| - voltageGet_handler(const FwIndexType portNum): F64 | ||
| - currentGet_handler(const FwIndexType portNum): F64 | ||
| - powerGet_handler(const FwIndexType portNum): F64 | ||
| } | ||
| } | ||
| Ina219ManagerComponentBase <|-- Ina219Manager : inherits | ||
| ``` | ||
|
|
||
| ## Port Descriptions | ||
| | Name | Type | Description | | ||
| |---|---|---| | ||
| | VoltageGet | sync input | Triggers voltage data collection and returns voltage in volts | | ||
| | CurrentGet | sync input | Triggers current data collection and returns current in amps | | ||
| | PowerGet | sync input | Triggers power data collection and returns power in watts | | ||
|
|
||
| ## Sequence Diagrams | ||
|
|
||
| ### VoltageGet | ||
| ```mermaid | ||
| sequenceDiagram | ||
| participant Manager | ||
| participant INA219 Manager | ||
| participant Zephyr Sensor API | ||
| participant INA219 Sensor | ||
|
|
||
| Manager-->>INA219 Manager: Call VoltageGet synchronous input port | ||
| INA219 Manager->>Zephyr Sensor API: Fetch sensor data | ||
| Zephyr Sensor API->>INA219 Sensor: Read sensor | ||
| INA219 Sensor->>Zephyr Sensor API: Return sensor data | ||
| Zephyr Sensor API->>INA219 Manager: Return voltage sensor_value struct | ||
| INA219 Manager->>INA219 Manager: Write telemetry | ||
| INA219 Manager-->>Manager: Return F64 voltage in volts | ||
| ``` | ||
|
|
||
| ### CurrentGet | ||
| ```mermaid | ||
| sequenceDiagram | ||
| participant Manager | ||
| participant INA219 Manager | ||
| participant Zephyr Sensor API | ||
| participant INA219 Sensor | ||
|
|
||
| Manager-->>INA219 Manager: Call CurrentGet synchronous input port | ||
| INA219 Manager->>Zephyr Sensor API: Fetch sensor data | ||
| Zephyr Sensor API->>INA219 Sensor: Read sensor | ||
| INA219 Sensor->>Zephyr Sensor API: Return sensor data | ||
| Zephyr Sensor API->>INA219 Manager: Return current sensor_value struct | ||
| INA219 Manager->>INA219 Manager: Write telemetry | ||
| INA219 Manager-->>Manager: Return F64 current in amps | ||
| ``` | ||
|
|
||
| ### PowerGet | ||
| ```mermaid | ||
| sequenceDiagram | ||
| participant Manager | ||
| participant INA219 Manager | ||
| participant Zephyr Sensor API | ||
| participant INA219 Sensor | ||
|
|
||
| Manager-->>INA219 Manager: Call PowerGet synchronous input port | ||
| INA219 Manager->>Zephyr Sensor API: Fetch sensor data | ||
| Zephyr Sensor API->>INA219 Sensor: Read sensor | ||
| INA219 Sensor->>Zephyr Sensor API: Return sensor data | ||
| Zephyr Sensor API->>INA219 Manager: Return power sensor_value struct | ||
| INA219 Manager->>INA219 Manager: Write telemetry | ||
| INA219 Manager-->>Manager: Return F64 power in watts | ||
| ``` | ||
|
|
||
| ## Requirements | ||
| | Name | Description | Validation | | ||
| |---|---|---| | ||
| | VoltageGet Port | The component shall provide access to voltage sensor data and return in volts | Integration test | | ||
| | CurrentGet Port | The component shall provide access to current sensor data and return in amps | Integration test | | ||
| | PowerGet Port | The component shall provide access to power sensor data and return in watts | Integration test | | ||
| | DeviceNotReady Event | The component shall emit a throttled warning event when the device is not ready | Verify event is emitted and throttled to 5 occurrences | | ||
|
|
||
| ## Change Log | ||
| | Date | Description | | ||
| |---|---| | ||
| | 2025-11-03 | Initial INA219 Manager component | |
Oops, something went wrong.
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.
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.
A bit of a big nit pick, but we should probably just name this component
INA219orINA219PowerMonitoror something to maintain the Application / Manager / Driver design pattern separation between things.A higher level
PowerMonitorManagercomponent might group together all of the individual power monitor components into a single interface with a little bit of logic that can be used to manipulate them.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.
Yeah the lack of consistency around component naming is maddening. This specific plan where we create specific device "managers" in the
Drvdir was discussed with @LeStarch but as long as we are consistent it doesn't matter. In this case this device manager is consistent with the Lis2mdl and Lsm6dso managers. I vote to keep the names as-is so we don't spend time futzing with the small potatoes stuff before launch. Some time post launch let's find agreement on a component naming scheme.Also, as you said the power monitor component will likely change before launch similar to the imu component shifting to a detumble component so there will likely be a chance to change that higher level component this month.