PDA

View Full Version : Simulating redline injection cut with a script - Would it be possible?


NRGz
27th February 2008, 19:06
Hi all

I've been trying to find any information about this in the forum, but unsuccesfully. That's quite strange since it would be a very, very easy and intuitive way of simulating the redline injection cut which modern electronic injections are able to work (if it's possible, which I don't know).

First of all, note the I've never tried to program a LFS script. I knew about the existence of the scripts, the Outgauge and all that stuff, but I've never felt the desire to customize or include any specific function into the game, and now I see that maybe it's quite late to start from zero :shrug:.

I wouldn't like you to consider this post as a "please-make-me-this-script-thanks", I think it could be something cool, realistic and maybe useful to have in LFS and that anyone could enjoy.

In the game, sometimes I tried to sham the throttle-cut when hitting the rev limiter just pressing the "I" button, which supposedly stalls the engine (or just cuts its virtual fuel supply :D), so when done repeteadly (smashing the "I" button), it looks like the engine is hitting the rev-limiter, [press "I" here] the ECU cuts the injection so the engine revs drop until a safe revs range [press "I" here], the ECU starts injecting fuel again according to the throttle position and go on....

What i'm asking myself is if there would be a way to do this automatically. Maybe a script or an external program via Outgauge which is able to read the rpms and, when the engine reachs the desired revs (maybe 500-800-1.000 rpms higher than when the red shift light lights up, this may depend on the car and would be selectable with a script), presses the "Ignition" key so the engine starts stalling, and then, once the engine revs drop below another desired number, starts the engine again. Or maybe it could be faked just starting the engine again after a certain time (some tenths, maybe.)

Well, I think that's all... Would it be possible to do it? :shrug:

Thanks in advance :)

Dygear
27th February 2008, 19:26
Yeah, I think this can be done. But only client site, you could not have it on mass with a server telling the client that they are revving to high and thus cutting their throttle. Could you by chance give me the value of each of the red lines for each of the cars?

JamesF1
27th February 2008, 19:40
Well thought out idea, I like it when people come in here not only with problems, but with solutions, too :D

NRGz
27th February 2008, 22:05
Thanks for reading, Dygear. Here we go, this are the official specs:

XRG - 7000 RPM

UF1 - 7000 RPM

RAC - 7000 RPM

XRR - 7500 RPM

FXR - 7500 RPM

XRT - 7500 RPM

RB4 - 7500 RPM

FXO - 7500 RPM

FOX - 7500 RPM

XFG - 8000 RPM

XFR - 8000 RPM

FZ5 - 8000 RPM

FZR - 8500 RPM

LX4 - 9000 RPM

LX6 - 9000 RPM

UFR - 9000 RPM

FBM - 9200 RPM

FO8 - 9500 RPM

MRT - 13000 RPM

BF1 - 20000 RPM (Yiiiha! ^^)


Well, about using it online, by the way we can use it when training offline. After we've got that working we may be able to start thinking in further projects such a making it work online =P

tristancliffe
27th February 2008, 22:13
Ah, a nice INSIM mod to make you slower, and to simulate rubbish rev limiters. Nice.

NRGz
27th February 2008, 22:37
Tristan, note that general road cars (such as the XFG or the XRG, for instance) with electronical injection systems cut injection the way we're trying to simulate here. If when using this mod your times get worse, I don't think it means that this is a worthless or rubbish mod but that the way you were driving previously was not the most real since the car didn't hit the rev limiter properly.

Anyway, we're not doing nothing more than changing the way the rev limiter is going to act, from a "just-keep-the-revs-there" to a "plink-plink-plink" way, which is more realistic when talking about street legal cars. And as that's what happens in real life, it would be more realistic. Also would be realistic, for instance, being able to mis-shift gears, but, hell, that would make you slower and it would be rubbish, huh? Calm down, this is just a racing simulator, the stopwatch times you're able to perform around a racetrack aren't the best of racing, as racing involves concentration, preparation, performance, knowledge of the vehicle you're racing with and, yes, a little bit of luck. And when you're able to keep all this under control is when you like to get astonished sometimes hitting the rev-limiter for pushing too hard, mis-shifting in that tough overtaking and listening the screams coming from your tyres when you have to apply full brakes to avoid the accident happening just in front of you.

Regards :)

_--NZ--_[HUN]
27th February 2008, 23:20
Tristan, note that general road cars (such as the XFG or the XRG, for instance) with electronical injection systems cut injection the way we're trying to simulate here. If when using this mod your times get worse, I don't think it means that this is a worthless or rubbish mod but that the way you were driving previously was not the most real since the car didn't hit the rev limiter properly.

Anyway, we're not doing nothing more than changing the way the rev limiter is going to act, from a "just-keep-the-revs-there" to a "plink-plink-plink" way, which is more realistic when talking about street legal cars. And as that's what happens in real life, it would be more realistic. Also would be realistic, for instance, being able to mis-shift gears, but, hell, that would make you slower and it would be rubbish, huh? Calm down, this is just a racing simulator, the stopwatch times you're able to perform around a racetrack aren't the best of racing, as racing involves concentration, preparation, performance, knowledge of the vehicle you're racing with and, yes, a little bit of luck. And when you're able to keep all this under control is when you like to get astonished sometimes hitting the rev-limiter for pushing too hard, mis-shifting in that tough overtaking and listening the screams coming from your tyres when you have to apply full brakes to avoid the accident happening just in front of you.

Regards :)

I see your point but I am not sure why is this so important, normally you won't rev the engine so high in a race so you don't hit the limiter so it doesn't matter how it works.
I think you don't have to tell Tristan what is racing, he may have more experience in it than you think :)

NRGz
27th February 2008, 23:29
;724049']I think you don't have to tell Tristan what is racing, he may have more experience in it than you think :)

Sure he does! I was not in the point to give "racing classes" to someone who could be my teacher, just wanted to offer my point of view about what we're trying to simulate here :thumb:

As you said, it may not be much important, but it could be a step more in the approach of a (even more) realistic racing simulator, since it's not the same hitting the rev-limiter and saying "Doh, I forgot to change at time, this doesn't accelerate more!" than "F**k, forgotting to change at time made me hit the rev-limiter, and that slowed me down!", as would happen in a real car. Anyway, this is just a try in order to see how it affects racing and the way you perform shifting during the race. :)

Dygear
28th February 2008, 04:53
I will take this under consideration. And the ONLY reason I am doing this is b/c you your self were willing to do some ground work (I know the RPM values of the cars, but I wanted to see if you was willing to do some leg work your self).

Dygear
28th February 2008, 05:09
Ok, the idea.

[Program:InSim] -> [Program:OutSim];
[Program:InSim] -> [Program:InSim:Key] -> [LFSScript];

The InSim Program starts things off, it will simply make the connection to the server so this whole thing can send commands to the console (I refer to the console as the area where you can type / commands into.) it will also be responsible for making the OutSim connection.

The OutSim Program gets things like Car information, and RPM information. When the RPM gets over red line, it will throw back to the InSim program that will send a key press for what ever key you bound the LFS Script to that will turn on and off your engine to simulate the hitting of the Rev Limiter.

The LFS Script it's self will simply be a script that turns on and off the ignition of the car.

Program Flow:
Live For Speed Client Start.
Live For Speed InSim Port Set.
InSim Program Start.
InSim Program Starts OutSim Connection.
OutSim Data is received about Car / RPM.
If Car->RPM is more then Car->RedLine
InSim Program Sends InSim Key Press Packet.
InSim Key Press Packet Activates LFSScript.


Anyone see any problems with this?

Hyperactive
28th February 2008, 07:18
I had a similar idea some time ago but with my method you would have modelled very simple engine/drivetrain damage by modifying the throttle/clutch/brake inputs directly. And brakes for a simple brake simulation. Playing some sounds, like brake squeel, missed gearshifts and all kinds of nasty sounds, just for offline experience :tilt:

