arrow-left

All pages
gitbookPowered by GitBook
1 of 36

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

model.deleteInput(input, line)

Delete line from specified input

@status current Introduced in 2.0.0

hashtag
Parameters

  • input (unsigned number) input number (use 0 for Input1)

  • line (unsigned number) input line (use 0 for first line)

hashtag
Return value

none

Model Functions

model.deleteInputs()

Delete all Inputs

@status current Introduced in 2.0.0

hashtag
Parameters

none

hashtag
Return value

none

model.defaultInputs()

Set all inputs to defaults

@status current Introduced in 2.0.0

hashtag
Parameters

none

hashtag
Return value

none

model.setCurve(curve, params)

Set Curve parameters

The first and last x value must -100 and 100 and x values must be monotonically increasing

@status current Introduced in 2.2.0

Example setting a 4-point custom curve:

  params = {}
  params["x"] =  {-100, -34, 77, 100}
  params["y"] = {-70, 20, -89, -100}
  params["smooth"] = true
  params["type"] = 1
  val =  model.setCurve(2, params)

setting a 6-point standard smoothed curve

hashtag
Parameters

  • curve (unsigned number) curve number (use 0 for Curve1)

  • params see model.getCurve return format for table format. setCurve uses standard lua array indexing and arrays start at index 1

hashtag
Return value

  • `` 0 - Everything okay

 val = model.setCurve(3, {smooth=true, y={-100, -50, 0, 50, 100, 80}})
   1 - Wrong number of points
   2 - Invalid Curve number
   3 - Cuve does not fit anymore
   4 - point of out of index
   5 - x value not monotonically increasing
   6 - y value not in range [-100;100]
   7 - extra values for y are set
   8 - extra values for x are set

model.insertMix(channel, line, value)

Insert a mixer line into Channel

@status current Introduced in 2.0.0, parameters below multiplex added in 2.0.13

hashtag
Parameters

  • channel (unsigned number) channel number (use 0 for CH1)

  • line (unsigned number) mix number (use 0 for first line(mix))

  • value (table) see model.getMix() for table format

hashtag
Return value

none

model.getSensor(sensor)

Get Telemetry Sensor parameters

@status current Introduced in 2.3.0

hashtag
Parameters

  • sensor (unsigned number) sensor number (use 0 for sensor 1)

hashtag
Return value

  • nil requested sensor does not exist

  • table with sensor data:

model.setGlobalVariable(index, flight_mode, value)

Sets current global variable value. See also model.getGlobalVariable()

hashtag
Parameters

  • index zero based global variable index, use 0 for GV1, 8 for GV9

