improved loco smoke

Discussion of rolling-stock creation & re-painting.

improved loco smoke

Unread postby tase » Fri May 27, 2011 7:16 am

hello.

playing with the engine and wagon scripts to enable MU sound & smoke, one side-effect was an EngineScript.lua with improved smoke generation.

specifically, the script now considers loco load (as seen by the prime mover, ammeter reading in effect) into smoke calculations and offers the
possibility of individualised smoke per locomotive.

looking at the script below, you will find the following constants that control smoke generation:

RATE:
this controls the overall smokiness of the exhaust. a low value like 0.01 will produce thick exhaust, something like 0.1 will produce nearly transparent exhaust.
realistic values are around 0.03 - 0.07, default is 0.04. if you set this to zero, the locomotive will spew maximum smoke regardless of conditions.
COL:
this controls the change in smoke color with load. more precisely, smoke produced under high load (high amperage) will be black (or nearly black, see below).
smoke produced under low load conditions will be a lighter color. a value of 0 will always produce dark smoke, 1 less so, 10 will produce light gray smoke darkening
only under highest load conditions. realistic values are around 3 - 6, default is 4. if you set this to zero, the smoke will be black regardless of conditions.
RPMCF and AMPCF:
this controls smoke generation at high engine RPMs and high engine loads respectively. for example, RPMCF = 0.1 and AMPCF = 0.9 will result in a locomotive
that smokes heavily under high load, but little at high engine rpms but low load. conversely AMPCF = 0.1 and RPMCF = 0.9 will produce a loco that will smoke heavily
at high engine rpms but little under load (starting a heavy consist on a hill, for example). the sum of AMPCF + RPMCF should be 1. if it is greater than 1, the exhaust
will create surges and puffs of smoke, like those produced by a hunting engine governor. realistic values are between 0 and 1 each, depending on what you want,
defaults are 0.3 and 0.7 for RPMCF and AMPCF.
BLNSS:
this controls the color of the smoke at low load settings. 1 is neutral gray smoke. less than 1 will create brownish smoke like on a lean-running engine, more than 1
will create bluish smoke like a worn engine that's burning oil. realistic values are between 0.8 and 1.2, 0 and 1 will produce yellow and purple smoke respectively.

IDLERPM, MAXRPM and MAXAMPS:
these control the conditions where maximum smoke is generated. you should set them to something sensible for your loco for best (realistic) results.

PUTTING IT ALL TOGETHER:
let's say you want to simulate a run-down piece of junk, a GP7 perhaps. first you should set RATE to somere around 0.02 for lots of smoke. COL should be in the 2 - 3
range for a nice thick cloud of soot, that is if you don't go after the leaking headgasket look in which case it should be 10 or more to simulate a steam rich exhaust.
RPMCF and AMPCF should both be set high, perhaps 0.5 and 0.7 for lots of smoke when starting and at road speed with those nice misadjusted governor exhaust
puffs. finally you could set BLNSS to 1.3 - 1.4 for a heavy oil drinker or perhaps 0.8 for a lean-runner.

alternatively, if you want to simulate a brand new GEVO, use a RATE of about 0.07, a COL of 5, RPMCF and AMPCF of 0.3 and 0.5 respectively and a BLNSS of 1. this
will produce a locomotive that will smoke little except under the heaviest load conditions.

or better yet, uncomment (remove the two dashes in front) these lines from function Initialise()
Code: Select all
-uncomment these to randomize smoke generation for each locomotive
   --RPMCF = math.random()
   --AMPCF = math.random()
   --BLNSS = 0.75 + (math.random() * 0.5)
   --COL = math.random() * 10
   --RATE = math.random() / 10

this will randomize smoke settings for each locomotive so you could have a healthy one and two sick as dogs. by default RPMCF and AMPCF vary between
0 and 1, BLNSS between 0.75 and 1.25, COL between 0 and 10 and RATE between 0.1 and 0.01. you can bias the values by adding a constant to the output
of the pseudorandom number generator (math.random() + 5 = [5..6]) or expand/contract the generation interval by multiplying or dividing with an appropriate
constant (see COL and RATE above).

i suggest creating a consist with 4 or more locos coupled with a buch of loaded coal hoppers on a ramp and using the randomization option described above. this
should give you an idea of the possible configurations.

have fun!

the script:
Code: Select all
--------------------------------------------------------------------------------------
-- Engine Script for controlling additional engines
-- RailWorks 2: Train Simulator
--------------------------------------------------------------------------------------
--adjust these to something sensible for your loco, defaults for ES44AC
IDLERPM = 350
FULLRPM = 1050
MAXAMPS = 2000

