Need help in Lua

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
maak_pk
Posts: 27
Joined: Sun Dec 13, 2020 11:37 am
Location: Pakistan

Need help in Lua

#1 Post by maak_pk »

hello
i am hoping someone to help me out in this. i am trying to make a plugin so when ever i apply collective the rudder should set to the define position as per rough formula i have calculated. but this code has some issues as rudder position comes to zero after few input by collective and peddals.
looking forward to this forum to guide me
regards

Code: Select all

[code]
old_thr=1
new_thr=1
new_rd=1
old_rd=1
function rd(rd)
new_rd=rd
print("rd"..rd)
if old_rd > new_rd then
print("+")

else
print("-")

end

print("new_rd"..new_rd)
print("old_rd"..old_rd)
old_rd=new_rd
end


function compare(thr)

thr = var_round(thr,2)
new_thr=thr
if thr >4.5 then
print("thr"..thr)
rd_set=(165.23*new_thr)-(16548*new_rd)
print ("rd_set"..rd_set)
if old_thr <= new_thr then
fsx_event("RUDDER_SET",rd_set)
print("ok")
else
fsx_event("RUDDER_SET",-rd_set)
print("no")

end

print("new"..new_thr)
print("old"..old_thr)
old_thr=new_thr

end
end




fsx_variable_subscribe("GENERAL ENG THROTTLE LEVER POSITION:1","Percent", compare)
fsx_variable_subscribe( "RUDDER POSITION", "Position", rd)
[/code]

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Need help in Lua

#2 Post by Sling »

You'll need to explain how you came to this. This doens't look right to me but it might make sense if you exlain the values and the range of values expected from rd_set, thr and rd.

Code: Select all

rd_set=(165.23*new_thr)-(16548*new_rd)

maak_pk
Posts: 27
Joined: Sun Dec 13, 2020 11:37 am
Location: Pakistan

Re: Need help in Lua

#3 Post by maak_pk »

Hi sling thanks for the reply
thr is the percentage of collective from 0 to 100
rd is the position of rudder from -1 to +1
and rd_set will set the value of event in prepar3d RUDDER_SET from -16383 to +16383 equation is bit rough i know but i am having a issue to set the rd_set with increase in thr(collective) and while reducing the thr, rd_set shud reduce from the last value where is stoped while increasing the thr.
hope this make some what clear what i am tring to do

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Need help in Lua

#4 Post by Sling »

Ok that helps.

A few points to consider.

Consider what is the starting position for rd. You have 1 but i suspect it will be close to 0.

How much change in rd do you need for a full change of thr. It will not be the full range else you will lose the control ability of the pedals.

Is this even required for a heli. Is a change in throttle not compensated for by the increase/decrease in tail rotor rpm.

I don't see why you are using the new_rd position in the formula. The new commanded position is simply a function of the throttle setting as far as i can tell. That said the new position should really be a relative position change rather than an absolute as it needs to take into account the position of the pedals right.

As you have it a change in throttle from increase to decrease creates a big jump from rd in one direction to the opposite direction. so when you make a small change up then down the rd value will be all over the place. What you need is to apply the delta of thr to the last rd value.

maak_pk
Posts: 27
Joined: Sun Dec 13, 2020 11:37 am
Location: Pakistan

Re: Need help in Lua

#5 Post by maak_pk »

Sling wrote: Thu Dec 17, 2020 11:11 am Ok that helps.

A few points to consider.

Consider what is the starting position for rd. You have 1 but i suspect it will be close to 0.

How much change in rd do you need for a full change of thr. It will not be the full range else you will lose the control ability of the pedals.

Is this even required for a heli. Is a change in throttle not compensated for by the increase/decrease in tail rotor rpm.

I don't see why you are using the new_rd position in the formula. The new commanded position is simply a function of the throttle setting as far as i can tell. That said the new position should really be a relative position change rather than an absolute as it needs to take into account the position of the pedals right.

As you have it a change in throttle from increase to decrease creates a big jump from rd in one direction to the opposite direction. so when you make a small change up then down the rd value will be all over the place. What you need is to apply the delta of thr to the last rd value.
Great help
Yes you are right rd starting point should be zero
For now I am trying to change in direct proportion to thr on both sides.
thr is not throttle its the collective position from 0 to 100.
I want something like that if thr is 10 rudder_set is 10% of its total position plus the input aval at rudder pedals to counter the 10% already increased
Similarly it increase as thr increases
And yes when thr is 100% rd_set will be at its max on one side and by applying rudder pedal in opposite direction will keep the heli neutral and won't have any more control on one side.
And as I reduce thr, rd_set will reduce in same proportion
Hope something can be done
Need some guidance
Regards

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Need help in Lua

#6 Post by Sling »

What you describe is straight forward but what I’m struggling with is what’s the use case for this. I’m no heli pilot but this kind of control seems weird to me. Perhaps Ralph can shed some light on this control scheme.

User avatar
Ralph
Posts: 7924
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Need help in Lua

#7 Post by Ralph »

If you're talking about a helicopter, then I guess with rudder pedals you mean the tail rotor pitch? That's not a 1:1 relation. It depends on the wind speed, wind angle, airspeed, torque, etc... You cannot just state 10% collective increase equals 10% tail rotor pitch increase. Maybe this works in FSX and Prepar3D where the helicopter modelling is terrible, but this will not work in X-Plane.

Post Reply