-
Notifications
You must be signed in to change notification settings - Fork 13.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mavlink split BATTERY_STATUS from SYS_STATUS update and handle all bricks #12034
Conversation
6b5c4c9
to
beff6bf
Compare
TODO: update the size based on number of connected batteries. |
So from looking at code second battery will come across as BATTERY_STATUS.id==1 right? That should work with existing QGC code. |
@DonLakeFlyer interestingly though, it doesn't show up in QGC when looking at battery data, only from the console. |
This can be debugged using QGC by slowing down the battery_status stream rate to the point you can see the last BATTERY_STATUS message in the mavlink inspector. For two batteries that should have BATTERY_STATUS.id = 1 and good values in it. |
Unless I am missing something, I am not able to alter the BATTERY_STATUS stream. When I try to alter it I get a mavlink on network on port 0 is not running (i tried starting various new mavlink streams as usual). I do see it in uorb top though. |
beff6bf
to
d34041d
Compare
I rebased this to master and added a fix to make it actually publish the Some questions have come up: How should we populate the These same questions hold for the |
Right now, |
dfd9fe6
to
00c2a74
Compare
00c2a74
to
5f26bc1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, couple of small comments.
Hi @dagar is this development only for pixhawk 4? We are trying to log 2 battery on cube autopilot. Current config is just for 1 brick. We modified fmuv3 config and brick valid pins and voltage and current adc pins. Currently it looks like it logs properly on log. And it also started to show on qgc. But it shows only one battery on at a time on qgc. if both is connected then it show brick 1 value. And also parameters should be added for battery 2. How should we progress on this issue? |
ef9d1c9
to
52e34ef
Compare
@feemi One of my colleagues (@stefandunca) is currently working on supporting multiple batteries in QGC. It should be merged there soon. But with the current version of QGC and this branch of Firmware, QGC should always show the information about the battery with the lowest percentage charge remaining. Is this what you are seeing? Parameters for extra batteries are a good point, I'll look into that. |
With current version of qgc and my px4 modification for fmuv3. QGC shows battery 1 bricks voltage values. If I disconnect battery 1 then it switches to secondary battery brick. Actually we are using multiple battery monitoring for VTOL power test measurement. Primary battery monitors for MC motors and secondary battery monitors FW motor. |
Do you have a log that I could see? Everything seems to work for me on a Pixhawk 4, so I am wondering if you have a configuration problem, or if I have done something wrong here. |
Here is the corresponding QGC PR: mavlink/qgroundcontrol#7575 |
52e34ef
to
a98d918
Compare
a98d918
to
331b78b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed, and added some inline comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple more details, otherwise good to merge.
struct PerBatteryData { | ||
PerBatteryData() : analyzer(SimpleAnalyzer::AVERAGE) {} | ||
MavlinkOrbSubscription *subscription; | ||
SimpleAnalyzer analyzer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do:
SimpleAnalyzer analyzer; | |
SimpleAnalyzer analyzer{SimpleAnalyzer::AVERAGE}; |
@@ -130,7 +135,7 @@ class MavlinkStreamHighLatency2 : public MavlinkStream | |||
|
|||
SimpleAnalyzer _airspeed; | |||
SimpleAnalyzer _airspeed_sp; | |||
SimpleAnalyzer _battery; | |||
// Use the SimplerAnalyzer because C++ needs this data type to have a default constructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left-over comment
@@ -44,6 +44,14 @@ | |||
#include "mavlink_simple_analyzer.h" | |||
#include "mavlink_stream.h" | |||
|
|||
struct PerBatteryData { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move the struct to the private part of MavlinkStreamHighLatency2
With regards to BATTERY_STATUS and SYS_STATUS mavlink spec:
|
Yes I have @ItsTimmy, Sorry for delayed answer btw Platform fmu-v3 pixhawk cube 2.1 You can see battery voltage and current values on both and how measured on firmware On the log you will also see major changes on voltage values. These are the plug disconnections to test how measurement changes. TimeStamp --------- Battery 1 --------- Battery 2 |
687c4ef
to
053479a
Compare
053479a
to
452deb3
Compare
@feemi I think the problem is that you are using batteries with different cell counts (is that correct?). The current implementation requires that all batteries have the same cell counts. So at the times where both batteries are connected, Battery 1 is getting an appropriate measurement of ~50% full, while Battery 2 is reading as 100% full because it is over the maximum voltage of a 4S battery. I'm not sure if this issue should be addressed in a separate PR, or should be addressed in this PR before merging. @bkueng ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this issue should be addressed in a separate PR, or should be addressed in this PR before merging. @bkueng ?
Let's do a separate PR.
FYI, clarifying in MAVLink to be done here: mavlink/mavlink#1182 |
@ItsTimmy Actually if there is no disconnection. 2 batteries are logging fine. I used different cells to show these measuring errors if you disconnected one batteries. If you want to address each log for each bricks it looks wrong data because currently firmware prioritize power brick according battery number. So even you use battery from brick 2. It starts to log it to battery_0 on log file. I think its kind of misleading. When you disconnect battery 1. It stops to log battery 2 to own log and it consider it is the only battery (which is true) and starts to log it on battery_0 section. |
Oh, I see the problem now. I will be working soon on an overhaul of the battery calibration system, and I think I should be able to address this issue there. I will tag you when I have a PR ready for those changes. I'm sorry for the confusion! |
Describe problem solved by the proposed pull request
The firmware should be able to handle the case when more than one battery is being used.
Test data / coverage
A Pixhawk 4 was used, with two batteries at different charge levels. Each battery was plugged in and removed from the board, and the MAVLink messages were observed. The batteries were switched so that in some tests, batter 1 was lowest, and in others, battery 2 was lowest. In every case, the correct MAVLink messages were sent.
Describe your preferred solution
For the
BATTERY_STATUS
topic, one message is sent for each battery, each with a uniqueid
. For theSYS_STATUS
andHIGH_LATENCY2
topics, the battery with the lowest remaining percentage is used.Describe possible alternatives
SYS_STATUS
andHIGH_LATENCY2
could be populated always with Battery 0, or with the "main" battery. But using the lowest battery is the safest option, so that a user will not fail to see a low battery if it is the secondary.