PX4GeoFenceManager.cc 2.8 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2 3 4 5 6 7 8 9 10 11 12
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

#include "PX4GeoFenceManager.h"
#include "Vehicle.h"
#include "FirmwarePlugin.h"
13
#include "ParameterManager.h"
Don Gagne's avatar
Don Gagne committed
14 15 16 17

PX4GeoFenceManager::PX4GeoFenceManager(Vehicle* vehicle)
    : GeoFenceManager(vehicle)
    , _firstParamLoadComplete(false)
18
    , _circleEnabled(false)
Don Gagne's avatar
Don Gagne committed
19 20
    , _circleRadiusFact(NULL)
{
21
    connect(_vehicle->parameterManager(), &ParameterManager::parametersReadyChanged, this, &PX4GeoFenceManager::_parametersReady);
22

23
    if (_vehicle->parameterManager()->parametersReady()) {
24 25
        _parametersReady();
    }
Don Gagne's avatar
Don Gagne committed
26 27 28 29 30 31 32 33 34 35 36 37
}

PX4GeoFenceManager::~PX4GeoFenceManager()
{

}

void PX4GeoFenceManager::_parametersReady(void)
{
    if (!_firstParamLoadComplete) {
        _firstParamLoadComplete = true;

38
        _circleRadiusFact = _vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, QStringLiteral("GF_MAX_HOR_DIST"));
Don Gagne's avatar
Don Gagne committed
39 40 41 42 43 44 45 46 47 48 49 50 51
        connect(_circleRadiusFact, &Fact::rawValueChanged, this, &PX4GeoFenceManager::_circleRadiusRawValueChanged);
        emit circleRadiusChanged(circleRadius());

        QStringList paramNames;
        QStringList paramLabels;

        paramNames << QStringLiteral("GF_ACTION") << QStringLiteral("GF_MAX_HOR_DIST") << QStringLiteral("GF_MAX_VER_DIST");
        paramLabels << QStringLiteral("Action:") << QStringLiteral("Radius:") << QStringLiteral("Max Altitude:");

        _params.clear();
        _paramLabels.clear();
        for (int i=0; i<paramNames.count(); i++) {
            QString paramName = paramNames[i];
52 53
            if (_vehicle->parameterManager()->parameterExists(FactSystem::defaultComponentId, paramName)) {
                Fact* paramFact = _vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, paramName);
Don Gagne's avatar
Don Gagne committed
54 55 56 57 58 59 60
                _params << QVariant::fromValue(paramFact);
                _paramLabels << paramLabels[i];
            }
        }
        emit paramsChanged(_params);
        emit paramLabelsChanged(_paramLabels);

61 62
        _circleEnabled = true;
        emit circleEnabledChanged(true);
Don Gagne's avatar
Don Gagne committed
63 64

        qCDebug(GeoFenceManagerLog) << "fenceSupported:circleSupported:polygonSupported:breachReturnSupported" <<
65
                                       _circleEnabled << polygonEnabled() << breachReturnEnabled();
Don Gagne's avatar
Don Gagne committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    }
}

float PX4GeoFenceManager::circleRadius(void) const
{
    if (_circleRadiusFact) {
        return _circleRadiusFact->rawValue().toFloat();
    } else {
        return 0.0;
    }
}

void PX4GeoFenceManager::_circleRadiusRawValueChanged(QVariant value)
{
    emit circleRadiusChanged(value.toFloat());
}