FlySpark logo
FlySpark logoFlySparkINAV setup guidesUpdated

INAV programming logic conditions

INAV programming lets the flight controller make a decision without a new flight mode. A logic condition reads a stick, a flight value or another condition, and its result can switch something else on, be compared, or drive an override. FlySpark's Programming tab, in the INAV configurator, is where those conditions live.

The board has 64 conditions, 8 global variables and 4 programming PIDs. The variables are shared numbers. They reset to 0 when the board powers up. Each condition is worked out many times a second, and the tab shows the live result when the flight controller is connected.

This is not the geozones map and it is not a waypoint mission. A condition can look at mission progress, and one operation can start a return home, but the return itself is INAV return to home. Betaflight GPS Rescue is a different firmware and a different screen.

Free. Hardware connections need Chrome or Edge on a computer; phones use the FlySpark app.

  • Free
  • Nothing to install
  • Demo without hardware

In short

INAV programming is a set of logic conditions the flight controller works out many times a second. FlySpark edits those conditions, eight global variables and four programming PIDs. A condition can compare a stick or a flight value, then override throttle, a channel or a mode.

Key facts

  • The Programming tab is INAV. It holds 64 logic conditions, 8 global variables and 4 programming PIDs.
  • Global variables reset to 0 at power-up. Conditions can set them and read them.
  • A number operand is -1000000 to 1000000. A programming PID gain is -32767 to 32767.
  • Low on a channel is below 1333 µs. High is above 1666 µs.
  • INAV 7 stops at operation 52. Later operations need INAV 8.
  • Return to home in the flight-mode list is INAV. It is not Betaflight GPS Rescue.
  • Chrome or Edge uses USB or Bluetooth. iPhone has no USB host.
  • Betaflight logoBetaflight
  • INAV logoINAV
  • ArduPilot logoArduPilot
  • PX4 logoPX4
  • BLHeli_S
  • Bluejay logoBluejay
  • AM32 logoAM32
  • ExpressLRS logoExpressLRS
  • EdgeTX logoEdgeTX
  • DroneCAN logoDroneCAN
  • MAVLink logoMAVLink

Try it

Cross 1666

High is above 1666 µs. Low is below 1333 µs. The lamp follows that rule.

1500 µs

Off

FlySpark

Features

  • 01

    64 logic conditions

    Each slot can be enabled, given an operation, and told when it runs. Unused slots stay empty. The card shows how many are in use.

  • 02

    Eight global variables

    V1 to V8 are numbers conditions can set, increase or decrease. They read live from the board and reset to 0 at power-up.

  • 03

    Four programming PIDs

    Each PID has a setpoint, a measurement and gains from -32767 to 32767. Clear disables that PID.

  • 04

    Operands

    A value can be a number, an RC channel, flight data, a flight mode, another condition, a global variable, a programming PID or a mission value.

  • 05

    Overrides

    Operations can force throttle, scale it, set an RC channel, invert a stick, set an axis angle or rate, or set a heading in navigation modes.

  • 06

    JavaScript card

    The same tab opens a JavaScript editor: examples, load from the flight controller, compile and apply.

  • 07

    INAV 7 and INAV 8

    INAV 7 stops at operation 52 and at flight operand 41. INAV 8 adds the later operations and the rest of the flight values.

What a logic condition is

A condition has an operation, one or two operands, an enabled switch, and a Runs choice. Runs can be Always, or only while another condition is true. That second choice is how you chain them: one condition becomes the activator for the next. A condition cannot use itself as the activator.

The operation list is grouped. Logic covers always true, AND, OR, XOR, NAND, NOR, NOT, sticky, edge, delay and timer. Compare covers equal, greater, less, about equal, changed by, and low, mid or high on a channel. Maths covers add, subtract, multiply, divide, modulo, lower of, higher of, sine, cosine, tangent, and the two maps between 0 and 1000.

