PA-30 Twin Comanche Gauges

Working on a instrument project or just finished a project? Show it to others!

Moderators: russ, Ralph

Message
Author
Jdleonr
Posts: 13
Joined: Wed Nov 24, 2021 7:45 pm

Re: PA-30 Twin Comanche Gauges

#11 Post by Jdleonr »

try with this the image does not disappear anymore it gives me the instrument as such but it does not work it gives me an error in execution
Attachments
NeedleLeft.png
NeedleLeft.png (1.86 KiB) Viewed 677 times
NeedleRigth.png
NeedleRigth.png (1.9 KiB) Viewed 677 times
FuelFlow.png

Jdleonr
Posts: 13
Joined: Wed Nov 24, 2021 7:45 pm

Re: PA-30 Twin Comanche Gauges

#12 Post by Jdleonr »

this error gives me in the console tab.

"ERROR - error in dataref callback: logic.lua:12: attempt to index a nil value (global 'NeedleLeft')"

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

Re: PA-30 Twin Comanche Gauges

#13 Post by JackZ »

There are some errors in your code:
1- The first requisite is to have your images that need to be rotated centered around their center of rotation. Like the following example
needle_left.png
needle_left.png (4.99 KiB) Viewed 639 times
Here the image is 512 x512 (can be smaller in height of course, but for demonstration purposes, it is better that way).
The center of the needle is at 256,256, and of course the image should be in png format with a transparent background (png with alpha channel)

2- If you want to modify (in your case rotate) the needles, then img_add_fullscreen() should point to a unique identifier (can be any name), like this:

Code: Select all

needle_left=img_add_fullscreen("NeedleLeft.png") -- here needle_left is the name of the resource identifier
needle_right=img_add_fullscreen("NeedleRigth.png")
But in your case the needle are not centered in the gauge, so I suggest you use instead img_add() that will allow you to position the image exactly where needed around their center of rotation.
https://siminnovations.com/wiki/index.php?title=Img_add

Code: Select all

needle_left=img_add("NeedleLeft.png", -256, 256,nil,nil) 
-- The origin of the gauge (0,0) is on the left topmost point of the instrument. 
-- We want the center of the needle to be positioned on the left of the bezel, hence we use half of the needle image width (512/2=256) and move to the left: -256 (actual value may vary depending of the real location of the center)
-- then the needle should be positioned on the middle of the height of the bezel, hence we use half of the needle image height (512/2=256) and move down: 256
-- nil is used for the sizes parameter, since we don't want to change the size of the original image

-- Same applies to the right needle
needle_right=img_add_fullscreen("NeedleRigth.png", 256,256,nil,nil) 
3- You can then use the resource id to rotate each needle by a certain angle (angle_left & angle_right).
Of course rotate uses TWO parameters: one is the image resource to be rotated, the second than angle of rotation to apply.
You only supplied one parameter, and this parameter was not a resource identifier, hence the error message

rotate() rotates an image by its center.
https://siminnovations.com/wiki/index.php?title=Rotate

Code: Select all

    rotate(needle_left,angle_left)
    rotate(needle_right,angle_right)
3- The main problem is now to determine the proper rotation angle for each needle (clockwise for the left needle, and anticlockwise for the right needle) according to the Fuel Flow value

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

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

Re: PA-30 Twin Comanche Gauges

#14 Post by JackZ »

If we observe the fuel flow graphic scale of the gauge, one can see there are two different scales in it: from 2 to 6 gph, then from 6 to 16 gph

The rotation angle needs to be adjusted according to the fuel flow value.
Let’s calculate for the right needle (clockwise)
1- if the ff is below 2 then the needle stays at the 2 position angle
2- if the ff is between 2 and 6 then the needle should point to: initial position + ((angle range sector concerned)/(ff-lowest value of the sector)
with:
-initial position: 2 position angle value
-angle range sector concerned: 6 position angle value-2 position angle value
- ff-lowest value of the range sector : actual fuel flow value (from the subscribe)-lowest value of the sector(here 2gph)

In the first sector case the values are

-initial position: 190 degrees or so (adjust by trial & error or by direct measurement on the gauge scale, with 0 degrees being the UP direction)
-angle range sector concerned: 215-190= 25 degrees
- ff-lowest value of the range sector : ff-2

The calculated formula for the 2 to 6 gph range is:
angle=190+(25 /(ff-2))

3- if the ff is between 6 and 16 then the needle should point to: initial position + ((angle range sector concerned)/(ff-lowest value of the sector)
with:
-initial position: 6 position angle value (should be 190+25=215 degrees
-angle range sector concerned: 16 position angle value- 6 position angle value (should be around 145 degrees)
- ff-lowest value of the range sector : actual fuel flow value (from the subscribe)-lowest value of the sector(here 6 gph)

The calculated formula for the 6 to 16 gph range is:
angle=215+(145 /(ff-6))
4- if the ff is above 16 gph the angle is fixed to 360
———-
The calculated angle can then be used in the rotate formula.
Last remark, the rotation angle in the calculation assumes that the needle points up at 0 degree initially. If like in our example the needle points to another angle here 90 degrees, this initial angle position value should be substracted in the rotate formula.

Note the rotate() can use the additional parameters to set the rotation direction (here « CW » for clockwise) with an animation effect.
https://siminnovations.com/wiki/index.php?title=Rotate

This part of the code should look like this:
Same principle applies for the other needle, with different angle values.

Code: Select all

function ff_data(ff1,ff2)
— right needle uses ff2 values
if ff2<=2 then 
    angle=190
elseif ff2<=6 then
     angle=190+(25 /(ff2-2))
elseif ff2<=16 then
     angle=215+(145 /(ff2-6))
 else 
     angle=360
  end

angle=angle-90
rotate(needle_right, angle, « LINEAR », 1, « CW »)

— Calculation for left needle (uses ff1 and turns counter clockwise)


       — insert the code here

—
angle=angle-270
rotate(needle_left, angle, « LINEAR », 1, « CCW »)

end
-------------------------------------
--       Data Subscription         --
-------------------------------------

fsx_variable_subscribe("ENG FUEL FLOW GPH:1", "Gallons per hour", 
                       "ENG FUEL FLOW GPH:2", "Gallons per hour", ff_data)

fs2020_variable_subscribe("ENG FUEL FLOW GPH:1", "Gallons per hour", 
                          "ENG FUEL FLOW GPH:2", "Gallons per hour", ff_data)

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

Post Reply