12-01-2022 10:04 AM - edited 12-01-2022 10:09 AM
Dear friends,
I need to be able to click a button and make a motor run for 5 seconds clockwise then stop, then when I click the button again, it runs for 5 seconds again counter clockwise. It needs to interchange between the two directions with every click. Currently, when I click the button it runs for five seconds clockwise and then after another five seconds it runs again without me clicking the button, it also runs clockwise again. I have linked my work below.
I’m new to LabView so I apologize if my code is sloppy or if I am using the wrong setup or function. Thank you for your help! Have a good day.
Best regards.
Nate
12-01-2022 10:39 AM
Please save for Labview 2018 or earlier. (File -> Save for Previous Version...).
I cannot see your code, but I suppose that you send an angle value to your motor? Or a direction command. You can alternate the direction between each iteration. Either incrementing a counter and doing mod 2 or simply inverting a boolean each time you click the button. Then send + or - angle depending on the value of the boolean (or if iteration mod 2 is 0 or 1).
12-02-2022 09:37 AM
This should be a file for LabVIEW 2018. Thank you for your help.
12-02-2022 10:13 AM
Your code isn't clear, maybe add some comments?
You are just sending a boolean. How are you telling to the motor which direction to go? True = clockwise, false = counterclockwise?
Also you have an external switch that you are reading with a DAQ? You should really be more specific in your question if you want to get some help.
Is this what you mean?
12-02-2022 10:23 AM
What do you want to do?
How can you do this?
Did you learn about LabVIEW being a "Data Flow" programming language? Did anyone talk to you about the importance of the Error Line, which using goes into and out of LabVIEW functions and sub-VIs on the lower corners?
Suppose you have a Function (or VI) called "Run Motor" that, when called, "runs the motor". Let's make it simple, have one Boolean input that if True makes the motor run Clockwise and if False makes it run Counter-clockwise. Let's also assume we have another Function called "Stop Motor".
Have you ever looked at the Timing functions in LabVIEW? Look at the function called "Stall".
So, now, with Run Motor, Stop Motor, and Stall (the first two having Error In and Error Out in their lower left corners and Run having the Boolean input "CW" in its upper left input), using pencil and paper, draw the Block Diagram for "Run the Motor CW for 5 seconds, then Stop".
What change do you have to make to "Run the Motor CCW for 5 seconds, then Stop"? [Hint -- it's the same code as before, but the input to one VI changes).
In LabVIEW, how do you make something repeat, over and over, until you tell it to stop? [Hint -- look at the Structure Palette on the Block Diagram].
Have you learned about the Shift Register, something that you put on the edge of a While or For loop to "feed-back" an Output (a wire that goes to the right-hand edge of the Structure) to a corresponding Input (a wire coming in from the left-hand edge of the Structure)? In your example, what changes every other loop? If you had that element in the Shift Register, how would you change it from one value to another?
At this point, you should see that you now have the motor going CW for 5 seconds, stopping, then going CCW for 5 seconds, stopping, then going CW again ...
Hmm. Maybe we want to wait 5 seconds, stop the motor, then just sit there until somebody pushes a button to say "Do it Again", or a different button that says "Stop". Actually, you never said how the motor starts, so instead of "Do it Again", we should call the button "Move".
Have you learned about the Event structure? This is something that "reacts to an Event", the most common of which is some interacts with a Control on the Front Panel, often a rectangular Boolean Control (like OK, Cancel, and Stop). Do you know why these "act differently" than the other Boolean Controls on the Palette?
Suppose, now, you have an Event Structure inside a While Loop, and you added a "Move" and "Stop" button to your Front Panel. What do you want to happen when you push the Move button? (You've already worked this one out, I hope). What do you want to happen when you push the Stop Button?
Problem (mostly) solved. I have no idea what the Express VIs in the code you attached are doing, but I don't really think it matters (and am reasonably sure it is "wrong").
Review:
Bob Schor