Sign up for our newsletter! 
Home News Products Downloads Forum Distributors Store Contact Us
PPE User Forum
May 23, 2013, 03:57:48 am *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1] 2  All
  Print  
Author Topic: Scripts for Torque and HP ?  (Read 14216 times)
0 Members and 1 Guest are viewing this topic.
TurboCat
Newbie
*
Offline Offline

Posts: 11


View Profile
« on: August 03, 2007, 07:34:54 am »

Hello there,

I'm not releasing a new script here - I frankly would not be able to write one - but I started wondering if it was technically possible to write a couple of scripts to calculate Instantaneous torque output and instantaneous horsepower output. I was able to find the math to convert torque to HP and vice versa, but couldn't find anything to derive say, torque from vehicle speed or RPM and using some time factor. Any ideas or anybody willing to give it a try ?

Thank-you.

TC
Logged
BlueJadeSS
Newbie
*
Offline Offline

Posts: 4


View Profile
« Reply #1 on: August 08, 2007, 11:54:57 am »

Torque is a factor of rotational force, therefore calculating torque from vehicle speed would require the amount of drag from the tires and from the air speed to be factored in. This is quite impractical because there is not real good way to come up with this factor consistently. I do know that the autotap program with the enhanced paramters supports engine torque (The computer calculates something from the transmission to get this parameter) maybe its possible to pull this from the engine computer, that would be much more reliable
« Last Edit: August 08, 2007, 04:24:15 pm by BlueJadeSS » Logged
Mr Whippy
Newbie
*
Offline Offline

Posts: 18


View Profile
« Reply #2 on: February 22, 2008, 03:41:07 pm »

Just FYI and for reference

power (net) = mass x acceleration x speed

We have speed, and we can input mass manually

Acceleration can be done by rate of change of speed
current speed - speed 1 frame ago / time (gap between frame times)

Now we have instantaneous net power


Now use engine rpm, input wheel rolling circumferance (just tyre dimensions would work too), and speed to calculate overall reduction ratio

Now just use net power at wheels in > torque = power / rpm (wheel speed from road speed and rolling circumferance) to get net torque at wheels, and then reduce by overall reduction ratio to calculate net torque effective at engine...

Aero and tyres are easy, transmission is best done as a self-input variable % addition.


Just need to edit in your specific variables to the script (weight, tyres, expected losses in drivetrain, aero Cx and area etc)


I will make one as it's a really good idea and simple maths Smiley

Dave
Logged
jdtrites
Newbie
*
Offline Offline

Posts: 22


View Profile
« Reply #3 on: February 22, 2008, 08:20:35 pm »

I just simply fitted the manufacturer's torque curve to a series of functions (three in fact) that relate to RPM.  Then assume the manufacturer's curve is at 100% engine load.  I then use the RPM to calculate the torque at 100% engine load, then use the Percent Engine Load and multiply it by the max torque for the specific RPM. That approximates the instantaneous torque.  Horsepower is just Tq*RPM/5252.
Logged
BrianP
Administrator
Hero Member
*****
Offline Offline

Posts: 1314


View Profile
« Reply #4 on: February 25, 2008, 11:55:22 am »

If you guys end up creating any useful scripts, and think they may be beneficial to others, I would be interested in including them with the software install. Just let me know if it's ok to do so when you post up the scripts.
Logged
Mr Whippy
Newbie
*
Offline Offline

Posts: 18


View Profile
« Reply #5 on: February 25, 2008, 12:21:39 pm »

//Define PID variables
///*
var vSpeedU = Obdii.GetPidValueMetric(“SAE.VSS”, Obdii.CurrentFrame – 1);
var vSpeedV = Obdii.GetPidValueMetric("SAE.VSS")

var vTimeU = Obdii.GetCurrentTime(Obdii.CurrentFrame - 1);
var vTimeV = Obdii.GetCurrentTime();
//*/

//Test PID inputs
/*
var vSpeedU = 22.22   // 50mph
var vSpeedV = 31.11   // 70mph

var vTimeU = 20      // 20
var vTimeV = 25      // 25 50-70 in 5s
*/

//Input details (SI metric)
var vMass = 1131   //kg

//Using: power = mass x acceleration x speed

var dV = vSpeedV - vSpeedU
var dT = vTimeV - vTimeU
var vAcceleration = dV / dT

vNetPowerWatt = vMass * vSpeedV * vAcceleration

vNetPowerKWatt = vNetPowerWatt * 0.001
vNetPowerBhp = vNetPowerKWatt * 1.359

