Skip to content

Ipf trig - #2478

Open
xznhj8129 wants to merge 5 commits into
iNavFlight:maintenance-10.xfrom
xznhj8129:ipf_trig
Open

Ipf trig#2478
xznhj8129 wants to merge 5 commits into
iNavFlight:maintenance-10.xfrom
xznhj8129:ipf_trig

Conversation

@xznhj8129

@xznhj8129 xznhj8129 commented Dec 14, 2025

Copy link
Copy Markdown

User description

Add support for arc function IPF LCs (see iNavFlight/inav#11179)


PR Type

Enhancement, New Feature


Description

  • Add support for inverse trigonometric functions (acos, asin, atan2)

  • Replace hardcoded operation numbers with named constants for maintainability

  • Update error messages and diagnostics to reflect new supported functions

  • Define new logic operators 57, 58, 59 for arc trigonometry operations


Diagram Walkthrough

flowchart LR
  A["New Arc Trig Functions"] -->|acos, asin, atan2| B["Expression Generator"]
  B -->|Generate Logic Commands| C["Logic Operators 57-59"]
  C -->|Map to Operations| D["INAV Constants"]
  A -->|Update Type Definitions| E["TypeScript Declarations"]
  B -->|Update Diagnostics| F["Editor Validation"]
Loading

File Walkthrough

Relevant files
Enhancement
5 files
helpers.js
Add arc trig functions and refactor operation constants   
+42/-14 
expression_generator.js
Implement code generation for arc trigonometric functions
+26/-3   
logicConditionOperators.js
Define new logic operators for arc trigonometry                   
+19/-1   
diagnostics.js
Update diagnostics to support arc trigonometric functions
+3/-3     
inav_constants.js
Add operation constants for arc trigonometric functions   
+7/-0     
Documentation
1 files
types.js
Add TypeScript type declarations for arc functions             
+3/-0     
Additional files
3 files
inav_SITL [link]   
inav_SITL [link]   
inav_SITL [link]   

@github-actions

Copy link
Copy Markdown

Branch Targeting Suggestion

You've targeted the master branch with this PR. Please consider if a version branch might be more appropriate:

  • maintenance-9.x - If your change is backward-compatible and won't create compatibility issues between INAV firmware and Configurator 9.x versions. This will allow your PR to be included in the next 9.x release.

  • maintenance-10.x - If your change introduces compatibility requirements between firmware and configurator that would break 9.x compatibility. This is for PRs which will be included in INAV 10.x

If master is the correct target for this change, no action is needed.


This is an automated suggestion to help route contributions to the appropriate branch.

@xznhj8129 xznhj8129 changed the title Ipf trig IPF acos/asin/atan2 Dec 14, 2025
@qodo-code-review qodo-code-review Bot changed the title IPF acos/asin/atan2 Ipf trig Dec 14, 2025
@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

Comment thread js/transpiler/api/definitions/helpers.js
Comment thread js/logicConditionOperators.js Outdated
@xznhj8129
xznhj8129 changed the base branch from master to maintenance-10.x January 28, 2026 17:07
@sensei-hacker sensei-hacker added this to the 10.0 milestone Feb 8, 2026
@sensei-hacker
sensei-hacker changed the base branch from maintenance-10.x to maintenance-9.x April 25, 2026 17:10
@sensei-hacker
sensei-hacker changed the base branch from maintenance-9.x to maintenance-10.x April 25, 2026 17:10
@sensei-hacker

Copy link
Copy Markdown
Member

It looks like you did a lot of great work here. Thanks.
Adding to the Qodo comments comments above, Claude suggests maybe checking the following.
Of course, Claude can be wrong, or you can choose to do things differently. We just want to make sure any choices are intentional.


  CRITICAL — Block merge
                                                                                                                                       
  1. Wrong opcode numbers (inav_constants.js, logicConditionOperators.js)                                                              
  Firmware PR #11179 already took opcode 57 for SET_ALTITUDE_TARGET. This PR assigns ACOS=57, ASIN=58, ATAN2=59 — but the correct      
  values are ACOS=58, ASIN=59, ATAN2=60. Sending wrong opcodes silently commands the wrong Logic Condition operation on the FC.        
                      
  2. Broken import path (helpers.js line 12)                                                                                           
  // Wrong — resolves to a non-existent path:
  import { OPERATION } from '../../transpiler/transpiler/inav_constants.js';                                                           
                                                                            
  // Correct:                                                                                                                          
  import { OPERATION } from '../../transpiler/inav_constants.js';
  This will crash the transpiler module on load.                                                                                       
                      
  ---                                                                                                                                  
  IMPORTANT — Should fix
                                                                                                                                       
  3. acos/asin input scaling is undocumented (expression_generator.js)
  The firmware divides operandA by operandB, and when operandB=0 it defaults to 1000. So Math.acos(0.5) actually computes              
  acos(0.5/1000) ≈ acos(0) = 90°, not acos(0.5) = 60°. The API docs say params: ['ratio'] implying -1..1 input, but the real expected  
  range is -1000..1000. Needs either a documentation fix or explicit operandB=1000.                                                    
                                                                                                                                       
  4. abs inavOperation silently removed (helpers.js)                                                                                   
  All sibling math functions got their hardcoded numbers replaced with named constants — correct. But abs had the inavOperation field
  removed entirely with no comment explaining why (it's because abs is emulated via MAX(x, SUB(0,x)) since firmware opcode 32 is       
  actually SET_OSD_LAYOUT). Should have an inline comment.
                                                                                                                                       
  5. SET_ALTITUDE_TARGET (57) missing from OPERATION_NAMES (inav_constants.js)                                                         
  Fixing the opcode numbers (item 1) will also require adding this missing entry.

@xznhj8129

Copy link
Copy Markdown
Author

The inav part was merged but i somehow missed this, i'll finish it

Resolve the inav_constants.js OPERATION_NAMES conflict and bring the
branch up to date with maintenance-10.x (it was 517 commits behind).

The firmware that actually merged (iNavFlight/inav#11179, plus a
SET_ALTITUDE_TARGET=57 inserted ahead of it) assigns the arc-trig
logic conditions as ACOS=58, ASIN=59, ATAN2=60 — one higher than the
57/58/59 this PR originally used. Renumber ACOS/ASIN/ATAN2 in the
OPERATION constants, OPERATION_NAMES, and LOGIC_OPERATORS to match,
so generated logic commands map to the correct firmware operations.
Firmware maintenance-10.x defines LOGIC_CONDITION_SET_ALTITUDE_TARGET=57
(navigationSetAltitudeTargetWithDatum): operand A = altitude datum flag
(0 takeoff / 1 MSL / 2 terrain), operand B = target altitude. It was
missing from the configurator, leaving a gap at 57.

Register it in the OPERATION constants, OPERATION_NAMES, and the
LOGIC_OPERATORS table (two operands, boolean output) so it is selectable
and labeled in the Logic Conditions editor.
@xznhj8129

xznhj8129 commented Jul 23, 2026

Copy link
Copy Markdown
Author

This is ready, reminder to me to update inav's docs/Programming Framework.md

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants