Torque model for rusefi

It's all about the code!
Post Reply
Posts: 3
Joined: Mon Aug 29, 2022 4:09 pm
Github Username: DetroiHP

Torque model for rusefi

Post by DetroitHP »

Hello everyone!
My name is Georgii, and i worked as an ems calibration specialist with Bosch MED ECU. I've asked Andrey for help with my current project, and we've found, that i could be useful for your project. We talked to Andrey and he asked me to write and article, were i make an assumption about torque structure and model, which could be easily implemented in rusefi and calibrated by everyone. Today we will not discuss the torque structure question, because i don't have enough data about your software, so i will talk just about torque model.
I've built a simulink model using my knowlege in this theme and somehow tested it. So, i hope you will enjoy this article

This article is written to explain how people can implement simple torque model in the aftermarket EMS to work with ESP and TCU.
I have to apologize for such «dirty» and barely watchable Simulink models. I’ve had limited amount of time to do them during my vacation.
1. Why do we need torque structure?
Torque structure is very convenient language for ECUs in the car and for internal EMS functions like low idle governor, rpm and speed limiters, traction control, drivability functions etc.
Without this language, coordinating all the functions and other ecu’s requests in the throttle body and ignition angle coordinates will be very difficuilt to live with.

2. Difference between torque structure and torque model.
Torque structure is made to coordinate all torque requests and make single torque request for air and ignition paths, which will be later transmitted to the torque model.
Torque model makes 2 tasks – it makes straight (torque request to volumetric efficiency and ignition angle request) and inverse (actuators to torque) torque conversions.
image.png (99.38 KiB) Viewed 349 times
Picture 1. Relationship between torque structure and model

3. Physics of the process.
There are 3 main variables to work with on the gasoline engine:
• Air mass in cylinder
• Ignition angle
In this article we won’t talk about working with AFR, because it doesn’t affect engine torque so much, but it can cause misfiring and engine damage. So we have to choose AFR mainly to decrease the average combustion temperature.
3.1. Air mass vs. Torque
Here the relationship is quite simple - more air means more torque.
It is worth mentioning 2 things:
• From the minimum the air mass is limited by the minimal pressure in the intake. If we will have too low pressure inside the manifold – engine can suck the oil threw valve stem seals and PCV system.
• From maximum air mass is also limited by torque and durability limits. If we will suddenly apply too much torque to some engine or transmission components – they can be damaged.

3.2. Ignition vs. Torque
Here the relationship is a bit more complicated.
From the top the ignition efficiency can be limited by knock limit (can be not), from the bottom we have the combustion limits – it means, that if we will tune the angle too low the engine can start misfiring.
Basically we can make the assumption:
• Retarded ignition = less torque
• Advanced ignition = more torque
Remark: The optimal ignition angle means the value of ignition angle, which makes the maximum torque in this exact working point. Mainly depends on the air charge and the engine speed.
image.png (111.13 KiB) Viewed 349 times
Picture 2. Ignition sweeps on 750 and 2520 RPM.
On the picture 2 is shown, that sometimes it is impossible to rich the optimal angle due to knock limitations. In OEM EMS the are 2 different ignition angle tables for optimal and maximum ignition limits and the efficiency is interpolated between them. But in the model, which will be further described we will make the assumption that efficiency at maximum possible angle = 1, so there will be one table for optimal ignition angle, which has 100% efficiency to make it possible to tune it on simple hub or roller dyno without using any type of rocket science.
image.png (159.44 KiB) Viewed 349 times
Picture 3. Ignition angle efficiency curve.
On picture 3 is the ignition angle efficiency curve. On x axis is ignition angle offset from optimal angle. If the optimal and current ignition angles are known, it is possible to calculate current torque using this single curve, and the curve will be sufficient for every operation point of the engine. This curve is individual for every engine, but it is easy to find on the test bench.

3.3. Lambda efficiency
It is not managed by torque model, but it is taken into account.
image.png (50.61 KiB) Viewed 349 times
Picture 4. Lambda efficiency curve.
There is also one other way to govern torque: turn of one or more cylinders, but based on my experience people often don’t want to work in this direction, so this topic will not be discussed in this article. But if you will ask me - i could explain it.

4. Torque model.
Torque model itself consists of 2 main blocks: Ignition and volumetric efficiency requests calculations and the current torque calculation blocks.
image.png (62.04 KiB) Viewed 349 times
Picture 5. Overview of torque model. Top: current torque calculation block. Bottom: requested VE and ignition angle calculation block. On the left: test scenarios for model testing.

To make things simple and to make this system to work «out of the box» I’ve made all the torque calculations in relative torque:
Relative torque(%) = absolute torque(NM)*100%/maximum torque(nm)
So just changing the ignition tables and one parameter (maximum torque) all system will work somehow.

