QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
APMRadioComponent.cc
Go to the documentation of this file.
1#include "APMRadioComponent.h"
2#include "ParameterManager.h"
3#include "Fact.h"
4#include "Vehicle.h"
5
6APMRadioComponent::APMRadioComponent(Vehicle *vehicle, AutoPilotPlugin *autopilot, QObject *parent)
7 : VehicleComponent(vehicle, autopilot, AutoPilotPlugin::KnownRadioVehicleComponent, parent)
8{
9 for (const QString &mapParam : _mapParams) {
11 (void) connect(fact, &Fact::valueChanged, this, &APMRadioComponent::_triggerChanged);
12 }
13
14 _connectSetupTriggers();
15}
16
18{
19 // The best we can do to detect the need for a radio calibration is look for attitude
20 // controls to be mapped as well as all attitude control rc min/max/trim still at defaults.
21 QList<int> mapValues;
22
23 // First check for all attitude controls mapped
24 for (int i = 0; i < _mapParams.count(); i++) {
25 mapValues << _vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, _mapParams[i])->rawValue().toInt();
26 if (mapValues[i] <= 0) {
27 return false;
28 }
29 }
30
31 // Next check RC#_MIN/MAX/TRIM all at defaults
32 for (const QString &mapParam : _mapParams) {
33 const int channel = _vehicle->parameterManager()->getParameter(-1, mapParam)->rawValue().toInt();
34 if (_vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, QStringLiteral("RC%1_MIN").arg(channel))->rawValue().toInt() != 1100) {
35 return true;
36 }
37 if (_vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, QStringLiteral("RC%1_MAX").arg(channel))->rawValue().toInt() != 1900) {
38 return true;
39 }
40 if (_vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, QStringLiteral("RC%1_TRIM").arg(channel))->rawValue().toInt() != 1500) {
41 return true;
42 }
43 }
44
45 return false;
46}
47
48void APMRadioComponent::_connectSetupTriggers()
49{
50 for (Fact *fact : _triggerFacts) {
51 (void) disconnect(fact, &Fact::valueChanged, this, &APMRadioComponent::_triggerChanged);
52 }
53 _triggerFacts.clear();
54
55 // Get the channels for attitude controls and connect to those values for triggers
56 for (const QString &mapParam : _mapParams) {
57 const int channel = _vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, mapParam)->rawValue().toInt();
58
59 Fact *fact = _vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, QStringLiteral("RC%1_MIN").arg(channel));
60 _triggerFacts << fact;
61 (void) connect(fact, &Fact::valueChanged, this, &APMRadioComponent::_triggerChanged);
62
63 fact = _vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, QStringLiteral("RC%1_MAX").arg(channel));
64 _triggerFacts << fact;
65 (void) connect(fact, &Fact::valueChanged, this, &APMRadioComponent::_triggerChanged);
66
67 fact = _vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, QStringLiteral("RC%1_TRIM").arg(channel));
68 _triggerFacts << fact;
69 (void) connect(fact, &Fact::valueChanged, this, &APMRadioComponent::_triggerChanged);
70 }
71}
72
73void APMRadioComponent::_triggerChanged()
74{
76
77 // Control mapping may have changed so we need to reset triggers
78 _connectSetupTriggers();
79}
bool setupComplete() const final
APMRadioComponent(Vehicle *vehicle, AutoPilotPlugin *autopilot, QObject *parent=nullptr)
A Fact is used to hold a single value within the system.
Definition Fact.h:19
void valueChanged(const QVariant &value)
This signal is only meant for use by the QT property system. It should not be connected to by client ...
Fact * getParameter(int componentId, const QString &paramName)
static constexpr int defaultComponentId
void setupCompleteChanged()
ParameterManager * parameterManager()
Definition Vehicle.h:578