Please help with scripts helicopter command.
Please help with scripts helicopter command.
Hello everyone,
I am trying to use HID Macro to add induced torque on a helicopter model. What I am trying to do is the higher the throttle value a certain factor would be added to the right rudder pedal, and with a low throttle value the factor would be zero.
I have been messing around for a few days with the program, but my lack of any kind of programming knowledge is getting me nowhere.
First of all, I can assume since the macro section cannot recocgnize my joystick axis movement, I have to do everything on the script tab, correct?
On the website there is a scripting help page, under Game device axis, there is a code line that states,
Sub AxisXChange(dev, axis, val)
Dim Message
Message = "Axis " & axis & " of device " & dev & " moved, value is " & val
end sub
HIDMacros.RegisterAxisEvent "Saitek X52 Flight Controller", "X", "AxisXChange", 5
I understand the RegisterAxisEvent where the "AxisXChange" is the procedure that is being called, but I dont understand this line
Message = "Axis " & axis & " of device " & dev & " moved, value is " & val
what is it supposed to do? When I copy the line to the HID Macro and move the joystick I get no action.
I tried doing something simple just to see if I could call a message using axis control, but it didnt work.
dim Message
Message = HIDMacro.FSXtext("hello world")
HIDMacros.registerAxisEvent "USB JOYSTICK", "X", "Message", 5000
It should show a text message on FSX when I moved the joystick axis more then 5000 units, correct?
I hope someone can give me some light with this matter, because I am really lost.
Thanks for the help
Fred
I am trying to use HID Macro to add induced torque on a helicopter model. What I am trying to do is the higher the throttle value a certain factor would be added to the right rudder pedal, and with a low throttle value the factor would be zero.
I have been messing around for a few days with the program, but my lack of any kind of programming knowledge is getting me nowhere.
First of all, I can assume since the macro section cannot recocgnize my joystick axis movement, I have to do everything on the script tab, correct?
On the website there is a scripting help page, under Game device axis, there is a code line that states,
Sub AxisXChange(dev, axis, val)
Dim Message
Message = "Axis " & axis & " of device " & dev & " moved, value is " & val
end sub
HIDMacros.RegisterAxisEvent "Saitek X52 Flight Controller", "X", "AxisXChange", 5
I understand the RegisterAxisEvent where the "AxisXChange" is the procedure that is being called, but I dont understand this line
Message = "Axis " & axis & " of device " & dev & " moved, value is " & val
what is it supposed to do? When I copy the line to the HID Macro and move the joystick I get no action.
I tried doing something simple just to see if I could call a message using axis control, but it didnt work.
dim Message
Message = HIDMacro.FSXtext("hello world")
HIDMacros.registerAxisEvent "USB JOYSTICK", "X", "Message", 5000
It should show a text message on FSX when I moved the joystick axis more then 5000 units, correct?
I hope someone can give me some light with this matter, because I am really lost.
Thanks for the help
Fred
Re: Please help with scripts helicopter command.
Hello Fred
Hmm, the example shows just how to read axis values, but you're right - there's no output in this example.
Try to add code:
into the AxisXChange procedure and if you have "Show buffer content" checked in Settings, you should see the Message in window title or as notification in taskbar.
Back to your problem:
Yes, axis can be only scripted, so you need to use a little bit of programming.
As a first step you need to write script to control your throttle and rudder through HIDmacros. Or rudder is enough and you can just read throttle position as axis value or via SimConnect from FSX.
So once you have procedure that sets rudder position through SimConnect based on axis value, then you can easily extend this procedure to read throttle value and addapt final rudder as needed (add factor you mentioned).
Hope it helps. If you proceed, don't hesitate to share your code here, it can be nice demonstration of scripting possibilities for others.
Hmm, the example shows just how to read axis values, but you're right - there's no output in this example.
Try to add code:
Code: Select all
HIDMacros.SetBuffer Message
Back to your problem:
Yes, axis can be only scripted, so you need to use a little bit of programming.
As a first step you need to write script to control your throttle and rudder through HIDmacros. Or rudder is enough and you can just read throttle position as axis value or via SimConnect from FSX.
So once you have procedure that sets rudder position through SimConnect based on axis value, then you can easily extend this procedure to read throttle value and addapt final rudder as needed (add factor you mentioned).
Hope it helps. If you proceed, don't hesitate to share your code here, it can be nice demonstration of scripting possibilities for others.
Petr Medek
LUAmacros author
LUAmacros author
Re: Please help with scripts helicopter command.
Hello Petr
thanks for the fast reply.
one of the problems I am facing is that I can´t get HIDMacros to constantly read the throttle position and apply the rudder automatic.
I have the following code, which in its basic it does what I want. Low throttle position means no rudder, higher throttle position means rudder apply.
I am using the Y axis as throttle
now using this code works only when I press compile It doesn´t work all the time.
I know that the RegisterAxisEvent command can call a procedure in HIDmacro. But I didnt quite understand how to use it. I didnt understand specially this part
what am I supposed to replace the "Axis", "of device" and "moved, value is" with?
I also didn´t quite understand your example 3.
Just one last thing, when using
the rudder position changed to abruptly,
I wanted to make more of a incremental change. So I tried to use and but it seems that any change I made the rudder moves to the left, if I have -16000 or +16000 the left rudder is pressed. I can´t seem to get a value to move the right rudder. but the command "RUDDER_RIGHT" works like a charm, pressing the right rudder.
thanks again for the support.
Fred
thanks for the fast reply.
one of the problems I am facing is that I can´t get HIDMacros to constantly read the throttle position and apply the rudder automatic.
I have the following code, which in its basic it does what I want. Low throttle position means no rudder, higher throttle position means rudder apply.
I am using the Y axis as throttle
Code: Select all
Dim colective
colective = HIDMacros.GetAxis ("USB JOYSTICK, "Y")
if colective >= 2000 then
HIDMacros.FSXEvent "RUDDER_RIGHT", 0
else
HIDMacros.FSXEvent "RUDDER_CENTER", 0
end if
I know that the RegisterAxisEvent command can call a procedure in HIDmacro. But I didnt quite understand how to use it. I didnt understand specially this part
Code: Select all
Sub AxisXChange(dev, axis, val)
Dim Message
Message = "Axis " & axis & " of device " & dev & " moved, value is " & val
end sub
I also didn´t quite understand your example 3.
Just one last thing, when using
Code: Select all
HIDMacros.FSXEvent "RUDDER_RIGHT", 0
I wanted to make more of a incremental change. So I tried to use
Code: Select all
HIDMacros.FSXEvent "AXIS_RUDDER_SET"
Code: Select all
HIDMacros.FSXEvent "RUDDER_SET"
thanks again for the support.
Fred
Last edited by willfred on 16 Aug 2011, 18:26, edited 3 times in total.
Re: Please help with scripts helicopter command.
Hello,
I thought I got the grasp with the RegisterAxisEvent, but maybe not so, I tried using it like this
It compiles, but when I move the throttle axis it doesnt change the rudder automatic, actually it doesnt change the rudder at all.
Thanks
I thought I got the grasp with the RegisterAxisEvent, but maybe not so, I tried using it like this
Code: Select all
Sub throttle(dev, axis, val)
Dim colective
colective = HIDMacros.GetAxis ("USB JOYSTICK, "Y")
if colective >= 2000 then
HIDMacros.FSXEvent "RUDDER_RIGHT", 0
else
HIDMacros.FSXEvent "RUDDER_CENTER", 0
end if
end sub
HIDMacros.RegisterAxisEvent "USB JOYSTICK, "Y", "Throttle", 500
Thanks
Re: Please help with scripts helicopter command.
Fred,
forget RUDDER_RIGHT and other events, you need to control rudder precisely.
So as I wrote: first step, control rudder through HIDmacros
In FSX, unmap you axis assigned to rudder as rudder postion will be set by HDM through SimConnect.
Then in HidMacros script use something like:
Adapt name of your joystick and axis.
Then you should be able to control rudder as usually.
Now add modification you need before SetFSXVariable code. You can read actual throttle axis position and apply some tuning.
Just an example I tried: apply double rudder on right side:
Hope it helps
forget RUDDER_RIGHT and other events, you need to control rudder precisely.
So as I wrote: first step, control rudder through HIDmacros
In FSX, unmap you axis assigned to rudder as rudder postion will be set by HDM through SimConnect.
Then in HidMacros script use something like:
Code: Select all
Sub RudderProc(dev, axis, val)
Dim lRudder
lRudder = HIDMacros.Axis2Float(val, -1, 1)
end if
HIDMacros.SetFSXVariable "RUDDER POSITION", "Position", lRudder
end sub
HIDMacros.RegisterAxisEvent "Saitek Pro Flight Rudder Pedals", "Rz", "RudderProc", 10
Then you should be able to control rudder as usually.
Now add modification you need before SetFSXVariable code. You can read actual throttle axis position and apply some tuning.
Just an example I tried: apply double rudder on right side:
Code: Select all
Sub RudderProc(dev, axis, val)
Dim lRudder
lRudder = HIDMacros.Axis2Float(val, -1, 1)
if (lRudder > 0) then
lRudder = lRudder * 2
end if
'HIDMacros.SetBuffer lRudder
HIDMacros.SetFSXVariable "RUDDER POSITION", "Position", lRudder
end sub
HIDMacros.RegisterAxisEvent "Saitek Pro Flight Rudder Pedals", "Rz", "RudderProc", 10
Petr Medek
LUAmacros author
LUAmacros author
Re: Please help with scripts helicopter command.
Hello,
Its been a long time, but I think I have managed to write the script.
Basically, when the throttle position is at a certain point the script will remap the rudder so that the center of the rudder is slightly to the right.
Now, the only problem I am having, is that the AxisRemap will only take effect if I make a input change to the pedals. For example, I am on the runway, my feet are off the pedals, they are straight. If I put full power the pedals are not going to be remaped to the right until I add a input to the pedal. As soon as I make a small change on the pedal, the AxisRemap will kick in. Is there a solution for this?
Thanks for all the help, and I hope this code help other home builders.
Its been a long time, but I think I have managed to write the script.
Basically, when the throttle position is at a certain point the script will remap the rudder so that the center of the rudder is slightly to the right.
Code: Select all
Sub FSXThrottle(val)
HIDMacros.SetFSXVariable "RUDDER POSITION", "PERCENT", val
end sub
Sub R1(dev, axis, val)
Dim FinalThrottle, throttle
HIDMacros.RegisterFSXVariable "GENERAL ENG THROTTLE LEVER POSITION:1", "PERCENT"
throttle= HIDMacros.GetFSXVariable("GENERAL ENG THROTTLE LEVER POSITION:1")
if ((throttle> 10) and (throttle< 20)) then
FinalThrottle = HIDMacros.AxisRemap(val, 0, 1, -90, 100, 0)
else
if ((throttle> 20) and (throttle< 30)) then
FinalThrottle = HIDMacros.AxisRemap(val, 0, 1, -80, 100, 0)
else
if ((throttle> 30) and (throttle< 40)) then
FinalThrottle = HIDMacros.AxisRemap(val, 0, 1, -70, 100, 0)
else
if (throttle> 40) then
FinalThrottle = HIDMacros.AxisRemap(val, 0, 1, -60, 100, 0)
else
FinalThrottle = HIDMacros.AxisRemap(val, 0, 1, -100, 100, 0)
end if
end if
end if
end if
call FSXThrottle(FinalThrottle)
end sub
HIDMacros.RegisterAxisEvent "Saitek ST290 Pro", "Rz", "R1", 1000
Thanks for all the help, and I hope this code help other home builders.
Re: Please help with scripts helicopter command.
2 comments:
- you need to register FSX variable only once, then you can read values. So the call of RegisterFSXVariable can be moved to the same level as RegisterAxisEvent
- yes, you can add RegisterAxisEvent also for throttle axis, calling the same routine R1. Then it's called also when you move throttle. You can even keep throttle controlled in FSX by assigning the axis in simulator (as you have today). By the additional RegisterAxisEvent call HIDmacros will just "listen" to throttle change and addapt rudder accordingly (but warning: will not work if you change throttle not using the joystick - by some autothrottle, mouse or key shortcut).
Hope it helps.
- you need to register FSX variable only once, then you can read values. So the call of RegisterFSXVariable can be moved to the same level as RegisterAxisEvent
- yes, you can add RegisterAxisEvent also for throttle axis, calling the same routine R1. Then it's called also when you move throttle. You can even keep throttle controlled in FSX by assigning the axis in simulator (as you have today). By the additional RegisterAxisEvent call HIDmacros will just "listen" to throttle change and addapt rudder accordingly (but warning: will not work if you change throttle not using the joystick - by some autothrottle, mouse or key shortcut).
Hope it helps.
Petr Medek
LUAmacros author
LUAmacros author
Re: Please help with scripts helicopter command.
Hello, Petr
Is it possible to increase sensitivity of a control, for example the x or y axis, via HIDMacros? Becasue I dont want to use the FSX settings, as the sensitivity is not big enough for my applications.
By the way, I have been taking a little break on my project. But as soon as I return I´ll post my code here so others can use it as needed.
Thanks for the great support.
Sincerely
fred
Is it possible to increase sensitivity of a control, for example the x or y axis, via HIDMacros? Becasue I dont want to use the FSX settings, as the sensitivity is not big enough for my applications.
By the way, I have been taking a little break on my project. But as soon as I return I´ll post my code here so others can use it as needed.
Thanks for the great support.
Sincerely
fred
Re: Please help with scripts helicopter command.
Ok never mind I think I got it, when using the HIDMacros.Axis2Float i just increased the range and it increased the sensitivity.
From
HIDMacros.Axis2Float(val, -100, 100)
to
HIDMacros.Axis2Float(val, -120, 120)
fred
From
HIDMacros.Axis2Float(val, -100, 100)
to
HIDMacros.Axis2Float(val, -120, 120)
fred