Pause and continue the time with Elapsed time.vi in LabVIEW

Elapsed Time.vi is a very useful Express vi which returns the elapsed time and can be reseted. Unfortunately there is no pause function in Elapsed Time.vi ( LabVIEW 8.5 to 2009). I had been looking for the examples of pausing and continuing the time in LabVIEW, but there seems not be a simple one.
So I created this myself. It is not efficient in term of excecution time, but it is simple to be made from scratch and memorized.

Basically the shift registers are used to store the previous elapsed time. When it is in the false (run) case, the elapsed time is added to the ‘total elapsed time’. When the vi in the true (pause) case, the total elapsed time is transferred to the start time and the Elapsed Time.vi is reseted (stopped). Hope this will be helpful. 🙂

 

———————–In response to Mark’s question——————————–

So I added the reset function for this SubVI:

When you reset the clock, you simply ‘reset’ it and send ‘0’ to elapsed time. Hope it helps.

Tags : , , ,

Scrolling the mouse wheel to change values in LabVIEW

This is a simple demo using the mouse wheel to control the numeric indicator in LabVIEW. The value of the ‘mouse wheel position’ increases or decreases when we scroll the mouse wheel forwards or backwards.
The reason of posting this is when I tried to using the mouse wheel to control a camera (to zoom in/out) in LabVIEW, it took me a lot of time finding the right example. If this post happends to be the top 3 of your google results, it should save you some time.
This VI was modified from the example ‘Basic Input Demo.vi’ in LabVIEW. Since the windows’s dll only returns the moved (or related) position of the mouse wheel, a shift register was employed to display the ‘absolute’ position.

Sorry that I cannot upload the .vi file for the limitation of wordpress.com. But it is easy enough to re-create this vi yourself from the snippet.
Note that:1. There is no ‘mouse wheel’ triggering event in the event structure (at least before LabVIEW 2009);
2. The .dll file in ‘Acquire input data.vi’ returns only the moved position of the mouse wheel comparing to the position when the dll was called last time;
3. The returned mouse wheel postion was divided by 120 in this demo, which may change according to different mouse setups.
4. The polling event (nodes in the while loop) could be put into the timeout case if you want to use event structure together with it (and the timeout shouldn’t be -1).

Tags : , ,

Preparing for LabVIEW CLD exam (1)

So I registered for the CLD (Certified LabVIEW Developer) exam on 5th August. I knew LabVIEW when I started my Ph.D in November 2007 and have been using it for 3 years. I had been “learning” LabVIEW for 2 years. In the 3rd year I was more of using it instead of learning more things. Since it is said that the CLD is suitable for users with experience of “a year and a half”, I think it is fair for me to take the exam.
There are 4 exam samples online (link) and they are said to be very similar to the actual exam. Also Darren’s note on CLD is very helpful (link). So my plan is taking the examples as the real exam and finding the knowledge I’m not aware of. One exam lasts 4 hours and I have to use one weekend to finish one. So the examples have to be finished before end of June (5 weeks to go).
I took the “ATM machine” examle last week and failed to finish it in time. I think that might be the most difficult one among the 4 (or not?). Anyway, fortunetly there is still time to fix that problem.

Here are what I have learned from the examples, and I will add more thoughts as the practice goes on. Hope this can be helpful:
1. We do not need to install any module beside LabVIEW to take the exam. It tests your coding ability instead of your module experience.
2. The logic of the exam is very complicated.
3. For me, the exam could be finished if more time (maybe 2 more hours) was given. Thus the challenge is how to finish it in the limited time. You cannot do that without good practice.
4. Use state machine, as stated in the exam. And I found the queue operation is not necessary in these 4 exam samples.
5. The project manager is not neccessary for there won’t be many versions of your code.
6. Folders named “SubVI” and “Control” are useful. Put the Top_level.vi in the top folder.
7. There could be file read/write operation, and thus we need to master how to manipulate the file path and text-related functions.
8. Draw the states clearly before coding, which saves you a lot of time later (Or, do not code before the logic of states is clear).
9. Because of 8, pens of different colours are very helpful (but is it allowed to bring our own pens?).
10. Set the preference of block diagram a ‘comfortable’ way. E.g. untick Display terminals as icons; untick Show dots at joints; untick Auto wiring; tick Default SubVI terminal as required.
11. Quick drop saves you time.
12. Save the code frequently in case of unknown situations.
13. If you cannot finish the code, create all SubVIs only with front panels. At least the program could be ran (with some missing functions).
14. Knowledge of timed loop and control reference are necessary (Update: I added an example in this post).

