1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-14 03:49:58 +03:00

Adding loiter radius to programming

Adding a loiter radius override to the programming. This change allows pilots to change their loiter radius on the fly. The minimum loiter radius will always be that set in Advanced Tuning, for safety. The maximum radius is 100000cm.

As part of this change, I increased the min and max constraints of the basic maths conditions. The were set to int16, however operands can be int32. Before the change, this caused clipping of the radius when performing basic calculus on it.
This commit is contained in:
Darren Lines 2021-09-22 22:32:56 +01:00
parent b51cb7739a
commit b66caae07a
4 changed files with 40 additions and 10 deletions

View file

@ -176,20 +176,20 @@ static int logicConditionCompute(
break;
case LOGIC_CONDITION_ADD:
return constrain(operandA + operandB, INT16_MIN, INT16_MAX);
return constrain(operandA + operandB, INT32_MIN, INT32_MAX);
break;
case LOGIC_CONDITION_SUB:
return constrain(operandA - operandB, INT16_MIN, INT16_MAX);
return constrain(operandA - operandB, INT32_MIN, INT32_MAX);
break;
case LOGIC_CONDITION_MUL:
return constrain(operandA * operandB, INT16_MIN, INT16_MAX);
return constrain(operandA * operandB, INT32_MIN, INT32_MAX);
break;
case LOGIC_CONDITION_DIV:
if (operandB != 0) {
return constrain(operandA / operandB, INT16_MIN, INT16_MAX);
return constrain(operandA / operandB, INT32_MIN, INT32_MAX);
} else {
return operandA;
}
@ -333,6 +333,11 @@ static int logicConditionCompute(
}
break;
case LOGIC_CONDITION_LOITER_OVERRIDE:
logicConditionValuesByType[LOGIC_CONDITION_LOITER_OVERRIDE] = constrain(operandA, 0, 100000);
LOGIC_CONDITION_GLOBAL_FLAG_ENABLE(LOGIC_CONDITION_GLOBAL_FLAG_OVERRIDE_LOITER_RADIUS);
return true;
break;
default:
return false;
break;
@ -533,6 +538,9 @@ static int logicConditionGetFlightOperandValue(int operand) {
#endif
break;
case LOGIC_CONDITION_OPERAND_FLIGHT_LOITER_RADIUS:
return getLoiterRadius(navConfig()->fw.loiter_radius);
default:
return 0;
break;
@ -720,3 +728,11 @@ int16_t getRcChannelOverride(uint8_t channel, int16_t originalValue) {
return originalValue;
}
}
uint32_t getLoiterRadius(uint32_t loiterRadius) {
if (LOGIC_CONDITION_GLOBAL_FLAG(LOGIC_CONDITION_GLOBAL_FLAG_OVERRIDE_LOITER_RADIUS)) {
return constrain(logicConditionValuesByType[LOGIC_CONDITION_LOITER_OVERRIDE], loiterRadius, 100000);
} else {
return loiterRadius;
}
}