4.1. Current torque calculation.
Basic idea behind current torque calculation:
Flywheel torque = Indicated torque – losses
Losses = f(coolant temp, VE, RPM, ambient pressure)
Indicated torque = Optimal torque * ignition efficiency * Lambda efficiency
image.png (44.81 KiB) Viewed 349 times
Picture 6. Current torque calculation.

There are 5 curves in this model:
• Optimal torque under normal conditions table – it describes how much torque engine should give under maximum ignition efficiency and lambda=1. X – rpm, Y – VE, Z – relative torque. This table is also individual for every engine
• Basic ignition angle table – ignition table, which tells with which angle engine riches its maximum efficiency under normal conditions (lambda = 1). X – rpm, Y – VE, Z – ignition angle. This table is very individual for every engine and should be picked on dyno with possibility to fix the RPM and good air blower.
• Basic lambda efficiency table – tells how much AFR effects on torque. X – lambda setpoint. This table is pretty similar for all engines. So it doesn’t really worth it to waste your time calibrating it.
• Lambda ignition angle correction – tells how much should ECU correct the ignition angle based on AFR in order to maintain the same ignition efficiency. This characteristic is pretty same for all modern engines (+- 1.5 degrees between the engines)
• Delta ignition angle efficiency – tells us how efficient is the current ignition angle, comparing with the basic angle. This curve is individual for every engine, but it differs not so much, based on my experience. I could be wrong, because I worked only with the engines, which were made in Russian Federation, and they had pretty same cylinder dimensions and combustion chamber configuration. Calibration procedure: You have to find the operation point, on which the most efficient angle is not limited by knock limit. Than you have to freeze the RPM on the test bench and freeze the VE request. After that move the angle down and measure the torque. After that you can calculate the efficiency for each angle offset, comparing current torque and maximum possible torque for this exact operation point.

4.1.1. Torque losses calculation.
image.png (64.13 KiB) Viewed 349 times
Picture 7. Torque losses calculation.
Torque losses calculation is based on 3 tables:
• Torque losses under normal conditions
• Coolant temperature correction
• Altitude correction.
All these tables do not differ much between the engines of one era. VW 1.4 tsi and Mercedes 5.5 AMG have pretty same table. But just in case I will discuss the two calibration procedures:

Procedure 1(chip and not as exact):
• Measure the coastdown on Neutral gear from 140kph.
• Calculate the power of chassis lossess for every speed.
• Measure the coastdown from 140kph with engaged gear and the turned off fuel on fixed throttle body position (5%, 10%, 20%....100%).
• Calculate power of losses for each run
• Engine power of losses = Losses on engaged gear – Losses on Neutral.
• Calculate torque from power
• Extrapolate losses to the all powerband
Procedure 2(not as chip, but more exact):
• Measure the fuel and air consumption as accurate as possible during the dyno runs
• Calculate BSFC form fuel consumption and other data
• Calculate average indicated torque
• Compare indicated torque and measured torque
• Losses = Indicated torque – Measured torque
• Make the table
image.png (57.24 KiB) Viewed 349 times
Picture 8. Overview of current torque calculation.
As it’s shown on pic.8 – after all the things we sum all the indicated torque and losses, then calculate absolute torque from reference torque using the multiplier. This is everything, that could be told about current torque calculation in this exact implementation.

4.2. Volumetric and ignition setpoints calculation.
The torque requests for air path and ignition path are separated for gasoline engine because there are some situations (p-part of idle governor, gearshift, traction control requests), when there is no sense to move the throttle. Air has too much inertia and it is hard to predict, and the speed of change of VE is much slower, than gearbox torque request, or TRC torque request. This decision allows us to govern torque more accurate and fast.
image.png (63.12 KiB) Viewed 349 times
Picture 9. Overview of calculation process for VE and ignition angle requests.
There are 5 tables involved in this calculation:
• Delta ignition to calculate the delta between optimal and requested angle, based on the requested efficiency. This table is the exact table, which was used to calculate efficiency from difference between current and optimal ignition angles, but table data and breakpoints are inverted. There is no need, to calibrate it, just invert the table from current torque calculation
• Minimum ignition angle – This table is individual for every engine. It can be calibrated without dyno: just set the VE and decrease the ignition angle, until lambda will start to wiggle on lean side, than take 2-3 degrees back, and this is your value. Caution: During these measurements you have to carefully watch EGT and catalytic converter temperature, because you can easily overheat something. So I recommend you not to drive the car yourself during the measurement process.
• VE request table – this table tells us, how much VE is needed to get torque request in this operation point. This table is simply the inverted basic torque table.
• Maximum VE – it is your volumetric efficiency limit to avoid its damage.
• Minimum VE – it is your minimum volumetric efficiency. This table is calibrated during coastdowns. The goal of limiting minimal VE is to avoid pressures below 0.35bar(abs) in the intake manifold. This value can vary from engine to engine. I recommend you to perform this measurement on the stock car via UDS, to see which pressure is suitable for your excact engines.

