|
| 1 | +:github_url: https://github.com/ros-controls/ros2_controllers/blob/{REPOS_FILE_BRANCH}/battery_state_broadcaster/doc/userdoc.rst |
| 2 | + |
| 3 | +.. _battery_state_broadcaster_userdoc: |
| 4 | + |
| 5 | +Battery State Broadcaster |
| 6 | +-------------------------------- |
| 7 | +The *Battery State Broadcaster* publishes battery status information as ``sensor_msgs/msg/BatteryState`` messages. |
| 8 | + |
| 9 | +It reads battery-related state interfaces from one or more batteries and exposes them in a standard ROS 2 message format. This allows easy integration with monitoring tools, logging systems, and higher-level decision-making nodes. |
| 10 | + |
| 11 | +Interfaces |
| 12 | +^^^^^^^^^^^ |
| 13 | + |
| 14 | +The broadcaster can read the following state interfaces from each configured battery: |
| 15 | + |
| 16 | +- ``battery_voltage`` *(mandatory)* (double) |
| 17 | +- ``battery_temperature`` *(optional)* (double) |
| 18 | +- ``battery_current`` *(optional)* (double) |
| 19 | +- ``battery_charge`` *(optional)* (double) |
| 20 | +- ``battery_percentage`` *(optional)* (double) |
| 21 | +- ``battery_power_supply_status`` *(optional)* (double) |
| 22 | +- ``battery_power_supply_health`` *(optional)* (double) |
| 23 | +- ``battery_present`` *(optional)* (bool) |
| 24 | + |
| 25 | +Published Topics |
| 26 | +^^^^^^^^^^^^^^^^^^ |
| 27 | + |
| 28 | +The broadcaster publishes two topics: |
| 29 | + |
| 30 | +- ``~/raw_battery_states`` (``control_msgs/msg/BatteryStateArray``) |
| 31 | + Publishes **per-battery state messages**, containing the raw values for each configured battery. |
| 32 | + |
| 33 | +- ``~/battery_state`` (``sensor_msgs/msg/BatteryState``) |
| 34 | + Publishes a **single aggregated battery message** representing the combined status across all batteries. |
| 35 | + |
| 36 | +.. list-table:: |
| 37 | + :header-rows: 1 |
| 38 | + |
| 39 | + * - Field |
| 40 | + - ``battery_state`` |
| 41 | + - ``raw_battery_states`` |
| 42 | + * - ``header.frame_id`` |
| 43 | + - Empty |
| 44 | + - Battery name |
| 45 | + * - ``voltage`` |
| 46 | + - Mean across all batteries |
| 47 | + - From battery's ``battery_voltage`` interface *(mandatory)* (NaN if unmeasured) |
| 48 | + * - ``temperature`` |
| 49 | + - Mean across batteries reporting temperature |
| 50 | + - From battery's ``battery_temperature`` interface if enabled, otherwise nan. |
| 51 | + * - ``current`` |
| 52 | + - Mean across batteries reporting current |
| 53 | + - From battery's ``battery_current`` interface if enabled, otherwise nan. |
| 54 | + * - ``charge`` |
| 55 | + - Sum across batteries reporting charge |
| 56 | + - From battery's ``battery_charge`` interface if enabled, otherwise nan. |
| 57 | + * - ``capacity`` |
| 58 | + - Sum across all batteries |
| 59 | + - From battery's ``capacity`` parameter if provided, otherwise nan. |
| 60 | + * - ``design_capacity`` |
| 61 | + - Sum across all batteries |
| 62 | + - From battery's ``design_capacity`` parameter if provided, otherwise nan. |
| 63 | + * - ``percentage`` |
| 64 | + - Mean across batteries reporting/calculating percentage |
| 65 | + - From battery's ``battery_percentage`` interface if enabled, otherwise calculated from battery's ``minimum_voltage`` and ``maximum_voltage`` parameters. |
| 66 | + * - ``power_supply_status`` |
| 67 | + - Highest reported enum value |
| 68 | + - From battery's ``battery_power_supply_status`` interface if enabled, otherwise 0 (unknown). |
| 69 | + * - ``power_supply_health`` |
| 70 | + - Highest reported enum value |
| 71 | + - From battery's ``battery_power_supply_health`` interface if enabled, otherwise 0 (unknown). |
| 72 | + * - ``power_supply_technology`` |
| 73 | + - Reported as-is if same across all batteries, otherwise set to *Unknown* |
| 74 | + - From battery's ``power_supply_technology`` parameter if provided, otherwise 0 (unknown). |
| 75 | + * - ``present`` |
| 76 | + - True |
| 77 | + - From battery's ``battery_present`` interface if enabled, otherwise true if the battery voltage value is valid (not NaN and not 0.0). |
| 78 | + * - ``cell_voltage`` |
| 79 | + - Empty |
| 80 | + - Empty |
| 81 | + * - ``cell_temperature`` |
| 82 | + - Empty |
| 83 | + - Empty |
| 84 | + * - ``location`` |
| 85 | + - All battery locations appended |
| 86 | + - From battery's ``location`` parameter if provided, otherwise empty. |
| 87 | + * - ``serial_number`` |
| 88 | + - All battery serial numbers appended |
| 89 | + - From battery's ``serial_number`` parameter if provided, otherwise empty. |
| 90 | + |
| 91 | + |
| 92 | +Parameters |
| 93 | +^^^^^^^^^^^ |
| 94 | +This controller uses the `generate_parameter_library <https://github.com/PickNikRobotics/generate_parameter_library>`_ to manage parameters. |
| 95 | +The parameter `definition file <https://github.com/ros-controls/ros2_controllers/blob/{REPOS_FILE_BRANCH}/battery_state_broadcaster/src/battery_state_broadcaster_parameters.yaml>`_ contains the full list and descriptions. |
| 96 | + |
| 97 | +List of parameters |
| 98 | +========================= |
| 99 | +.. generate_parameter_library_details:: ../src/battery_state_broadcaster_parameters.yaml |
| 100 | + |
| 101 | +Example Parameter File |
| 102 | +========================= |
| 103 | + |
| 104 | +An example parameter file for this controller is available in the `test directory <https://github.com/ros-controls/ros2_controllers/blob/{REPOS_FILE_BRANCH}/battery_state_broadcaster/test/battery_state_broadcaster_params.yaml>`_: |
| 105 | + |
| 106 | +.. literalinclude:: ../test/battery_state_broadcaster_params.yaml |
| 107 | + :language: yaml |
| 108 | + |
| 109 | +Migration for ``ipa320/ros_battery_monitoring`` users |
| 110 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 111 | + |
| 112 | +If you were previously using the ``battery_state_broadcaster`` from the ``ipa320/ros_battery_monitoring package``, you can switch directly to this package. The configuration style using ``sensor_name`` is still supported for backward compatibility, but it may be removed in a future release. |
| 113 | + |
| 114 | +To adapt your setup to the new ``battery_state_broadcaster`` configuration: |
| 115 | + |
| 116 | +1. Update your hardware interface name from ``voltage`` → ``battery_voltage``. |
| 117 | + |
| 118 | +2. Convert your controller parameters from |
| 119 | + |
| 120 | + .. code-block:: yaml |
| 121 | +
|
| 122 | + battery_state_broadcaster: |
| 123 | + ros__parameters: |
| 124 | + sensor_name: "battery_state" |
| 125 | + design_capacity: 100.0 |
| 126 | + # https://github.com/ros2/common_interfaces/blob/rolling/sensor_msgs/msg/BatteryState.msg |
| 127 | + power_supply_technology: 2 |
| 128 | +
|
| 129 | + to: |
| 130 | + |
| 131 | + .. code-block:: yaml |
| 132 | +
|
| 133 | + battery_state_broadcaster: |
| 134 | + ros__parameters: |
| 135 | + batteries: ["battery_state"] |
| 136 | + battery_state: |
| 137 | + design_capacity: 100.0 |
| 138 | + power_supply_technology: 2 |
| 139 | +
|
| 140 | +**Notes**: |
| 141 | + |
| 142 | +- Parameters must provide **either** sensor_name **or** batteries. |
| 143 | +- If both are empty → the broadcaster will fail to configure. |
| 144 | +- If both are set → the broadcaster will throw an error. |
0 commit comments