SensorsComponent.cc 3.5 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
#include "SensorsComponentController.h"
17

Don Gagne's avatar
Don Gagne committed
18 19 20
const char* SensorsComponent::_airspeedBreakerParam =   "CBRK_AIRSPD_CHK";
const char* SensorsComponent::_airspeedDisabledParam =  "FW_ARSP_MODE";
const char* SensorsComponent::_airspeedCalParam =       "SENS_DPRES_OFF";
21

22
const char* SensorsComponent::_magEnabledParam =  "SYS_HAS_MAG";
23 24
const char* SensorsComponent::_magCalParam =  "CAL_MAG0_ID";

25
SensorsComponent::SensorsComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
26
    VehicleComponent(vehicle, autopilot, parent),
27 28
    _name(tr("Sensors"))
{
Tomaz Canabrava's avatar
Tomaz Canabrava committed
29
    _deviceIds = QStringList({QStringLiteral("CAL_GYRO0_ID"), QStringLiteral("CAL_ACC0_ID") });
30 31 32 33 34 35 36 37 38
}

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

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

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

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

bool SensorsComponent::setupComplete(void) const
{
54
    foreach (const QString &triggerParam, _deviceIds) {
55
        if (_vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, triggerParam)->rawValue().toFloat() == 0.0f) {
56 57 58
            return false;
        }
    }
59 60 61 62 63 64
    bool magEnabled = true;
    if (_vehicle->parameterManager()->parameterExists(FactSystem::defaultComponentId, _magEnabledParam)) {
        magEnabled = _vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, _magEnabledParam)->rawValue().toBool();
    }

    if (magEnabled && _vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, _magCalParam)->rawValue().toFloat() == 0.0f) {
65 66
        return false;
    }
67

68
    if (_vehicle->fixedWing() || _vehicle->vtol()) {
Don Gagne's avatar
Don Gagne committed
69 70 71 72
        if (!_vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, _airspeedDisabledParam)->rawValue().toBool() &&
                _vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, _airspeedBreakerParam)->rawValue().toInt() != 162128 &&
                _vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, _airspeedCalParam)->rawValue().toFloat() == 0.0f) {
            return false;
73 74 75
        }
    }

76 77 78
    return true;
}

Don Gagne's avatar
Don Gagne committed
79
QStringList SensorsComponent::setupCompleteChangedTriggerList(void) const
80
{
Don Gagne's avatar
Don Gagne committed
81 82
    QStringList triggers;
    
83
    triggers << _deviceIds << _magCalParam << _magEnabledParam;
84
    if (_vehicle->fixedWing() || _vehicle->vtol()) {
Don Gagne's avatar
Don Gagne committed
85
        triggers << _airspeedCalParam << _airspeedBreakerParam;
Don Gagne's avatar
Don Gagne committed
86 87 88
    }
    
    return triggers;
89 90
}

91
QUrl SensorsComponent::setupSource(void) const
92
{
93
    return QUrl::fromUserInput("qrc:/qml/SensorsComponent.qml");
94 95
}

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