08-24-2015 08:11 AM
Hello,
I have a channel called "Engine Speed". This channel ranges in numberic values from 0 - 3000. I want to create a channel called "Op_Sensor_Desired_Pressure" that is the same length as "Engine Speed" which I am familiar with. I want my populate my Op_Sensor_Desired_Pressure channel with data that I have.
I have attached a CSV file that lists the Engine Speed with Op_Sensor_Desired_Pressure value. So what I want is when the engine speed value is = to what is in my CSV file I want to populate my Op_Sensor_Desired_Pressure value with the spec listed in my sheet. On the values that do not exist then I would like to present it with a "NoValue"
I thought about using a dictionary but cannot get it to work. (Like below) I have also attached a set of data that I am using.
Dim dict3, j, t
Set dict3 = CreateObject("Scripting.dictionary")
j = chnlength(1)
Dict3.Add "630","1"
DICT3.ADD "1010","2"
DICT3.ADD "1020","3"
Call ChnAlloc("Op_Sensor_Desired_Pressure",j,,,,2)
For t = 1 to j
IF dict3.Exists(ChT(t,"Engine Speed")) Then
CHD(t,"Op_Sensor_Desired_Pressure") = Dict3.Item(ChnVal(t,"Engine Speed"))
Else
ChD(t,"Op_Sensor_Desired_Pressure") = "NoValue"
End If 'dict3
Next
Solved! Go to Solution.
08-25-2015 02:18 PM
Hi J,
We could get the dictionary object to work, but I think a channel lookup will run faster and be at least as easy.
Call Data.Root.Clear Call DataFileLoad(RawFilePath, "TDM") Call DataFileLoad(FitFilePath, "CSV") Set RawGroup = Data.Root.ChannelGroups(1) Set FitGroup = Data.Root.ActiveChannelGroup Set RawSpeedChannel = RawGroup.Channels("Engine Speed") Set FitSpeedChannel = FitGroup.Channels("Engine Speed") Set RawPressChannel = RawGroup.Channels.Add("Op_Sensor_Desired_Pressure", DataTypeChnFloat64) Set FitPressChannel = FitGroup.Channels("Op_Sensor_Desired_Pressure") iMax = RawSpeedChannel.Size Call ChnLinGen(RawPressChannel, Null, Null, iMax) T1 = FitSpeedChannel.GetReference(eRefTypeNameName) FOR i = 1 TO iMax R1 = RawSpeedChannel(i) n = ChnFind("Ch(T1) = R1") IF n > 0 THEN RawPressChannel(i) = FitPressChannel(n) NEXT ' i
This does exactly what you asked for. I think if I were you, though, I'd consider interpolating pressure values between the fit points. Let me know if you decide to do that and find you need help.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
08-26-2015 08:02 AM
Hi again J,
If your pressure vs. engine speed curve is always a series of clearly defined lines, then we could do a piecewise linear scaling with a single Calculate() command that would run even faster. I gave you the general solution above in case your pressure vs. engine speed curve is ever non-linear.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
08-26-2015 09:34 AM
Thank you for this Brad! It is not however what I am looking to do.
I want to be able to take this reference data and place it with the original data so I can tell how far I am off from Desired pressure.
The point i am using as a reference is the Engine speed. I know that at 1200 RPM the pressure should be x and if the actual data is not x I would be able to see that.
I will not have a channel that is full as my engine speed could increment in 1 value and my spreedsheet increaments in 10's.
Does that make more sense as to why I was using the Dictionary?
thanks J
08-26-2015 04:24 PM
Hi J,
I went ahead and added the linear interpolation between the closest 2 fit points to each measured engine speed value.
Call DataFileLoad(RawFilePath, "TDM") Call DataFileLoad(FitFilePath, "CSV") Set RawGroup = Data.Root.ChannelGroups(1) Set FitGroup = Data.Root.ActiveChannelGroup Set RawSpeedChannel = RawGroup.Channels("Engine Speed") Set FitSpeedChannel = FitGroup.Channels("Engine Speed") Set RawPressChannel = RawGroup.Channels.Add("Op_Sensor_Desired_Pressure", DataTypeChnFloat64) Set FitPressChannel = FitGroup.Channels("Op_Sensor_Desired_Pressure")
iMax = RawSpeedChannel.Size XMin = CCh(FitSpeedChannel, 1) XMax = CCh(FitSpeedChannel, 2) FOR i = 1 TO iMax X = RawSpeedChannel(i) n = PNo(FitSpeedChannel, X) Xn = FitSpeedChannel(n) IF X = Xn THEN Y = FitPressChannel(n) ElseIF X < XMin THEN X1 = FitSpeedChannel(n+0) Y1 = FitPressChannel(n+0) X2 = FitSpeedChannel(n+1) Y2 = FitPressChannel(n+1) m = (Y2 - Y1)/(X2 - X1) Y = Y1 - m*(X1 - X) ElseIF X > XMax THEN X1 = FitSpeedChannel(n-1) Y1 = FitPressChannel(n-1) X2 = FitSpeedChannel(n+0) Y2 = FitPressChannel(n+0) m = (Y2 - Y1)/(X2 - X1) Y = Y2 + m*(X - X2) ELSE IF X > Xn THEN X1 = FitSpeedChannel(n-0) Y1 = FitPressChannel(n-0) X2 = FitSpeedChannel(n+1) Y2 = FitPressChannel(n+1) ELSE ' X < Xn X1 = FitSpeedChannel(n-1) Y1 = FitPressChannel(n-1) X2 = FitSpeedChannel(n+0) Y2 = FitPressChannel(n+0) END IF m = (Y2 - Y1)/(X2 - X1) Y = Y1 + m*(X - X1) END IF RawPressChannel(i) = Y NEXT ' i
I'm attaching a usefull TDV file to show the correlations and the gap between measured and desired oil pressure.
Brad Turpin
DIAdem Product Support Engineer
National Instruments