PX4RadioComponent.cc 2.84 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

10

Don Gagne's avatar
Don Gagne committed
11
#include "PX4RadioComponent.h"
Don Gagne's avatar
Don Gagne committed
12
#include "PX4AutoPilotPlugin.h"
13

Don Gagne's avatar
Don Gagne committed
14
PX4RadioComponent::PX4RadioComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
15
    VehicleComponent(vehicle, autopilot, parent),
16 17 18 19
    _name(tr("Radio"))
{
}

Don Gagne's avatar
Don Gagne committed
20
QString PX4RadioComponent::name(void) const
21 22 23 24
{
    return _name;
}

Don Gagne's avatar
Don Gagne committed
25
QString PX4RadioComponent::description(void) const
26 27 28 29 30 31
{
    return tr("The Radio Component is used to setup which channels on your RC Transmitter you will use for each vehicle control such as Roll, Pitch, Yaw and Throttle. "
              "It also allows you to assign switches and dials to the various flight modes. "
              "Prior to flight you must also calibrate the extents for all of your channels.");
}

Don Gagne's avatar
Don Gagne committed
32
QString PX4RadioComponent::iconResource(void) const
33
{
34
    return "/qmlimages/RadioComponentIcon.png";
35 36
}

Don Gagne's avatar
Don Gagne committed
37
bool PX4RadioComponent::requiresSetup(void) const
38
{
Don Gagne's avatar
Don Gagne committed
39
    return _autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1 ? false : true;
40 41
}

Don Gagne's avatar
Don Gagne committed
42
bool PX4RadioComponent::setupComplete(void) const
43
{
Don Gagne's avatar
Don Gagne committed
44
    if (_autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() != 1) {
45 46 47 48
        // The best we can do to detect the need for a radio calibration is look for attitude
        // controls to be mapped.
        QStringList attitudeMappings;
        attitudeMappings << "RC_MAP_ROLL" << "RC_MAP_PITCH" << "RC_MAP_YAW" << "RC_MAP_THROTTLE";
49
        foreach(const QString &mapParam, attitudeMappings) {
Don Gagne's avatar
Don Gagne committed
50
            if (_autopilot->getParameterFact(FactSystem::defaultComponentId, mapParam)->rawValue().toInt() == 0) {
51 52
                return false;
            }
53
        }
54
    }
55 56
    
    return true;
57 58
}

Don Gagne's avatar
Don Gagne committed
59
QStringList PX4RadioComponent::setupCompleteChangedTriggerList(void) const
60
{
Don Gagne's avatar
Don Gagne committed
61 62
    QStringList triggers;
    
Don Gagne's avatar
Don Gagne committed
63
    triggers << "COM_RC_IN_MODE" << "RC_MAP_ROLL" << "RC_MAP_PITCH" << "RC_MAP_YAW" << "RC_MAP_THROTTLE";
Don Gagne's avatar
Don Gagne committed
64 65
    
    return triggers;
66 67
}

Don Gagne's avatar
Don Gagne committed
68
QUrl PX4RadioComponent::setupSource(void) const
69
{
70
    return QUrl::fromUserInput("qrc:/qml/RadioComponent.qml");
71 72
}

Don Gagne's avatar
Don Gagne committed
73
QUrl PX4RadioComponent::summaryQmlSource(void) const
74
{
Don Gagne's avatar
Don Gagne committed
75
    return QUrl::fromUserInput("qrc:/qml/PX4RadioComponentSummary.qml");
76
}
Don Gagne's avatar
Don Gagne committed
77

Don Gagne's avatar
Don Gagne committed
78
QString PX4RadioComponent::prerequisiteSetup(void) const
Don Gagne's avatar
Don Gagne committed
79
{
Don Gagne's avatar
Don Gagne committed
80
    if (_autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() != 1) {
81 82 83 84 85 86
        PX4AutoPilotPlugin* plugin = dynamic_cast<PX4AutoPilotPlugin*>(_autopilot);
        
        if (!plugin->airframeComponent()->setupComplete()) {
            return plugin->airframeComponent()->name();

        }
Don Gagne's avatar
Don Gagne committed
87 88 89 90
    }
    
    return QString();
}