SensorsComponent.cc 3 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 11 12 13 14

/// @file
///     @author Don Gagne <don@thegagnes.com>

#include "SensorsComponent.h"
Don Gagne's avatar
Don Gagne committed
15
#include "PX4AutoPilotPlugin.h"
Don Gagne's avatar
Don Gagne committed
16 17
#include "QGCQmlWidgetHolder.h"
#include "SensorsComponentController.h"
18

19 20
const char* SensorsComponent::_airspeedBreaker =    "CBRK_AIRSPD_CHK";
const char* SensorsComponent::_airspeedCal =        "SENS_DPRES_OFF";
21

22
SensorsComponent::SensorsComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
23
    VehicleComponent(vehicle, autopilot, parent),
24 25
    _name(tr("Sensors"))
{
26
    _deviceIds << QStringLiteral("CAL_MAG0_ID") << QStringLiteral("CAL_GYRO0_ID") << QStringLiteral("CAL_ACC0_ID");
27 28 29 30 31 32 33 34 35
}

QString SensorsComponent::name(void) const
{
    return _name;
}

QString SensorsComponent::description(void) const
{
36
    return tr("Sensors Setup is used to calibrate the sensors within your vehicle.");
37 38
}

39
QString SensorsComponent::iconResource(void) const
40
{
41
    return "/qmlimages/SensorsComponentIcon.png";
42 43 44 45 46 47 48 49 50
}

bool SensorsComponent::requiresSetup(void) const
{
    return true;
}

bool SensorsComponent::setupComplete(void) const
{
51 52
    foreach (const QString &triggerParam, _deviceIds) {
        if (_autopilot->getParameterFact(FactSystem::defaultComponentId, triggerParam)->rawValue().toFloat() == 0.0f) {
53 54 55 56
            return false;
        }
    }

57 58 59 60 61 62 63 64
    if (_vehicle->fixedWing() || _vehicle->vtol()) {
        if (_autopilot->getParameterFact(FactSystem::defaultComponentId, _airspeedBreaker)->rawValue().toInt() != 162128) {
            if (_autopilot->getParameterFact(FactSystem::defaultComponentId, _airspeedCal)->rawValue().toFloat() == 0.0f) {
                return false;
            }
        }
    }

65 66 67
    return true;
}

Don Gagne's avatar
Don Gagne committed
68
QStringList SensorsComponent::setupCompleteChangedTriggerList(void) const
69
{
Don Gagne's avatar
Don Gagne committed
70 71
    QStringList triggers;
    
72 73 74
    triggers << _deviceIds;
    if (_vehicle->fixedWing() || _vehicle->vtol()) {
        triggers << _airspeedCal << _airspeedBreaker;
Don Gagne's avatar
Don Gagne committed
75 76 77
    }
    
    return triggers;
78 79
}

80
QUrl SensorsComponent::setupSource(void) const
81
{
82
    return QUrl::fromUserInput("qrc:/qml/SensorsComponent.qml");
83 84
}

85
QUrl SensorsComponent::summaryQmlSource(void) const
86
{
87 88
    QString summaryQml;
    
Don Gagne's avatar
Don Gagne committed
89 90 91 92
    if (_vehicle->fixedWing() || _vehicle->vtol()) {
        summaryQml = "qrc:/qml/SensorsComponentSummaryFixedWing.qml";
    } else {
        summaryQml = "qrc:/qml/SensorsComponentSummary.qml";
93 94 95
    }
    
    return QUrl::fromUserInput(summaryQml);
96
}
Don Gagne's avatar
Don Gagne committed
97 98 99 100 101 102 103 104 105 106 107 108

QString SensorsComponent::prerequisiteSetup(void) const
{
    PX4AutoPilotPlugin* plugin = dynamic_cast<PX4AutoPilotPlugin*>(_autopilot);
    Q_ASSERT(plugin);
    
    if (!plugin->airframeComponent()->setupComplete()) {
        return plugin->airframeComponent()->name();
    }
    
    return QString();
}