Ask Your Question

Attempting to read Battery % via Mavros

asked 2021-04-15 15:07:25 -0500

nightpoison gravatar image

updated 2021-04-24 15:30:20 -0500

jayess gravatar image

I have a quadcopter running a Pixhawk flight controller. I am also running a RPI 4 companion board, and I have a serious of nodes setup for flight and a number of other operations. One node is my information node, were I am collecting all the current data for distribution to other nodes or requests from the user.

I'm attempting to ready the battery status and I'm getting some weird figures.

First, my setup.

I've imported 'BatteryState' from sensor_msg.msg, and set up a subscriber for the topic.

from import BatteryState

rospy.Subscriber('mavros/battery', BatteryState, self._batteryStatus)

The callback, thus far, is simple. I'm just printing the percentage from the msg that was passed to the callback.

def _batteryStatus(self, msg):
    rospy.loginfo('INFORMATION -> _batteryStatus()')
    print("\t>>>> {}".format(msg.percentage))

I am getting information, but it doesn't exactly make sense to me. Here is what I'm seeing

[INFO] [1617909365.376757]: INFORMATION -> _batteryStatus()


[INFO] [1617909365.389045]: INFORMATION -> _batteryStatus()


[INFO] [1617909367.376466]: INFORMATION -> _batteryStatus()


[INFO] [1617909367.384906]: INFORMATION -> _batteryStatus()


as you can see from my code, I'm not calling different data points, yet, the data seems to alternate between two different values.

now if print the entire message I see that there are two different 'Percentage' data points. However, neither of the points seem to be an accurate representation of the actual power. When I took the batter off the quad and placed it on the charger it showed that there was only 8% power on the battery.

Any help or suggestions on how I can view the battery status, specifically percentage of power remaining.

edit retag flag offensive close merge delete


did you try to look at the information with rosrun rqt_graph rqt_graph? Perhaps that information displayed is coming from a different source? What about running rostopic info <topic>

Also I assume the battery voltage is coming from the pixhawk adc. Are you using another remote and RC link capable of displaying the telemetry? For example a crossfire nano, and a taranais, or paired via bluetooth / wifi to a GCS?

Just trying to understand if the data in other sources seems to be correct.

AndreW_CRA gravatar image AndreW_CRA  ( 2021-04-24 19:54:00 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2021-04-23 10:36:45 -0500

nightpoison gravatar image

So after some more research and just good old fashion trial and error, I came across the primary issue. Looking at the Pixhawks configuration via QGroundControl application it seems that the power settings were configured for 3S batteries. Where I am using 4S. So I updated the settings, configured the voltage divider and set new values. I'm not getting appropriate battery readings.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2021-04-15 15:07:25 -0500

Seen: 340 times

Last updated: Apr 24 '21