DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Script help

I am very new to coding and diadem so I was hoping for some help. I want to create a script that will call out a channel (i.e. motor speed) and create a lap counter. In my screenshot, every other point or flag is the point I want which is one lap. So when motor speed goes from negative to positive every other spot. Then place that in a table that I can copy to excel with the time stamp. Any help in this is appreciated. 

Diadem Script Help.PNG

0 Kudos
Message 1 of 4
(285 Views)

Hi cjenks,

 

To detect the zero crossing, you can use the “Event Search” function

 

Walter_Rick_0-1651751022160.png

 

 

With these parameters

Walter_Rick_1-1651751022163.png

 

 

NoValues means that a certain marker – the NoValue – is set where the condition not fullfills.

 

Walter_Rick_2-1651751022165.png

 

 

To delete all NoValues you can use the function “Process NoValues”

Walter_Rick_3-1651751022167.png

 

 

With these parameters

 

Walter_Rick_4-1651751022168.png

 

 

The you need a for-loop the select every second value.

 

In the dialog you can use the short-key CTRL-SHIFT-C in each dialog to copy the necessary script commands into the clipboard and from there into the script editor (or use the “Recording Mode” of script). After that you must complete the script with the for-loop.

 

Here is the script.

' detect all zero crossings
ChnEventList1 = ChnEventDetectionSlope("[1]/Time", "[1]/Speed", 0, "increasing", 500)
Call ChnEventCreateStatusChn("/EventStatus", ChnEventList1, "[1]/Speed", NOVALUE, 1)

' remove NoValues
NovMeth          = "Delete"
NovCtrlChn       = "XY"
ChnNovIP         = False
NoVChnX          = False
NovReplaceVal    = 0
Call ChnNovHandle("[1]/EventStatus", "'[1]/Time'", "Delete", "XY", False, False, 0)

dim oChn, oResChn, iLoop, iIndex
set oChn    = Data.Root.ChannelGroups(1).Channels("Time1")
set oResChn = Data.Root.ChannelGroups(1).Channels.Add("Result", DataTypeChnFloat64)

' select every second value
iIndex = 0
for iLoop = 1 to oChn.Size step 2
  iIndex  = iIndex + 1
  oResChn(iIndex) = oChn(iLoop)
next

 

Greetings

Walter

Message 2 of 4
(247 Views)

Walter,

 

I cant thank you enough. I really appreciate the thoughtful and helpful response. 

0 Kudos
Message 3 of 4
(216 Views)

Wow Walter! That is a great way to get timestamps from an event search. I have a much more complicated way of doing it but this streamlines the process greatly. Thanks

0 Kudos
Message 4 of 4
(158 Views)