14 return tr(
"Configure each battery's source and estimate, the shared charge levels and the power monitors.");
19 return QStringLiteral(
"/qmlimages/Battery.svg");
25 tr(
"Voltage"), tr(
"Current"), tr(
"Power module"), tr(
"Cells"), tr(
"LiPo"),
26 tr(
"Capacity"), tr(
"Low battery"), tr(
"Critical battery"), tr(
"Emergency"),
43 const int source = parameterManager->
getParameter(componentId,
"BAT1_SOURCE")->
rawValue().toInt();
44 const bool estimated = source == 0 || source == 2 || _canFiltered();
49 return parameterManager->
getParameter(componentId,
"BAT1_V_CHARGED")->
rawValue().toFloat() != 0.0f &&
56 return {
"BAT1_SOURCE",
"BAT1_V_CHARGED",
"BAT1_V_EMPTY",
"BAT1_N_CELLS",
"UAVCAN_ENABLE",
"UAVCAN_SUB_BAT"};
61 return QUrl::fromUserInput(QStringLiteral(
"qrc:/qml/QGroundControl/AutoPilotPlugins/PX4/PX4BatteryComponent.qml"));
67 for (
int index = 1;
_parameterFact(_batteryParam(index,
"SOURCE")); index++) {
68 for (
const char*
const suffix : {
"SOURCE",
"V_CHARGED",
"V_EMPTY",
"N_CELLS"}) {
69 triggers.append(_batteryParam(index, suffix));
82 [
this](
int componentId,
Fact* fact) {
83 if (componentId != _vehicle->defaultComponentId() || !fact->name().startsWith(
"BAT")) {
88 (void) connect(fact, &Fact::valueChanged, this, &PX4BatteryComponent::_triggerUpdated);
89 emit setupCompleteChanged();
91 (void) connect(fact, &Fact::valueChanged, this, &PX4BatteryComponent::summaryItemsChanged);
92 emit summaryItemsChanged();
100 while (
_parameterFact(_batteryParam(batteryCount + 1,
"SOURCE"))) {
109 QList<int> shownBatteries;
110 for (
int index = 1; index <= batteryCount; index++) {
111 if (index == 1 ||
_parameterFact(_batteryParam(index,
"SOURCE"))->rawValue().toInt() != -1 ||
113 shownBatteries.append(index);
118 const bool grouped = shownBatteries.size() > 1;
120 QList<VehicleSummaryItem> items;
121 for (
const int index : shownBatteries) {
122 const QString group = grouped ? tr(
"Battery %1").arg(index) : QString();
123 const auto caption = [grouped](
const QString& single,
const QString& inGroup) {
124 return grouped ? inGroup : single;
126 const auto addValue = [
this, &items, &group, index, battery1Incomplete](
const char* suffix,
127 const QString& text,
bool isCount) {
130 items.append({text, tr(
"N/A"), VehicleSummaryItem::Muted, group});
133 const bool unset = fact->
rawValue().toFloat() == 0.0f;
135 (index == 1 && battery1Incomplete && unset) ? VehicleSummaryItem::Attention
136 : VehicleSummaryItem::Normal,
141 items.append({caption(tr(
"Battery Source"), tr(
"Source")), source->
enumStringValue(),
142 VehicleSummaryItem::Normal, group});
143 addValue(
"V_CHARGED", caption(tr(
"Battery Full"), tr(
"Full")),
false);
144 addValue(
"V_EMPTY", caption(tr(
"Battery Empty"), tr(
"Empty")),
false);
145 addValue(
"N_CELLS", caption(tr(
"Number of Cells"), tr(
"Number of Cells")),
true);
151QString PX4BatteryComponent::_batteryParam(
int batteryIndex,
const char* suffix)
153 return QStringLiteral(
"BAT%1_%2").arg(batteryIndex).arg(QLatin1String(suffix));
156bool PX4BatteryComponent::_canFiltered()
const
158 const Fact*
const enable =
_parameterFact(QStringLiteral(
"UAVCAN_ENABLE"));
159 const Fact*
const subscription =
_parameterFact(QStringLiteral(
"UAVCAN_SUB_BAT"));
160 return enable && subscription && enable->
rawValue().toInt() > 0 && subscription->
rawValue().toInt() == 2;
The AutoPilotPlugin class is an abstract base class which represents the methods and objects which ar...
A Fact is used to hold a single value within the system.
QString cookedValueString() const
QString enumStringValue()
QVariant rawValue() const
QStringList searchKeywords() const final
Translated search terms for the whole component, for pages without vehicleConfigJson() sections.
QUrl setupSource() const final
bool setupComplete() const final
PX4BatteryComponent(Vehicle *vehicle, AutoPilotPlugin *autopilot, QObject *parent=nullptr)
QStringList setupCompleteChangedTriggerList() const final
QList< VehicleSummaryItem > summaryItems() const final
Values for this component's card on the Summary page. A component with none falls back to summaryQmlS...
QString description() const final
QStringList summaryChangedTriggerList() const final
Parameters whose change emits summaryItemsChanged, besides those that change setupComplete.
QString iconResource() const final
void setupTriggerSignals() final
bool parameterExists(int componentId, const QString ¶mName) const
Fact * getParameter(int componentId, const QString ¶mName)
void factAdded(int componentId, Fact *fact)
static constexpr int defaultComponentId
VehicleComponent(Vehicle *vehicle, AutoPilotPlugin *autopilot, AutoPilotPlugin::KnownVehicleComponent KnownVehicleComponent, QObject *parent=nullptr)
Fact * _parameterFact(const QString &name) const
Fact of a parameter of the default component, nullptr when the vehicle does not have it.
virtual void setupTriggerSignals()
static QString _valueWithUnits(const Fact *fact)
The fact's value followed by its units, when it has any.