--this is the smoke generation rate, higher means less smoke, towards 0 means maximum smoke
RATE = 0.04
--this controls smoke discoloration at low power settings, 1 means dark black, higher is lighter gray
COL = 4
--this controls smoke generation at high RPMs, 0 means none, 1 means a lot
RPMCF = 0.3
--this controls smoke generation at high load (amperage), meaning as above
AMPCF = 0.7
--this controls the blueness of the smoke, 1.2 is bluish smoke, 0.8 is brownish smoke
BLNSS = 1.0

RPM_ID = 1709
RPMD_ID = 1710
AMPS_ID = 1711

function Initialise ()

-- Turn off "surge" at start.
   Call( "Exhaust:SetEmitterActive", 1 )

   gPrevRPM = 0
   gPrevRPMDelta = 0
   gPrevAmps = 0
   
   --uncomment these to randomize smoke generation for each locomotive
   RPMCF = math.random()
   AMPCF = math.random()
   BLNSS = 0.8 + (math.random() * 0.4)
   COL = math.random() * 10
   RATE = math.random() / 10

   Call( "BeginUpdate" )

end

function OnControlValueChange ( name, index, value )

   if Call( "*:ControlExists", name, index ) then

      Call( "*:SetControlValue", name, index, value );

   end

end

function Update ( time )

-- Get rpm values for this vehicle.
   rpm = Call( "*:GetControlValue", "RPM", 0 )
   rpm_change = Call( "*:GetControlValue", "RPMDelta", 0 )
   amps = Call("*:GetControlValue", "Ammeter", 0)

   --compute control values as ratio to max
   gCurRPM = (rpm - IDLERPM) / (FULLRPM - IDLERPM);
   gCurAmps = amps / MAXAMPS;

   exhaustrate = RATE - RATE * ((( gCurRPM * RPMCF ) + (( gCurAmps ) * AMPCF )))
   exh_col = (( MAXAMPS - amps ) / MAXAMPS ) * COL
   Call( "Exhaust:SetEmitterRate", exhaustrate )
   Call( "Exhaust:SetEmitterColour", exh_col, exh_col, exh_col*BLNSS )


-- If this is a player train and this vehicle is the driven one, then send
-- RPM values in both directions along train. Note the Driven control is set
-- by the simulation script, which only runs on the vehicle the player is driving.
-- Only send messages if values have changed.

   if ( Call( "GetIsPlayer" ) == 1 ) then

      if ( Call( "*:GetControlValue", "Active", 0 ) == 1 ) then
         if ( rpm ~= gPrevRPM ) then
            Call( "SendConsistMessage", RPM_ID, gCurRPM, 1 )
            Call( "SendConsistMessage", RPM_ID, gCurRPM, 0 )
         end
         if ( rpm_change ~= gPrevRPMDelta ) then
            Call( "SendConsistMessage", RPMD_ID, rpm_change, 1 )
            Call( "SendConsistMessage", RPMD_ID, rpm_change, 0 )
         end
         if ( amps ~= gPrevAmps ) then
            Call( "SendConsistMessage", AMPS_ID, gCurAmps, 1 )
            Call( "SendConsistMessage", AMPS_ID, gCurAmps, 0 )
         end
      end

      gPrevRPM = gCurRPM
      gPrevRPMDelta = rpm_change
      gPrevAmps = gCurAmps

   end

end

-- Core sim function executed if a consist message is received.

function OnConsistMessage ( msg, argument, direction )

-- If this is not the driven vehicle then update the controls for RPM values with the supplied data.

   if ( Call( "*:GetControlValue", "Active", 0 ) == 0 ) then

      Call( "Exhaust:SetEmitterActive", 1 )

      if ( msg == RPM_ID ) then
         Call( "*:SetControlValue", "RPM", 0, IDLERPM + ( FULLRPM - IDLERPM) * argument )
      elseif ( msg == RPMD_ID ) then
         Call( "*:SetControlValue", "RPMDelta", 0, argument )
      elseif ( msg == AMPS_ID ) then
         Call( "*:SetControlValue", "Ammeter", 0, MAXAMPS * argument )
      end

-- Pass message along in same direction.
      Call( "SendConsistMessage", msg, argument, direction )

   end

end
Last edited by tase on Sat May 28, 2011 3:45 am, edited 1 time in total.
tase
 

Re: improved loco smoke

Unread postby micaelcorleone » Fri May 27, 2011 8:48 am

I think Railsimulator.com would be interested in your scripts. Why don't you send them a mail: support@railsimulator.com

