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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Daq mx for automatic control

Hello, 

 

I am currently controlling a linear actuator by clicking two buttons on/off its actuation. I attached the code. I am just wondering is there a way to set it as a automatic control the actuator- for example, when I run the program, is it possible to have the actuator run automatically or periodically by setting a period of time so I do not need to keep clicking the button for on/off? I was thinking flat sequence structure but I am not too sure. Any suggestions or ideas please? Thank you in advance!!!!!  

0 Kudos
Message 1 of 10
(2,645 Views)

Yes.  It's called programming.  Look up "State Machine".  You'll probably see tons of messages on the forum where people are asking to do similar things related to timing.

 

I doesn't even need to be as formal as a state machine.  An elapsed Time Express VI will output True when the time is up.  When the Express VI is true, change the value of the button.

0 Kudos
Message 2 of 10
(2,616 Views)

I agree with RavensFan.  You can easily take your posted code and make it "automatic" by making the following (almost-trivial) changes:

  1. Move "Digital Ctrl" outside the While Loop.
  2. Place a Shift Register on the While Loop.
  3. Wire the Digital Ctrl to the left Shift Register, wire the left Shift Register to a Boolean "Not", and output of the Not to the right Shift Register.
  4. Wire the just-created input wire from the left Shift Register to the DAQmx Write.
  5. Change the time on the Wait (ms) to be the time you want the On and Off states to last.
  6. Run the code.  The Digital Line will go from the Digital Ctrl state to the other state and back, staying in each state the amount of time wired to the Wait (ms) delay.

Note the use of the Delay to control the rate at which the loop runs.  For example, if you put 1000 (ms) as its input, and everything else in the loop takes less than this time (do you know why I need to say this?), the loop will run at 1 Hz, and you will have created a Flip-Flop that runs at 0.5 Hz (since it takes 2 seconds to repeat).

 

Bob Schor

Message 3 of 10
(2,606 Views)

Hi Bob. Thanks for the replay! I am pretty new to LabVIEW and trying to learn how to achieve the my goal by watching Youtube video and HELP examples.

 

I am wondering for step 3 for the Boolean "Not", should I put in inside the while loop or outside the while loop? Also I am trying to understand the delay control. Is it because for the full actuation (extend and retract), if I want the program to run at 1Hz per cycle, I will need to input it as 2000ms wait time for the full actuation? 

 

Thanks so much! 

0 Kudos
Message 4 of 10
(2,599 Views)

Regarding the "Not" -- Have you any experience with Digital Circuits?  Do you know what a "Flip-Flop" is?  (What does it sound like?  It Flips and Flops from True to False, as though there was a "Not" in the circuit that changed its value each time through the loop.)  Try building a While Loop with Shift Register, boolean True wired outside on the left to initialize it, and a Not in the middle.  Put an Indicator anywhere on the wire on the inside, and a Stop button to stop it.  Now run it.  Can you see the Indicator change?  What, it's going too fast?  Put a Wait (ms) inside, experiment with the value you wire to it to get it to change "as you like it".

 

Oooh, did I answer both questions?

 

Bob Schor

0 Kudos
Message 5 of 10
(2,490 Views)

Hi, Bob. Thanks for the response. I have learnt a bit "Flip-Flop" but it was a while ago... Just to make it clean for myself. Based on my code: only the control button will be wired to the left of the shift register and the boolean "Not" gate should be inside?

 

Thanks 

0 Kudos
Message 6 of 10
(2,475 Views)

Here is the simple type of Boolean toggle they are talking about.  You need to implement something similar into your DAQmx Write.  Even better would be a simple state machine so look into those.  They allow you to easily modify and add new features to your code later.

Bool Timed Toggle.png

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
Message 7 of 10
(2,463 Views)

Thanks for the reply. I have very similar structure in my code but just a bit confused with what Bob said putting the boolean control outside of the while loop? Also, if I have two daq write for controlling my actuator, is it possible to implement the Boolean toggle to both of mine two daq write for atomically controlling my actuator?

 

Thanks alot!!!

0 Kudos
Message 8 of 10
(2,451 Views)

NIquist initialized the Flip-Flop with a Boolean Constant, I initialized it with a Boolean Control (in case it matters to you if it is True first, then False, or False first, then True.

 

Do you know about Case structures?  If you wire the Flip-Flop (inside the loop) to the Case Selector, it will alternate between the True and False cases.  Put the code you want to run in the "True" case inside (here is a quiz -- do you put it inside the True, or inside the False, case?).  Put the False code inside the other case.  Note that if you are (properly) using the Error Line, you will "reuse" the Error Line in both Cases (that is, one Error Line wire goes into and out of the Case Structure -- you wire it directly in one Case (say, True), then in the other Case, you connect the Input and Output tunnels (which will look like little white rectangles, and will raise Error Flags) together, which colors them in and makes the Error go away.

 

Bob Schor

0 Kudos
Message 9 of 10
(2,429 Views)

Putting the control outside the loop allows you to select which state the DAQ will write when you first start up the program.  If you don't need to be able to change it, just use a bool constant like in my example.

 

If you want to have more than one lines change you can certainly do that but you need to be specific about the timing in the sequence(s).

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
0 Kudos
Message 10 of 10
(2,408 Views)