@@ -198,28 +198,101 @@ inav.events.sticky(
198198
199199---
200200
201+ ## Variables
202+
203+ ### Let/Const Variables
204+
205+ Use ` let ` or ` const ` to define reusable expressions that are compiled into the logic:
206+
207+ ``` javascript
208+ // Define reusable calculations
209+ let distanceThreshold = 500 ;
210+ let altitudeLimit = 100 ;
211+ let combinedCondition = inav .flight .homeDistance > distanceThreshold && inav .flight .altitude > altitudeLimit;
212+
213+ // Use in conditions
214+ if (combinedCondition) {
215+ inav .override .vtx .power = 4 ;
216+ }
217+ ```
218+
219+ ** Benefits:**
220+ - Makes code more readable with named values
221+ - Compiler automatically optimizes duplicate expressions
222+ - Variables preserve their custom names through compile/decompile cycles
223+
224+ ** Important:** ` let ` /` const ` variables are ** compile-time substituted** , not runtime variables. For runtime state, use ` inav.gvar[] ` .
225+
226+ ### Ternary Operator
227+
228+ Use ternary expressions for conditional values:
229+
230+ ``` javascript
231+ // Assign based on condition
232+ let throttleLimit = inav .flight .cellVoltage < 330 ? 25 : 50 ;
233+
234+ if (inav .flight .cellVoltage < 350 ) {
235+ inav .override .throttleScale = throttleLimit;
236+ }
237+
238+ // Inline in expressions
239+ inav .override .vtx .power = inav .flight .homeDistance > 500 ? 4 : 2 ;
240+ ```
241+
242+ ** Use when:** You need conditional value assignment in a single expression.
243+
244+ ---
245+
201246## Available Objects
202247
248+ The ` inav ` namespace provides access to all flight controller data and control functions:
249+
250+ - ` inav.flight ` - Flight telemetry (including ` flight.mode.* ` )
251+ - ` inav.override ` - Override flight parameters
252+ - ` inav.rc ` - RC channels
253+ - ` inav.gvar ` - Global variables (0-7)
254+ - ` inav.pid ` - Programming PID outputs (` pid[0-3].output ` )
255+ - ` inav.waypoint ` - Waypoint navigation
256+ - ` inav.events.edge ` - Edge detection
257+ - ` inav.events.sticky ` - Latching conditions
258+ - ` inav.events.delay ` - Delayed execution
259+
260+ ### Flight Mode Detection
261+
262+ Check which flight modes are currently active via ` inav.flight.mode.* ` :
263+
264+ ``` javascript
265+ if (inav .flight .mode .poshold === 1 ) {
266+ inav .gvar [0 ] = 1 ; // Flag: in position hold
267+ }
268+
269+ if (inav .flight .mode .rth === 1 ) {
270+ inav .override .vtx .power = 4 ; // Max power during RTH
271+ }
272+ ```
273+
274+ ** Available modes:** ` failsafe ` , ` manual ` , ` rth ` , ` poshold ` , ` cruise ` , ` althold ` , ` angle ` , ` horizon ` , ` air ` , ` acro ` , ` courseHold ` , ` waypointMission ` , ` user1 ` through ` user4 `
275+
276+ ### PID Controller Outputs
277+
278+ Read output values from the 4 programming PID controllers (configured in Programming PID tab):
279+
203280``` javascript
204- const {
205- flight, // Flight telemetry
206- override, // Override flight parameters
207- rc, // RC channels
208- gvar, // Global variables (0-7)
209- waypoint, // Waypoint navigation
210- edge, // Edge detection
211- sticky, // Latching conditions
212- delay // Delayed execution
213- } = inav;
281+ if (inav .pid [0 ].output > 500 ) {
282+ inav .override .throttle = 1600 ;
283+ }
214284
285+ inav .gvar [0 ] = inav .pid [0 ].output ; // Store for OSD display
215286```
216287
288+ ** Available:** ` inav.pid[0].output ` through ` inav.pid[3].output `
289+
217290---
218291
219292## Tips
220293
221- 1 . ** Initialize variables on arm** using ` edge() ` with ` flight.armTimer > 1000 `
222- 2 . ** Use gvars for state** - they persist between logic condition evaluations
294+ 1 . ** Initialize variables on arm** using ` inav.events. edge()` with ` inav. flight.armTimer > 1000`
295+ 2 . ** Use inav.gvar for state** - they persist between logic condition evaluations
2232963 . ** edge() duration = 0** means instant trigger on condition becoming true
2242974 . ** edge() duration > 0** adds debounce time
2252985 . ** if statements are continuous** - they execute every cycle
0 commit comments