Further requested VE could be transmitted to the air model, or you could use PID, which uses difference between requested VE and current VE to govern the throttle body

Posts: 2
Joined: Wed Sep 21, 2022 12:25 am
Github Username: kylerwinters

Re: Torque model for rusefi

Post by kylerwinters »

This definitely neededs to be implement with torque-based chassis. I'm currently using a maxxecu with a LS swapped 2008 BMW M3 with M3 DCT and it drives not so well due to the lack of somewhat accurate torque calculations.

I was planning on developing a torque calculation based on what other ECUs like EMTRON does, to fix the DCT transmission shifting issues. This would also integrate the MSR and other torque requests from the chassis over canbus with a custom module for my Maxxecu setup. However, it would be simpler to write the code directly in the ECU. I would be happy to move over to Rusefi if we can get this torque calculation project going! I'm glad to see that we have an expert on here to hopefully help us on the math side of things!

I can write all the needed code to get the E9x/E60 BMW chassis working plug and play over CANBUS with rusefi along with the highly desired e9x M3/335is DCT transmission. My car would be a pretty good tester of an OEM-like torque control strategy since it would integrate a TCU that requires accurate torque and the MSR and other torque control from the M3 DSC. I think this ECU could be pretty popular with E9x/E60 LS swap crowd.
I'll comment with more info tomorrow.
Last edited by kylerwinters on Wed Sep 21, 2022 10:55 pm, edited 1 time in total.
User avatar
Site Admin
Posts: 13134
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: Torque model for rusefi

Post by AndreyB »

kylerwinters wrote:
Wed Sep 21, 2022 12:51 am
if we can get this torque calculation projector going!
Would not realistically start until something changes, like additional contributors show up or get hired. First step is gap analysis and rough road map of what needs to be added in what reasonable sequece to get torque model implemented.
Very limited telepathic abilities - please post logs & tunes where appropriate -

Always looking for C/C++/Java/PHP developers! Please help us see
Posts: 3
Joined: Mon Aug 29, 2022 4:09 pm
Github Username: DetroiHP

Re: Torque model for rusefi

Post by DetroitHP »

we could try to generate C-code from the model i've made. But i don't know if simulink can generate C or C++ code, which suits your other code, but it's worth trying.
If it will be possible to integrate generated code in your project - i could develop this model further and we could make the implementation of this thing in your project.
User avatar
Posts: 3733
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: Torque model for rusefi

Post by kb1gtt »

Is scilab of interest in this effort? I see this review.
Welcome to the friendlier side of internet crazy :)
Posts: 2
Joined: Wed Sep 21, 2022 12:25 am
Github Username: kylerwinters

Re: Torque model for rusefi

Post by kylerwinters »

What do you think of the way EMTRONs torque management is implemented?

It seems to be pretty simple and at the same time looks like it would work very well. Seems very easy to tune. Looks like motec uses the same approach.

I'm all for a complex torque management system. It'll make an OEM implementation drive very well. However, if the complexity of the torque model is preventing this project from continuing then maybe a simpler model might be more favorable.
Posts: 3
Joined: Mon Aug 29, 2022 4:09 pm
Github Username: DetroiHP

Re: Torque model for rusefi

Post by DetroitHP »

I've written nearly the same thing in the article above, that was made by Motec and other ecu manufacturers.The basic idea is everywhere the same - torque = indicated torque*current efficiency minus torque losses.
And the tables are also the same - basic air table, ignition angle table, ignition retard gain.
So maybe it's my fault - i've descibed the things more complicated, than they actially are

To make the described algorythm work good enough you have to calibrate 1 table - basic ignition(you will do it anyway in every ecu) and one constant, which transfers relative torque to metric torque. Other tables are pretty same for all cars. If you want more precision - you can calibrate losses and ignition efficiency curve. Finally - if you want to make broad band of ignition angle torque governor - you could calibrate min.angle table. All these calibrations can be performed in 1 day on dyno(basic ignition table and ignition efficiency) and 2 days on the road(min.ignition and losses), if your car will not be broken during calibration.

It's a bit more sophisticated in OEM ECU's, so i didn't even tried to fit it here, because it doesn't worth wasted time, needed for its calibration, if you are not making precise product and don't have billions to waste.
Post Reply