zibo 737 flap lever

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Post Reply
Message
Author
Timgoodwinjr
Posts: 8
Joined: Tue Apr 05, 2022 6:21 pm

zibo 737 flap lever

#1 Post by Timgoodwinjr »

Hello all. I could use some help. I am still very new to all of this and i have looked everywhere to look. I am currently building a home cockpit for my son. i have the mcp all down and working and have now moved to the flap lever. i would like to use a pot to control the flaps as seen on 737sim. i have downloaded the available 737-800x instrument which does not currently have hardware included. i am able to add the pot (this is located on the last line of the attached code) when i use the pot there is no movement to the lever or needle on the gauge i do however notice that the le flaps annun flickers a bit. I am sure i am missing some sort of calibration needed for the pot or such. Could someone help me with this. I am sorry to bother but still really new to this. thank you.

Code: Select all

-- This is a modification of Russ Barlow's EADT x737NG Flaps-Autobrakes instrument that converts it for use with the ZiboMod 737.
-- The autobrake knob and indicator lights use ZIBO datarefs and commands so they will only work correctly with the ZIBO 737. 
-- An X-Plane dataref is used to slow the movement of the flap pointer.
-- Tested with ZiboMod 737-800 v.3.40 and Air Manager 3.7.
-- GoodSim 5/28/20

-- LOAD FLAPS AUTOBRAKE PANEL           
backgrouund_img      = img_add_fullscreen ( "background.png" )              -- FLAP POSITION DIAL REDRAWN
flap_pointer_img     = img_add ( "flap_pointer.png" , 138 , 35 , 98 , 98 )  -- 135 , 33 , 104 , 104
ab_knob_img          = img_add ( "auto_brake_knob.png" , 30 , 76 , 65 , 65 )
autobrake_amber_lite = img_add ( "ab_disarm.png" , 34 , 23 , 58 , 29, "visible:false" )
antiskid_amber_lite  = img_add ( "as_inop.png" , 27 , 165 , 59 , 29, "visible:false" )
le_green_lite        = img_add ( "LE_green.png" , 186 , 160 , 59 , 27, "visible:false" )
le_amber_lite        = img_add ( "LE_yellow.png" , 121 , 160 , 57 , 26, "visible:false" )

rotate  ( flap_pointer_img ,0 )          
rotate  ( ab_knob_img ,0 )               

-- FLAPS & SLATS INDICATORS                                                                  
function flaps ( LE_transit_on , LE_extend_on, flap_deploy_ratio )
    visible ( le_amber_lite, LE_transit_on > 0 )       
    visible ( le_green_lite, LE_extend_on > 0 )              
    rotate  ( flap_pointer_img , 262 * flap_deploy_ratio ) -- 0/0  1/.125  2/.25  5/.375  10/.5   15/.625 25/.75  30/.875  40/1   (Pos/Ratio)
end                                                    -- 0/0  1/34    2/67   5/101   10/134  15/168  25/201  30/235   40/268 (Pos/Deg)

-- AUTOBRAKE & INDICATORS
function autobrake ( autobrake_setting, AB_disarm_on, AS_inop_on )
    visible ( autobrake_amber_lite, AB_disarm_on > 0 )           
    visible ( antiskid_amber_lite,    AS_inop_on > 0 )      
    autobrake_setting = var_cap ( autobrake_setting , 0 , 5 )  -- ENSURES VALUE OF ZIBO KNOB POSITION IS BETWEEN RTO - MAX
    rotate  ( ab_knob_img , -45 + autobrake_setting * 45 )     -- ROTATES 2D KNOB ACCORDING TO ZIBO'S SELECTED (OR CMD'D) POSITION   
end

function ab_rotate ( direction )                           -- THIS ROTATES ZIBO KNOB ACCORDING TO 2D KNOB'S SELECTED POSITION
    if direction == 1 then 
        xpl_command ( "laminar/B738/knob/autobrake_up" )    -- COMMANDS ZIBO KNOB CW
    elseif direction == -1 then
        xpl_command ( "laminar/B738/knob/autobrake_dn" )    -- COMMANDS ZIBO KNOB CCW    
    end
end

-- THIS IS ACTVATED WHEN 2D KNOB IS TURNED & RETURNS CW OR CCW DIRECTION TO FUNCTION ab_rotate
ab_knob = dial_add ( nil , 30 , 76 , 65 , 65 , ab_rotate ) 
 
xpl_dataref_subscribe ( "laminar/B738/autobrake/autobrake_pos", "FLOAT",  
                        "laminar/B738/autobrake/autobrake_disarm", "FLOAT",
                        "laminar/B738/annunciator/anti_skid_inop", "FLOAT", autobrake )

xpl_dataref_subscribe ( "laminar/B738/annunciator/slats_transit", "FLOAT", 
                        "laminar/B738/annunciator/slats_extend", "FLOAT",
                        "sim/flightmodel2/controls/flap_handle_deploy_ratio", "FLOAT", flaps )
 
hw_pot_flap = hw_adc_input_add("flaplever", flaps)                                                                                                                     

Timgoodwinjr
Posts: 8
Joined: Tue Apr 05, 2022 6:21 pm

