-
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 20 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 | ||
| # ) |
82 changes: 82 additions & 0 deletions
82
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,82 @@ | ||
| // ====================================================================== | ||
| // \title Ina219Manager.cpp | ||
| // \author nate | ||
| // \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() {} | ||
|
|
||
| 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 |
52 changes: 52 additions & 0 deletions
52
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,52 @@ | ||
| 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 | ||
|
|
||
| } | ||
| } |
65 changes: 65 additions & 0 deletions
65
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,65 @@ | ||
| // ====================================================================== | ||
| // \title Ina219Manager.hpp | ||
| // \author nate | ||
| // \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(); | ||
|
|
||
| void configure(const struct device* dev); // helper function to configure device for the class | ||
|
|
||
| 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 |
66 changes: 66 additions & 0 deletions
66
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,66 @@ | ||
| # Drv::Ina219Manager | ||
|
|
||
| Manager for Ina219 device | ||
|
|
||
| ## Usage Examples | ||
| Add usage examples here | ||
|
|
||
| ### Diagrams | ||
| Add diagrams here | ||
|
|
||
| ### Typical Usage | ||
| And the typical usage of the component here | ||
|
|
||
| ## Class Diagram | ||
| Add a class diagram here | ||
|
|
||
| ## Port Descriptions | ||
| | Name | Description | | ||
| |---|---| | ||
| |---|---| | ||
|
|
||
| ## Component States | ||
| Add component states in the chart below | ||
| | Name | Description | | ||
| |---|---| | ||
| |---|---| | ||
|
|
||
| ## Sequence Diagrams | ||
| Add sequence diagrams here | ||
|
|
||
| ## Parameters | ||
| | Name | Description | | ||
| |---|---| | ||
| |---|---| | ||
|
|
||
| ## Commands | ||
| | Name | Description | | ||
| |---|---| | ||
| |---|---| | ||
|
|
||
| ## Events | ||
| | Name | Description | | ||
| |---|---| | ||
| |---|---| | ||
|
|
||
| ## Telemetry | ||
| | Name | Description | | ||
| |---|---| | ||
| |---|---| | ||
|
|
||
| ## Unit Tests | ||
| Add unit test descriptions in the chart below | ||
| | Name | Description | Output | Coverage | | ||
| |---|---|---|---| | ||
| |---|---|---|---| | ||
|
|
||
| ## Requirements | ||
| Add requirements in the chart below | ||
| | Name | Description | Validation | | ||
| |---|---|---| | ||
| |---|---|---| | ||
|
|
||
| ## Change Log | ||
| | Date | Description | | ||
| |---|---| | ||
| |---| Initial Draft | |
36 changes: 36 additions & 0 deletions
36
FprimeZephyrReference/Components/PowerMonitor/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}/PowerMonitor.fpp" | ||
| SOURCES | ||
| "${CMAKE_CURRENT_LIST_DIR}/PowerMonitor.cpp" | ||
| # DEPENDS | ||
| # MyPackage_MyOtherModule | ||
| ) | ||
|
|
||
| ### Unit Tests ### | ||
| # register_fprime_ut( | ||
| # AUTOCODER_INPUTS | ||
| # "${CMAKE_CURRENT_LIST_DIR}/PowerMonitor.fpp" | ||
| # SOURCES | ||
| # "${CMAKE_CURRENT_LIST_DIR}/test/ut/PowerMonitorTestMain.cpp" | ||
| # "${CMAKE_CURRENT_LIST_DIR}/test/ut/PowerMonitorTester.cpp" | ||
| # DEPENDS | ||
| # STest # For rules-based testing | ||
| # UT_AUTO_HELPERS | ||
| # ) |
29 changes: 29 additions & 0 deletions
29
FprimeZephyrReference/Components/PowerMonitor/PowerMonitor.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,29 @@ | ||
| // ====================================================================== | ||
| // \title PowerMonitor.cpp | ||
| // \author nate | ||
| // \brief cpp file for PowerMonitor component implementation class | ||
| // ====================================================================== | ||
|
|
||
| #include "FprimeZephyrReference/Components/PowerMonitor/PowerMonitor.hpp" | ||
|
|
||
| namespace Components { | ||
|
|
||
| // ---------------------------------------------------------------------- | ||
| // Component construction and destruction | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| PowerMonitor ::PowerMonitor(const char* const compName) : PowerMonitorComponentBase(compName) {} | ||
|
|
||
| PowerMonitor ::~PowerMonitor() {} | ||
|
|
||
| // ---------------------------------------------------------------------- | ||
| // Handler implementations for typed input ports | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| void PowerMonitor ::run_handler(FwIndexType portNum, U32 context) { | ||
| this->voltageGet_out(0); | ||
| this->currentGet_out(0); | ||
| this->powerGet_out(0); | ||
| } | ||
|
|
||
| } // namespace Components |
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.