Skip to content

question on javascript programming #11725

Closed

Description

@CristianoUspace

Hi there, I'm familiarising with INAV 9.1.0. Looking at JavaProgramming, I'm wondering if I can use it to move elevons during transition for managing the asset change from TAIL SITTING to Horizontal Flight. Something like that:

where:

RC Channel 7 is used for mode selection (high is mixer control 2 - QUAD configuration, with IMU axis offset ON); mid is transition; low is fixed wing mixer control 1);
RC Channel 6 (is used in the servo mixer to move simultanously the two elevons up and down).

Ideally, when switching from TAIL to fixed wing, elevons should slightly pitch the nose down; when switching from FIXED wing should pitch the nose up. Would it work like that?

/// SMOOTH TRASITION FOR TAIL SITTER

if (inav.rc[6].low || inav.rc[6].high) {

	inav.gvar[0] = 0;

}

if (inav.gvar[1] = Null || inav.gvar[1] = 0) {
inav.gvar[1] = inav.rc[6];
}

if (inav.gvar[1] != inav.rc[6]) {

	if (inav.rc[6].mid && inav.gvar[1] > inav.rc[6]) { // from HIGH to MID - > transition TAIL to fixed wing
		inav.gvar[0] = 1;
	}

	if (inav.rc[6].mid && inav.gvar[1] < inav.rc[6]) { // from LOW to MID - > transition fixed wing to TAIL
		inav.gvar[0] = 2;
	}



	inav.gvar[1] = inav.rc[6];
	}

if (inav.gvar[0] == 1) {

		inav.rc[5] = 1750;
}

if (inav.gvar[0] == 2) {
inav.rc[5] = 1250;
}

Activity

  1. sensei-hacker commented on Jul 15, 2026

    @sensei-hacker
    Member

    A couple things that may make this easier to read and reason about:

    1. gvars can never be null, so that check can be removed for readability

    2. Code is normally more readable if you name your variables

    let oldRC6 = inav.rc[6];
    
    if ( oldRC6 > 1500) {
    
    1. I don't know about this part, but worth thinking about - if you need to increase forward pitch, and it happens that the elevons are wired to pitch, you MAY want the programming to increase pitch directly, rather than trying to end up with pitch being increased as a side effect of the ailerons moving, as a result of overriding the RC channel.

    2. Since the radio is sending rc[5] you don't want to fight against your own own input. Rather than setting the mixer to use rc[5] and then having the programming tab and the radio fight over control of the channel, I would add a mixer line with gvar[4] or whichever gvar. So the mixer knows that the elevon is a mix of the gvar and whatever other inputs.

  2. CristianoUspace commented on Jul 15, 2026

    @CristianoUspace
    Author

    Thanks for replying. That's interesting.. How I'm supposed to act directly on a given pitch expected output? I totally agree with you. My approach would be a total failure: Since rc[5] is no way linked to a given attitude, loopback would try to counteract by spinning the 2 engines below to keep the nose pointing up...
    It is not clear to me how to use the HMI. Can I write code directly in the window? I tried to write the code in Visual Studio, copy and paste it, but got no results. If you have a document providing full usage of the javascript programming feature, I'll get through it. Cheers

  3. sensei-hacker commented on Jul 15, 2026

    @sensei-hacker
    Member

    You can certainly write directly in the Configuraror window. That's probably easiest because then you get the full Intellicode auto complete for all of the INAV stuff etc. Syntax checking for the INAV stuff, etc. (The editor in Configurator is actually the same editor that VSCode uses, but wired up specifically for the INAV library).

    Copy and paste SHOULD work as well.

    The documentation is is the wiki:
    https://github.com/iNavFlight/inav/blob/master/docs/javascript_programming/JAVASCRIPT_PROGRAMMING_GUIDE.md

    would try to counteract by spinning the 2 engines below to keep the nose pointing up.
    How I'm supposed to act directly on a given pitch expected output?

    Yeah I would first get clear -- do you want to change the PITCH, or do you want to change an OUTPUT, such as a servo?

    To change a servo, put in a mixer line for that servo. That new mixer line can reference a gvar, an RC channel, the target pitch, whatever is appropriate. That's to change the servo position, NOT the pitch target.

    To override the pitch angle target, you can use
    inav.override.flightAxis.pitch.angle

  4. CristianoUspace commented on Jul 17, 2026

    @CristianoUspace
    Author

    Ciao Sensei and all, please find here the js script for what we discussed and its transpilation to INAV logic. The idea is to use gvar[0] for register the mode (0 - QUAD, 2 - FIXED aircraft), linked to rc[7] (a three pos switch); gvar[1] is set to 1 only when in TRANSITION (i.e. rc[7] on its middle value). I didn't use edge or other events, it works for every cycle. Every time rc[7] gets in its low or high position gvar[1] is set to 0 and gvar[2] (a counter) is set to 0. Only when gvar[1] == 1, depending on the current value of gvar[0]: the counter gvar[2] is increased by one and the pitch angle is overridden to -45 or 45 degs, until the counter gets to 50.

    I'm curious to test it in flight --- at banks seems it works fine.

    SMOOTH TRASITION FOR TAIL SITTER.txt

    note few issues with the GUI: for some reasons, as you leave the JS programming GUI without saving, and then you come back, the input text field get frozen. No copy, no return, you can't write into it. Seems disabled. You then need to disconnect, close the INAV GUI, then reopen it and get back to JS Programming.... I'm testing it on INAV 9.1.1. on Windows 11 OS. Cheers

  5. locked and limited conversation to collaborators on Sep 22, 2026
  6. converted this issue into a discussion #12007 on Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions