Adding some vibration effects to your needles

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Message
Author
JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Adding some vibration effects to your needles

#1 Post by JackZ »

Hello to all.

At a friend's request, I have recently converted a dozen of needle "vintage" gauges to add some vibration effects to them. Useful for old propellers planes, since this adds some realism to vintage gauges.

I designed a real quick and dirty method to do that, so I thought I would be interresting to give you the “step by step” process in the following posts.

Adding vibration effects to a needle is really immersive. To be more realistic, the code can adjust the amount of "vibrations" (namely, the deviations around the target value) according to the engine's speed. The higher the engine speed, the higher the frequency of the vibrations.
The method has been designed for FSX/P3D, but can be easily adapted for XPlane.
In FSX/P3D, the Simconnect "Engine vibration" variable is not very reliable, so I used instead the "GENERAL ENG COMBUSTION SOUND PERCENT:1","percent" variable which is equivalent.
I chose to assign three ranges of vibrations according to the engine speed (idle, midrange and full speed).The amount and frequency of vibrations can be adjusted to taste by modifying the customizations variables at the beginning of the code (more explanations later on).

For the purpose of this tutorial, I will transform a standard instrument into a "vibrating one" in a few steps.

Ready? Let's go!
Last edited by JackZ on Thu Mar 15, 2018 6:17 pm, edited 3 times in total.
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Re: Adding some vibration effects to your needles

#2 Post by JackZ »

For the purpose of this tutorial, I will be using the stock Baron 58 airpeed gauge found in the AM store.

Of course, I strongly urge you to create a clone copy of this gauge BEFORE working on it!

When opened in the Create/Edit mode, the script of this gauge looks like this:

Code: Select all

img_add_fullscreen("airspeed_backdrop.png")
img_neddle = img_add_fullscreen("neddle.png")

function PT_airspeed(airspeed)
    -- rotate the needle only if airspeed is above 25kts
	airspeed = var_cap(airspeed, 25, 260)
	
    img_rotate(img_neddle, airspeed*320/220 - 38)
end

xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/airspeed_kts_pilot", "FLOAT", PT_airspeed)
fsx_variable_subscribe("AIRSPEED INDICATED", "knots", PT_airspeed)
We will add some code snippets supplied here, which have been divided in TWO parts:
- The “customization variables” snippet, located at the beginning of our code
- The “vibration code” snippet, that uses a timer function to simulate the vibration.
Each code snippet is heavily commented for convenience.

STEP 1- Adding the “Custom variables” section:
At the very beginning of the code of our gauge, we will add this code (Please use the "Select All" button and copy/paste the code as shown):

Code: Select all

-----------------------------------------------------------
--               Customization section 
-- simply uncomment the varaiable that suits you
------------------------------------------------------------
-- sample Values for a modern single engine (Cessna, Piper, Robin)
-- frequency=40 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
-- vibmax=80 --beginning of max vibrations in %power
-- valmax=0.05 -- range of max vibration values
-- vibmid=30 --beginning of medium vibrations in %power
-- valmid=0.07 -- range of medium vibration values
-- viblow=0.5 -- low idle
-- vallow=0.09 -- range of low vibration values

-- sample Values for a WWII Fighter
frequency=65 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
vibmax=80 --beginning of max vibrations in %power
valmax=0.5 -- range of max vibration values
vibmid=30 --beginning of medium vibrations in %power
valmid=1  -- range of medium vibration values
viblow=0.25 -- low idle
vallow=2 -- range of low vibration values

-- sample values for a WW1 Fighter
-- frequency=70 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
-- vibmax=75 --beginning of max vibrations in %power
-- valmax=4 -- range of max vibration values
-- vibmid=40 --beginning of medium vibrations in %power
-- valmid=2.5
-- viblow=0.1 --low idle
-- vallow=3.5
---------------------------------------------------------------------------------------------------------
--        -Do not modify values beyond this line!                                         
---------------------------------------------------------------------------------------------------------
These are the variables used to define the amount of “vibration” for each engine speed (max, middle, idle).
I enclosed also some sample values for more pronounced effects (such as for a very old WW1 airplane gauge).

Once done, the gauge code should now look like this:

Code: Select all

-----------------------------------------------------------
--               Customization section 
-- simply uncomment the varaiable that suits you
------------------------------------------------------------
-- sample Values for a modern single engine (Cessna, Piper, Robin)
-- frequency=40 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
-- vibmax=80 --beginning of max vibrations in %power
-- valmax=0.05 -- range of max vibration values
-- vibmid=30 --beginning of medium vibrations in %power
-- valmid=0.07 -- range of medium vibration values
-- viblow=0.5 -- low idle
-- vallow=0.09 -- range of low vibration values

-- sample Values for a WWII Fighter
frequency=65 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
vibmax=80 --beginning of max vibrations in %power
valmax=0.5 -- range of max vibration values
vibmid=30 --beginning of medium vibrations in %power
valmid=1  -- range of medium vibration values
viblow=0.25 -- low idle
vallow=2 -- range of low vibration values

-- sample values for a WW1 Fighter
-- frequency=70 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
-- vibmax=75 --beginning of max vibrations in %power
-- valmax=4 -- range of max vibration values
-- vibmid=40 --beginning of medium vibrations in %power
-- valmid=2.5
-- viblow=0.1 --low idle
-- vallow=3.5
---------------------------------------------------------------------------------------------------------
--        -Do not modify values beyond this line!                                         
--------------------------------------------------------------------------------------------------------
img_add_fullscreen("airspeed_backdrop.png")
img_neddle = img_add_fullscreen("neddle.png")

function PT_airspeed(airspeed)
    -- rotate the needle only if airspeed is above 25kts
	airspeed = var_cap(airspeed, 25, 260)
	
    img_rotate(img_neddle, airspeed*320/220 - 38)
end

xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/airspeed_kts_pilot", "FLOAT", PT_airspeed)
fsx_variable_subscribe("AIRSPEED INDICATED", "knots", PT_airspeed)
A quick note 1: Here we chose to use some "moderate" vibrations.
If you want to decrease the speed of the vibration effects, increase the frequency value. The frequency value could range between 30 to 100 msec.
The valmax, valmid and vallow should be adjusted accordingly, since they are added/substracted to the target value. The greater the value, the wider the "fluctuation movement" of the needle (the amplitude of the vibration) around its target value.
he vibmax, vibmid, viblow values are the threshold vibration (actually sound level) % values

A quick note 2: these "value ranges" are to be coherent with the value to be displayed. In our example we are displaying the speed in knots, basically in the 0-250 kts range, so a maximum needle variation of +/- 10 knots seems to be fair.
If we were displaying RPMs for example, the maximum needle variation should be +-100RPM to be noticeable.
Experimentation is the key.

Ready for the STEP 2?
Last edited by JackZ on Thu Mar 15, 2018 6:24 pm, edited 9 times in total.
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Re: Adding some vibration effects to your needles

#3 Post by JackZ »

STEP 2: Adding the vibration code:

We will add the following vibration code, just before the subscription and function section:

Code: Select all

---------- Needle vibration Section ---------------------------------------
-- Local variables
local needle_value=0
local rand=1
local val=0
local vibrationlvl=0

function vibrate(soundrpm) -- Function that adjusts the vibration level according to the sound level

   if soundrpm<0.1 then -- When the sound level is too low, the level of vibration is set to zero
      vibrationlvl=0
   else
      vibrationlvl=soundrpm
   end
end -- function

function timer_callback() -- function called every 40 mseconds, used to move the needle

   rand=-rand -- offset value of the needle, alternatively to the left or to the right
   -- setting up of the amplitude of vibrations depending of the % of sound produced, since engine vibration is not reliable
   -- (Change val values to taste at the begining of the code!)
   if vibrationlvl>vibmax then  -- high rpm, small amplitude of needle movements (high vibration speed)
      val=valmax
   elseif vibrationlvl>vibmid then -- medium range rpm, medium amplitude of needle movements
      val=valmid
   elseif vibrationlvl>viblow then --slow rpm, smaller amplitude of needle movements
          val=vallow
   else -- engine stopped, no needle movements
         val=0
    end
   
   needlepos=needle_value+(rand*val) -- calculation of the needle movement (adding a random +/-value to the real value)
--------------------------------------------------------------------------------------	
-- IMPORTANT !!!! move your img_rotate HERE!!!
--------------------------------------------------------------------------------------	


--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
end -- function


---------------------------------------------------------------------------------------------------------
-- Subscription to the Engine SOUND LEVEL variable to adjust vibration levels in real time
-- Needle vibration related to engine sound volume 
fsx_variable_subscribe("GENERAL ENG COMBUSTION SOUND PERCENT:1","percent",vibrate)

--------------------------- Timer used for engine vibration : the "frequency" parameters in msec is used for setting the vibration speed: a value of 40 is 
timer_start(0,frequency,timer_callback)

--------------------  END of Vibration code Section ------------------------------------------------
So our gauge code should now look like this:

Code: Select all


-----------------------------------------------------------
--               Customization section 
-- simply uncomment the varaiable that suits you
------------------------------------------------------------
-- sample Values for a modern single engine (Cessna, Piper, Robin)
-- frequency=40 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
-- vibmax=80 --beginning of max vibrations in %power
-- valmax=0.05 -- range of max vibration values
-- vibmid=30 --beginning of medium vibrations in %power
-- valmid=0.07 -- range of medium vibration values
-- viblow=0.5 -- low idle
-- vallow=0.09 -- range of low vibration values

-- sample Values for a WWII Fighter
frequency=65 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
vibmax=80 --beginning of max vibrations in %power
valmax=0.5 -- range of max vibration values
vibmid=30 --beginning of medium vibrations in %power
valmid=1  -- range of medium vibration values
viblow=0.25 -- low idle
vallow=2 -- range of low vibration values

-- sample values for a WW1 Fighter
-- frequency=70 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
-- vibmax=75 --beginning of max vibrations in %power
-- valmax=4 -- range of max vibration values
-- vibmid=40 --beginning of medium vibrations in %power
-- valmid=2.5
-- viblow=0.1 --low idle
-- vallow=3.5
---------------------------------------------------------------------------------------------------------
--        -Do not modify values beyond this line!                                         
--------------------------------------------------------------------------------------------------------
img_add_fullscreen("airspeed_backdrop.png")
img_neddle = img_add_fullscreen("neddle.png")


---------- Needle vibration Section ---------------------------------------
-- Local variables
local needle_value=0
local rand=1
local val=0
local vibrationlvl=0

function vibrate(soundrpm) -- Function that adjusts the vibration level according to the sound level

   if soundrpm<0.1 then -- When the sound level is too low, the level of vibration is set to zero
      vibrationlvl=0
   else
      vibrationlvl=soundrpm
   end
end -- function

function timer_callback() -- function called every 40 mseconds, used to move the needle

   rand=-rand -- offset value of the needle, alternatively to the left or to the right
   -- setting up of the amplitude of vibrations depending of the % of sound produced, since engine vibration is not reliable
   -- (Change val values to taste at the begining of the code!)
   if vibrationlvl>vibmax then  -- high rpm, small amplitude of needle movements (high vibration speed)
      val=valmax
   elseif vibrationlvl>vibmid then -- medium range rpm, medium amplitude of needle movements
      val=valmid
   elseif vibrationlvl>viblow then --slow rpm, smaller amplitude of needle movements
          val=vallow
   else -- engine stopped, no needle movements
         val=0
    end
   
   needlepos=needle_value+(rand*val) -- calculation of the needle movement (adding a random +/-value to the real value)
--------------------------------------------------------------------------------------	
-- IMPORTANT !!!! move your img_rotate HERE!!!
--------------------------------------------------------------------------------------	


--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
end -- function


---------------------------------------------------------------------------------------------------------
-- Subscription to the Engine SOUND LEVEL variable to adjust vibration levels in real time
-- Needle vibration related to engine sound volume 
fsx_variable_subscribe("GENERAL ENG COMBUSTION SOUND PERCENT:1","percent",vibrate)

--------------------------- Timer used for engine vibration : the "frequency" parameters in msec is used for setting the vibration speed: a value of 40 is 
timer_start(0,frequency,timer_callback)

--------------------  END of Vibration code Section ------------------------------------------------

function PT_airspeed(airspeed)
    -- rotate the needle only if airspeed is above 25kts
	airspeed = var_cap(airspeed, 25, 260)
	
    img_rotate(img_neddle, airspeed*320/220 - 38)
end
-------------------------- Suscription varaibale section ----------------------------------------------
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/airspeed_kts_pilot", "FLOAT", PT_airspeed)
fsx_variable_subscribe("AIRSPEED INDICATED", "knots", PT_airspeed)
We are almost finished, ready for the STEP 3?
Last edited by JackZ on Thu Feb 02, 2023 8:32 pm, edited 5 times in total.
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Re: Adding some vibration effects to your needles

#4 Post by JackZ »

STEP 3: Adapting the code:

Now comes the (relatively) tricky part.
We have to modifiy slightly the code part devoted originally to the movement of the needle.

In our original gauge code, you will have to locate this:

Code: Select all

function PT_airspeed(airspeed)
    -- rotate the needle only if airspeed is above 25kts
	airspeed = var_cap(airspeed, 25, 260)
	
    img_rotate(img_neddle, airspeed*320/220 - 38)
end
This function is called by the variable_subscribe(), each time the airspeed changes.
In this function (whatever its name), we will rotate the needle accordingly, using img_rotate()
img_rotate(img_neddle, airspeed*320/220 - 38)

Now that the vibration routine has been added, the "airspeed" variable is no longer used, since it is constantly modified to "fluctuate" around the target value.
We will use instead the "needlepos" variable, as this value will tell the current position of the needle.
So the code changes to

img_rotate(img_neddle, needlepos*320/220 - 38)

And since we now longer use the airspeed variable we add the following line BEFORE the img_rotate()

needle_value=airspeed

No big deal hey? :D
Here again our code should now look like this:

Code: Select all

-----------------------------------------------------------
--               Customization section 
-- simply uncomment the varaiable that suits you
------------------------------------------------------------
-- sample Values for a modern single engine (Cessna, Piper, Robin)
-- frequency=40 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
-- vibmax=80 --beginning of max vibrations in %power
-- valmax=0.05 -- range of max vibration values
-- vibmid=30 --beginning of medium vibrations in %power
-- valmid=0.07 -- range of medium vibration values
-- viblow=0.5 -- low idle
-- vallow=0.09 -- range of low vibration values

-- sample Values for a WWII Fighter
frequency=65 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
vibmax=80 --beginning of max vibrations in %power
valmax=0.5 -- range of max vibration values
vibmid=30 --beginning of medium vibrations in %power
valmid=1  -- range of medium vibration values
viblow=0.25 -- low idle
vallow=2 -- range of low vibration values

-- sample values for a WW1 Fighter
-- frequency=70 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
-- vibmax=75 --beginning of max vibrations in %power
-- valmax=4 -- range of max vibration values
-- vibmid=40 --beginning of medium vibrations in %power
-- valmid=2.5
-- viblow=0.1 --low idle
-- vallow=3.5
---------------------------------------------------------------------------------------------------------
--        -Do not modify values beyond this line!                                         
--------------------------------------------------------------------------------------------------------
img_add_fullscreen("airspeed_backdrop.png")
img_neddle = img_add_fullscreen("neddle.png")


---------- Needle vibration Section ---------------------------------------
-- Local variables
local needle_value=0
local rand=1
local val=0
local vibrationlvl=0

function vibrate(soundrpm) -- Function that adjusts the vibration level according to the sound level

   if soundrpm<0.1 then -- When the sound level is too low, the level of vibration is set to zero
      vibrationlvl=0
   else
      vibrationlvl=soundrpm
   end
end -- function

function timer_callback() -- function called every 40 mseconds, used to move the needle

   rand=-rand -- offset value of the needle, alternatively to the left or to the right
   -- setting up of the amplitude of vibrations depending of the % of sound produced, since engine vibration is not reliable
   -- (Change val values to taste at the begining of the code!)
   if vibrationlvl>vibmax then  -- high rpm, small amplitude of needle movements (high vibration speed)
      val=valmax
   elseif vibrationlvl>vibmid then -- medium range rpm, medium amplitude of needle movements
      val=valmid
   elseif vibrationlvl>viblow then --slow rpm, smaller amplitude of needle movements
          val=vallow
   else -- engine stopped, no needle movements
         val=0
    end
   
   needlepos=needle_value+(rand*val) -- calculation of the needle movement (adding a random +/-value to the real value)
--------------------------------------------------------------------------------------	
-- IMPORTANT !!!! move your img_rotate HERE!!!
--------------------------------------------------------------------------------------	


--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
end -- function


