Jump to content
The simFlight Network Forums

"Smoother" braking when only a button is available.


spokes2112

Recommended Posts

Here is a Lua file that progressively apply and/or disengage brakes, adjustable in both directions, for those who only have a button for brakes.

 

[INSTALLATION]

  1. FS closed
  2. Copy the complete code block below, paste it into an empty .txt file & rename it Smooth_Brake.Lua
  3. Place the above file in the FS/Modules folder
  4. Add the following to the [Auto] section of the  FSUIPC(4).ini file - X=Lua Smooth_Brake - Where X is the next available number in the [Auto] section. (pg. 42 - FSUIPC4 for Advanced Users.pdf)
  5. Comment out ( ; ) or remove the original brake button listing in the [buttons] section.  
  6. Start FS
  7. Make sure the button is not programmed through the FS assignments dialog.
  8. For a simple, non-complex assignment to the joystick button see the picture below. For a complex assignment see pg. 22 - FSUIPC4 for Advanced Users.pdf - Using something similar to this for a button press - xx=CP(-0,11)0,0,CL6:S,211 and this for release - xx=CU(-0,11)0,0,CL6:C,211. Where 6 is the numbered lua under the [LuaFiles] section of FSUIPC(4).ini in my case as an example. Use the FSUIPC facility, "Reload Buttons", from the user interface in the Buttons tab to confirm assignment.
  9. Adjust user settings to ones own liking. Assign a keyboard key to reload the file using Lua Smooth Brake as the control sent to use for reloading tuning modifications.  
  10. One can use the Logging facilities in FSUIPC, using the right hand side of the dialog (FSX + only), using 0BC4, 0BC6 & 0BC8 with a type of U16, display to FS Window, to help in adjusting user settings. 

 

Smooth_Brake.jpg?dl=0

 

The above settings result in this -

1=P0,0,CL6:S,211

2=U0,0,CL6:C,211 

 

 

 

[USAGE]

Basically all this does is gradually increase (depending on settings) the brake strength as the assigned brake button is pushed. It also works in reverse, on brake disengagement. One could, for instance press the brake button for only 1 second and after that toggle the brakes on & off at a repetitive rate to keep, lets say, ~ 50% brake strength. It's much better than full on or full off. The settings as given below give around a 2.75 second span between brakes off to full brake strength.

 

 

 
Smooth_Brake.Lua -

--------------------- USER SETTINGS
rate_on = 300	            -- RATE AT WHICH BRAKES ARE APPLIED
minimum = 3500              -- MINIMUM BRAKES ON FIRST APPLY = REQUIRED PERCENT * 16384
rate_off = 300	            -- RATE AT WHICH BRAKES ARE RELEASED
dis_pbrake = 1              -- DISENGAGE PARKING BRAKE ON BRAKE APPLICATION? REQUIRES A REAPPLY FOR BRAKE ACTIVATION!
diff_brake_override = 0     -- !!!! GIVES AN ALTERNATE DIFFERENTIAL BRAKE AXIS PRIORITY OVER BRAKES 
                            -- EXAMPLE - THE "T_FLIGHT HOTAS" ALTERNATE AXIS ON THROTTLE SECTION
			    -- SEE PG.1 "FSUIPC LUA LIBRARY" - "n = ipc.axis(joynum, "axis")" FOR MORE INFORMATION.
--------------------- END USER SETTINGS

function stop()
	brake = ipc.readUW(0x0BC4)
		-- Get Parking Brakes If Button Pressed And Parking Brake Disengage Is Active
		if ipc.testflag(211) == true and dis_pbrake == 1 then
			p_brake = ipc.readUW(0x0BC8)
				-- Disengage Parking Brakes If Set
				if p_brake == 32767 then
					ipc.control(65752, 0)
				end	
		end	
		-- Brakes On
		while brake < 16383 and ipc.testflag(211) == true do		
					-- Differential Braking Override
					if diff_brake_override == 1 then
                                                -- REQUIRES CUSTOM ATTRIBUTES FOR SPECIFIC HARDWARE
						special = ipc.axis(0,"S")
						if special > 1000 or special < -1000 then
							brake = 0
							break
						end
					end
			brake = math.min(16384, brake + rate_on)
			brake = math.max(minimum, brake)
			brake_shift = logic.Shl(brake, 16) + brake   		
			ipc.writeUD(0x0BC4, brake_shift)	
		end
		-- Brakes Off
		while brake > 0 and ipc.testflag(211) == false do					
					-- Differential Braking Override
					if diff_brake_override == 1 then
                                                -- REQUIRES CUSTOM ATTRIBUTES FOR SPECIFIC HARDWARE
						special = ipc.axis(0,"S")
						if special > 1000 or special < -1000 then
							brake = 0
							break
						end
					end		
			brake = brake - rate_off
			brake = math.max(0, brake)
			brake_shift = logic.Shl(brake, 16) + brake   		
			ipc.writeUD(0x0BC4, brake_shift)	
		end 	
