38 Replies Latest reply on Apr 20, 2017 10:00 PM by yyang

# How to calculate the time of an object movement from the speed depending on the time

Dear Forum Members,

I need to calculate the time how long objects have covered a distance D by using the speed depending on the time V(t) (in m/min) and the timestamp when the object is gone (starttime).

The speed is a PI Point. The timestamp when the object is gone is given by the starttime of the PI EF attached to the object. The EF endtime isn't the timestamp when the object has covered the distance.

The distance depends on the objects.

For example:

Object 1, D: 7,60m     PI EF Starttime: 01/12/2016 06:57:18

Object 2, D: 8,34m     PI EF Starttime: 01/12/2016 08:43:17

Object 3, D: 5,74m     PI EF Starttime: 02/12/2016 18:57:23

Is it possible to calculate it with PI-DataLink or with PI-Analysis ?

Thanks,

Best regards,

Nicolas

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hi

Wouldn't this simply be a matter of dividing the speed with the distance covered? Your result would be in minutes, which you can add to the start time using an expression analysis.

I assume you're using an event frame generation analysis to start the event frames. If so I would move the logics for that into an expression analysis and write the output to an attribute. Then use that output attribute to trigger the event frame. This means you have access to the timestamp of the event frame in your expression analysis by using Timestamp(MyOutputAttribute), which you can then use to add your resulting minutes from the calculation of time.

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hello Asle,

thank you for replying to my discussion.

Actually, I cannot divide the speed with the distance because the speed isn't constant. That's my difficulty.

For the moment, the PI EF are generated with PI EF GEN.

Thanks,

Best regards,

Nicolas

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hmm, that's what I thought

