QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PX4EscComponent.cc
Go to the documentation of this file.
1#include "PX4EscComponent.h"
2
3#include "Fact.h"
4
5namespace {
6
7// Keep in sync with PX4EscRows.js timerParams()
8constexpr int kTimerGroupCount = 8;
9
10} // namespace
11
12PX4EscComponent::PX4EscComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
13 : VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
14 , _name(tr("ESC"))
15{}
16
18{
19 return tr("Calibrate PWM ESCs and configure DShot and DroneCAN ESC settings.");
20}
21
23{
24 return QStringLiteral("/InstrumentValueIcons/bolt.svg");
25}
26
28{
29 return {
30 tr("Electronic speed controller"), tr("Calibration"), tr("Motor"), tr("PWM"), tr("DShot"), tr("DroneCAN"),
31 };
32}
33
35{
36 return QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/AutoPilotPlugins/PX4/PX4EscComponent.qml"));
37}
38
40{
41 QStringList triggers{"DSHOT_BIDIR_EN", "MOT_POLE_COUNT"};
42 for (int i = 0; i < kTimerGroupCount; i++) {
43 triggers.append(QStringLiteral("PWM_MAIN_TIM%1").arg(i));
44 triggers.append(QStringLiteral("PWM_AUX_TIM%1").arg(i));
45 }
46
47 return triggers;
48}
49
50QList<VehicleSummaryItem> PX4EscComponent::summaryItems() const
51{
52 // Output protocol values of -1 and above are PWM or OneShot, below -1 are DShot
53 bool pwm = false;
54 bool dshot = false;
55 for (int i = 0; i < kTimerGroupCount; i++) {
56 for (const QString& prefix : {QStringLiteral("PWM_MAIN_TIM"), QStringLiteral("PWM_AUX_TIM")}) {
57 const Fact* const protocol = _parameterFact(prefix + QString::number(i));
58 if (!protocol) {
59 continue;
60 }
61 if (protocol->rawValue().toInt() < -1) {
62 dshot = true;
63 } else {
64 pwm = true;
65 }
66 }
67 }
68
69 QList<VehicleSummaryItem> items;
70 if (dshot && pwm) {
71 items.append({tr("Output"), tr("DShot and PWM")});
72 } else if (dshot) {
73 items.append({tr("Output"), tr("DShot")});
74 } else if (pwm) {
75 items.append({tr("Output"), tr("PWM")});
76 }
77
78 if (dshot) {
79 Fact* const bidirectional = _parameterFact(QStringLiteral("DSHOT_BIDIR_EN"));
80 if (bidirectional) {
81 items.append({tr("Bidirectional DShot"), bidirectional->enumStringValue(),
82 bidirectional->rawValue().toInt() == 0 ? VehicleSummaryItem::Muted
83 : VehicleSummaryItem::Normal});
84 }
85 const Fact* const poles = _parameterFact(QStringLiteral("MOT_POLE_COUNT"));
86 if (poles) {
87 items.append({tr("Motor Poles"), poles->cookedValueString()});
88 }
89 }
90
91 return items;
92}
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.
Definition Fact.h:15
QString cookedValueString() const
Definition Fact.cc:489
QString enumStringValue()
Definition Fact.cc:248
QVariant rawValue() const
Definition Fact.h:87
PX4EscComponent(Vehicle *vehicle, AutoPilotPlugin *autopilot, QObject *parent=nullptr)
QList< VehicleSummaryItem > summaryItems() const final
Values for this component's card on the Summary page. A component with none falls back to summaryQmlS...
QString iconResource() const final
QUrl setupSource() const final
QStringList summaryChangedTriggerList() const final
Parameters whose change emits summaryItemsChanged, besides those that change setupComplete.
QStringList searchKeywords() const final
Translated search terms for the whole component, for pages without vehicleConfigJson() sections.
QString description() const final
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.