end 
 
event.flag(211, "stop")
Link to comment
Share on other sites

Nice idea, but starting and Killing threads is a rather inefficient way of doing things. Why not use event.button to trigger the braking on / off and have the Lua plug-in loaded initially by an [Auto] line in the INI?

 

 

You'd need to either test the button in the loop as well, or use the events to set asnd clear a value or flag which is tested in your loop, so it can exit.

 

Alternatively, but similar, use event.param in a similarly loaded plug-in, and just have your button events using luavalue with different parameters for on and off? Again, you'd test in the loop.

 

Or, again, event.flag. and assign to luaset and luaclear for on and off, and test the flag in the loop.

 

Any event-based plug-in is far better than one which is continually started and ruthlessly 'killed' (the latter action is equivalent to using Task Manager to terminate a hung process. It isn't very nice). Killing threads used to be the only way before I devised the event system. With events the plug in is loaded and compiled just once and lays dormant until the event occurs. 

 

Regards

Pete

Link to comment
Share on other sites

  • 2 years later...

I know this is a very old thread but the image you displayed initially is no longer there. How do I set up my joystick? Steps 8 to end have been an issue to surpass for me. 

Edit: I have figured it out :) thanks, works perfectly. 

Edited by EnoB
Link to comment
Share on other sites

  • 4 weeks later...
On 3/1/2018 at 12:49 AM, EnoB said:

I know this is a very old thread but the image you displayed initially is no longer there. How do I set up my joystick? Steps 8 to end have been an issue to surpass for me. 

Edit: I have figured it out :) thanks, works perfectly. 

What did you do in 8, 9, 10? Without the image it's hard to understand.

Thanks

Link to comment
Share on other sites

  • 2 years later...
  • 4 months later...
On 8/10/2015 at 10:30 AM, spokes2112 said:

Here is a Lua file that progressively apply and/or disengage brakes, adjustable in both directions, for those who only have a button for brakes.

[USAGE]

Basically all this does is gradually increase (depending on settings) the brake strength as the assigned brake button is pushed. It also works in reverse, on brake disengagement. One could, for instance press the brake button for only 1 second and after that toggle the brakes on & off at a repetitive rate to keep, lets say, ~ 50% brake strength. It's much better than full on or full off. The settings as given below give around a 2.75 second span between brakes off to full brake strength.
Smooth_Brake.Lua -

Hello @spokes2112

I tried your lua script today with P3D v5, but it does not work, could you confirm that ? Thanks

Link to comment
Share on other sites

  • 11 months later...
13 hours ago, atf said:

i did all the steps , but the brakes do not activate .

Try activating lua debug logging, as well as monitoring the offsets as mentioned in step 10.

If you keep the console window open while you activate the assigned button, you should be able to see what is going on. You can attach your FSUIPC7.log file (complete) and FSUIPC7.ini file here and I can take a look.

John
 

  • Like 1
Link to comment
Share on other sites

Can you attach a compete log please, not a partial log.

15 hours ago, atf said:

i think the offsets aren't changed, but im a newb at this 

Maybe, did you add the offset monitoring? I cannot tell from a partial log. It may also depend on the aircraft being used, so I need to see the full log.

John

Link to comment
Share on other sites

I have just set this up for the stock 152 and it seems to work as advertised. I found it was a bit slow for my liking, and changed the rate_on and rate_off to 500 (from 300).

There are a few strange things in your (continuation) log:

Quote

   732297  6520 Button changed: bRef=0, Joy=4 (D), Btn=0, Pressed
   732297  6520 [Buttons] 14=PD,0,CL1:D,0
   732485  6520 LUA: "C:\FSUIPC7\Smooth_Brake.lua": killed
   733360  6520 Button changed: bRef=0, Joy=4 (D), Btn=0, Released
   733360  6520 [Buttons] 15=UD,0,CL1:R,0
   733547  6520 LUA: "C:\FSUIPC7\Smooth_Brake.lua": killed
   733610  4692 LUA.32: beginning "C:\FSUIPC7\Smooth_Brake.lua"
 