You'll have to calculate the distance travelled between each event in the speed tag then. Let's say you get 10 events in the speed tag during one minute (and they're not evenly distributed) you'll calculate each time period separately, and then you can use a TagTot-function for your intermediate calculation to totalize the movement across a given time period.

Things are made a bit complicated by the fact that you're generating EF's in the EF generator, but we can work this out by using OLEDB Enterprise to query the list of EF's and then pull this into PI System Explorer again using an AF Table.

1. Install OLEDB Ent on your AF Server, or "publish" it as a linked server on your SQL Server box.

2. Set up a table connection to the data source (PI System Explorer->Library->Table Connections)

3. Set up a linked AF Table and collect the list of EF's from a SQL query

4. Link this AF Table into your AF element by using Table Lookup data referenced attributes.

5. Use the timestamp (and possibly object movement and type found in the EF's) in your analyses for further calculation

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

I kept on thinking about this one, and it's probably not as straight forward as I thought.

Even if you create an analysis calculating the length of the movement between '*' and PrevEvent('SpeedTag','*') you'll struggle to get the exact time, unless the speed tag frequency is high enough. You'll be left with lots of individual parts of movement length, which you can sum up and compare with your known movement length of the object.

The higher the frequency of the tag, the more accurate you'll be in your summary of length travelled. It needs to be triggered by the speed tag, and you need to compare the sum with the length you already know. Once your sum is >= the known length, you can calculate the time span between the start time and now.

What do think of this procedure? Anyone else have another way, perhaps?

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hi Nicolas,

mathematcally it would be the integral of v(t) in dt so in AF it would be a total.

Supposing the speed is meters per second you can use an attribute template (PI Point data reference) in the element frame template:

3 of 3 people found this helpful
• ###### Re: How to calculate the time of an object movement from the speed depending on the time

I misundertood the question. You need the time it took to cover the distance, while I calculated the distance covered.

Well, this case is different and you could just get the time speed has been greater than 0 during the Event Frame.

If it was moving, it was covering distance independently from the speed. Or there is something I am missing?

So you can create an intermediate attribute (Formula DR) of the element to be 1 when speed is higher than 0 and 0 otherwise and then do the total of it as in my previous post (I have not tried but it should work, I suppose).

3 of 3 people found this helpful
• ###### Re: How to calculate the time of an object movement from the speed depending on the time

I think Nicola Gargano got it right here, object is moving when speed is greater than 0.

( That reminds me some math problems at university where I was trying to use too much variable to what was actually necessary! )

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Ah, of course.

Why keep it simple when you can calculate the hell out of it

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hello,

Nicola, I did what you suggested. Even although I want to calculate the time when the object has covered a distance D, your calculation of the distance is interesting for another case.

Unfortunately, it doesn't seem to work because I get a value too high, 68020m whereas the value should be 1147m.

`Well, this case is different and you could just get the time speed has been greater than 0 during the Event Frame.If it was moving, it was covering distance independently from the speed. Or there is something I am missing?`

The time to cover the distance depends on the speed. So, I don't think it would be enough to check if the speed is higher than 0.

Moreover, the endtime of the PI EF isn't the moment when the distance D is covered. I don't know when the distance is covered.

Thanks,

Best regards,

Nicolas

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Looks like what you want is: you know the speed v(t) and its time stamp: t = 0, t1, t2, t3...tn, you supply a distance s(tx) at any time point tx, you want to know tx -0.  This tx can be in between the given time stamps such as t2 and t3.

From a rigid body dynamics point of view, as long as you have the full information of the velocity, you will have the full information of the time and displacement (or distance).  So I am not sure why you need the "distance" information again such as: Object 1, D: 7,60m    PI EF Starttime: 01/12/2016 06:57:18.

Note that the velocity is a vector that contains directions but the speed is just a scalar.  One thing you might want to check is: do you always measure the speed and distance in the same direction?

From a numerical method point of view,  if your speed is not a step function then you will always run into numerical errors.  This error can be huge. That is the reason why Asle Frantzen suggested you to increase the frequency of the tag to reduce this error. I also noticed that 68020/1147 is roughly 60.  So could you double check your engineering unit as suggested here?

https://livelibrary.osisoft.com/LiveLibrary/content/en/server-v7/GUID-F46E6FF2-2275-4A1E-AE98-3EE2A5D2CCF8

Finally, again you have both distance and speed values, but you should only use one of them.  If you decide to use the speed,  then the only option is, as Nicola Gargano suggested, perform time integral of your v(t) at each time point.  In this way, you should have s(t) at each time point as shown below.

Note that PI uses the trapezoidal rule to calculate the integral.  So that at any given s(tx), the value of tx can be obtained from linear interpolations.

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hello Justin,

thank you for replying to my discussion.

Looks like what you want is: you know the speed v(t) and its time stamp: t = 0, t1, t2, t3...tn, you supply a distance s(tx) at any time point tx, you want to know tx -0.  This tx can be in between the given time stamps such as t2 and t3.

Exactly.

So I am not sure why you need the "distance" information again such as

Object 1, D: 7,60m PI EF Starttime 01/12/2016 06:57:18.

I meant "D" is the distance covered by the object 1. I want to know the timestamp when the object has covered the distance D, knowing the object is left its position at 01/12/2016 06:57:18.

I don't know S(t). I have to calculate it from the speed v(t). So I will do as Nicola Gargano suggested.

One thing you might want to check is: do you always measure the speed and distance in the same direction?

Yes I do. Actually, the object moves on a production line.

So could you double check your engineering unit as suggested here?

I configured the Distance attribute in the PI EF library like below:

The speed is in m/s.

Did I configured it correctly ?

So that at any given s(tx), the value of tx can be obtained from linear interpolations

So I suppose I have to create PI Point mapped to the attribute. Can I map a PI Point to a PI EF attribute ?

How can I obtain the value of tx from linear interpolations in PI AF ?

Thanks,

Best regards,

Nicolas

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hi Nicolas,

the time to cover the distance depends on the speed, but the total time is the time the object it was moving (unless you have more than 1 movement per Event Frame and you want to get the time per movement), so calculating the time speed is greater than 0 should make the trick.

Regarding the higher than expected value you got... did you use the intermediate element attribute I suggested (Formula: IF v(t)>0 THEN 1 ELSE 0) and then make the total of this latest (using as source UOM [s]?

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hello Nicola,

I think there is a misunderstanding about my problem. Sorry, I will try to be more clear. I drew a production line with an uncoiler at the entry and a coiler at the exit. We use a welding seam to join together the next coil to the previous coil. The welding seam moves along the production line with a speed V(t). The event frame starts when the welding seam leaves its original position at the line entry and finishes when the welding seam is located at the end of the production line. The event frame is generated by PI EF Gen and a process digital signal.

I want to calculate the time when the welding seam has covered for example 7.6m, 12.5m, 57.8m, 87.3m.

That's why I cannot use the Formula: IF v(t)>0 THEN 1 ELSE 0 because the time depends on the speed value.

As Justin told me, the distance S(t) is obtained from the time integration of V(t). So that at any given s(tx), the value of tx can be obtained from linear interpolations.

How can I obtain the value of tx from linear interpolations in PI AF ?

Thanks,

Best regards,

Nicolas

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Thank you Nicolas Isambourg for sticking to the syntax I used.  And thanks a lot for the nice picture!

Before I provide you more insights in Mechanical Engineering at a high level though...

One more comment for your plot is:  s(tx) is a input variable that has nothing do with your Event Frame.  The only information your Event Frame provides is the t0 (the starting time point) and (possibly) the length between Coil A and B.  That could be the reason why Patrice Thivierge and Nicola Gargano were confused by "the distance D" you mentioned in your first post.

Your welding seam is moving in one direction only so the short answer to your question is: create a PI point for s(tx), map it to an AF attribute and use FindEq.  Please note that as shown below, you can always find all of the functions in the Functions explorer in PI System Explorer in Analyses.   Then witness the PI server performs the linear interpolation for you.

Now, as a Mechanical Engineer, I want to go one step further: I am curious to know the reason why you need to know that tx. Again from a Rigid Body Dynamics point of view,  if the acceleration of your wield seam is not a constant, you may have enormous numerical errors.

So you probably want to share the screenshot of your full v(ti) data with me to prove that your calculation is meaningful.

Also is the uncoiler you mentioned the actual physical stuff or is it just something you draw in CAD?

Is there anything moving in a direction that is  perpendicular to the plane you draw?

This is what I meant by perpendicular

1 of 1 people found this helpful
• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hello Justin,

thank you for answering to my questions.

s(tx) is a input variable that has nothing do with your Event Frame

I don't agree, (or I don't understand), because s(tx) is calculated from the speed v(t) between the starttime and the endtime of a PI Event Frame. (The event frame starts when the welding seam leaves its original position at the line entry and finishes when the welding seam is located at the end of the production line). For each PI Event Frame, I need to calculate the time offset at different positions.

How do I calculate the distance s(tx) from the speed v(t) between the startime and the endtime of a PI Event Frame ? The PI Event Frames are generated by PI EF Gen.

How can I use the FindEq function in the attributes of the PI Event Frame ?

Now, as a Mechanical Engineer, I want to go one step further: I am curious to know the reason why you need to know that tx.

I want to know when the welding seam go through the different painting zones of the production line.

Again from a Rigid Body Dynamics point of view,  if the acceleration of your wield seam is not a constant, you may have enormous numerical errors.

So you probably want to share the screenshot of your full v(ti) data with me to prove that your calculation is meaningful.

Generally, the speed is constant. Sometimes, the production line may stop or slow down.

Is there anything moving in a direction that is  perpendicular to the plane you draw?

No, there isn't.

The coil is charged at the entry of the line on a uncoiler. The coil is rolled up at the exit of the line with a coiler. Between the uncoiler and the coiler, the coil is painted in different zones.

Thanks,

Best regards,

Nicolas

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Clarification 1:

For those who are still confused, I recommend you to take a step back and look at this from a Mechanical Engineering perspective at a high level:

Speed v(ti) is known but distance s(ti) at each ti is unknown  except that the total length s(Event Frame EndTime) is known.  So to find the tx that corresponds to a specific s(tx), time integration and interpolation is a must, especially when tx does not equal to ti, there is no free lunch

An example of tx and ti data may look like this:

ti = [1,2,3,4,5]

tx = [1.5,2.5,3.5,4.5]

I think Nicolas Isambourg and I are on the same page for this now.

Clarification 2:

What I meant by "s(tx) has nothing to do with the Event Frame" is:  as shown on your plot, in terms of PI data, these s(tx) values 7.6, 12.5, 57.8 and 87.3 etc are not existing PI AF attributes/PI points or AF attributes that are calculated within the PI Event Frame.

I guess Patrice Thivierge and Nicola Gargano may think you might have stored these s(tx) values somewhere in PI therefore they suggested you to calculate the "time when the speed is not zero".  To be fair, yes, I understand your frustration: if the solution is really that simple then you wouldn't have asked us how to calculate s(t) from v(t) in the first place.  There is indeed no free lunch.

Anyway, since you are on the same page with me. Let's move on to the next topic, the solution.

Clarification 3:

TagTot functions or the "Total"method you saw in  EF always thinks the integrand has the unit = something/day.  Unfortunately It is hard-coded.

So even if you have changed the UOM or Eng Units of v(t) to be m/s.  You have to convert the integral to the correct values yourself.

Now let's make our life easy and create a PI point called st with Unit: m. Did you notice that I didn't use stx here because of the clarification 2?

Unit of vt is m/s.  Again witness the following 4 things:

1. st value in Archive Editor is correct;

2. If I move my cursor to anywhere on the st curve, for example when stx = 17.7833 m, Time Stamp is: 12/30/2016 09:34:03 AM;

Witness FindEq gave you the same 12/30/2016 09:34:03 AM.

3. TagTot('vt',TimeStamp(PrevVal('vt','*')),'*')*1440*60, did you see the reason why I have to multiply the value by 1440*60?  It is your job to figure out the correct conversion factor.

Now test my solution on your own machine, use the exact same data as I used (same value and same time stamp) before you do anything and see if you can get it to work.  After your test is successful, then use your own data and add the attribute to your EF.

1.

2.

3.

1 of 1 people found this helpful
• ###### Re: How to calculate the time of an object movement from the speed depending on the time

FYI, The next Release of PI AF will have an additional new TagTotal function that will respect the time set in the starttime and endtime parameters.  so the integral will be for the time span and not the day.

1 of 1 people found this helpful
• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Thanks a lot! That's great news.

PS: I apologize that I was too extreme when mentioning the conversion factor for TagTot

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hello Justin,

thank you very much for the clarifications.

Sorry, I was unavailable last week.

So the values of the "st" PI Point aren't calculated between the starttime and endtime of the event frame ?

When is the value reset ?

Thanks,

Best regards,

Nicolas

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Nicolas Isambourg , have you tried my step-by-step solution? Does it work?

1. Time stamp of st comes from your vt.  Therefore   "So the values of the "st" PI Point aren't calculated between the starttime and endtime of the event frame" is not correct.

2. To reset st to 0 anytime you can add just one "if" statement. Like:  If digital state = new welding seam is moving then st = 0 else st = TagTot().

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Just out of curiosity,  have you solved your issue?

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Nicloas we haven't heard back from you since a couple of weeks ago. Is the problem resolved?

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hello,

sorry, I was on holiday the 2 last weeks and a lot of work before.

Don't you think the calculation of st should be

st + TagTot('vt',TimeStamp(PrevVal('vt','*')),'*')*1440*60

Thanks,

Best regards,

Nicolas

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

No problem, just want to make sure everything is OK.

The equation should be:

s(t) = s(t0) + TagTot('vt',TimeStamp(PrevVal('vt','*')),'*')*1440*60, t0 is the time point when the object is at its starting position.

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hello Justin,

I woud like to be sure to understand correctly.

By calculating st between TimeStamp(PrevVal('vt','*')) and '*', you calculate the distance covered by the object when vt changes, isn't it ?

Below are some archived values of vt:

 12,03238 01/02/2017 21:43:36 11,92577 01/02/2017 23:11:20 10,53646 01/02/2017 23:11:23 10,53646 01/02/2017 23:11:25 9,20283 01/02/2017 23:11:27 8,42403 01/02/2017 23:11:28 8,32783 01/02/2017 23:11:29 5,76033 01/02/2017 23:11:39 7,4295 01/02/2017 23:11:40 10,50257 01/02/2017 23:11:43 11,94685 01/02/2017 23:11:44 11,92043 01/02/2017 23:11:47 12,03261 02/02/2017 07:02:07 12,03062 02/02/2017 14:52:31

Below are the event frames for which I need to calculate the distance covered by the object between 01/02/2017 21:43 and 02/02/2017 14:52

EF 1 StartTime: 01/02/2017 21:54:17 EndTime: 02/02/2017 01:43:18

EF 2 StartTime: 02/02/2017 01:43:21 EndTime: 02/02/2017 03:12:47

EF 3 StartTime: 02/02/2017 03:12:50 EndTime: 02/02/2017 05:21:25

EF 4 StartTime: 02/02/2017 05:21:28 EndTime: 02/02/2017 07:43:12

EF 5 StartTime: 02/02/2017 07:43:15 EndTime: 02/02/2017 09:12:32

EF 6 StartTime: 02/02/2017 09:12:35 EndTime: 02/02/2017 11:41:56

EF 7 StartTime: 02/02/2017 11:41:59 EndTime: 02/02/2017 14:31:43

I am not sure I will be able to calculate st between the starttime and endtime for each event frames with your calculation.

What do you think about  it ?

Thanks,

Best regards,

Nicolas

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Nicolas,

"By calculating st between TimeStamp(PrevVal('vt','*')) and '*', you calculate the distance covered by the object when vt changes, isn't it ?"

No, it calculates the st even if vt does not change.  For example, distance between 01/02/2017 23:11:23 and 01/02/2017 23:11:25 will be calculated.

I am not sure I will be able to calculate st between the starttime and endtime for each event frames with your calculation.What do you think about  it ?

The best way to understand my solution is to try my step-by-step solution shown above. It is working on my machine.

Again as I said before,

EF1 corresponds to object 1.  So you or your engineer must define a PI point called: vt_object1, and store the speed of object 1 in vt_object1.   Calculate st_object1 by using vt_object1.

EF2 corresponds to object 2.  So you or your engineer must define a PI point called: vt_object2, and store the speed of object 2 in vt_object2.  Calculate st_object2 by using vt_object2.

And so on.

In order to get what you want, it is crucial that your engineers are keeping track of each object in each Event Frame separately and systematically.

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hello Justin,

sorry, I reply only now to your message. I had a lot of work this last month.

I tried your step-by-step solution shown above. I created the vt and st PI Points, the vt and st attributes and the analysis which calculates st from TagTot('vt',TimeStamp(PrevVal('vt','*')),'*')*1440*60

Actually, the equation doesn't seem to be correct because, in my opinion, the result of the TagTot equation should be added to the previous value of st.

In my example, the vt speed is 1m/s at 00:00:00 until 00:00:03. The length covered in 3 seconds is 3 meters. At 00:00:03, the st value is 3. That's correct.

Then the vt speed is 2m/s at 00:00:04. The length covered in 1 second is 2 meters and 5 meters in 4 seconds. However, the st value is 1.5m. That's wrong, the object has moved back. It isn't possible.

That's why, I think the equation should be :

TagTot('vt',TimeStamp(PrevVal('vt','*')),'*')*1440*60 + PrevVal('st','*').

What do you think about it ?

Thanks,

Best regards,

Nicolas

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Good to hear from you.  I see, looks like what you really want is the total length that has been covered by your object.  Then,  in fact,  you might want to use:

TagTot('vt','t0','*')*1440*60

Or in the following example:

TagTot('vt','17-mar-2017 11:00:00AM','*')*1440*60

Is this what you want?

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hello Justin,

that's exactly what I want.

In my case, t0 is the starttime of a PI EF.

How can I do this calculation between the starttime and the endtime of a PI EF ?

Thanks,

Best regards,

Nicolas

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Great!

Can't you simply store the startime and endtime of the EF to a attribute/PI tag??

See below:

1. Data Reference= String Builder
2. Config String= "%StartTime%";
3. Data Reference= String Builder
4. Config String= "%EndTime%";

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hello Justin,

I don't understand how the %starttime% and %endtime%" substitution parameters are related to a PI EF ?

Thanks,

Best regards,

Nicolas

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hello Nicloas,

There are many details in PI Event Frame so the most efficient way for you to learn them in a systematic way is to take one of our courses and click around in PI System Explorer (in a test environment of course).  Without doing so, you might always get confused by the PI terminologies we used.

Configuring Analytics with PI AF

Open Event Frame, new attribute, use String Builder and %starttime%,it calculates the start time of the Event Frame.

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hello Justin,

thank you again for replying to my topic.

Ok, I understood how to configure a PI EF Attribute which represents the start time.

What I don't understand is how to create a PI Analysis which uses this PI EF attribute ?

Thanks,

Best regards,

Nicolas

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Nicolas,

https://techsupport.osisoft.com/Troubleshooting/KB/KB01425

Example:

This is Element SL Tank 103

This is EF Template, witness String Builder is used to obtain EndTime and StartTime  in this EF,

This is how SL Tank 103 utilizes StartTime and EndTime in EF,witness Relative Path Syntax were used:

\\YOURSEVER\YOURAFDATABASE\EventFrames[SL Tank 103 Overflow]|StartTime

In Analysis,

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hello Justin,

the StringBuilder settings for the EFStartTime and EFEndTime attributes are:

\\........\..........\EventFrames[SL Tank 103 Overflow]|StartTime and  \\........\..........\EventFrames[SL Tank 103 Overflow]|EndTime

"SL Tank 103 Overflow" is the name of a Event Frame ? So this configuration is for a specific EF ?

Thanks,

Best regards,

Nicolas

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

It is an example that shows you how to retrieve the starttime and endtime in Attributes from an Event Frame

Best,

Justin

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hello Justin,

In my case, I need to do the calculation for the active Event Frame for which I don't know the name.

Can I do it ?

Thanks,

Best regards,

Nicolas

• ###### Re: How to calculate the time of an object movement from the speed depending on the time

Hey Nicolas,

Thank you for trying to push our products to the limit.

But to query data from variables you don't even know the name does not seems to be a valid operation from a computer science of view.