If they choose to use it we could have the improved smoke in every loco by default.

Nice discovery. !!*ok*!!
User avatar
micaelcorleone
 
Posts: 1668
Joined: Tue Oct 05, 2010 11:04 am
Location: Bavaria, Germany

Re: improved loco smoke

Unread postby Kali » Fri May 27, 2011 10:01 am

The E7 script I posted uses the difference between the throttle setting ( desired output ) and the RPM ( actual output ) for some things which is a fairly cheap hack way of simulating fuel flow and for old engines the amount of unburned crud :p; I did think about load somewhat, but actually the ammeter setting in RW just shows the applied tractive effort and is totally dependent on engine RPM which is ( unless you scripted it cleverly ) totally dependent on throttle setting. The ammeter reading falls as speed increases - this is back-EMF - the load at the generator ( and engine ) does NOT fall - in fact goes up - as speed increases in a DE with a load regulator. Kuju seem to have fallen into the same trap with the field divert idea :(

- Simple version - in the end the amount of work ( in this case tractive effort/speed ) a diesel locomotive does is dependent on the amount of fuel it's using, no matter what fancy transmission. To accelerate a train you have to have the same amount of tractive effort that the air/rolling resistance is taking up - which increases with speed - and *then* some more to accelerate.

Randomness in the smoke colour is a good idea though and it's good to see someone else scripting! it would be really good to adjust that nice work you've done to make it right :)

-Caveat: that is for DC traction motors, I have no idea how the control systems for squirrel-cage AC motors work - it would seem that as the magnetic field is always rotating faster than the motor cage there is no back-EMF. I would guess then that the generator ( alternator ) output - and thus engine load - goes up and down as a function of the slip in the motor, but they're still a bit of a mystery to me.
Last edited by Kali on Fri May 27, 2011 11:58 am, edited 2 times in total.
Kali
 
Posts: 1600
Joined: Mon Mar 14, 2011 1:00 am
Location: England-by-Sea

Re: improved loco smoke

Unread postby PapaXpress » Fri May 27, 2011 10:38 am

Thanks Tase. !!*ok*!!

I really like all the little tweaks coming out lately, but putting one of my many RL work hats on, I see an opportunity for scripts to be lost, merged incorrectly, or overridden mistakenly by the model owners who only want to do good. I see more pain than pleasure. Having said that, I am also very new to LUA scripting which I understand has been around for some time, so I have to wonder how all this is handled in other games. Are there "official" fan based script groups (for their respective games of course) which maintain a list and source of "master scripts"? Should we consider doing something like that here, or am I just thinking to broadly?

I am not trying to criticize anyone's efforts here. I just want to understand the logistics of how to best maintain all these custom scripts.
Image
"Just post some random unrelated text. We have members here who can help you with that." ~ Chacal
"When all else fails, read the instructions... if that doesn't work either, try following them." ~ Old Prof
Image
The Grade Crossing - Atlanta North Project - Virtual Rail Creations
User avatar
PapaXpress
 
Posts: 5147
Joined: Sat Oct 23, 2010 10:30 pm
Location: that "other" timezone

Re: improved loco smoke

Unread postby Samwolf » Fri May 27, 2011 10:43 am

@PapaXpress

Check your PM. !*cheers*!
If God had intended for man to fly, He wouldn't have given us the railroads.
User avatar
Samwolf
 
Posts: 762
Joined: Mon Aug 30, 2010 6:57 pm
Location: South Carolina, CSA

Re: improved loco smoke

Unread postby Kali » Fri May 27, 2011 12:57 pm

PapaXpress wrote:Thanks Tase. !!*ok*!!

I really like all the little tweaks coming out lately, but putting one of my many RL work hats on, I see an opportunity for scripts to be lost, merged incorrectly, or overridden mistakenly by the model owners who only want to do good. I see more pain than pleasure. Having said that, I am also very new to LUA scripting which I understand has been around for some time, so I have to wonder how all this is handled in other games. Are there "official" fan based script groups (for their respective games of course) which maintain a list and source of "master scripts"? Should we consider doing something like that here, or am I just thinking to broadly?

I am not trying to criticize anyone's efforts here. I just want to understand the logistics of how to best maintain all these custom scripts.


We do need something; I made some substantial changes to how the multiple unit engine rpm handling is done so you can couple different engines together and they'll all match RPM to the throttle setting ( somewhat ); on the other hand my smoke handling isn't as comprehensive as this, but if you use this script & couple an ES44 to a SD70, you'll lose the SD70 sound at high RPM because it's being told to rev too high.
Kali
 
