Calculation channel


Recommended Posts

Hello, I’m having issues with a velocity sensor. I would like to use a displacement sensor ,called stroke ,I record to determine velocity. I know I have to (stroke[0]-stroke[1])/(stroke.time[0]-stroke.time[1]). I want to do the whole array so would I do a for or while loop? And where would it go? I don’t believe it would go in an event as I’ve read it comes in blocks and won’t process correctly. I was thinking of a v channel but not sure how to do it correctly. I want to use data in a graph after. 

Link to comment
Share on other sites

So you are streaming the input?  Do you want to log the velocity, or just trend it?  If you just want to trend it, you can just trend the calculation:

(stroke[0,10000] - stroke[1,10000]) / (stroke.time[0,10000] - stroke.time[1,10000])

That would go right in the Y Expression for the graph.

Link to comment
Share on other sites

  • 4 weeks later...

hello, I am having a strange problem. I'm setting up a basic counter. I tried it in Labjack test panel and it works okay. after numerous tries in DAQ, I decided to try the basic counter sample and was successful. The problem lies in my .ctl somehow. I can't get the RawCounts channel to read anything. After reconfiguring my startup sequence, I copied and pasted the sample startup and just changed the pin offset to match my Labjack( I did it in basic counter to get it to work). I'm still not getting anything. Basic counter sample works fine but my .ctl doesn't. Maybe you can see something I missed? Also, I've double and triple checked to channel settings compared to sample.

SHOCKDYNO.ctl

Link to comment
Share on other sites

Then why does it work in the basic counter sample,  which is configured as 7? Also, as I said, everything is exactly the same in both but mine doesn’t work. 
I have the pin reset in my startup and that didn’t work either. That’s why I copied the sample startup sequence to no avail. 

Link to comment
Share on other sites

It says 4 but I changed it to 7 and it works. No alerts. As I said, when I load basic sample and change pin to 7, the RawCounts increments by turning gear tooth wheel. When I load my document it doesn’t. I’ve quadruple checked the settings and nothing increments. Baffling. 

Link to comment
Share on other sites

You can use an odd pin offset configuration. The valid pin offsets depends on the device. For the U3, 4-8 is valid. For the U6, 0-8 is valid.

Your STARTUP1 script contains everything you should need to get going with a counter and your RawCounts channel looks set up correctly to read it. One thing I noticed is that you almost certainly have the wrong header file path, the include would not resolve correctly if you are using 64-bit Windows. You can better handle OS bitness related path issues by using a try catch block around the include. The following is what we use in our examples and should work correctly for 32-bit or 64-bit Windows:

try
   include("c:\program files (x86)\labjack\drivers\labjackud.h")
catch()
   include("c:\program files\labjack\drivers\labjackud.h")
endcatch

If you are still having issues with the counter not incrementing, I would recommend removing your actual signal and using a test signal. Connecting a wire to FIO7 and touching the free end to the inside back of a GND terminal should cause edges and therefore increment the counter some arbitrary amount. We would also recommend you try running the counter setup sequence manually after startup.

Link to comment
Share on other sites

Crazy! I went this afternoon to try and it was working fine. Don’t know if it was an issue with the way I tried resetting it but all is good. 
Next question 

I want to use my rawcounts in my post-process data processing. Can I stream the rawcounts channel? I want to be able to filter my other channels based on the rawcounts. Since it’s set at 1 second timing, Compared to my stream of 1000, I don’t see how my data would line up properly. 
Also, can I have the same channel with different names? I want to stream them but also setup a variable value component I can watch live. 

Link to comment
Share on other sites

Hello. Apparently I must have done something wrong resetting because when I went back it was working. 
Is it possible to stream the rawcounts channel? I want to use it in post run data processing. I need it to line up with my streaming channels. I don’t think it will line up reading at 1second intervals when I’m streaming at 1000/ sec. 
Also, can you use the same channel with a different name? I’d like to use some variable value components to display real time readings. 

Link to comment
Share on other sites

You can stream the counters, but that will look a little different in terms of the channel configuration. To read Counter0 while streaming you must read channel 210 as an A to D I/O Type and channel 224 (TC_Capture) as an A to D I/O Type. The following page has additional information about the timer/counter stream channel changes:

https://labjack.com/support/datasheets/u3/operation/stream-mode/digital-inputs-timers-counters

We also have a few DAQFactory examples that stream timers/counters at the bottom of the following page:

https://labjack.com/support/software/examples/ud/daqfactory

Link to comment
Share on other sites

Thanks, I’ll read up on that. As far as channel names, I’d like to have 2different names for the same channel. One I can stream and the other I can set timing to something like 0.01 to put in a variable value box for real time readings. 
So I would have a channel named force on channel 0 with timing of 0 and one named force1 on channel 0 with timing of 0.01. Then I can stream force and put force1 in a variable value box. 
Thanks

Link to comment
Share on other sites

  • 2 weeks later...

hello

Is it possible to use the event of a channel to control my LJTic_DAC? I have a 60 tooth wheel and want to rotate it 140 teeth. if I use an if statement in event with appropriate LJ command, will that work? Im using rawcounts channel to count.

Link to comment
Share on other sites

Yes, you can do that but you have to be careful.  Just remember that the script in the channel Event runs in the same thread as the Timing loop so any delay in executing the script could affect your timing.  For example, if you have your input channel timing set to 0.02, and you do the LJTic_DAC command and that takes 0.03 seconds, then your input channel will only read at every 0.03 seconds since it was tied up adjusting the LJTic_DAC.  That is why it is sometimes better to have a secondary loop in a sequence watching the input and tweaking an output separately.  That all said, in your case, you are probably fine...

Link to comment
Share on other sites

I tried using a separate sequence to do that but for some reason it wouldn’t work correctly. Seemed like the sequence would get kicked out at some point and not execute the rest of the lines. 
By that I mean, I would watch the sequence in the workspace and the black line showing the sequence running would disappear before it was finished. Tried a few different things and couldn’t figure out why. Thought a channel event might work better. 

Link to comment
Share on other sites

If the sequence doesn't run all the way through then there is likely an error and a corresponding error message in the command / alert window.  Moving the script to an event won't likely eliminate the error, so you should probably chase that down.

Link to comment
Share on other sites

Hello,

As a follow up, does an if statement only evaluate one time? I believe that is my problem. The sequence runs through and checks once and the value isn't met and it just ends the sequence. I assume I need to put a while(1) before the if to keep it in a loop until the value is met?

On another note , all of a sudden i'm getting a communication failure message. previously it was intermittent and I paid no attention to it but now it won't communicate at all. I tried it in LJ control panel and things work fine, but not in DAQFactory..any ideas?

Link to comment
Share on other sites

No problem.  We just didn't get the notification of the new post for some reason.  Sorry about that and I'm glad you followed up.

Unless an if() statement is in a loop, it only executes once.  But aren't you calling the sequence from your event?  Or do you want it to just run, continuously checking the value.  If the second, then yes, you need to put a while(1) along with some sort of delay() to get it to check every so often.  Something like:

while(1)
   if (...)
   endif
   delay(1)
endwhile

The delay should probably match the Timing of your input channel.  There is no reason to check it faster than the values are updating.

As for comm errors, that's going to be on the LabJack side, but here are few items to note:

1) you cannot run DAQFactory at the same time LJControlPanel or Kipling is running.  For that matter, you can't run it at the same time as any other program that is accessing the LabJack.  This is a limitation of the LabJackUD  and M drivers, not DAQFactory.
2) watch out for using First Found (D# 0) and an actual ID at the same time in an application.  You should only use First Found if you only have one LabJack, and in my opinion, never, since inevitably, once you see how flexible the LabJack's are, you end up buying a second one!  If you have two, then it is possible that First Found will find the same LabJack that you specified the ID for, and it won't be able to open two connections to the device.  This becomes more complicated because First Found is not predictable on what it considers "first", so might give you a different LabJack when you restart DAQFactory.  So it might work for a while and then, after a restart, stop working.
3) make sure you are running the latest drivers and firmware from LabJack.  Being fully updated fixes a surprising number of issues.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share