Obdii.PidValue.English = vNetPowerBhp
Obdii.PidValue.Metric = vNetPowerKWatt




Not 100% yet, with test inputs it works ok though (not been out to the car to test the readings for what I want (is that syntax even right for the PID time -1 frame??))

Not sure on the timestamp format, afaik it's milliseconds, so I'd need to multiply that by 1000 to get SI units for time if it's not right.


Feel free to use the script Brian, anything to get more people interested in this software (big fan myself Smiley )

When I've made sure this works I'll add inputs for tyre/wheel size (to get rolling circumferance), and an rpm monitor, then we can in theory get net instantaneous torque...

Then adding simple aero and tyre drag var's and a rough losses for the drivetrain we should be able to get a pretty good flywheel figure (gross bhp/torque)



Will have a play with it for definate in the car. Shame we can't 'simulate' these away from the car as this one needs wheel speed to test Smiley

Also I think this needs divide by zero protection (ie, when we stop the car will it error?)


Cheers

Dave
« Last Edit: February 25, 2008, 12:24:44 pm by Mr Whippy » Logged
BrianP
Administrator
Hero Member
*****
Offline Offline

Posts: 1314


View Profile
« Reply #6 on: February 25, 2008, 01:08:10 pm »

Hi Dave,

You should use this to get the timestamps for the speed:

var vTimeU = Obdii.GetPidTimeStamp(“SAE.VSS”, Obdii.CurrentFrame – 1);
var vTimeV = Obdii.GetPidTimeStamp(“SAE.VSS”);


Your current script will fail when it calls Obdii.GetCurrentTime() when it tries to pass it a parameter. Obdii.GetCurrentTime() returns the current time since data logging started. You are really after the PID time stamps for speed.

The time is in milliseconds.

-Brian
Logged
Mr Whippy
Newbie
*
Offline Offline

Posts: 18


View Profile
« Reply #7 on: February 25, 2008, 02:59:32 pm »

//Define PID variables

var vSpeedU = Obdii.GetPidValueMetric("SAE.VSS", Obdii.CurrentFrame – 1);
var vSpeedV = Obdii.GetPidValueMetric("SAE.VSS");

var vTimeU = Obdii.GetPidTimeStamp("SAE.VSS", Obdii.CurrentFrame – 1);
var vTimeV = Obdii.GetPidTimeStamp("SAE.VSS");


//Test PID inputs

//var vSpeedU = 22.22   // 50mph
//var vSpeedV = 31.11   // 70mph

//var vTimeU = 20      // 20
//var vTimeV = 25      // 25 50-70 in 5s


//Input details (SI metric)
var vMass = 1260

//Using power = mass x acceleration x speed

dV = vSpeedV - vSpeedU
dT = vTimeV - vTimeU
vAcceleration = dV / dT

vNetPowerWatt = vMass * vSpeedV * vAcceleration

vNetPowerKWatt = vNetPowerWatt * 0.001
vNetPowerBhp = vNetPowerWatt * 0.001359

Obdii.PidValue.English = vNetPowerBhp
Obdii.PidValue.Metric = vNetPowerKWatt



All seems ok apart from the nested -1 frame step part... getting the following error

"EXCEPTION 104:SyntaxError: missing ) after arguement list"

Not sure as I copied yours and the help file syntax for Obdii.CurrentFrame perfectly...


Is this because I'm not actually running it in the car... just pressing Test Script button right now.

Thanks

Dave
Logged
BrianP
Administrator
Hero Member
*****
Offline Offline

Posts: 1314


View Profile
« Reply #8 on: February 25, 2008, 05:53:18 pm »

Wow, I just spent about 2 hours trying to figure this one out...  Embarrassed I was debugging deep within the Javascript engine, only to find the problem was actually much simpler (and not a bug in our software Smiley).