Why is the lua being killed and restarted?

As indicated in the instructions, you should start the lua from the FSUIPC7.ini [Auto] section (or profile [Auto.xxx] section if only using in certain profiles).
And are you sure you have assigned your button to set/clear the 211 flag using the LuaSet and LuaClear controls?
If you do that, your log should look something like this:

Quote

    39953 LUA.2: Waiting for an event in "D:\FSUIPC7\SmoothBrake.lua"
    44625 *** EVENT: Cntrl= 65569 (0x00010021), Param= 0 (0x00000000) DME
    48562 *** EVENT: Cntrl= 65569 (0x00010021), Param= 0 (0x00000000) DME
    65265 Button changed: bRef=0, Joy=1 (T), Btn=0, Pressed
    65265 [Buttons.Cessna 152 Asobo] 2=PT,0,CL30:S,211
    65265 LUA: "SmoothBrake.lua": Flag 211 set
    65281 LUA.2: Lua Flag event: calling "stop" in "D:\FSUIPC7\SmoothBrake.lua"
    65281 LUA.2: D:\FSUIPC7\SmoothBrake.lua:12
 

I see no evidence of flag 211 being set in your logs, so it looks like the script "stop" function isn't being called.

Maybe show me your FSUIPC7.ini file....

John

Link to comment
Share on other sites

What are these:

Quote

14=PD,0,CL1:D,0     -{LuaDebug Smooth_Brake}-
15=UD,0,CL1:R,0     -{Lua Smooth_Brake}-

?

Please remove/delete those assignments, and assign to LuaSet and LuaClear, both with parameter 211, as explained in step 8 and also in the attached screenshot.

How do you expect this to work if you are not following the instructions?

The lua is ran automatically from your [Auto] section . When you press your assigned button, that should call LuaSet to set flag 211, which is the flag the script is waiting on for action. It then does its stuff (i.e. gradually applies the brakes) until you release the button, which should be assigned to LuaClear for flag 211, which will then gradually release the brakes.

John

Link to comment
Share on other sites

3 minutes ago, atf said:

ive set it as in the picture , but i really dont know what to do .

?

If you have set it as in the picture, what more is there to do?
Have you tried it?

As I said, your ini showed you assigned to LuaDebug and Lua, not LuaSet and LuaClear, as specified in the instructions.

You are obviously not following the instructions assigning to those controls....

I'm sorry, but I cannot help you if you are not following instructions or doing as I advise. It really isn't that complicated.

Can you explain what you are having difficulty with, or why you 'really dont know what to do'?

I will be finishing for the day/weekend in 10 mins....

Link to comment
Share on other sites

8 minutes ago, atf said:

i still dont know how to set it in the config .

You don't need to touch/edit your FSUIPC7.ini file manually - you already have the script starting from your [Auto] section. Just assign your buttons as shown in the diagram (your joystick and button number will be different, the rest the same). And remove those other assignments which are not needed.

Link to comment
Share on other sites

solved it , thank you .

the issue was that i hadn't added the Auto section correctly and then everything cascaded . 

please accept my humble apologies for being dumb , and thank you again for helping me out , have a nice weekend.

10 minutes ago, John Dowson said:

You don't need to touch/edit your FSUIPC7.ini file manually - you already have the script starting from your [Auto] section. Just assign your buttons as shown in the diagram (your joystick and button number will be different, the rest the same). And remove those other assignments which are not needed.

 

Link to comment
Share on other sites

1 minute ago, atf said:

solved it , thank you .

the issue was that i hadn't added the Auto section correctly and then everything cascaded . 

Well, your [Auto] section was fine in the ini you posted:

Quote

[Auto]
1=Lua Smooth_Brake

Your issue was certainly in the button assignments, which were assigned to LuaDebug and Lua, and not LuaSet and LuaClear, as specified in the instructions and as I have been trying to tell you...

But nevermind. Glad you finally got it working, although you still don't seem to understand what your issue was... It helps to try and understand how the lua file is working!

Enjoy your weekend.

Cheers,

John

Link to comment
Share on other sites

  • 1 year later...

What happens with the Maddog X? Have you tried logging what the lua is doing to see what the issue is with this aircraft?
I don't have the Maddog X so cannot really help you, but logging the offsets suggested in the initial post, as well as using lua debug logging, should show you what is happening - especially if you compare the log output to that produced with an aircraft where the script is working as expected.

John

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.