FYI: this is my drawing of the state machine. It will be messier if there was just one colour.

I will carry on the exam simulation this weekend and my timeline is: finish the state diagram within 1 hour; Create the structure and SubVIs with only terminals and descriptions in 1 hour; try to finish all the functions in 2 hours.

Good luck to me.

Update: Related post Preparing for LabVIEW CLD exam (2)

Tags : ,

Days of PhD (5)

Sorry for the late post. So I have been writing thesis these days (fingers crossed) and did draw some more comics just did upload them. Now here is one of them. Hope you’ll like it.

P.S. I found that there is a lot of potential work for my academic writing. Talk is totally another issue. Good luck to me.

Making the number of shift registers programmable

Shift register is very handy in LabVIEW programming. To add one more shift register (say, shift one more time), what you need is only click and drag down the shift register. If you want to recall the data generated in a loop 5 times ago, you drag down 4 more shift registers and pick the bottom one.

But the drawbacks are obvious,
1. It is not neat nor scalable in coding.
2. User cannot modify it without modifying the code.

So here is a alternative method for large/unstable number of shift registers — using the queue in the loop. The thought was quite straightforward, just to find something that can buffer the data. I’m sure there are many cleverer ways.


So the queue is used to store the data. With enqueuing and dequeuing we can do the shifting. The case structure is to determine if we shifted the right number, and the condition can be modified (e.g. if(get queue state==#shift regisiters) ).

The problem is solved now. Please let me know if you got better solutions:)

Tags : ,

7 sins of IMAQ module

I have been using IMAQ module in LabVIEW these days, and the integration of many algorithms saved me a lot of time. It is the core module when we want to do Machine Vision. I haven’t digged into it since the subset seems OK for my job. But in this post I’m not saying the beauty of it, instead, I’m going to tell seven sins of the IMAQ module. Just to clarify, I splitted some up in order to make it “7”. All the problems are based on vision development module 2009.

1. It has to be in IMAQ. Sometime I just want a simple “2D array filter” to proceed my 2D data, but there is no such a node in the core functions, although I though it’s not complex. And the fact is, if I want to proceed my raw 2D array in any ‘image’ way, I have to buy and call IMAQ module to do that, plus conversion back and forth. That’s not handy.

2.  Non-standard connector layout. Here is the connector  layout:

It’s not using standard 4224 layout pattern, and the wiring becomes a chaos in this case.

3. Old style front panel. Here is the front panel comparison of the “IMAQ create.vi” and “Open/Create/Replace file.vi”

As you can see, the controls and indicators are different in two VIs. So if we have IMAQ VIs with other VIs in the same top level, we will have diffrent front panel controls if we just create controls by right clicking.

4.IMAQ VIs should support all image types which makes sense” as described in the NI idea exchange.

5. Along with the last sin, there is no boolean array input/ output in “IMAQ ArrayToImage.vi” and “IMAQ ImageToArray.vi”. Actually boolean 2D array is quite useful in many pattern recognization applications. (Yeah, this is the extra sin I just divided from last one)

6. “Image Dsc Out” missing in some VIs. E.g, after the proceeding of the image and we want to convert it back to an array, do we need to release the buffer we created? If yes, there is no such a connector on the output. I assume all the VI without the “Image out” connector is to be used as indicators, but still, it’s better to keep it uniform.

7. We have to create buffer to manipulate images. In this module it’s not as smart as in Array functions, we need to create one buffer to proceed an image, mutiple buffers for mutiple ones (or, use one buffer one by one). It would be nicer if NI can make this easier.

Anyway, IMAQ is a very useful module and hope I’ll study ultilize it better in the future.

Tags : ,

微博的瞬时记忆

我不喜欢鸡,是因为我小时候到奶奶家,曾亲眼看过杀鸡的场景。那是一群,我伯父取向其中最肥的一只,其它几只纷纷逃窜。但是没走几步,就又开始悠哉的吃食了。那只鸡被反掐住脖子,刀子一划便在滴血,扑腾了几下就挂掉了。之后是拔毛,刨腹,把肠子肚子什么拉出来丢到桶里。我清楚地记得有一只鸡溜达回来,看到桶里的肠子就很快地叼走了。我想,鸡的记忆是瞬时的吧?几秒钟的恐惧被食物的吸引冲淡了,也忘掉刚才沦为刀下鬼的是自己的同伴,或可能就是它自己。

前几天看到两篇文章,一个是《南方人物周刊2010年度人物——微博客》,一个是《娱乐至死》,是讨论微博和娱乐的。我最近的主要“娱乐”就是微博了。其实我上微博的目的很简单,ID叫@科学玩家,想找一些志同道合的人,谈谈技术,谈谈科学。后来接触的人多了,信息也杂了起来。我还是尽量的保持不被“琐事”所累,一门心思地读圣贤书。但谁也无法独善其身,大量的信息扑面而来的时候,你想不关注也不行的。于是,像我这么消息不灵通的人,也几乎第一时间知道了王家岭矿难,玉树地震,南京化工厂爆炸,舟曲泥石流,李刚之子事件,到最近的乐清碾人事件。

我开始是漠不关心,后来偶尔跟着喊一喊,掉掉眼泪,到一度的情绪高涨,大有愤青的模样了。但是喊完也就喊完了,骂够了,舒服了,日子该过还是得过,我的论文还是要赶紧写出来。而事件中那些人的日子如何了,就和我没什么关系了。我可以煞有介事地大谈特谈舆论监管,跟着便是冷笑话和萌物,前一条慨叹民生疾苦,后一条秀新买的数码。情绪和思维的切换达到前所未有的速度,比Alt-Tab来的快多了。

这或许就是微博里面体现的,微信息,微思考。我可以被短短140字打动,之后又投入到另一140字的情景中。《娱乐至死》的漫画里,奥威尔预言权威会打压舆论,禁止信息的流动,从而达到控制人民思想的目的;赫胥黎预言权威们会倾倒大量的“垃圾”信息,混杂到“有威胁性”的信息中,叫你无暇分辨,无心思考。“奥兹曼认为,对未来作出正确预测的,不是奥威尔,而是赫胥黎”是这篇漫画的最后一句。我比较“乐观地”认为,欧美等政府是在按照赫胥黎的想法出牌,而中国政府还是采取比较低级的打压政策。
或者说,我国人民除了面对上面的压力之外,自己也在主动地将信息遗忘在海量的娱乐中?

我不提倡大家过苦行僧搬的生活,或者每天苦大仇深地要如何如何。仇恨永远不该成为主旋律,我希望大家都能幸福,至少认为自己幸福。但是如果某事触动了你敏感的神经,让你真的为之一震,我们也应该把这个事儿当个事儿了,不要骂娘声刚落,立刻又幸福了起来。因为这个幸福是短暂的,是廉价的。同样廉价的还有莫名的惊恐和愤怒,虽然真相往往掌握在有关部门手里,但这不该成为我们看到菜刀边哭喊着四处逃窜,菜刀收起来就放心吃食的理由。如果我没有将事情解决的能力,那我至少保持着关注,看看别人是如何解决,或到底有没有解决。

舆论的力量是强大的,同时也是短暂而脆弱的。如果我是王家岭矿难某遇险矿工的妻子,我会很欣慰地看到网上关于此事铺天盖地的曝光。仿佛一群素未谋面的街坊四邻,敲锣打鼓地从四面八方出现,呜呜泱泱地要去衙门讨公道,或去找青天大老爷。然后短短数日,听说玉树地震,于是这群热情的邻里们又吹着喇叭走掉了,剩下茫然的寡妇和她背后的笑声。
就在昨天,看到微博上一个MM在喊,她的20岁的年轻同学因政府建设用地的事,被政府的人围殴死了。也就在她一系列的@后面,跟了几条“没的美剧追了,该追韩剧”的感慨(现已删除)。那我想,这位同学的记忆也是短暂的吧?像我一样。

我做个预言的话,或者我的这个文章石沉大海,不足以激起共鸣的浪花;或者会被转,有人会感慨,共鸣,然后下一条是星座运势,或厨房秘籍了。

Playing the music with the spark gap

I posted an article <Play the music with your DAQ card> some days ago. It saves you when you have no sound card but only a data acquisition card to play the music (and you’re welcome:)). Now what if you have no speaker but only a Jacob’s Ladder?  We borrowed a Jacob’s Ladder from the physics department and had a play with it. Using the electric arc we are able to play the tunes!
This is the video I uploaded in youtube, please help yourself:)

