Battery_measure Module Documentation¶
Toolbox: Sensors and Actuators

Introduction¶
One-sentence Description: This module acquires battery-related status measurement data by subscribing to the PX4 uORB
battery_statustopic, supporting battery information reading in both simulation and real-flight scenarios.
This module is a power sensor information reading component within the RflySim toolchain’s Sensors and Actuators interface library. It outputs various battery status information—including raw voltage, filtered voltage, current, discharge capacity, and measurement timestamps—based on user configuration. In real-flight scenarios using PX4 + Pixhawk, valid battery measurement data can only be obtained if the Pixhawk hardware is correctly connected to the power module. In RflySim simulation scenarios, this module retrieves simulated battery status data from either the simulated PX4 firmware or the CopterSim simulation model, enabling development tasks such as drone endurance simulation and low-battery return-to-home logic testing when used in conjunction with the RflySim3D visualization environment.
Port Descriptions¶
Input Ports (Inputs)¶
This module has no input ports.
Output Ports (Outputs)¶
Based on configuration, one or more of the following output ports may be enabled:
| Port Name | Data Type | Dimension | Description |
|---|---|---|---|
Voltage |
double |
1×1 |
Battery voltage, in volts |
Filtered Voltage |
single |
1×1 |
Filtered battery voltage, in volts |
Current |
single |
1×1 |
Battery current, in amperes |
mAH |
single |
1×1 |
Cumulative discharge capacity, in mAh |
Timestamp |
int32 |
1×1 |
Timestamp of this measurement |
Parameter Configuration (Parameters)¶
The following parameters can be configured in the Mask dialog box opened by double-clicking the module:
| Parameter Name | Type | Default Value | Available Values/Range | Description |
|---|---|---|---|---|
Voltage |
bool |
false |
true/false |
Whether to enable the Voltage output port |
Filtered Voltage |
bool |
false |
true/false |
Whether to enable the Filtered Voltage output port |
Current |
bool |
false |
true/false |
Whether to enable the Current output port |
mAH |
bool |
false |
true/false |
Whether to enable the mAH output port |
Timestamp |
bool |
false |
true/false |
Whether to enable the Timestamp output port |
Sample time (s) |
double |
0.01 |
>0 |
Module sampling time, in seconds |
Parameter Configuration Notes¶
Output Port Selection¶
Users may select the required battery status outputs based on their needs; enabling an option will automatically generate the corresponding output port.
Sample time (s)¶
This parameter controls the frequency at which the module reads battery status data from the uORB topic, and should match the actual update frequency of the flight controller’s sensor outputs. The default value is generally sufficient.
Module Characteristics (Block Characteristics)¶
| Characteristic | Value |
|---|---|
| Supported Data Types | double, single, int32 |
| Direct Feedthrough | No |
| Sample Time | Discrete |
| Code Generation Support | No |
Data Communication Protocol¶
This module acquires battery status data via uORB topic subscription and does not involve external network communication.
Related Modules¶
| Module Name | Description |
|---|---|
GPS_measure |
Sensor module for acquiring GPS positioning data |
IMU_measure |
Inertial measurement sensor module for acquiring gyroscope and accelerometer data |
Mag_measure |
Sensor module for acquiring magnetometer data |
Baro_measure |
Barometric pressure sensor module for acquiring altitude data |
OpticalFlow_measure |
Sensor module for acquiring optical flow data |
Rangefinder_measure |
Sensor module for acquiring distance sensor data |
ESC_read |
Sensor module for acquiring ESC (electronic speed controller) status information |
Notes and Common Issues¶
- Initialization Order: This module retrieves battery data by subscribing to the uORB topic
battery_status. Before simulation starts, ensure thebattery_statuspublisher on the PX4 flight controller side has completed initialization. In real-flight scenarios, the Pixhawk flight controller must be correctly connected to the power module; otherwise, the module will not obtain valid battery data, and outputs will remain at default zero or invalid values. - Sample Time Matching: The module’s sample time should match the update frequency of the flight controller’s uORB topic, typically set to ≤0.1 s. An overly large sample time will cause delayed updates of battery status data, affecting the accuracy of simulations involving low-voltage alarms and battery estimation.
- Output Data Type Matching: Different output ports use different data types: Voltage outputs are
double, while all others (except Timestamp, which isint32) aresingle. When connecting to other Simulink modules, ensure data type compatibility to avoid type mismatch errors. - Real-World Data Dependency: In real-flight scenarios, the current and discharge capacity data output by this module depend on the accuracy of the Pixhawk power module’s metering. If data discrepancies occur, calibrate the Pixhawk power module parameters before proceeding with simulation or testing.
Changelog¶
v4.0(2024-08-12): Initial release. Implements acquisition of battery status data via subscription to the uORB topicbattery_status, supports configurable outputs for voltage, filtered voltage, current, discharge capacity, and timestamp, and allows custom sample time configuration.