I've been using the built-in variometer function included with both my FrSky X9D+ transmitter and my new Jumper T16 transmitter for more that four years. Both transmitters use OpenTX as an operating system. An RC friend just purchased a FlySky altimeter sensor to retrofit a couple of fixed wing gliders. He was impressed with the tonal information (beeps) that I was getting from my transmitter and wanted to replicate the experience with his planes. All of his fleet use FlySky receivers, so he bought a couple of FlySky ibus altitude sensors. It turns out that the FlySky sensors only produce an output of altitude without any indication of vertical speed (Vspd) that is automatically provided by a FrSky altimeter sensor.

The lack of a vertical speed indication, a variometer, doesn't allow the user to estimate whether the model is increasing in altitude or decreasing in altitude without glancing down at the transmitter screen. This is not desired since the rate of change in altitude must be calculated in one's head and it requires the modeler to look away from the model to the transmitter screen, which could cause him/her to lose control.

So I volunteered to write a LUA script to imitate what I was getting from the built-in variometer function in my radios using FrSky receivers and sensors. I figured that there are other FlySky users that might benefit from having a variometer function.

Current Status:

The 3rd-pass script is working well. It generates a short higher frequency beep when the model is increasing its altitude and a longer, lower frequency, beep when the model is decreasing in altitude. The first attempt was useable for me, using a FrSky altitude sensor, but did not work very well for my friend with his FlySky sensor. My FrSky altitude sensor did not generate a lot of random noise, whereas his sensor generated a bunch of random readings that tended to cause the script to beep constantly, for no reason.

We discovered that the FlySky sensor was effectively uncalibrated. My friend had two sensors. Sensor 1 generated 30 feet of altitude difference when the model was elevated only 3-4 feet. Sensor 2 only generated 2.5 feet of altitude change when the model was raised 7 feet. We overcame this calamity by adjusting the ratio entry in the telemetry parameter screen of the transmitter ( 0.3 for sensor 1 and 2.7 for sensor 2). That is a lot of variability!!! I can't really recommend that anybody purchase a FlySky altitude sensor after this experience.

But the sensor readings are producing approximately the correct output now, after some calibration. 

Using the Script:

The script must be located in the /SCRIPTS/MIXES directory on the transmitter's SD card. 

You should have the lua option checked (and the transmitter's firmware updated to at least OpenTX 2.2) to use this script. When you power the transmitter it will compile the script into a binary executable called vrio.luac, which runs faster and consumes less memory.

Then go to the model menus use the page button until you get to the CUSTOM SCRIPTS page. It should now look like this:

Select the vrio script and press the enter button to see this screen:

Here you can make parameter changes to the way the script operates. 

  1. The Switch parameter specifies which switch to use to turn on/off the variometer beep sounds. The switch is hard-coded to turn on the beep sounds when in the "back" position.
  2. ClimbMax sets the max limit for climb in feet/sec. Above this limit the beep sounds no longer increase in frequency. The range is limited to between 10 feet/s and 50 feet/s.
  3. SinkMax sets the max limit for sink in feet/s. Below this limit the beep sounds no longer decrease in frequency. The range is limited to between -10 feet/s and -50 feet/s.
  4. ClimbMin and SinkMin set the range of the dead zone where no sound is generated because the model is presumed to be not gaining or losing much altitude. ClimbMin range is between 0 feet/s and 10 feet/s. SinkMin range is between -10 feet/s and 0 feet/s.

The right side of the page displays the current altitude, in feet/10.24, and the vertical speed in feet/s/10.24. I added these to help with debugging problems. 

Flying with the Script:

It functions similar to the built-in variometer in OpenTX. When climbing the transmitter will emit a short (100ms) beep tone between 1.1 kHz and 2kHz. The faster the model climbs, the higher the frequency until the limit of 2kHz. When sinking the transmitter will emit a longer (400ms) tone between 900Hz and 500Hz. The faster it sinks the lower the frequency, etc. If the model is in the specified dead zone the variometer will be silent.

The Code:

-- vrio.lua: variometer script to convert altitude to
-- audible tones that indicate vertical speed in feet/s.
-- altitude sensor must be labled "Alt" in telemetry list.
-- It is suggested that the altitude sensor filter be activated.
-- Bud Bennett 2020-10-05

local AltID = 0
local altitude = 0
local altitudeOld = 0
local timeNow = 0
local timeOld = 0
local vspd = 0
local freq = 1000
local tsample = 25
local n = 1

-- All limits in feet/s
local inputs = {
	{"ClimbMin", VALUE,0,10,2},
	{"SinkMin", VALUE,-10,0,-2}

local outputs = {"Alti", "Vsp"}

local function init()
	AltID = getFieldInfo("Alt")['id']
	print ("AltID = ", AltID)
-- sw:Switch, cm:ClimbMax, sm:SinkMax, cn:ClimbMin, sn:SinkMin
local function calculateVspeed(sw,cm,sm,cn,sn)
	timeNow = getTime()
	-- perform noise averaging on samples
	if (timeNow-timeOld)<tsample then
	  if n==1 then
	    altitude = getValue(AltID)
	    altitude = getValue(AltID) + altitude
	  n = n + 1
	  return altitude/(n-1),vspd
	  altitude = (altitude + getValue(AltID))/n
	  n = 1
	--altitude = getValue(AltID) -- in feet 
	--print ("Altitude = ",altitude)
	--print ("Freq = ", freq)
	--print ("Vspd = ",vspd)
	--print ("ClimbMax = ", cm)
	--print ("ClimbMin = ", cn)
	vspd = (altitude - altitudeOld)/((timeNow - timeOld)/100)  -- feet/s
	timeOld = timeNow
	altitudeOld = altitude
	-- check limits (now in feet/s)
	if vspd>cm then
	  vspd = cm
	elseif vspd<sm then
	  vspd = sm
	elseif vspd>sn and vspd<cn then
	  vspd = 0
	-- set tone frequency
	if vspd>0 and sw<-200 then
	  freq = 1100 + 900*vspd/cm
	  tsample = 25
	elseif vspd<0 and sw<-200 then
	  freq = 900 - 400*vspd/sm
	  tsample = 50
	  return altitude,vspd
	return altitude, vspd

return {input=inputs, output=outputs, init=init, run=calculateVspeed} 

I'm not going to go into any details about the code. If you're interested in writing your own OpenTX scripts, I can recommend the OpenTX 2.2 lua Reference Guide as a place to start.