Jump to content
The simFlight Network Forums
spokes2112

"Smoother" braking when only a button is available.

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")

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
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

×

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.