Variables cover set, increase and decrease of a global variable. Overrides cover arming, throttle, sticks, axis angle and rate, heading, loiter radius, minimum ground speed and ignoring a GPS fix. Outputs cover the control profile, the OSD layout, VTX power, band and channel, an IO port, LED pin PWM, gimbal sensitivity and starting compass calibration.

INAV 7 does not offer every row. The tab keeps operations whose id is below 53 on INAV 7, and shows the full list on INAV 8. If a condition you saved on a newer board is opened on an older one, expect the later operations to be missing rather than silently doing the new thing.

Operands: numbers, sticks and flight data

A number operand is a typed value from -1000000 to 1000000. Use it for a threshold, a delay in milliseconds, or a throttle pulse. An RC channel operand is channel 1 to 34. Low means the channel is below 1333 microseconds. High means it is above 1666 microseconds. Mid is the band between those two.

Flight data is the list the firmware reports: armed time, distances, RSSI, voltages in centivolts, current in centiamps, used capacity, satellites, speeds, altitude, throttle percent, attitude, and flags such as armed, returning home, landing and failsafe. INAV 8 adds the values after flight operand 41, including height above ground, mixer profile, wind and the later link figures. INAV 7 stops at 42 flight values, numbered from 0.

Flight mode is a named mode, including manual, return to home, position hold, cruise, altitude hold, angle, horizon, air mode and waypoint mission. Return to home in that list is the INAV mode. It is not Betaflight GPS Rescue. A logic-condition operand points at one of the other 64 slots. A global-variable operand is V1 to V8. A programming-PID operand is PID 1 to 4. Mission operands report whether a mission is flying, the current and next waypoint, and distances.

About equal is true when A is within 1 percent of B. Changed by is true when A changes by at least B within 100 ms. Edge is true for B milliseconds when A turns true. Delay becomes true only after A has stayed true for B milliseconds. Timer alternates on for A milliseconds and off for B milliseconds. Divide returns 0 when B is 0, so a condition does not fault on a zero divisor.

Global variables and programming PIDs

The eight global variables sit in their own card, labelled V1 to V8, with the live number from the board. The footer says they are shared numbers conditions can set and read, and that they reset to 0 at power-up. A set-variable operation writes B into variable A. Increase and decrease add or subtract B. Nothing on the card types a starting value that survives power-off. If you need a count of flaps or a timer tick, it starts again at 0 every time the board boots.

Four programming PIDs are separate from the flight PIDs on a Betaflight or INAV PID tab. Each one can be enabled, given a setpoint and a measurement, and given gains. Every gain is limited to -32767 through 32767. Clear turns that PID off. The setpoint and the measurement are operands, so a PID can chase a flight value, a variable or a number.

Use a programming PID when a condition needs a smooth approach to a target, such as a camera tilt or a flap that follows airspeed. Use a plain compare when you only need on or off. The live condition result and the live variable values are the check that the chain is doing what you think, before you fly it.

Overrides, outputs and the JavaScript editor

An override operation changes what the craft does while the condition is true. Set throttle forces a pulse in microseconds. Scale throttle scales it to a percent. Set RC channel forces channel A to B microseconds. Invert roll, pitch or yaw reverses that stick. Swap roll and yaw exchanges those two sticks. Set axis angle holds roll, pitch or yaw, numbered 0, 1 and 2, at B degrees. Set axis rate rotates that axis at B degrees per second.

Set heading sets a heading target in navigation modes. Set loiter radius takes centimetres. Set minimum ground speed takes metres per second. Ignore GPS fix treats the GPS as having no fix while the condition is true. Allow arming anyway skips the arming safety checks. That last one is a bypass. Use it only when you understand which check you are skipping, on the ground, with the props off.

Output operations do not fly the craft. They switch the control profile, show an OSD layout, set VTX power, band or channel, drive an IO port on or off, set LED pin PWM duty from 0 to 100, set gimbal sensitivity, or start compass calibration. Compass calibration from a condition is a start command. The alignment and the sweep itself are the compass screen.

The JavaScript card opens an editor. The button says examples, load from the flight controller, compile and apply. It is another way to write the same programming, not a second flight controller. If you use it, read the result back on the logic-conditions card so you can see which slots the script filled.