Re: zibo 737 flap lever

#2 Post by Timgoodwinjr »

I forgot to add the following error that i get in the debugger.

ERROR - Error in hardware ADC input callback: logic.lua:22: attempt to compare number with nil

this is what is on line 22
visible ( le_green_lite, LE_extend_on > 0 )

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: zibo 737 flap lever

#3 Post by Keith Baxter »

Hi,

Your hw_adc_input_add() has the same callback as the dataref subscribe. <flaps> This is causing the error.
Also you need to write to the flaps lever dataref.

Try this instead of your hw_adc_input_add() and it should work.

Code: Select all

hw_pot_flap = hw_adc_input_add("flaplever", function(flap_lever)
   xpl_dataref_write("laminar/B738/flt_ctrls/flap_lever", "FLOAT",flap_lever)
end)

Also, for your gauge use
https://siminnovations.com/wiki/index.p ... ate_linear

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

Timgoodwinjr
Posts: 8
Joined: Tue Apr 05, 2022 6:21 pm

Re: zibo 737 flap lever

#4 Post by Timgoodwinjr »

Thank you for your reply Keith,
I am looking forward to getting back to the sim pc to test this out. I will report back soon!
thanks again

Timgoodwinjr
Posts: 8
Joined: Tue Apr 05, 2022 6:21 pm

Re: zibo 737 flap lever

#5 Post by Timgoodwinjr »

Keith!
Thank you very very much. I was able to get the pot to do what i needed by adding the following code to the original code. I wont know for sure as far as if the settings line up with the latches on my cockpit lever until i get it built and installed into the sim. I will be sure to report back again once that has been completed.
and again thank you

Code: Select all

function flap_lever(value)


  xpl_dataref_write("laminar/B738/flt_ctrls/flap_lever", "FLOAT",{value})
 -- xpl_dataref_write("sim/flightmodel/engine/ENGN_thro", "FLOAT[8]", {value})
end

-- Create a ADC input 
hw_pot_flap = hw_adc_input_add("flaplever", flap_lever)                                                                                                                     

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: zibo 737 flap lever

#6 Post by Keith Baxter »

Timgoodwinjr wrote: Thu May 12, 2022 6:00 pm Keith!
Thank you very very much. I was able to get the pot to do what i needed by adding the following code to the original code. I wont know for sure as far as if the settings line up with the latches on my cockpit lever until i get it built and installed into the sim. I will be sure to report back again once that has been completed.
and again thank you
Hi,

Yes. That is good. Well done.
There is a difference between Synchronous and Asynchronous coding.

synchronous operations block instructions until the task is completed, while asynchronous operations can execute without blocking other operations.

I provided a Asynchronous option so that there would be no blocking.

You have to determine the value of each flap notch and then use a table.
That is why I mentioned the <interpolate_linear()> With that we can control the value sent to the sim.

When you get to that. Driving a servo or stepper for the gauge etc. I will assist.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: zibo 737 flap lever

#7 Post by Keith Baxter »

Hi @Timgoodwinjr

I did this bit of code so that all can see how to write the correct lever position value from the pot value. The <n> values are the pot values when the flap lever is in a position.

Code: Select all


--These are the positions and ratio values in the sim 
-- 0/0  1/.125  2/.25  5/.375  10/.5   15/.625 25/.75  30/.875  40/1 

--These are the POT values at each position. I have done it this way so that you can understand what is happening. You could just add the values to the table and do away with all the n var's
--Lets say that the pot only turns 80%

n1 = 0
n2 = 0.05
n3 = 0.1
n4 = 0.2
n5 = 0.35
n6 = 0.4
n7 = 0.5
n8 = 0.6
n9 = 0.8

--Create a interpolate table using the above values.
local flap_position = {{n1, 0},
                       {n2,0.125},
                       {n3,0.25},					   
                       {n4,0.375},
                       {n5,0.5},					   
                       {n6,0.625},					   
                       {n7,0.75},					   
                       {n8,0.875},					   
                       {n9,1}}					   
					   
hw_pot_flap = hw_adc_input_add("Flap Lever", function(flap_lever)
   new_flap_lever = var_cap(flap_lever,0,0.8)
   xpl_dataref_write("laminar/B738/flt_ctrls/flap_lever", "FLOAT",interpolate_linear(flap_position, new_flap_lever))
end)
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

Timgoodwinjr
Posts: 8
Joined: Tue Apr 05, 2022 6:21 pm

Re: zibo 737 flap lever

#8 Post by Timgoodwinjr »

Keith,
Thank you for posting the correct code. I hope i did not offend you in any way. I appreciate your help and now looking at your code i understand what you were saying originally.
Thanks again
Tim

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: zibo 737 flap lever

#9 Post by Keith Baxter »

Timgoodwinjr wrote: Fri May 13, 2022 8:24 pm Keith,
Thank you for posting the correct code. I hope i did not offend you in any way. I appreciate your help and now looking at your code i understand what you were saying originally.
Thanks again
Tim
Hi Tim,

No problems, all is good.

There was nothing wrong with the code you posted. I just wanted to explain the difference.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

Post Reply