From 711d1811f9bda661ed99d154d3b4475bac2f3b73 Mon Sep 17 00:00:00 2001 From: frogmane <7685285+xznhj8129@users.noreply.github.com> Date: Sun, 14 Dec 2025 15:25:30 -0500 Subject: [PATCH 1/3] add arc functions to ipf --- docs/Programming Framework.md | 3 +++ .../javascript_programming/OPERATIONS_REFERENCE.md | 4 ++-- .../api_definitions_summary.md | 2 +- docs/javascript_programming/index.md | 2 +- src/main/programming/logic_condition.c | 14 ++++++++++++++ src/main/programming/logic_condition.h | 3 +++ 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/docs/Programming Framework.md b/docs/Programming Framework.md index 4233f78487d..e97287c7171 100644 --- a/docs/Programming Framework.md +++ b/docs/Programming Framework.md @@ -119,6 +119,9 @@ for complete documentation on using JavaScript to program your flight controller | 54 | Mag calibration | Trigger a magnetometer calibration. | | 55 | Set Gimbal Sensitivity | Scales `Operand A` from [`-16` : `15`] | 56 | Override Minimum Ground Speed | When active, sets the minimum ground speed to the value specified in `Operand A` [m/s]. Minimum allowed value is set in `nav_min_ground_speed`. Maximum value is `150` | +| 57 | Trigonometry: ACos | Computes ACOS of (`Operand A` / `Operand B`) using the fast approximation. If `Operand B` is `0`, `1000` is used. Input is clamped to [-1, 1] and the result is returned in degrees. | +| 58 | Trigonometry: ASin | Computes ASIN of (`Operand A` / `Operand B`) using the fast approximation. If `Operand B` is `0`, `1000` is used. Input is clamped to [-1, 1] and the result is returned in degrees. | +| 59 | Trigonometry: ATan2 | Computes ATAN2 using `Operand A` as Y and `Operand B` as X with the fast approximation. Returns the angle in degrees. | ### Operands diff --git a/docs/javascript_programming/OPERATIONS_REFERENCE.md b/docs/javascript_programming/OPERATIONS_REFERENCE.md index 3506abd2c56..948a7c7fe92 100644 --- a/docs/javascript_programming/OPERATIONS_REFERENCE.md +++ b/docs/javascript_programming/OPERATIONS_REFERENCE.md @@ -11,7 +11,7 @@ All INAV logic condition operations supported by the firmware are now fully impl ✅ **Arithmetic**: ADD, SUB, MUL, DIV, MODULUS (via +, -, *, /, %) ✅ **Comparisons**: EQUAL, GREATER_THAN, LOWER_THAN, APPROX_EQUAL (via ===, >, <, approxEqual()) ✅ **Logical**: AND, OR, NOT, XOR, NAND, NOR (via &&, ||, !, xor(), nand(), nor()) -✅ **Math**: MIN, MAX, SIN, COS, TAN, ABS (via Math.min/max/sin/cos/tan/abs) +✅ **Math**: MIN, MAX, SIN, COS, TAN, ACOS, ASIN, ATAN2, ABS (via Math.min/max/sin/cos/tan/acos/asin/atan2/abs) ✅ **Scaling**: MAP_INPUT, MAP_OUTPUT (via mapInput(), mapOutput()) ✅ **Flow control**: STICKY, EDGE, DELAY, TIMER, DELTA (via on.* and helper functions) ✅ **Variables**: GVAR_SET, GVAR_INC, GVAR_DEC (via assignments, ++, --) @@ -98,7 +98,7 @@ if (rc[0].low && rc[1].mid && rc[2].high) { - RC channels: `rc[0]` through `rc[17]` (18 channels) - RC channel properties: `.value` (1000-2000us), `.low` (<1333us), `.mid` (1333-1666us), `.high` (>1666us) -- All trig functions (sin/cos/tan) take degrees, not radians +- Trig functions: sin/cos/tan take degrees; acos/asin use ratios (-1..1) and atan2 returns degrees from y/x inputs - MODULUS operator bug fixed: `%` now correctly generates MODULUS operation - MAP_INPUT normalizes to [0:1000], MAP_OUTPUT scales from [0:1000] diff --git a/docs/javascript_programming/api_definitions_summary.md b/docs/javascript_programming/api_definitions_summary.md index 710af423808..2ce71e069d1 100644 --- a/docs/javascript_programming/api_definitions_summary.md +++ b/docs/javascript_programming/api_definitions_summary.md @@ -72,7 +72,7 @@ Waypoint mission data: Math functions: - **Basic**: min, max, abs -- **Trig**: sin, cos, tan (degrees) +- **Trig**: sin, cos, tan (degrees), acos/asin (ratio inputs), atan2 (y, x -> degrees) - **Mapping**: mapInput, mapOutput - **Arithmetic**: add, sub, mul, div, mod (operators) diff --git a/docs/javascript_programming/index.md b/docs/javascript_programming/index.md index 272d344eb7a..d6738d48a78 100644 --- a/docs/javascript_programming/index.md +++ b/docs/javascript_programming/index.md @@ -65,7 +65,7 @@ Comprehensive guide to all INAV logic condition operations: - ✅ Arithmetic: `+`, `-`, `*`, `/`, `%` - ✅ Comparisons: `===`, `>`, `<`, `approxEqual()` - ✅ Logical: `&&`, `||`, `!`, `xor()`, `nand()`, `nor()` -- ✅ Math: `Math.min()`, `Math.max()`, `Math.sin()`, `Math.cos()`, `Math.tan()`, `Math.abs()` +- ✅ Math: `Math.min()`, `Math.max()`, `Math.sin()`, `Math.cos()`, `Math.tan()`, `Math.acos()`, `Math.asin()`, `Math.atan2()`, `Math.abs()` - ✅ Scaling: `mapInput()`, `mapOutput()` - ✅ Flow control: `edge()`, `sticky()`, `delay()`, `timer()`, `whenChanged()` - ✅ Variables: `gvar[0-7]`, `let`, `var` diff --git a/src/main/programming/logic_condition.c b/src/main/programming/logic_condition.c index edba68b8e94..62b799a128d 100644 --- a/src/main/programming/logic_condition.c +++ b/src/main/programming/logic_condition.c @@ -404,6 +404,20 @@ static int logicConditionCompute( return tan_approx(DEGREES_TO_RADIANS(operandA)) * temporaryValue; break; + case LOGIC_CONDITION_ACOS: + temporaryValue = (operandB == 0) ? 1000 : operandB; + return RADIANS_TO_DEGREES(acos_approx(constrainf((float)operandA / (float)temporaryValue, -1.0f, 1.0f))); + break; + + case LOGIC_CONDITION_ASIN: + temporaryValue = (operandB == 0) ? 1000 : operandB; + return RADIANS_TO_DEGREES(asin_approx(constrainf((float)operandA / (float)temporaryValue, -1.0f, 1.0f))); + break; + + case LOGIC_CONDITION_ATAN2: + return RADIANS_TO_DEGREES(atan2_approx((float)operandA, (float)operandB)); + break; + case LOGIC_CONDITION_MIN: return (operandA < operandB) ? operandA : operandB; break; diff --git a/src/main/programming/logic_condition.h b/src/main/programming/logic_condition.h index 74ea96c98ee..c73a0db4111 100644 --- a/src/main/programming/logic_condition.h +++ b/src/main/programming/logic_condition.h @@ -86,6 +86,9 @@ typedef enum { LOGIC_CONDITION_RESET_MAG_CALIBRATION = 54, LOGIC_CONDITION_SET_GIMBAL_SENSITIVITY = 55, LOGIC_CONDITION_OVERRIDE_MIN_GROUND_SPEED = 56, + LOGIC_CONDITION_ACOS = 57, + LOGIC_CONDITION_ASIN = 58, + LOGIC_CONDITION_ATAN2 = 59, LOGIC_CONDITION_LAST } logicOperation_e; From b0313a4dc985b20bcd72ae4140d8bf4e11d706e4 Mon Sep 17 00:00:00 2001 From: frogmane <7685285+xznhj8129@users.noreply.github.com> Date: Sun, 29 Mar 2026 12:46:01 -0400 Subject: [PATCH 2/3] correct enum --- src/main/programming/logic_condition.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/programming/logic_condition.h b/src/main/programming/logic_condition.h index c73a0db4111..34155ea082e 100644 --- a/src/main/programming/logic_condition.h +++ b/src/main/programming/logic_condition.h @@ -86,9 +86,10 @@ typedef enum { LOGIC_CONDITION_RESET_MAG_CALIBRATION = 54, LOGIC_CONDITION_SET_GIMBAL_SENSITIVITY = 55, LOGIC_CONDITION_OVERRIDE_MIN_GROUND_SPEED = 56, - LOGIC_CONDITION_ACOS = 57, - LOGIC_CONDITION_ASIN = 58, - LOGIC_CONDITION_ATAN2 = 59, + LOGIC_CONDITION_SET_ALTITUDE_TARGET = 57, + LOGIC_CONDITION_ACOS = 58, + LOGIC_CONDITION_ASIN = 59, + LOGIC_CONDITION_ATAN2 = 60, LOGIC_CONDITION_LAST } logicOperation_e; From ec70becbce14c6c17bad520a5a5c4f58e5510254 Mon Sep 17 00:00:00 2001 From: frogmane <7685285+xznhj8129@users.noreply.github.com> Date: Fri, 10 Apr 2026 21:30:16 -0400 Subject: [PATCH 3/3] Fix logic condition opcode docs --- docs/Programming Framework.md | 6 +++--- docs/development/msp/inav_enums.json | 5 ++++- docs/development/msp/inav_enums_ref.md | 5 ++++- docs/javascript_programming/OPERATIONS_REFERENCE.md | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/Programming Framework.md b/docs/Programming Framework.md index e97287c7171..595f8a5e1d7 100644 --- a/docs/Programming Framework.md +++ b/docs/Programming Framework.md @@ -119,9 +119,9 @@ for complete documentation on using JavaScript to program your flight controller | 54 | Mag calibration | Trigger a magnetometer calibration. | | 55 | Set Gimbal Sensitivity | Scales `Operand A` from [`-16` : `15`] | 56 | Override Minimum Ground Speed | When active, sets the minimum ground speed to the value specified in `Operand A` [m/s]. Minimum allowed value is set in `nav_min_ground_speed`. Maximum value is `150` | -| 57 | Trigonometry: ACos | Computes ACOS of (`Operand A` / `Operand B`) using the fast approximation. If `Operand B` is `0`, `1000` is used. Input is clamped to [-1, 1] and the result is returned in degrees. | -| 58 | Trigonometry: ASin | Computes ASIN of (`Operand A` / `Operand B`) using the fast approximation. If `Operand B` is `0`, `1000` is used. Input is clamped to [-1, 1] and the result is returned in degrees. | -| 59 | Trigonometry: ATan2 | Computes ATAN2 using `Operand A` as Y and `Operand B` as X with the fast approximation. Returns the angle in degrees. | +| 58 | Trigonometry: ACos | Computes ACOS of (`Operand A` / `Operand B`) using the fast approximation. If `Operand B` is `0`, `1000` is used. Input is clamped to [-1, 1] and the result is returned in degrees. | +| 59 | Trigonometry: ASin | Computes ASIN of (`Operand A` / `Operand B`) using the fast approximation. If `Operand B` is `0`, `1000` is used. Input is clamped to [-1, 1] and the result is returned in degrees. | +| 60 | Trigonometry: ATan2 | Computes ATAN2 using `Operand A` as Y and `Operand B` as X with the fast approximation. Returns a signed angle in degrees in `(-180, 180]`. | ### Operands diff --git a/docs/development/msp/inav_enums.json b/docs/development/msp/inav_enums.json index ffe24b3f24c..31e98b833cb 100644 --- a/docs/development/msp/inav_enums.json +++ b/docs/development/msp/inav_enums.json @@ -2055,7 +2055,10 @@ "LOGIC_CONDITION_SET_GIMBAL_SENSITIVITY": "55", "LOGIC_CONDITION_OVERRIDE_MIN_GROUND_SPEED": "56", "LOGIC_CONDITION_SET_ALTITUDE_TARGET": "57", - "LOGIC_CONDITION_LAST": "58" + "LOGIC_CONDITION_ACOS": "58", + "LOGIC_CONDITION_ASIN": "59", + "LOGIC_CONDITION_ATAN2": "60", + "LOGIC_CONDITION_LAST": "61" }, "logicWaypointOperands_e": { "_source": "inav/src/main/programming/logic_condition.h", diff --git a/docs/development/msp/inav_enums_ref.md b/docs/development/msp/inav_enums_ref.md index af53d1c6b9a..4c975cc7464 100644 --- a/docs/development/msp/inav_enums_ref.md +++ b/docs/development/msp/inav_enums_ref.md @@ -3155,7 +3155,10 @@ | `LOGIC_CONDITION_SET_GIMBAL_SENSITIVITY` | 55 | | | `LOGIC_CONDITION_OVERRIDE_MIN_GROUND_SPEED` | 56 | | | `LOGIC_CONDITION_SET_ALTITUDE_TARGET` | 57 | | -| `LOGIC_CONDITION_LAST` | 58 | | +| `LOGIC_CONDITION_ACOS` | 58 | | +| `LOGIC_CONDITION_ASIN` | 59 | | +| `LOGIC_CONDITION_ATAN2` | 60 | | +| `LOGIC_CONDITION_LAST` | 61 | | --- ## `logicWaypointOperands_e` diff --git a/docs/javascript_programming/OPERATIONS_REFERENCE.md b/docs/javascript_programming/OPERATIONS_REFERENCE.md index e4491b870fe..6ad1315256b 100644 --- a/docs/javascript_programming/OPERATIONS_REFERENCE.md +++ b/docs/javascript_programming/OPERATIONS_REFERENCE.md @@ -101,7 +101,7 @@ if (inav.rc[0].low && inav.rc[1].mid && inav.rc[2].high) { - RC channels: `rc[0]` through `rc[17]` (18 channels) - RC channel properties: `.value` (1000-2000us), `.low` (<1333us), `.mid` (1333-1666us), `.high` (>1666us) -- Trig functions: sin/cos/tan take degrees; acos/asin use ratios (-1..1) and atan2 returns degrees from y/x inputs +- Trig functions: sin/cos/tan take degrees; acos/asin use ratios (-1..1) and atan2 returns a signed angle in (-180, 180] degrees from y/x inputs - MODULUS operator bug fixed: `%` now correctly generates MODULUS operation - MAP_INPUT normalizes to [0:1000], MAP_OUTPUT scales from [0:1000]