Sign up for our newsletter! 
Home News Products Downloads Forum Distributors Store Contact Us
PPE User Forum
June 20, 2013, 03:29:46 am *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Distance from speed and time?  (Read 4703 times)
0 Members and 1 Guest are viewing this topic.
faior
Newbie
*
Offline Offline

Posts: 2


View Profile
« on: September 14, 2009, 03:57:45 pm »

Yeah, what the title says.. Ive been trying to make some script which gives you this.. without success :/

Problem is, that it starts to minus things when speed starts to go down from the max reached. And this gives the readings like 1 kilometres -> 1.2 kilometres -> 1.1 -> 1.3 -> 1.0 etc.

Could someone give some example script maybe? Or is this even possible?
Logged
Weston@PPE
Administrator
Hero Member
*****
Offline Offline

Posts: 1742


View Profile
« Reply #1 on: September 15, 2009, 05:01:11 pm »

Could you please post this script? I would like to see what you tried to do.

It seems like it would be possible. The accuracy would depend on how often a new frame was recorded (because speed changes).

Here is what I threw together. Let me know if it works. In this script I am assuming that the script name was SCRIPT.DISTANCE. If you don't name it this, you will have to edit some parts of the script.


function GetRequiredPids()
{
   Obdii.AddRequiredPid("SAE.VSS");
}

var Speed = Obdii.GetPidValueEnglish("SAE.VSS");
var TotalDistance = 0.0;
var PrevDistance = Obdii.GetPidValueEnglish("SCRIPT.DISTANCE", Obdii.CurrentFrame - 1);

if(PrevDistance != null)
   TotalDistance = PrevDistance;

// We have our last distance travelled, and the speed. Calculate the time and distance traveled since then.
var LastTime = Obdii.GetPidTimeStamp("SCRIPT.DISTANCE", Obdii.CurrentFrame - 1);
var CurrentTime = Obdii.GetCurrentTime();

var TimeDiff = (CurrentTime - LastTime) / 1000; // Convert to Seconds.
Speed = Speed / 60 / 60; // Get Distance per Second

/* Hours / 60 = Minutes; Minutes / 60 = Seconds */

TotalDistance += TimeDiff * Speed;

Obdii.PidValue.English = TotalDistance;
Obdii.PidValue.Metric = TotalDistance * 1.609344; // Miles converted to Kilometers
« Last Edit: September 15, 2009, 05:13:17 pm by Weston@PPE » Logged
faior
Newbie
*
Offline Offline

Posts: 2


View Profile
« Reply #2 on: September 16, 2009, 12:35:26 pm »

Ahh! That works like a charm, thank you very much! Smiley

I think my script didnt work because of the missing "+=" thingy, I did have about the same code that yours is, except that. And I did have the problem too that it added too much to the total distance, because I just "distance + distance" instead of using totaldistance += speed * time.

But this is useful, thanks again.
Logged
Weston@PPE
Administrator
Hero Member
*****
Offline Offline

Posts: 1742


View Profile
« Reply #3 on: September 17, 2009, 05:29:34 pm »

What I did was calculate the miles per second traveled, and multiplied it by the time since the last calculation.

That same line could have been written like this:
TotalDistance = TotalDistance + TimeDiff * Speed

Or, you could even do this:
var DistanceDiff = TimeDiff * Speed;
TotalDistance += DistanceDiff; // (Or TotalDistance = TotalDistance + DistanceDiff;)


+= is just a shorthand way of adding something to a number.
Logged
archangele
Newbie
*
Offline Offline

Posts: 1


View Profile
« Reply #4 on: April 07, 2010, 11:44:23 am »

How do you bundle this into a script?
Logged
Pierre@PPE
Full Member
***
Offline Offline

Posts: 129


View Profile
« Reply #5 on: April 08, 2010, 08:39:02 am »

Hi.

To bundle this into a script do the following...

From the main menu of ScanXL, select Tools > Script Editor.
Press the New Script button
Press the Edit Script button
Copy the script test from the post above and past it into the Script Editor window (the bottom part) overwriting the example code.
Change the name to SCRIPT.DISTANCE and save.

That's the basics of it.
Logged
Pages: [1]
  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.14 seconds with 20 queries.
Home | News | Products | Downloads | Forum | Distributors | Store | Contact Us
Copyright © 2012 Palmer Performance Engineering, Inc. All Rights Reserved.