|
|
@ -22,11 +22,12 @@ APMGeoFenceManager::APMGeoFenceManager(Vehicle* vehicle) |
|
|
|
: GeoFenceManager(vehicle) |
|
|
|
: GeoFenceManager(vehicle) |
|
|
|
, _fenceSupported(false) |
|
|
|
, _fenceSupported(false) |
|
|
|
, _breachReturnSupported(vehicle->fixedWing()) |
|
|
|
, _breachReturnSupported(vehicle->fixedWing()) |
|
|
|
|
|
|
|
, _circleSupported(false) |
|
|
|
|
|
|
|
, _polygonSupported(false) |
|
|
|
, _firstParamLoadComplete(false) |
|
|
|
, _firstParamLoadComplete(false) |
|
|
|
, _circleRadiusFact(NULL) |
|
|
|
, _circleRadiusFact(NULL) |
|
|
|
, _readTransactionInProgress(false) |
|
|
|
, _readTransactionInProgress(false) |
|
|
|
, _writeTransactionInProgress(false) |
|
|
|
, _writeTransactionInProgress(false) |
|
|
|
, _fenceEnableFact(NULL) |
|
|
|
|
|
|
|
, _fenceTypeFact(NULL) |
|
|
|
, _fenceTypeFact(NULL) |
|
|
|
{ |
|
|
|
{ |
|
|
|
connect(_vehicle, &Vehicle::mavlinkMessageReceived, this, &APMGeoFenceManager::_mavlinkMessageReceived); |
|
|
|
connect(_vehicle, &Vehicle::mavlinkMessageReceived, this, &APMGeoFenceManager::_mavlinkMessageReceived); |
|
|
@ -80,7 +81,7 @@ void APMGeoFenceManager::sendToVehicle(const QGeoCoordinate& breachReturn, const |
|
|
|
fenceEnableFact->setRawValue(0); |
|
|
|
fenceEnableFact->setRawValue(0); |
|
|
|
|
|
|
|
|
|
|
|
// Total point count, +1 polygon close in last index, +1 for breach in index 0
|
|
|
|
// Total point count, +1 polygon close in last index, +1 for breach in index 0
|
|
|
|
_cWriteFencePoints = (validatedPolygonCount ? (validatedPolygonCount + 1) : 0) + 1 ; |
|
|
|
_cWriteFencePoints = validatedPolygonCount ? validatedPolygonCount + 1 + 1 : 0; |
|
|
|
_vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, _fenceTotalParam)->setRawValue(_cWriteFencePoints); |
|
|
|
_vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, _fenceTotalParam)->setRawValue(_cWriteFencePoints); |
|
|
|
|
|
|
|
|
|
|
|
// FIXME: No validation of correct fence received
|
|
|
|
// FIXME: No validation of correct fence received
|
|
|
@ -106,11 +107,11 @@ void APMGeoFenceManager::loadFromVehicle(void) |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Point 0: Breach return point (ArduPlane only)
|
|
|
|
// Point 0: Breach return point (always sent, but supported by ArduPlane only)
|
|
|
|
// Point [1,N]: Polygon points
|
|
|
|
// Point [1,N]: Polygon points
|
|
|
|
// Point N+1: Close polygon point (same as point 1)
|
|
|
|
// Point N+1: Close polygon point (same as point 1)
|
|
|
|
int cFencePoints = _vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, _fenceTotalParam)->rawValue().toInt(); |
|
|
|
int cFencePoints = _vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, _fenceTotalParam)->rawValue().toInt(); |
|
|
|
int minFencePoints = 6; |
|
|
|
int minFencePoints = 5; |
|
|
|
qCDebug(GeoFenceManagerLog) << "APMGeoFenceManager::loadFromVehicle" << cFencePoints; |
|
|
|
qCDebug(GeoFenceManagerLog) << "APMGeoFenceManager::loadFromVehicle" << cFencePoints; |
|
|
|
if (cFencePoints == 0) { |
|
|
|
if (cFencePoints == 0) { |
|
|
|
// No fence
|
|
|
|
// No fence
|
|
|
@ -242,8 +243,19 @@ bool APMGeoFenceManager::_geoFenceSupported(void) |
|
|
|
|
|
|
|
|
|
|
|
void APMGeoFenceManager::_updateSupportedFlags(void) |
|
|
|
void APMGeoFenceManager::_updateSupportedFlags(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
emit circleSupportedChanged(circleSupported()); |
|
|
|
bool newCircleSupported = _fenceSupported && _vehicle->multiRotor() && _fenceTypeFact && (_fenceTypeFact->rawValue().toInt() & 2); |
|
|
|
emit polygonSupportedChanged(polygonSupported()); |
|
|
|
if (newCircleSupported != _circleSupported) { |
|
|
|
|
|
|
|
_circleSupported = newCircleSupported; |
|
|
|
|
|
|
|
emit circleSupportedChanged(newCircleSupported); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool newPolygonSupported = _fenceSupported && |
|
|
|
|
|
|
|
((_vehicle->multiRotor() && _fenceTypeFact && (_fenceTypeFact->rawValue().toInt() & 4)) || |
|
|
|
|
|
|
|
_vehicle->fixedWing()); |
|
|
|
|
|
|
|
if (newPolygonSupported != _polygonSupported) { |
|
|
|
|
|
|
|
_polygonSupported = newPolygonSupported; |
|
|
|
|
|
|
|
emit polygonSupportedChanged(newPolygonSupported); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void APMGeoFenceManager::_parametersReady(void) |
|
|
|
void APMGeoFenceManager::_parametersReady(void) |
|
|
@ -258,11 +270,9 @@ void APMGeoFenceManager::_parametersReady(void) |
|
|
|
QStringList paramLabels; |
|
|
|
QStringList paramLabels; |
|
|
|
|
|
|
|
|
|
|
|
if (_vehicle->multiRotor()) { |
|
|
|
if (_vehicle->multiRotor()) { |
|
|
|
_fenceEnableFact = _vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, QStringLiteral("FENCE_ENABLE")); |
|
|
|
|
|
|
|
_fenceTypeFact = _vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, QStringLiteral("FENCE_TYPE")); |
|
|
|
_fenceTypeFact = _vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, QStringLiteral("FENCE_TYPE")); |
|
|
|
|
|
|
|
|
|
|
|
connect(_fenceEnableFact, &Fact::rawValueChanged, this, &APMGeoFenceManager::_updateSupportedFlags); |
|
|
|
connect(_fenceTypeFact, &Fact::rawValueChanged, this, &APMGeoFenceManager::_updateSupportedFlags); |
|
|
|
connect(_fenceTypeFact, &Fact::rawValueChanged, this, &APMGeoFenceManager::_updateSupportedFlags); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_circleRadiusFact = _vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, QStringLiteral("FENCE_RADIUS")); |
|
|
|
_circleRadiusFact = _vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, QStringLiteral("FENCE_RADIUS")); |
|
|
|
connect(_circleRadiusFact, &Fact::rawValueChanged, this, &APMGeoFenceManager::_circleRadiusRawValueChanged); |
|
|
|
connect(_circleRadiusFact, &Fact::rawValueChanged, this, &APMGeoFenceManager::_circleRadiusRawValueChanged); |
|
|
@ -293,8 +303,7 @@ void APMGeoFenceManager::_parametersReady(void) |
|
|
|
emit paramLabelsChanged(_paramLabels); |
|
|
|
emit paramLabelsChanged(_paramLabels); |
|
|
|
|
|
|
|
|
|
|
|
emit fenceSupportedChanged(_fenceSupported); |
|
|
|
emit fenceSupportedChanged(_fenceSupported); |
|
|
|
emit circleSupportedChanged(circleSupported()); |
|
|
|
_updateSupportedFlags(); |
|
|
|
emit polygonSupportedChanged(polygonSupported()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
qCDebug(GeoFenceManagerLog) << "fenceSupported:circleSupported:polygonSupported:breachReturnSupported" << |
|
|
|
qCDebug(GeoFenceManagerLog) << "fenceSupported:circleSupported:polygonSupported:breachReturnSupported" << |
|
|
@ -318,26 +327,12 @@ void APMGeoFenceManager::_circleRadiusRawValueChanged(QVariant value) |
|
|
|
|
|
|
|
|
|
|
|
bool APMGeoFenceManager::circleSupported(void) const |
|
|
|
bool APMGeoFenceManager::circleSupported(void) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (_fenceSupported && _vehicle->multiRotor() && _fenceEnableFact && _fenceTypeFact) { |
|
|
|
return _circleSupported; |
|
|
|
return _fenceEnableFact->rawValue().toBool() && (_fenceTypeFact->rawValue().toInt() & 2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool APMGeoFenceManager::polygonSupported(void) const |
|
|
|
bool APMGeoFenceManager::polygonSupported(void) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (_fenceSupported) { |
|
|
|
return _polygonSupported; |
|
|
|
if (_vehicle->multiRotor()) { |
|
|
|
|
|
|
|
if (_fenceEnableFact && _fenceTypeFact) { |
|
|
|
|
|
|
|
return _fenceEnableFact->rawValue().toBool() && (_fenceTypeFact->rawValue().toInt() & 4); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (_vehicle->fixedWing()) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QString APMGeoFenceManager::editorQml(void) const |
|
|
|
QString APMGeoFenceManager::editorQml(void) const |
|
|
|