---------------------------------------------------------------------------------------------------------
-- Subscription to the Engine SOUND LEVEL variable to adjust vibration levels in real time
-- Needle vibration related to engine sound volume 
fsx_variable_subscribe("GENERAL ENG COMBUSTION SOUND PERCENT:1","percent",vibrate)

--------------------------- Timer used for engine vibration : the "frequency" parameters in msec is used for setting the vibration speed: a value of 40 is 
timer_start(0,frequency,timer_callback)

--------------------  END of Vibration code Section ------------------------------------------------

function PT_airspeed(airspeed)
    -- rotate the needle only if airspeed is above 25kts
	airspeed = var_cap(airspeed, 25, 260)
    needle_value=airspeed	--<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<line added
    img_rotate(img_neddle, needlepos*320/220 - 38) <<<<<<<<<<<<<<<<<<<<<<<<<< line modified
end
-------------------------- Suscription variabale section ----------------------------------------------
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/airspeed_kts_pilot", "FLOAT", PT_airspeed)
fsx_variable_subscribe("AIRSPEED INDICATED", "knots", PT_airspeed)
And now for the grand finale, the infamous STEP 4!
Last edited by JackZ on Thu Feb 02, 2023 8:34 pm, edited 5 times in total.
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Re: Adding some vibration effects to your needles

#5 Post by JackZ »

STEP 4: Moving the img_rotate()

in the original code, the same function was used to do some calculation on the airspeed variable and rotate the needle image.

Code: Select all

function PT_airspeed(airspeed)
    -- rotate the needle only if airspeed is above 25kts
	airspeed = var_cap(airspeed, 25, 260) -- calculations about the airspeed
	
	img_rotate(img_neddle, airspeed*320/220 - 38) -- rotation of the Airspeed needle
end
We used the needlepos variable instead of the airspeed variable in the img_rotate(), now the last thing to do is to MOVE (I mean Cut/Paste) the img_rotate() to our vibrate function.

in other terms,

img_rotate(img_neddle, needlepos*320/220 - 38)

should be moved into the following commented section of the vibration code:

Code: Select all

--------------------------------------------------------------------------------------	
-- IMPORTANT !!!! move your img_rotate HERE!!!
---------------------------------------------------------------------------------------------	

-- YES, THIS ONE!!!!!
---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
Your final code should now look like this:

Code: Select all

-----------------------------------------------------------
--               Customization section 
-- simply uncomment the varaiable that suits you
------------------------------------------------------------
-- sample Values for a modern single engine (Cessna, Piper, Robin)
-- frequency=40 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
-- vibmax=80 --beginning of max vibrations in %power
-- valmax=0.05 -- range of max vibration values
-- vibmid=30 --beginning of medium vibrations in %power
-- valmid=0.07 -- range of medium vibration values
-- viblow=0.5 -- low idle
-- vallow=0.09 -- range of low vibration values

-- sample Values for a WWII Fighter
frequency=65 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
vibmax=80 --beginning of max vibrations in %power
valmax=0.5 -- range of max vibration values
vibmid=30 --beginning of medium vibrations in %power
valmid=1  -- range of medium vibration values
viblow=0.25 -- low idle
vallow=2 -- range of low vibration values

-- sample values for a WW1 Fighter
-- frequency=70 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
-- vibmax=75 --beginning of max vibrations in %power
-- valmax=4 -- range of max vibration values
-- vibmid=40 --beginning of medium vibrations in %power
-- valmid=2.5
-- viblow=0.1 --low idle
-- vallow=3.5
---------------------------------------------------------------------------------------------------------
--        -Do not modify values beyond this line!                                         
--------------------------------------------------------------------------------------------------------
img_add_fullscreen("airspeed_backdrop.png")
img_neddle = img_add_fullscreen("neddle.png")

---------- Needle vibration Section ---------------------------------------
-- Local variables
local needle_value=0
local rand=1
local val=0
local vibrationlvl=0

function vibrate(soundrpm) -- Function that adjusts the vibration level according to the sound level

   if soundrpm<0.1 then -- When the sound level is too low, the level of vibration is set to zero
      vibrationlvl=0
   else
      vibrationlvl=soundrpm
   end
end -- function