Naturally the idea died off instantly when I searched for some base c++ files to start with. I was like omg, tcp ports, insim, communication omg :D

BlakjeKaas
28th February 2008, 11:42
Uhm, I don't want to ruin everything, but what if you shift when the car is turned off when you just hit the limiter?

AndroidXP
28th February 2008, 11:48
Uhm, I don't want to ruin everything, but what if you shift when the car is turned off when you just hit the limiter?
I don't see a problem...?

That said, wouldn't outgauge and sendkeys/directinput keystroke emulation be a much simpler approach than doing the whole insim stuff?

BlakjeKaas
28th February 2008, 11:59
Well, will it detect if the engine is off when I shift?
It would be disastrous if I shift and I can't accelerate.

AndroidXP
28th February 2008, 12:07
If you shift your RPM drop dramatically, so it immediately activates the engine again anyway.

The code must be something like this:


engine_off = false;
if (RPM >= max_rpm-50 && !engine_off) { //50 = safety margin
send('I');
engine_off = true;
}
else if (RPM < max_rpm-200 && engine_off) { //200 = adjust to how far you want the revs to fall before activating again
send('I');
engine_off = false;
}

pasibrzuch
28th February 2008, 12:49
Something tells me, that soon after someone will make this insim mod, Scawen will release new patch with ignition cut simulated 3 times better.
I keep Tristan with his words that he'll claim then that this is rubish feature that make us slower = )
But, if someone want to be even more clever, please make this insim ap to simulate second revlimiter at mid revs, used by rally cars to build up turbo pressure and have 100% of torque at lunch.

AndroidXP
28th February 2008, 12:54
But, if someone want to be even more clever, please make this insim ap to simulate second revlimiter at mid revs, used by rally cars to build up turbo pressure and have 100% of torque at lunch.That's technically impossible to do with InSim or any other external method, FYI.

pasibrzuch
28th February 2008, 13:48
So why you posted an example code how could it work then?
It is as hard changing 1 digit in source code (if it exist...)

Now the turbine is building pressure even when ignition is off, so it would work in patch Y.

ps. finally I managed to google the 'FYI' thing, because I always thought it means 'F**k You Idiot' :razz: and I was like "why people are so agressive nowadays...?"

AndroidXP
28th February 2008, 13:54
Now the turbine is building pressure even when ignition is off, so it would work in patch Y.It is? How odd.

mcgas001
28th February 2008, 14:01
Now the turbine is building pressure even when ignition is off, so it would work in patch Y.

I acutally have seen this too. If you drive a car upto X speed then hit "i", if you throttle the turbo boost still goes up, even tho ignotion if off. I think this could be a bug?

E: or this acutally ment to happen in a real car?

tristancliffe
28th February 2008, 14:12
Whilst there won't be much heat (the primary source of energy on an IC turbo), there will still be air pumped down the exhaust, which will tend to accelerate the turbo a bit. Is the rate of boost build up the same or lower with the engine off?

mcgas001
28th February 2008, 14:17
Whilst there won't be much heat (the primary source of energy on an IC turbo), there will still be air pumped down the exhaust, which will tend to accelerate the turbo a bit. Is the rate of boost build up the same or lower with the engine off?

Excatly the same from what i can see. on my test i got the XRT, Drove to 3rd gear (redline) pressed i then try'd accelerating, Just sounded like the car was still running. So yea excatly the same.

AndroidXP
28th February 2008, 14:25
Seems like the current turbo modelling just takes the amount of air being "processed"/pumped by the engine as energy source, disregarding the heat difference between actual burnt gasses and simply passing-through air. :shrug:

mcgas001
28th February 2008, 14:38
Seems like the current turbo modelling just takes the amount of air being "processed"/pumped by the engine as energy source, disregarding the heat difference between actual burnt gasses and simply passing-through air. :shrug:

Indeed, Does Scawen know this? or shall one of us make a bug report. :shrug:

pasibrzuch
28th February 2008, 15:02
I'm sure it was discussed somewhere in one of turbo lag and boost moddeling thread (http://www.lfsforum.net/showthread.php?t=4324)s, so it may be known for Devs.

tristancliffe
28th February 2008, 15:21
I would bet that Scawen knows about this, but the turbo model hasn't been updated for a long time (as it was close enough for most purposes, and certainly not the weakest link).

nlhans
1st March 2008, 12:16
To get a bit back to the rev limiter thing (and not the turbo's), this is not that difficult to achieve.

I've set up a similar thing for a school end project (at secondary school :D). I wanted to test my program (which is designed to be a cruise control and automatic gearbox and so on) whether the controls work.

What I've done is hook up the G25 to my program, so it gets the throttle and clutch input, and then hook up a virtual controller to the same programmer so it sends it through. This way I can add personal code to decide whether the program should took control or not. With Cruise Control, the user could set a speed, and my program calculates how much throttle there is required to maintain that speed. For automatic gearboxes it might be cool to have the clutch involved too for smooth gear changes.

So basically:

[Steering wheel G25] -> (Data: throttle, clutch, buttons etc.) [My program] -> (Clutch, throttle) [Virtual Joystick] -> [Live for speed]

instead of:
[Steering wheel G25] -> [Live for Speed]

Now, first: I'm not going to release the whole code (yet). The reason why is because this doesn't work on just any computer. You have to install the virtual joystick (which is in this case a 3rd party driver, and maybe lead to conflicts), set it up just fine, and the program code needs to be changed to make it work for other steering wheels as well. And then there is calibration: I've had some problems with this too, and it's still not completely solved.

Another reason (why I also don't release the full source code) is because I'm afraid of racing bots or other utilities that really start to make quick and good racing easier. As I just mentioned , I use it for a school project. It's only for demonstration purposes only. Like, I built a super fast shifter in the past. It listened to the shift LED which you have in game, and when it goes off it does a sort like power shift. In other words: shifting in 50ms completely automatically. Not very fair, and I think it's best to keep it just as a proof of concept.

Of course, I need to proof it. So I've added some replays of the 3 demo cars (only demo user :() with a rev limiter. I can set whilst driving by using steering wheel buttons.. Take a look at the throttle when it's limiting. It's repeatedly cut off. Just like the idea was here, cut the ignition off. Well, I cut the throttle of because I've the resources to do that (and don't have the hazards to work with annoying functions like SendKeys. If you use this, you can't chat and race at the same time, as there is constantly input going on).

An example of my code:

public void Tick(IGameData Data)
{
if (Data.RPM > this.LimitRPM * 100)// Is the RPM above the rev limiter RPM?
{
COut.Throttle = 0; // Cut of throttle
}
else
{
COut.Throttle = CIn.Throttle; // Use the input throttle from the normal steeringwheel
}
COut.Clutch = CIn.Clutch; // Clutch redirecting..
}
this.LimitRPM is a preset RPM (for example 80, that would make 8000 rpm). I can adjust this with my steering wheel whilst driving (a whole bunch of other code..).

COut and CIn are some libraries I wrote to listen and send clutch and throttle data.

When the Data.RPM (RPM from OutGauge) gets too high, the throttle just cuts of. Otherwise, the incoming throttle is just the same as the outgoing throttle. This isn't completely realistic, because in real-life it would be most likely to smash the throttle cable (as it might set it on and off like 5 times a second). But: it does work. See the replays (place them into dir data/spr/)

(Note, the formula car replay might seem not that exciting in the first place. Sorry for that, might make a better on soon. At the end though, I do have got the car bit crashed (Up side down), and played a little bit by changing gears, and pressing the break whilst letting it cut into the rev limiter. You see why the rev limiter is so inaccurate when it's in neutral, or any other situation which doesn't give the engine a lot of load.)