A safe way to test a condition

Add one condition, enable it, and pick an operation you can see. A high check on a spare channel is the usual first test: flip the switch and watch the live result change. Then point a second condition at the first with Runs set to while that condition is true. Save, and confirm the live flags still match the switch.

Do not test Set throttle, Allow arming anyway, or an axis override in the air on the first try. Those change the craft. Props off, on the bench, with a battery only if the motors must be powered, and with someone who can pull the battery. A compare or a global-variable write is the safe experiment.

Chrome or Edge on a computer connects over USB or Bluetooth. The Android app adds Wi-Fi. iPhone uses Bluetooth or Wi-Fi and has no USB host. The modes page is where flight modes get their switches. Programming can read those modes. It does not replace the mode ranges. Navigation numbers stay on the navigation page.

FlySpark

Add an INAV logic condition

  1. Open Programming

    Connect an INAV board and open the Programming tab. Note whether the firmware is 7 or 8, because INAV 7 hides operations from id 53 up.

  2. Add a condition

    Add a condition, enable it, and pick the operation. Set the operands. A number is -1000000 to 1000000. A channel low is below 1333 µs and high is above 1666 µs.

  3. Choose when it runs

    Leave Runs on Always, or run it only while another condition is true. Watch the live result as you move the switch.

  4. Save and read it back

    Save to the board. If you used a global variable, remember it returns to 0 at the next power-up.

Troubleshooting

Common problems and fixes

  • Problem

    An operation is missing

    Fix

    INAV 7 only lists operations below id 53. The later overrides and outputs need INAV 8.

  • Problem

    A global variable went back to 0

    Fix

    That is power-up. The eight variables are not saved as starting values. A condition has to write them again after boot.

  • Problem

    The live result never changes

    Fix

    The condition is disabled, Runs points at another condition that is false, or the channel thresholds are 1333 and 1666 µs and the switch is not past them.

  • Problem

    Divide does nothing

    Fix

    Divide returns 0 when the second operand is 0. Give B a non-zero value.

FAQ

Frequently asked questions

What is INAV programming?

Logic conditions, eight global variables and four programming PIDs. Each condition is an operation on one or two operands, worked out many times a second.

How many INAV logic conditions are there?

64. The card shows how many are in use. Each one can run always, or only while another condition is true.

What are INAV global variables?

Eight numbers, V1 to V8. Conditions can set, increase or decrease them. They reset to 0 when the board powers up.

What is a programming PID?

One of four PIDs on this tab, separate from the flying PIDs. Gains run from -32767 to 32767. Each has a setpoint and a measurement.

What does low, mid and high mean on a channel?

Low is below 1333 microseconds. High is above 1666 microseconds. Mid is between them. Channels are numbered 1 to 34.

Does INAV 7 have every operation?

No. INAV 7 stops at operation 52 and at flight operand 41. INAV 8 adds the rest.

Is return to home here GPS Rescue?

No. The flight-mode operand Return to home is INAV. GPS Rescue is Betaflight. Navigation settings are on the INAV navigation page.

Can I write the conditions in JavaScript?

Yes. The JavaScript card loads examples or the flight controller's script, then compiles and applies it. Read the logic-conditions card afterwards to see the slots it filled.

Can I set this in Chrome?

Yes. Chrome or Edge connects over USB or Bluetooth. Android adds Wi-Fi. iPhone uses Bluetooth or Wi-Fi and has no USB host.

Will a condition arm the craft by itself?

Allow arming anyway skips arming safety checks while it is true. It is not a normal arm switch. Test it on the bench with the propellers off.

References

Sources

The official documentation behind the background facts on this page.

  1. INAV Programming FrameworkINAV on GitHub · github.com
  2. INAV WikiINAV on GitHub · github.com
  3. INAV NavigationINAV on GitHub · github.com

Tools

See every FlySpark tool

Ready to try it?

Free. Hardware connections need Chrome or Edge on a computer; phones use the FlySpark app.