function timer_callback() -- function called every 40 mseconds, used to move the needle

   rand=-rand -- offset value of the needle, alternatively to the left or to the right
   -- setting up of the amplitude of vibrations depending of the % of sound produced, since engine vibration is not reliable
   -- (Change val values to taste at the begining of the code!)
   if vibrationlvl>vibmax then  -- high rpm, small amplitude of needle movements (high vibration speed)
      val=valmax
   elseif vibrationlvl>vibmid then -- medium range rpm, medium amplitude of needle movements
      val=valmid
   elseif vibrationlvl>viblow then --slow rpm, smaller amplitude of needle movements
          val=vallow
   else -- engine stopped, no needle movements
         val=0
    end
   
   needlepos=needle_value+(rand*val) -- calculation of the needle movement (adding a random +/-value to the real value)
--------------------------------------------------------------------------------------	
-- IMPORTANT !!!! move your img_rotate HERE!!!
--------------------------------------------------------------------------------------	

    img_rotate(img_neddle, needlepos*320/220 - 38)

--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
end -- function


---------------------------------------------------------------------------------------------------------
-- Subscription to the Engine SOUND LEVEL variable to adjust vibration levels in real time
-- Needle vibration related to engine sound volume 
fsx_variable_subscribe("GENERAL ENG COMBUSTION SOUND PERCENT:1","percent",vibrate)

--------------------------- Timer used for engine vibration :-------------------------------------
-- the "frequency" parameters in msec is used for setting the vibration speed:
-- a value of 40 imsec is usually Ok

timer_start(0,frequency,timer_callback)

--------------------  END of Vibration code Section ------------------------------------------------
function PT_airspeed(airspeed)
    -- rotate the needle only if airspeed is above 25kts
	airspeed = var_cap(airspeed, 25, 260)
	needle_value=airspeed
end
-------------------------- Suscription variable section ----------------------------------------------
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/airspeed_kts_pilot", "FLOAT", PT_airspeed)
fsx_variable_subscribe("AIRSPEED INDICATED", "knots", PT_airspeed)
THAT'S IT! If all went well, you now have converted a "dull" Airspeed indicator gauge into a nice "Vintage Vibrating Needle Airspeed gauge (TM)"!. :roll:

You can then give a try to your new gauge in the Edit/Create mode, run the gauge and then input a % value ranging between 0.0 (no movement) and 100.0 (high speed vibrations) for the "GENERAL ENG COMBUSTION SOUND PERCENT:1" variable.

Of course, feel free to modify the customization variables at the begining of the code to your taste, and with the v3.x version , you could even add them to user properties.
I have added three sets of preset values (modern, WWII and WWI engines) for your convenience, simply uncomment the ones you like.

Don’t hesitate to comment or ask any questions.
Enjoy!

Jacques
Last edited by JackZ on Thu Mar 15, 2018 6:33 pm, edited 15 times in total.
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

SimPassion
Posts: 5346
Joined: Thu Jul 27, 2017 12:22 am

Re: Adding some vibration effects to your needles

#6 Post by SimPassion »

Nice Tutorial Jacques
I will give it a try at some stage

Gilles

JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Re: Adding some vibration effects to your needles

#7 Post by JackZ »

Merci Gilles!

Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

jacquesvde
Posts: 16
Joined: Thu Jul 14, 2016 4:10 pm

Re: Adding some vibration effects to your needles

#8 Post by jacquesvde »

Nice Tutorial Jacques :D

I translate the text into French to understand. :roll:

Thank you very much,

Best regards
JacquesV

JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Re: Adding some vibration effects to your needles

#9 Post by JackZ »

Thanks JacquesV! 8-)

Here's a video of the result: A DC3/C47 panel with all the vibrating needles. Some gauges are completely original ones designed especially for the DC3/C47(tank capacity selector, brakes pressure, etc...).
The vibration rate is related to the starting of the engines, and the frequency (not the amplitude) of the vibrations is increasing with engine RPM to be realistic.

All custom coded gauges, including some code for internal lighting, depending on the FSX time of day.
By night (4.34 in the video), the gauges will turn almost black if not using the Panel lighting switch.
Pretty neat, but you know that already JacquesV, since you have done all the graphics of these vintage gauges!... :P



JacquesZ
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

frumpy
Posts: 361
Joined: Sat Jan 30, 2016 12:01 pm

Re: Adding some vibration effects to your needles

#10 Post by frumpy »

Well done, interesting addition!

Post Reply