05-04-2022 10:43 AM
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.
05-05-2022 06:44 AM
Hi cjenks,
To detect the zero crossing, you can use the “Event Search” function
With these parameters
NoValues means that a certain marker – the NoValue – is set where the condition not fullfills.
To delete all NoValues you can use the function “Process NoValues”
With these parameters
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
05-06-2022 03:38 PM
Walter,
I cant thank you enough. I really appreciate the thoughtful and helpful response.
05-13-2022 10:08 AM
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