From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Trigger serial vi in a case structure

Thanks Albert. Really gratefully.

I have just been able to see the vi, it was of great help. But, my problem is how to trigger the visa actions using the signal my Accelerometer is acquiring.

 

Let me explain the Logic of this program

 

An accelerometer is placed on a body. The body will be vibrating at frequency within this 3 ranges. 5-10Hz, 15-20Hz and 25-30Hz. If at for example 5-10Hz, I want to send signals to  a motor to move to position A and if at another instance where the vibration signals acquire is at 15-20Hz I want motor to move to position B and if lastly if the vibration signal acquired is 25-30Hz I want motor to move to position C.

 

Now I have been able to write a simple code to acquire the accelerometer signal and PROCESS it to determine what frequency  is been applied to the body. (That is the first part of my program). Also I have a simple code that can move my motor using serial communication to position I want separately. This I have turned into a subvi which is attached in my earlier mail.

 

Now the problem is that I have simply placed this subvi in a case structure and it is awaiting the vibrating signal to respond. How do I after processing the vibration signal ALERT the VISA subvi to run the motor to be initiated so that my motor will move to a position I want it to go to.

 

If for example Case 0 is the case where the accelerometer reads 5-10Hz, after acquiring the signal and processing it to know that I am getting 5-10Hz range of vibrating signal, how do I move my motor  to position A.

 

Please Kindly assist on this.

0 Kudos
Message 11 of 16
(872 Views)

To make things more clearer, I have attached two separate vi that I am trying to combine in their combine form (in my own way)smileysad: and  the response I am getting.

Anytime I click the run button, the inner case structure labeled 1 with the attached visa always move in respective of what signals is coming from the accelerometer section which is the case ( the outer vi labeled 1) because the case I am using is a frequency case between 5-10Hz (Case 0).

 

The motor just move and stopped at the point I want it to stop. But I want it to move by accessing the accelerometer signal and determine that it is within the range of 5-10Hz before moving which it is not doing.

0 Kudos
Message 12 of 16
(870 Views)

It looks like you are trying to make a state machine.  A state machine might be a good choice for your project.  Look at the examples for more information.

 

Some hints:

Learn about and use type definitions (often called typedefs) for your enum (the one with Initialise, Move Motor+, ...).  Then the item labels will appear as the selector labels in the case structure. A case called Move Motor+ is much easier to understand than "3".  If you need to make changes (which always happens), changing the typedef changes all the instances including constants automatically.

 

What is the purpose of running the for loop "i" times?  When i = 0 the loop will not run and the outputs will all be default. When i = thousands or millions the loop may take a very long time to complete.

 

Change the output tunnels on the case structures so that Use Default if Unwired is unchecked, except possibly for the Stop boolean.  It is unlikely that default is what you want for the other outputs, especially the state enum.

 

Lynn

0 Kudos
Message 13 of 16
(863 Views)

Hi all,

I tried to follow all the advice on enum typedef, for loop but still my vi is not behaving the way I had expected. The inner case is not updating itself and the main problem of how to connect the DAQmx to trigger the position2code.vi is still a major problem.

0 Kudos
Message 14 of 16
(856 Views)

I'll do my best, give me some time.

 

If I understood you correctly:

1) measure the vibration, and calculate it.

 

2) depending on the vibration goto position x

 

3)stay there until the vibration is different.

 

? if no vibration or a higher vibration is detected what should the program do.

 

In my view a while with inside 3 steps. (1,2,3) and then start again.

I only would add the situation vibration unknown, action go nowhere, do nothing.

 

greetings from the Netherlands
0 Kudos
Message 15 of 16
(845 Views)

Hi Albert would really be grateful,

 

Let me clarify certain things.

 

If I understood you correctly:

1) measure the vibration, and calculate it. (2 parts of the vibration: The amplitude and the Frequency which a tone measurements vi can do easily)

 

2) depending on the vibration goto position x (depending on the Frequency part of the vibration which will at any time be within 3 ranges of 5-10Hz,15-20Hz and 25-30Hz, programmed the motor using serial communication and tell it to move to 3 different corresponding position A, B and C.  A for 5-10Hz,B for 15-20Hz and C for 25-30Hz)

 

3)stay there until the vibration is different.(Surely based on theory the vibration Amplitude would reduce at this point. But still we need the programmer to measure the new Amplitude of vibration and compared it with the Amplitude obtain in step 1)

 

  If no vibration or a higher vibration is detected what should the program do.

 


4) Then the position we go to in step 2 is not a permanent solution to see that the vibration amplitude reduces; it can still be reduced more by either moving the motor a little Clockwise(CW)  or AntiClockwise(ACW). So we will move the motor a little CW first and get another amplitude. Called this new amplitude A+. Also we will move it a little ACW. Call this new one another name A-; Then we will compare Amplitude A+, A- and choose the one with the lowest amplitude and ask the motor to move the same motion it moved to get the lowest amplitude between A+ and A-

 

Thanks, your support will be highly appreciated.

0 Kudos
Message 16 of 16
(843 Views)