1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-13 11:29:56 +03:00

Updates with tested code and docs

Fixed typo
Updated document
Finished & tested LCs for:
- Delay
- Timer
- Delta
- Approx. Equal
This commit is contained in:
Darren Lines 2022-12-01 19:36:35 +00:00
parent 026e40c297
commit 10dc8d91dc
3 changed files with 29 additions and 17 deletions

View file

@ -81,6 +81,10 @@ IPF can be edited using INAV Configurator user interface, of via CLI
| 45 | FLIGHT_AXIS_ANGLE_OVERRIDE | Sets the target attitude angle for axis. In other words, when active, it enforces Angle mode (Heading Hold for Yaw) on this axis (Angle mode does not have to be active). `Operand A` defines the axis: `0` - Roll, `1` - Pitch, `2` - Yaw. `Operand B` defines the angle in degrees | | 45 | FLIGHT_AXIS_ANGLE_OVERRIDE | Sets the target attitude angle for axis. In other words, when active, it enforces Angle mode (Heading Hold for Yaw) on this axis (Angle mode does not have to be active). `Operand A` defines the axis: `0` - Roll, `1` - Pitch, `2` - Yaw. `Operand B` defines the angle in degrees |
| 46 | FLIGHT_AXIS_RATE_OVERRIDE | Sets the target rate (rotation speed) for axis. `Operand A` defines the axis: `0` - Roll, `1` - Pitch, `2` - Yaw. `Operand B` defines the rate in degrees per second | | 46 | FLIGHT_AXIS_RATE_OVERRIDE | Sets the target rate (rotation speed) for axis. `Operand A` defines the axis: `0` - Roll, `1` - Pitch, `2` - Yaw. `Operand B` defines the rate in degrees per second |
| 47 | EDGE | `Operand A` is activation operator [`boolean`], `Operand B` is the time for the edge to stay active [ms]. After activation, operator will return `true` until the time in Operand B is reached | | 47 | EDGE | `Operand A` is activation operator [`boolean`], `Operand B` is the time for the edge to stay active [ms]. After activation, operator will return `true` until the time in Operand B is reached |
| 48 | DELAY | This will return `true` when `Operand A` is true, and the delay time in `Operand B` [ms] has been exceeded. |
| 49 | TIMER | `true` for the duration of `Operand A` [ms]. Then `false` for the duration of `Operand B` [ms]. |
| 50 | DELTA | This returns `true` when the value of `Operand A` has changed by the value of `Operand B` or greater. |
| 51 | APPROX_EQUAL | `true` if `Operand B` is within 1% of `Operand A`. |
### Operands ### Operands

View file