Posts: 1600
Joined: Mon Mar 14, 2011 1:00 am
Location: England-by-Sea

Re: improved loco smoke

Unread postby tase » Fri May 27, 2011 2:51 pm

hello.

kali, you raise a point re traction motor amps vs engine load. however, this is why i also use engine rpm to compute the final value for smoke rate.

concerning script versions, what you need is revision control; this is a good starter: http://en.wikipedia.org/wiki/Revision_control
if you decide to go that way, i can offer help and advice setting up a cvs or svn repository as i've used them extensively.

finally, here's the updated version of "improved smoke" that now handles rpms and amps correctly across different brands of locomotives.
you need to edit IDLERPM, MAXRPM and MAXAMPS to match the locomotive you update.
and ofcourse, if anyone wants to use, modify or improve this script in whole or in part, you're welcome!

LE, fixed bug that would prevent smoke generation if engine was not part of player consist at session start
Last edited by tase on Sat May 28, 2011 3:46 am, edited 3 times in total.
tase
 

Re: improved loco smoke

Unread postby PapaXpress » Fri May 27, 2011 3:05 pm

tase wrote:concerning script versions, what you need is revision control; this is a good starter: http://en.wikipedia.org/wiki/Revision_control
if you decide to go that way, i can offer help and advice setting up a cvs or svn repository as i've used them extensively.


Would creating a SoureForge site make sense? I believe they use SVN.
Image
"Just post some random unrelated text. We have members here who can help you with that." ~ Chacal
"When all else fails, read the instructions... if that doesn't work either, try following them." ~ Old Prof
Image
The Grade Crossing - Atlanta North Project - Virtual Rail Creations
User avatar
PapaXpress
 
Posts: 5147
Joined: Sat Oct 23, 2010 10:30 pm
Location: that "other" timezone

Re: improved loco smoke

Unread postby tase » Fri May 27, 2011 3:11 pm

i theory yes; however sourceforge essentially offers a "one size fits all" service, even though they advertise it as highly customisable.

in the end, just try it and see if it works
tase
 

Re: improved loco smoke

Unread postby Kali » Fri May 27, 2011 6:46 pm

tase wrote:hello.

kali, you raise a point re traction motor amps vs engine load. however, this is why i also use engine rpm to compute the final value for smoke rate.



Well, the thing is the ammeter reading going up and down with speed doesn't change the load at all! if your motors generate 50A per mph, your ammeter is 3kA at 0mph and 1.5kA at 30mph the load on the engine is the same unless the load regulator is exciting the generator more to try & keep the tractive effort up, in which case the load will go up until it trips a field divert and then it starts over - but with a weaker field there's less back EMF, and so the ammeter reading goes up.

Dick Cowen has adopted the base engine script I posted here it seems; it was deliberately back-compatible with the stock script RSC uses by keeping the same behavior for the old message IDs. My smoke code is rather lazy :p
Kali
 
Posts: 1600
Joined: Mon Mar 14, 2011 1:00 am
Location: England-by-Sea

Re: improved loco smoke

Unread postby tase » Fri May 27, 2011 8:18 pm

ok, i understand
tase
 

Re: improved loco smoke

Unread postby BNSF650 » Fri May 27, 2011 9:38 pm

Do you have any photos? Or video of the new smoke?
Image
New Era of Train Simulation
User avatar
BNSF650
 
Posts: 2016
Joined: Mon May 31, 2010 10:27 pm
Location: Texas

Re: improved loco smoke

Unread postby tase » Sat May 28, 2011 4:10 am

here you go:
You do not have the required permissions to view the files attached to this post.
tase
 

Re: improved loco smoke

Unread postby captkilljoy » Sat May 28, 2011 4:11 pm

This is great thank you very much.
User avatar
captkilljoy
 
Posts: 45
Joined: Wed Feb 02, 2011 4:32 pm

Re: improved loco smoke

Unread postby ex-railwayman » Fri Apr 03, 2015 7:50 pm

Has anyone tried this modification in TS2015 please, people???

Cheerz. ex-railwayman.
i7 10700k 3.8GHz Eight Core CPU, Gigabyte Z590 AORUS ELITE AX, 32GB RAM, nVidia RTX3060ti 8GB, WIN10 PRO 64-bit. 10TB HDDs in total.
ex-railwayman
 
Posts: 1203
Joined: Tue Jun 22, 2010 6:17 pm
Location: Nottingham, England

Next

Return to Rolling-Stock Design

Who is online

Users browsing this forum: No registered users and 3 guests