9#include <px4_msgs/msg/battery_status.hpp>
10#include <px4_ros2/common/context.hpp>
11#include <px4_ros2/utils/message_version.hpp>
12#include <px4_ros2/utils/subscription.hpp>
28 context,
"fmu/out/battery_status" +
29 px4_ros2::getMessageNameVersion<px4_msgs::msg::BatteryStatus>())
76 const px4_msgs::msg::BatteryStatus& battery =
last();
77 const uint8_t cell_count = battery.cell_count;
79 if (cell_count == 0) {
80 RCLCPP_WARN_THROTTLE(_node.get_logger(), *_node.get_clock(), 1000,
81 "Failed to retrieve battery cell voltage: cell count unknown.");
82 return Eigen::VectorXf();
85 Eigen::VectorXf cell_voltages(cell_count);
86 for (uint8_t i = 0; i < cell_count; ++i) {
87 cell_voltages(i) = battery.voltage_cell_v[i];
Provides access to the vehicle's battery status.
Definition battery.hpp:24
uint8_t cellCount() const
Get the vehicle's battery cell count.
Definition battery.hpp:66
float dischargedCapacityMah() const
Get the vehicle's battery cumulative discharged capacity.
Definition battery.hpp:52
float currentA() const
Get the vehicle's battery current.
Definition battery.hpp:45
float voltageV() const
Get the vehicle's battery voltage.
Definition battery.hpp:38
float remaningFraction() const
Get the vehicle's battery remaining charge as a fraction.
Definition battery.hpp:59
Eigen::VectorXf cellVoltagesV() const
Get the voltages of each cell in the vehicle's battery.
Definition battery.hpp:74
Definition context.hpp:18
Provides a subscription to arbitrary ROS topics.
Definition subscription.hpp:27
const px4_msgs::msg::BatteryStatus & last() const
Get the last-received message.
Definition subscription.hpp:57