[youtube=http://www.youtube.com/watch?v=pTe_pGYcpnk]

For the people who are not convinient to browse youtube, you can also find it in this link (tudou.com, a video server in China).
Sorry I didn’t edit this phone recorded video, and you have to rotate your head to the left to view it. So we converted the sound file to a sequence of train pulses in LabVIEW, which triggers the Jacob’s Ladder to genenrate sparks. By changing the duty cycle and the frequency of the pulses, we are able to change the volumes and tunes.

P.S. We are not playing all the music, for the tune and pace range of the Jacob’s Ladder is very limited. It only makes the sound when the electric arc appears.

Tags : ,

Return the bigger values of 2 arrays

I came up with a similar question (<Return #elements of an array greater than a certain value>) before, and today this one “What’s the efficient way of comparing 2 arrays and returning an array with the bigger values?” was posted in gsdzone.net forum.

This is not a complex problem and many responses were given. But all of them suggested using a for loop to compare the elements one by one. Most of the comparison and numeric nodes in LabVIEW are polymorphic and we should take use of them efficiently. I tried the following code and it works 🙂

So a single Max & Min node can do the job.

A thought that may or may not be helpful (or even correct!) in optimization: Always try to do it with polymorphic nodes when you did it with a loop; always try to do it in one loop when you did it with several loops.
Thanks to rogel who brought up this problem.

Tags : ,

Run consumer loop without waiting

Producer/Consumer loop (PC loop) is one of the most important architectures in LabVIEW. It gives a good solution when your data producing rate is faster than your consuming rate. A typical example is analysing/storing the data while acquiring new ones. We dont want any slowness or jag of the post-process  interrupt the acqusition. Thus PC loop create a space from the memory and uses it as a buffer to deal with the asynchronous tasks.

In this architecture, the consumer loop will wait (for timeout period) until there is a new element in the queue. What if we want to run the consumer loop regardless the queue is empty or not? Sometime, we want to output waveforms until new waveform is generated. I modified the PC loop as following:

 

Note: Since the consumer loop runs all the time, we need a ‘wait until‘ node in it to save the CPU. It is not shown in the figure and sorry about that.

So the consumer loop does the normal things (like output pre-defined signals) when there is no element in the queue (determined by state of queue.vi). And when there is, the consumer loop dequeues it and updates the state (like updating signals). I think this thought is logical and similar to human thought. An alternative method is to enqueue the same element after we de-queue it. In this case the loops will be keeping enqueuing and de-queuing. I don’t quite like this method, of which the thought is not straightforward.

Tags : , ,