As it turns out (at least in my web browser), if you copy and paste that code into the editor, it turns the minus character '-' into the unicode 0x0096 character (which looks the same as the minus, but isn't). When this happens, it creates the syntax error you are seeing. To fix it, just delete the minus and type it in again.

Let me know if that works for you.
Logged
Mr Whippy
Newbie
*
Offline Offline

Posts: 18


View Profile
« Reply #9 on: February 26, 2008, 02:12:49 am »

Haha, doh. Sorry about that Brian.

I had re-typed alot of the code (the " 's for example changed, so needed re-doing), and I copied the actual syntax string from the help file (which also used the web " 's once into the code window)

The ONE thing I didn't do however was re-write the minus sign.

I guess this is the bad thing about copying/pasting code.

Thanks for your time working this out, I will work on this script in my free time and hopefully get a nice torque figure, and with more variables add expected losses calc'd from speed to get closer to gross power/torque figures Smiley

Thanks

Dave
Logged
Mr Whippy
Newbie
*
Offline Offline

Posts: 18


View Profile
« Reply #10 on: February 26, 2008, 07:16:05 am »

Hmmm...

Tried to run it at lunch time and got these outputs...

1.#QO

SAE.VSS was recording fine in km/h, so I am thinking that the time recording wasn't going to plan.

I'll have to write a small test script that just displays the time step from current frame to last frame and see if that works.


Really hard to diagnose this as well since you need to be rolling to get a readout... might try do the same kind of thing with a variable that works at a standstill like rpm in the place of speed Smiley


Will post more progress later.

Dave
Logged
BrianP
Administrator
Hero Member
*****
Offline Offline

Posts: 1314


View Profile
« Reply #11 on: February 26, 2008, 10:56:22 am »

When you are debugging this, keep in mind that the very first run has no "Obdii.CurrentFrame - 1". So when you ask for that value, it gives you the first frame.

Also, it helps debugging if you print some of your variables out. Use the Obdii.ConsolePrint() function to display the variables to the console.
Logged
Mr Whippy
Newbie
*
Offline Offline

Posts: 18


View Profile
« Reply #12 on: February 26, 2008, 11:34:38 am »

Hehe, already done and considered Smiley

Was just thinking about the syntax of the -1 request as I walked in the door 5 mins ago.

I will also print some outputs to check whats going on at each stage...!

Thanks

Dave
Logged
Mr Whippy
Newbie
*
Offline Offline

Posts: 18


View Profile
« Reply #13 on: September 12, 2008, 07:26:52 am »

Just come back to this and have managed to get it working nicely on a graph plot (with the if statement to set var's on first frame and not get NaN's or div by 0)

Right now I have added the following variable inputs:

vehicle curb weight (sans full fuel load as per spec for curb weight, basically the car ready to drive except just reserve fuel)
vehicle fuel tank size
vehicle fuel tank % full
vehicle fuel density (probably make this a toggle for diesel/petrol true/false thingy)
passenger weight
luggage weight

That should get you an easy to input weight setup, ie, you weigh the car, know your own weight, maybe have luggage/kit onboard, and you can get quite accurate just moving the % fuel tank value to, so if you have half a tank add 0.5 variable...

So thats a nice way to try be consistent and accurate with the weight input.


Then I've added:

tyre width, profile, tyre diameter OEM
tyre width, profile, tyre diameter corrected (for what you have fitted, because the speed sensor is reading for OEM tyre size)

speedo correction factor (another correction factor, you might set this using GPS, to get the actual speed the OBD is sending the script accurate to real life)


Then I've added:

cross sectional area
coeff of drag
tyre rolling coeff

then I've calc'd the power losses through aero and tyre drag for the given speed (once corrected, and using the total mass)

I've calc'd net bhp, then added these losses to get a rough wheels figure.



My next step, after a bit of testing, is to tidy it all up so it's neat and tidy with the variable names all clearly defined/commented at the top, then add a new section.

Using the corrected speed, and the wheel correct rolling circumferance given, I will calculate the speed of the diff (have a final drive input too), and so for at least a 2wd vehicle, i can calculate the average drivetrain speed and use a columb friction to add 'losses' here too, using a friction input value.

IF I were really tempted I could record engine rpm (slows it down a bit too much on my 1999 OBD setup for super smooth graphs), then I could calculate the drivetrain speeds in two different areas.
You could then do some of your own maths, doing coastdown's and recording the power loss vs rpm of clutch up and down, of the drivetrain components vs speed, and simply add the correct friction (torque) to the system to simulate that too.


It's already giving pretty accurate figures for my car... you just have to be on a flat road Smiley

Dave
Logged
phuz
Newbie
*
Offline Offline

Posts: 20


View Profile
« Reply #14 on: October 08, 2008, 10:37:32 am »

Well, I tried to run this script, and I just get a returned value of "1" the whole time.  I have both the SAE.VSS and SCRIPT.BHP enabled.

Maybe this helps....When I do test script, instead of getting 0, like I should, I get "PidValue.Engilsh = 1.#QNAN" and same for Metric.
« Last Edit: October 08, 2008, 10:42:33 am by phuz » Logged
Pages: [1] 2  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.145 seconds with 20 queries.
Home | News | Products | Downloads | Forum | Distributors | Store | Contact Us
Copyright © 2012 Palmer Performance Engineering, Inc. All Rights Reserved.