Skip to content

Commit 8d22001

Browse files
asiemsennateinactionMikefly123
authored
Power monitor (#76)
* create Ina219 manager and driver components (not impl) * Add Ina219 Driver to CMAKE * fixing power monitor generations * Impl PowerMonitor * implemented ina219 manager cpp * add run handler function * Add comments * add powermonitorManager and inu219Manager to topology * fix typo * Override min number of rate group ports * add helper function for power monitor device configure and add solar power monitor to topology * fixed instances * change member variable naming * fix build errors * fixing build errors * Update Device Tree * Fixed Pin Names * Added Bus Voltage Range * Fixed Telem Writes * Feedback * Unify power monitor * Fill out power monitor sdd * Initial power monitor test * Test passing * More Device Tree Tweaks! Dialing things in to match the power monitor performance with our system --------- Co-authored-by: Nate Gay <[email protected]> Co-authored-by: Michael Pham <[email protected]>
1 parent 86238b2 commit 8d22001

24 files changed

+802
-13
lines changed

FprimeZephyrReference/Components/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Include project-wide components here
22

3-
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Drv/")
3+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/AntennaDeployer/")
4+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/BootloaderTrigger/")
5+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Burnwire/")
46
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ComDelay/")
7+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Drv/")
58
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FatalHandler")
9+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FsSpace/")
610
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ImuManager/")
711
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/NullPrmDb/")
12+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/PowerMonitor/")
813
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Watchdog")
9-
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Burnwire/")
10-
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/BootloaderTrigger/")
11-
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/AntennaDeployer/")
12-
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FsSpace/")

FprimeZephyrReference/Components/Drv/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Helpers/")
2+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Ina219Manager/")
23
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Lis2mdlManager/")
34
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Lsm6dsoManager/")
45
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/RtcManager")
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}/Ina219Manager.fpp"
20+
SOURCES
21+
"${CMAKE_CURRENT_LIST_DIR}/Ina219Manager.cpp"
22+
# DEPENDS
23+
# MyPackage_MyOtherModule
24+
)
25+
26+
### Unit Tests ###
27+
# register_fprime_ut(
28+
# AUTOCODER_INPUTS
29+
# "${CMAKE_CURRENT_LIST_DIR}/Ina219Manager.fpp"
30+
# SOURCES
31+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/Ina219ManagerTestMain.cpp"
32+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/Ina219ManagerTester.cpp"
33+
# DEPENDS
34+
# STest # For rules-based testing
35+
# UT_AUTO_HELPERS
36+
# )
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// ======================================================================
2+
// \title Ina219Manager.cpp
3+
// \brief cpp file for Ina219Manager component implementation class
4+
// ======================================================================
5+
6+
#include "FprimeZephyrReference/Components/Drv/Ina219Manager/Ina219Manager.hpp"
7+
#include <Fw/Types/Assert.hpp>
8+
9+
namespace Drv {
10+
11+
// ----------------------------------------------------------------------
12+
// Component construction and destruction
13+
// ----------------------------------------------------------------------
14+
15+
Ina219Manager ::Ina219Manager(const char* const compName) : Ina219ManagerComponentBase(compName) {}
16+
17+
Ina219Manager ::~Ina219Manager() {}
18+
19+
// ----------------------------------------------------------------------
20+
// Helper methods
21+
// ----------------------------------------------------------------------
22+
23+
void Ina219Manager::configure(const struct device* dev) {
24+
this->m_dev = dev;
25+
}
26+
27+
// ----------------------------------------------------------------------
28+
// Handler implementations for typed input ports
29+
// ----------------------------------------------------------------------
30+
31+
F64 Ina219Manager ::currentGet_handler(FwIndexType portNum) {
32+
if (!device_is_ready(this->m_dev)) {
33+
this->log_WARNING_HI_DeviceNotReady();
34+
return 0;
35+
}
36+
this->log_WARNING_HI_DeviceNotReady_ThrottleClear();
37+
38+
struct sensor_value current;
39+
40+
sensor_sample_fetch_chan(this->m_dev, SENSOR_CHAN_CURRENT);
41+
42+
sensor_channel_get(this->m_dev, SENSOR_CHAN_CURRENT, &current);
43+
44+
this->tlmWrite_Current(sensor_value_to_double(&current));
45+
46+
return sensor_value_to_double(&current);
47+
}
48+
49+
F64 Ina219Manager ::powerGet_handler(FwIndexType portNum) {
50+
if (!device_is_ready(this->m_dev)) {
51+
this->log_WARNING_HI_DeviceNotReady();
52+
return 0;
53+
}
54+
this->log_WARNING_HI_DeviceNotReady_ThrottleClear();
55+
56+
struct sensor_value power;
57+
58+
sensor_sample_fetch_chan(this->m_dev, SENSOR_CHAN_POWER);
59+
60+
sensor_channel_get(this->m_dev, SENSOR_CHAN_POWER, &power);
61+
62+
this->tlmWrite_Power(sensor_value_to_double(&power));
63+
64+
return sensor_value_to_double(&power);
65+
}
66+
67+
F64 Ina219Manager ::voltageGet_handler(FwIndexType portNum) {
68+
if (!device_is_ready(this->m_dev)) {
69+
this->log_WARNING_HI_DeviceNotReady();
70+
return 0;
71+
}
72+
this->log_WARNING_HI_DeviceNotReady_ThrottleClear();
73+
74+
struct sensor_value voltage;
75+
76+
sensor_sample_fetch_chan(this->m_dev, SENSOR_CHAN_VOLTAGE);
77+
78+
sensor_channel_get(this->m_dev, SENSOR_CHAN_VOLTAGE, &voltage);
79+
80+
this->tlmWrite_Voltage(sensor_value_to_double(&voltage));
81+
82+
return sensor_value_to_double(&voltage);
83+
}
84+
85+
} // namespace Drv
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
module Drv {
2+
port VoltageGet -> F64
3+
port CurrentGet -> F64
4+
port PowerGet -> F64
5+
}
6+
7+
module Drv {
8+
@ Manager for Ina219 device
9+
passive component Ina219Manager {
10+
# Ports
11+
@ Port to read the voltage in volts
12+
sync input port voltageGet: VoltageGet
13+
14+
@ Port to read the current in amps
15+
sync input port currentGet: CurrentGet
16+
17+
@ Port to read the power in watts
18+
sync input port powerGet: PowerGet
19+
20+
# Telemetry channels
21+
22+
@ Telemetry channel for voltage in volts
23+
telemetry Voltage: F64
24+
25+
@ Telemetry channel for current in amps
26+
telemetry Current: F64
27+
28+
@ Telemetry channel for power in watts
29+
telemetry Power: F64
30+
31+
@ Event for reporting INA219 not ready error
32+
event DeviceNotReady() severity warning high format "INA219 device not ready" throttle 5
33+
34+
###############################################################################
35+
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
36+
###############################################################################
37+
@ Port for requesting the current time
38+
time get port timeCaller
39+
40+
@ Port for sending textual representation of events
41+
text event port logTextOut
42+
43+
@ Port for sending events to downlink
44+
event port logOut
45+
46+
@ Port for sending telemetry channels to downlink
47+
telemetry port tlmOut
48+
49+
}
50+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// ======================================================================
2+
// \title Ina219Manager.hpp
3+
// \brief hpp file for Ina219Manager component implementation class
4+
// ======================================================================
5+
6+
#ifndef Drv_Ina219Manager_HPP
7+
#define Drv_Ina219Manager_HPP
8+
9+
#include "FprimeZephyrReference/Components/Drv/Ina219Manager/Ina219ManagerComponentAc.hpp"
10+
11+
#include <zephyr/device.h>
12+
#include <zephyr/drivers/sensor.h>
13+
#include <zephyr/kernel.h>
14+
namespace Drv {
15+
16+
class Ina219Manager final : public Ina219ManagerComponentBase {
17+
public:
18+
// ----------------------------------------------------------------------
19+
// Component construction and destruction
20+
// ----------------------------------------------------------------------
21+
22+
//! Construct Ina219Manager object
23+
Ina219Manager(const char* const compName //!< The component name
24+
);
25+
26+
//! Destroy Ina219Manager object
27+
~Ina219Manager();
28+
29+
public:
30+
// ----------------------------------------------------------------------
31+
// Helper methods
32+
// ----------------------------------------------------------------------
33+
34+
//! Configure the INA219 device
35+
void configure(const struct device* dev);
36+
37+
private:
38+
// ----------------------------------------------------------------------
39+
// Handler implementations for typed input ports
40+
// ----------------------------------------------------------------------
41+
42+
//! Handler implementation for currentGet
43+
//!
44+
//! Port to read the current in amps
45+
F64 currentGet_handler(FwIndexType portNum //!< The port number
46+
) override;
47+
48+
//! Handler implementation for powerGet
49+
//!
50+
//! Port to read the power in watts
51+
F64 powerGet_handler(FwIndexType portNum //!< The port number
52+
) override;
53+
54+
//! Handler implementation for voltageGet
55+
//!
56+
//! Port to read the voltage in volts
57+
F64 voltageGet_handler(FwIndexType portNum //!< The port number
58+
) override;
59+
60+
// ----------------------------------------------------------------------
61+
// Member variables
62+
// ----------------------------------------------------------------------
63+
64+
//! Zephyr device stores the initialized LIS2MDL sensor
65+
const struct device* m_dev;
66+
};
67+
68+
} // namespace Drv
69+
70+
#endif
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Drv::Ina219Manager
2+
3+
The INA219 Manager component interfaces with the INA219 current/power monitor to provide voltage, current, and power measurements.
4+
5+
## Usage Examples
6+
7+
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.
8+
9+
### Typical Usage
10+
11+
1. The component is instantiated and initialized during system startup
12+
2. A manager calls any of the input ports: `VoltageGet`, `CurrentGet`, or `PowerGet`
13+
3. On each call, the component:
14+
- Fetches fresh sensor samples from the sensor
15+
- Converts sensor data to double precision floating point
16+
- Writes telemetry data
17+
- Returns data in SI units
18+
19+
## Class Diagram
20+
21+
```mermaid
22+
classDiagram
23+
namespace Drv {
24+
class Ina219ManagerComponentBase {
25+
<<Auto-generated>>
26+
}
27+
class Ina219Manager {
28+
- m_dev: const struct device*
29+
+ Ina219Manager(const char* compName)
30+
+ ~Ina219Manager()
31+
+ configure(const struct device* dev)
32+
- voltageGet_handler(const FwIndexType portNum): F64
33+
- currentGet_handler(const FwIndexType portNum): F64
34+
- powerGet_handler(const FwIndexType portNum): F64
35+
}
36+
}
37+
Ina219ManagerComponentBase <|-- Ina219Manager : inherits
38+
```
39+
40+
## Port Descriptions
41+
| Name | Type | Description |
42+
|---|---|---|
43+
| VoltageGet | sync input | Triggers voltage data collection and returns voltage in volts |
44+
| CurrentGet | sync input | Triggers current data collection and returns current in amps |
45+
| PowerGet | sync input | Triggers power data collection and returns power in watts |
46+
47+
## Sequence Diagrams
48+
49+
### VoltageGet
50+
```mermaid
51+
sequenceDiagram
52+
participant Manager
53+
participant INA219 Manager
54+
participant Zephyr Sensor API
55+
participant INA219 Sensor
56+
57+
Manager-->>INA219 Manager: Call VoltageGet synchronous input port
58+
INA219 Manager->>Zephyr Sensor API: Fetch sensor data
59+
Zephyr Sensor API->>INA219 Sensor: Read sensor
60+
INA219 Sensor->>Zephyr Sensor API: Return sensor data
61+
Zephyr Sensor API->>INA219 Manager: Return voltage sensor_value struct
62+
INA219 Manager->>INA219 Manager: Write telemetry
63+
INA219 Manager-->>Manager: Return F64 voltage in volts
64+
```
65+
66+
### CurrentGet
67+
```mermaid
68+
sequenceDiagram
69+
participant Manager
70+
participant INA219 Manager
71+
participant Zephyr Sensor API
72+
participant INA219 Sensor
73+
74+
Manager-->>INA219 Manager: Call CurrentGet synchronous input port
75+
INA219 Manager->>Zephyr Sensor API: Fetch sensor data
76+
Zephyr Sensor API->>INA219 Sensor: Read sensor
77+
INA219 Sensor->>Zephyr Sensor API: Return sensor data
78+
Zephyr Sensor API->>INA219 Manager: Return current sensor_value struct
79+
INA219 Manager->>INA219 Manager: Write telemetry
80+
INA219 Manager-->>Manager: Return F64 current in amps
81+
```
82+
83+
### PowerGet
84+
```mermaid
85+
sequenceDiagram
86+
participant Manager
87+
participant INA219 Manager
88+
participant Zephyr Sensor API
89+
participant INA219 Sensor
90+
91+
Manager-->>INA219 Manager: Call PowerGet synchronous input port
92+
INA219 Manager->>Zephyr Sensor API: Fetch sensor data
93+
Zephyr Sensor API->>INA219 Sensor: Read sensor
94+
INA219 Sensor->>Zephyr Sensor API: Return sensor data
95+
Zephyr Sensor API->>INA219 Manager: Return power sensor_value struct
96+
INA219 Manager->>INA219 Manager: Write telemetry
97+
INA219 Manager-->>Manager: Return F64 power in watts
98+
```
99+
100+
## Requirements
101+
| Name | Description | Validation |
102+
|---|---|---|
103+
| VoltageGet Port | The component shall provide access to voltage sensor data and return in volts | Integration test |
104+
| CurrentGet Port | The component shall provide access to current sensor data and return in amps | Integration test |
105+
| PowerGet Port | The component shall provide access to power sensor data and return in watts | Integration test |
106+
| 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 |
107+
108+
## Change Log
109+
| Date | Description |
110+
|---|---|
111+
| 2025-11-03 | Initial INA219 Manager component |

0 commit comments

Comments
 (0)