@ -86,7 +86,7 @@ void pgResetFn_logicConditions(logicCondition_t *instance)
logicConditionState_t logicConditionStates[MAX_LOGIC_CONDITIONS]; logicConditionState_t logicConditionStates[MAX_LOGIC_CONDITIONS];
static int logicConditionCompute( static int logicConditionCompute(
int32_t currentVaue, int32_t currentValue,
logicOperation_e operation, logicOperation_e operation,
int32_t operandA, int32_t operandA,
int32_t operandB, int32_t operandB,
@ -106,8 +106,10 @@ static int logicConditionCompute(
break; break;
case LOGIC_CONDITION_APPROX_EQUAL: case LOGIC_CONDITION_APPROX_EQUAL:
uint16_t offest = operandA / 100; {
return ((operandB >= (operandA - offest)) && (operandB <= (operandA + offest))); uint16_t offest = operandA / 100;
return ((operandB >= (operandA - offest)) && (operandB <= (operandA + offest)));
}
break; break;
case LOGIC_CONDITION_GREATER_THAN: case LOGIC_CONDITION_GREATER_THAN:
@ -165,13 +167,13 @@ static int logicConditionCompute(
} }
//When both operands are not met, keep current value //When both operands are not met, keep current value
return currentVaue; return currentValue;
break; break;
case LOGIC_CONDITION_EDGE: case LOGIC_CONDITION_EDGE:
if (operandA && logicConditionStates[lcIndex].timeout == 0 && !(logicConditionStates[lcIndex].flags & LOGIC_CONDITION_FLAG_TIMEOUT_SATISFIED)) { if (operandA && logicConditionStates[lcIndex].timeout == 0 && !(logicConditionStates[lcIndex].flags & LOGIC_CONDITION_FLAG_TIMEOUT_SATISFIED)) {
if (operandB < 100) { if (operandB < 100) {
logicConditionStates[lcIndex].timeout = millis() + 100; logicConditionStates[lcIndex].timeout = millis();
} else { } else {
logicConditionStates[lcIndex].timeout = millis() + operandB; logicConditionStates[lcIndex].timeout = millis() + operandB;
} }
@ -193,13 +195,13 @@ static int logicConditionCompute(
case LOGIC_CONDITION_DELAY: case LOGIC_CONDITION_DELAY:
if (operandA) { if (operandA) {
if (logicConditionStates[lcIndex].flags & LOGIC_CONDITION_FLAG_TIMEOUT_SATISFIED) { if (logicConditionStates[lcIndex].timeout == 0) {
return true; logicConditionStates[lcIndex].timeout = millis() + operandB;
} else if (logicConditionStates[lcIndex].timeout > millis()) { } else if (millis() > logicConditionStates[lcIndex].timeout ) {
logicConditionStates[lcIndex].flags |= LOGIC_CONDITION_FLAG_TIMEOUT_SATISFIED; logicConditionStates[lcIndex].flags |= LOGIC_CONDITION_FLAG_TIMEOUT_SATISFIED;
return true; return true;
} else if (logicConditionStates[lcIndex].timeout == 0) { } else if (logicConditionStates[lcIndex].flags & LOGIC_CONDITION_FLAG_TIMEOUT_SATISFIED) {
logicConditionStates[lcIndex].timeout = millis() + operandB; return true;
} }
} else { } else {
logicConditionStates[lcIndex].timeout = 0; logicConditionStates[lcIndex].timeout = 0;
@ -210,18 +212,22 @@ static int logicConditionCompute(
break; break;
case LOGIC_CONDITION_TIMER: case LOGIC_CONDITION_TIMER:
if (logicConditionStates[lcIndex].timeout > millis() && currentVaue) { if ((logicConditionStates[lcIndex].timeout == 0) || (millis() > logicConditionStates[lcIndex].timeout && !currentValue)) {
logicConditionStates[lcIndex].timeout millis() + operandB; logicConditionStates[lcIndex].timeout = millis() + operandA;
return false;
} else if ((logicConditionStates[lcIndex].timeout == 0) || (logicConditionStates[lcIndex].timeout > millis() && currentVaue)) {
logicConditionStates[lcIndex].timeout millis() + operandA;
return true; return true;
} else if (millis() > logicConditionStates[lcIndex].timeout && currentValue) {
logicConditionStates[lcIndex].timeout = millis() + operandB;
return false;
} }
return currentVaue; return currentValue;
break; break;
case LOGIC_CONDITION_DELTA: case LOGIC_CONDITION_DELTA:
return false; {
int difference = logicConditionStates[lcIndex].lastValue - operandA;
logicConditionStates[lcIndex].lastValue = operandA;
return ABS(difference) >= operandB;
}
break; break;
case LOGIC_CONDITION_GVAR_SET: case LOGIC_CONDITION_GVAR_SET:
@ -848,6 +854,7 @@ void logicConditionUpdateTask(timeUs_t currentTimeUs) {
void logicConditionReset(void) { void logicConditionReset(void) {
for (uint8_t i = 0; i < MAX_LOGIC_CONDITIONS; i++) { for (uint8_t i = 0; i < MAX_LOGIC_CONDITIONS; i++) {
logicConditionStates[i].value = 0; logicConditionStates[i].value = 0;
logicConditionStates[i].lastValue = 0;
logicConditionStates[i].flags = 0; logicConditionStates[i].flags = 0;
logicConditionStates[i].timeout = 0; logicConditionStates[i].timeout = 0;
} }

View file

@ -193,6 +193,7 @@ PG_DECLARE_ARRAY(logicCondition_t, MAX_LOGIC_CONDITIONS, logicConditions);
typedef struct logicConditionState_s { typedef struct logicConditionState_s {
int value; int value;
int32_t lastValue;
uint8_t flags; uint8_t flags;
timeMs_t timeout; timeMs_t timeout;
} logicConditionState_t; } logicConditionState_t;