type
(number) 0 = custom, 1 = calculated
  • name (string) Name

  • unit (number) See list of units in the appendix of the OpenTX Lua Reference Guide

  • prec (number) Number of decimals

  • id (number) Only custom sensors

  • instance (number) Only custom sensors

  • formula (number) Only calculated sensors. 0 = Add etc. see list of formula choices in Companion popup

  • flight_mode Flight mode number (0 = FM0, 8 = FM8)

  • value new value for global variable. Permitted range is from -1024 to 1024.

  • hashtag
    Return value

    none

    hashtag
    Notice

    Global variable can only store integer values, any floating point value is converted into integer value by truncating everything behind a floating point.

    model.setLogicalSwitch(switch, value)

    Set Logical Switch parameters

    @status current Introduced in 2.0.0

    hashtag
    Parameters

    • switch (unsigned number) logical switch number (use 0 for LS1)

    • value (table) see model.getLogicalSwitch() for table format

    hashtag
    Return value

    none

    hashtag
    Notice

    If a parameter is missing from the value, then that parameter remains unchanged.

    To set the and member (which is Lua keyword) use the following syntax: model.setLogicalSwitch(30, {func=4,v1=1,v2=-99, ["and"]=24})

    model.setOutput(index, value)

    Set servo parameters

    @status current Introduced in 2.0.0

    hashtag
    Parameters

    • index (unsigned number) channel number (use 0 for CH1)

    • value (table) servo parameters, see model.getOutput() for table format

    hashtag
    Return value

    none

    hashtag
    Notice

    If a parameter is missing from the value, then that parameter remains unchanged.

    model.resetTimer(timer)

    Reset model timer to a startup value

    @status current Introduced in TODO

    hashtag
    Parameters

    • timer (number) timer index (0 for Timer 1)

    hashtag
    Return value

    none

    model.getFlightMode(index)

    Return input data for given input and line number

    @status current Introduced in 2.3.10, uses Lua's normal indexing for trimsValues and trimsModes tables as of 2.9.0

    hashtag
    Parameters

    model.getOutput(index)

    Get servo parameters

    @status current Introduced in 2.0.0

    hashtag
    Parameters

    model.getInput(input, line)

    Return input data for given input and line number

    @status current Introduced in 2.0.0, curveType/curveValue/carryTrim added in 2.3, inputName added 2.3.10, flighmode reworked in 2.3.11

    hashtag
    Parameters

    model.setInfo(value)

    Set the current Model information

    @status current Introduced in 2.0.6, changed in TODO

    hashtag
    Parameters

    index (unsigned number) output number (use 0 for CH1)

    hashtag
    Return value

    • nil requested output does not exist

    • table output parameters:

      • name (string) name

      • min (number) Minimum % * 10

      • max (number) Maximum % * 10

      • offset (number) Subtrim * 10

      • ppmCenter (number) offset from PPM Center. 0 = 1500

      • symetrical (number) linear Subtrim 0 = Off, 1 = On

      • revert (number) irection 0 = ­­­---, 1 = INV

      • curve

        • (number) Curve number (0 for Curve1)

        • or nil if no curve set

    input (unsigned number) input number (use 0 for Input1)
  • line (unsigned number) input line (use 0 for first line)

  • hashtag
    Return value

    • nil requested input or line does not exist

    • table input data:

      • name (string) input line name

      • inputName (string) input input name

      • source (number) input source index

      • weight (number) input weight

      • offset (number) input offset

      • switch (number) input switch index

      • curveType (number) curve type (function, expo, custom curve)

      • curveValue (number) curve index

      • carryTrim (boolean) input trims applied

      • 'flightModes' (number) bit-mask of active flight modes

    value model information data, see model.getInfo()

    hashtag
    Return value

    none

    hashtag
    Notice

    If a parameter is missing from the value, then that parameter remains unchanged.

    model.getSwashRing()

    Get heli swash parameters

    @status current Introduced in 2.8.0

    Parameters

    none

    Return value

    • table with heli swash parameters:

    • type (number) 0=---, 1=120, 2=120X, 3=140, 4=90

    • value (number) swash ring value (normally 0)

    • 'collectiveSource' (number) source index

    • 'aileronSource' (number) source index

    • 'elevatorSource' (number) source index

    • 'collectiveWeight'(value) -100 to 100

    • 'aileronWeight' (value) -100 to 100

    • 'elevatorWeight' (value) -100 to 100

    model.insertInput(input, line, value)

    Insert an Input at specified line

    @status current Introduced in 2.0.0, curveType/curveValue/carryTrim added in 2.3, inputName added 2.3.10

    hashtag
    Parameters

    • input (unsigned number) input number (use 0 for Input1)

    • line (unsigned number) input line (use 0 for first line)

    • value (table) input data, see model.getInput()

    hashtag
    Return value

    none

    model.setSwashRing(params)

    Set heli swash parameters

    @status current Introduced in 2.8.0

    Parameters

    • value (table) swash ring parameters, see model.getSwashRing() for table format

    Return value

    none

    Notice

    If a parameter is missing, then that parameter remains unchanged.

    index (unsigned number) flight mode number (use 0 for FM0)

    hashtag
    Return value

    • nil requested input or line does not exist

    • table input data:

      • name (string) input line name

      • switch (number) input switch index

      • fadeIn (number) fade in value (in 0.1s)

      • fadeOut (number) fade out value (in 0.1s)

      • trimsValues (table) table of trim values:

        • key is trim number (starts from 1)

        • value

      • trimsModes (table) table of trim mode:

        • key is trim number (starts from 1)

        • value

    model.getCurve(curve)

    Get Curve parameters

    Note this function uses Lua's usual index starting with 1 since version 2.9.0.

    @status current Introduced in 2.0.12, uses Lua's normal indexing for x and y tables as of 2.9.0

    hashtag
    Parameters

    • curve (unsigned number) curve number (use 0 for Curve1)

    hashtag
    Return value

    • nil requested curve does not exist

    • table curve data:

    model.getCustomFunction(function)

    Get Custom Function parameters

    @status current Introduced in 2.0.0, TODO rename function

    hashtag
    Parameters

    • function (unsigned number) custom function number (use 0 for CF1)

    hashtag
    Return value

    • nil requested custom function does not exist

    • table custom function data:

    model.setCustomFunction(function, value)

    Set Custom Function parameters

    @status current Introduced in 2.0.0, TODO rename function

    hashtag
    Parameters

    • function (unsigned number) custom function number (use 0 for CF1).

    • value (table) custom function parameters, see for table format

    hashtag
    Return value

    none

    hashtag
    Notice

    If a parameter is missing from the value, then that parameter remains unchanged.

    model.resetSensor(sensor)

    Reset Telemetry Sensor parameters

    @status current Introduced in 2.3.11

    hashtag
    Parameters

    model.setFlightMode(index, params)

    Set Flight mode parameters

    @status current Introduced in 2.3.10

    hashtag
    Parameters

    model.getGlobalVariable(index, flight_mode)

    Return current global variable value

    Example:

    hashtag
    Parameters

    is trim value
    is trim mode
    name
    (string) name
  • type (number) type

  • smooth (boolean) smooth

  • points (number) number of points

  • y (table) table of Y values:

    • key is point number (starts from 1)

    • value is y value

  • x (table) only included for custom curve type:

    • key is point number (starts from 1)

    • value is x value

  • switch
    (number) switch index
  • func (number) function index

  • name (string) Name of track to play (only returned only returned if action is play track, sound or script)

  • value (number) value (only returned only returned if action is not play track, sound or script)

  • mode (number) mode (only returned only returned if action is not play track, sound or script)

  • param (number) parameter (only returned only returned if action is not play track, sound or script)

  • active (number) 0 = disabled, 1 = enabled

  • sensor (unsigned number) sensor number (use 0 for sensor 1)

    hashtag
    Return value

    • nil

    index (unsigned number) flight mode number (use 0 for FM0)
  • params see model.getFlightMode return format for table format.

  • hashtag
    Return value

    none

    model.getCustomFunction()

    model.setModule(index, value)

    Set RF module parameters

    @status current Introduced in 2.2.0, modified in 2.3.12 (proto/subproto)

    hashtag
    Parameters

    • index (number) module index (0 for internal, 1 for external)

    • value module parameters, see model.getModule()

    hashtag
    Return value

    none

    hashtag
    Notice

    If a parameter is missing from the value, then that parameter remains unchanged.

    index zero based global variable index, use 0 for GV1, 8 for GV9
  • flight_mode Flight mode number (0 = FM0, 8 = FM8)

  • hashtag
    Return value

    • nil requested global variable does not exist

    • number current value of global variable

    hashtag
    Notice

    a simple warning or notice

      -- get GV3 (index = 2) from Flight mode 0 (FM0)
      val = model.getGlobalVariable(2, 0)

    model.getMix(channel, line)

    Get configuration for specified Mix

    @status current Introduced in 2.0.0, parameters below multiplex added in 2.0.13

    hashtag
    Parameters

    channel (unsigned number) channel number (use 0 for CH1)

  • line (unsigned number) mix number (use 0 for first line(mix))

  • hashtag
    Return value

    • nil requested channel or line does not exist

    • table mix data:

      • name (string) mix line name

      • source (number) source index

      • weight (number) weight (1024 == 100%) value or GVAR1..9 = 4096..4011, -GVAR1..9 = 4095..4087

      • offset (number) offset value or GVAR1..9 = 4096..4011, -GVAR1..9 = 4095..4087

      • switch (number) switch index

      • multiplex (number) multiplex (0 = ADD, 1 = MULTIPLY, 2 = REPLACE)

      • curveType (number) curve type (function, expo, custom curve)

      • curveValue (number) curve index

      • flightModes (number) bit-mask of active flight modes

      • carryTrim (boolean) carry trim

      • mixWarn (number) warning (0 = off, 1 = 1 beep, .. 3 = 3 beeps)

      • delayUp (number) delay up (time in 1/10 s)

      • delayDown (number) delay down

      • speedUp (number) speed up

      • speedDown (number) speed down

    model.getInputsCount(input)

    Return number of lines for given input

    @status current Introduced in 2.0.0

    hashtag
    Parameters

    • input (unsigned number) input number (use 0 for Input1)

    hashtag
    Return value

    • number number of configured lines for given input

    model.getTimer(timer)

    Get model timer parameters

    @status current Introduced in 2.0.0, name added in 2.3.6

    hashtag
    Parameters

    • timer (number) timer index (0 for Timer 1)

    hashtag
    Return value

    • nil requested timer does not exist

    • table timer parameters:

    mode
    (number) timer trigger source: off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw
  • start (number) start value [seconds], 0 for up timer, 0> down timer

  • value (number) current value [seconds]

  • countdownBeep (number) countdown beep (0­ = silent, 1 =­ beeps, 2­ = voice)

  • minuteBeep (boolean) minute beep

  • persistent (number) persistent timer

  • name (string) timer name

  • model.getLogicalSwitch(switch)

    Get Logical Switch parameters

    @status current Introduced in 2.0.0

    hashtag
    Parameters

    • switch (unsigned number) logical switch number (use 0 for LS1)

    hashtag
    Return value

    • nil requested logical switch does not exist

    • table logical switch data:

    func
    (number) function index, see
    .
  • v1 (number) V1 value (index)

  • v2 (number) V2 value (index or value)

  • v3 (number) V3 value (index or value)

  • and (number) AND switch index

  • delay (number) delay (time in 1/10 s)

  • duration (number) duration (time in 1/10 s)

  • Logical Switch Function Constants

    model.getInfo()

    Get current Model information

    @status current Introduced in 2.0.6, changed in 2.2.0, filename added in 2.6.0, extendedLimits, jitterFilter, and labels added in 2.8.0

    hashtag
    Parameters

    none

    hashtag
    Return value

    • table model information:

      • name (string) model name

    extendedLimits
    (boolean) extended limits enabled
  • jitterFilter (number) model level ADC filter

  • bitmap (string) bitmap name (not present on X7)

  • filename (string) model filename

  • model.deleteMixes()

    Remove all mixers

    @status current Introduced in 2.0.0

    hashtag
    Parameters

    none

    hashtag
    Return value

    none

    model.getModule(index)

    Get RF module parameters

    Type values:

    • 0 NONE

    • 1 PPM

    • 2 XJT_PXX1

    • 3 ISRM_PXX2

    • 4 DSM2

    • 5 CROSSFIRE

    • 6 MULTIMODULE

    • 7 R9M_PXX1

    • 8 R9M_PXX2

    • 9 R9M_LITE_PXX1

    • 10 R9M_LITE_PXX2

    • 11 R9M_LITE_PRO_PXX1

    • 12 R9M_LITE_PRO_PXX2

    • 13 SBUS

    • 14 XJT_LITE_PXX2

    subType values for XJT_PXX1:

    • -1 OFF

    • 0 D16

    • 1 D8

    @status current Introduced in 2.2.0

    hashtag
    Parameters

    • index (number) module index (0 for internal, 1 for external)

    hashtag
    Return value

    • nil requested module does not exist

    • table module parameters:

    2 LR12
    subType
    (number) protocol index
  • modelId (number) receiver number

  • firstChannel (number) start channel (0 is CH1)

  • channelsCount (number) number of channels sent to module

  • Type (number) module type

  • if the module type is Multi additional information are available

  • protocol (number) protocol number (Multi only)

  • subProtocol (number) sub-protocol number (Multi only)

  • channelsOrder (number) first 4 channels expected order (Multi only)

  • model.setTimer(timer, value)

    Set model timer parameters

    @status current Introduced in 2.0.0, name added in 2.3.6

    hashtag
    Parameters

    • timer (number) timer index (0 for Timer 1)

    • value timer parameters, see model.getTimer()

    hashtag
    Return value

    none

    hashtag
    Notice

    If a parameter is missing from the value, then that parameter remains unchanged.

    model.deleteMix(channel, line)

    Delete mixer line from specified Channel

    @status current Introduced in 2.0.0

    hashtag
    Parameters

    • channel (unsigned number) channel number (use 0 for CH1)

    • line (unsigned number) mix number (use 0 for first line(mix))

    hashtag
    Return value

    none

    model.getMixesCount(channel)

    Get the number of Mixer lines that the specified Channel has

    @status current Introduced in 2.0.0

    hashtag
    Parameters

    • channel (unsigned number) channel number (use 0 for CH1)

    hashtag
    Return value

    • number number of mixes for requested channel

    model.deleteFlightModes()

    Clear all flightModes

    @status current Introduced in 2.3.10

    hashtag
    Parameters

    none

    hashtag
    Return value

    none