View Full Version : Need help with logic
bacarpenter
09-03-2015, 15:35
I'm trying to make a program that will make three motors turn until the lifts they are controlling hit the limit switch we have at the bottom of the lifts. I need the lifts to go in order from the lowest to the highest lift (we have encoders) As of currently I've been putting logic into periodic tasks but I can't seem to get it to work. Anyone have any ideas?
I posted the code that I'm currently using, this is a vi I made that is inside of periodic tasks
Alan Anderson
09-03-2015, 15:55
A loop does not produce an output until it ends. Your VI will execute until the limit switch is activated, then end and output a value of zero.
I don't understand the description of what you want to do. Can you give some more detail, and maybe include a picture or diagram of what you're controlling?
bacarpenter
09-03-2015, 16:31
A loop does not produce an output until it ends. Your VI will execute until the limit switch is activated, then end and output a value of zero.
I don't understand the description of what you want to do. Can you give some more detail, and maybe include a picture or diagram of what you're controlling?
We have three lifts with an attachment connected to them to pick up crates and there are limit switches at the bottom of the lift so I'm trying to make logic that when a button is pressed on the joystick the corresponding lift will go down till it hits the switch
Alan Anderson
09-03-2015, 17:12
I'm not quite sure what the picture is supposed to show me, but I'll take a guess. Is each lift a lead screw driven by a belt from a motor?
Are all three lifts independent, or do they need to coordinate with each other somehow? I will assume that each lift works on its own.
Once the button is pressed, do you want the lift motor to continue running until the limit switch is activated, or do you want the motor to stop when the button is released? I will assume that you want the button to start the motor, and only the limit switch will stop it. (That's dangerous, but it sounds like what you asked for.)
The simple way to do it is to use a flat sequence inside a neverending while loop in Periodic Tasks. The first frame of the sequence waits for the joystick button to be pressed. The second frame sets the motor to run the lift downward. The third frame waits for the limit switch to be activated. The fourth frame stops the motor. If that's not enough of a hint, ask for more help about what you don't understand.
There should also be a failsafe in the part that waits for the limit switch. I suggest an "abort" button on the joystick that stops the lift motor on command, and also a timer that stops it if too much time has elapsed. You could also stop driving the motor if the encoder indicates that the lift has moved too far, or if it has stopped.
bacarpenter
09-03-2015, 18:04
All your assumptions are correct. The only problem is that I've never used flat sequences outside of auto so how exactly does one flat sequence?
Alan Anderson
09-03-2015, 18:20
Just put the flat sequence inside a while loop in Periodic Tasks. Right-click on the edge and add frames as needed.
Each of the "wait until" steps should be implemented as a while loop inside one of the frames. Put the code to read a joystick button or limit switch inside the loop, with the logic set up to stop the loop when the desired condition occurs. Also add a 5-20 millisecond Wait inside the loop, to keep it from running as fast as possible and starving other tasks of CPU time.
bacarpenter
09-03-2015, 18:23
That's really simple thanks! :]
bacarpenter
10-03-2015, 15:38
Just put the flat sequence inside a while loop in Periodic Tasks. Right-click on the edge and add frames as needed.
Each of the "wait until" steps should be implemented as a while loop inside one of the frames. Put the code to read a joystick button or limit switch inside the loop, with the logic set up to stop the loop when the desired condition occurs. Also add a 5-20 millisecond Wait inside the loop, to keep it from running as fast as possible and starving other tasks of CPU time.
I tried to do what you said but the while loop inside of the flat sequence runs and the outside loops isn't executed. I posted a picture of what I currently have
Alan Anderson
10-03-2015, 16:25
I tried to do what you said but the while loop inside of the flat sequence runs and the outside loops isn't executed. I posted a picture of what I currently have
With that code, you're essentially taking a snapshot of the joystick button and the limit switch before the flat sequence begins, and not reading them again until it has ended.
You need to put the Joystick Get and the Switch Get Value functions inside their respective loops, so that you're repeatedly reading their current value.
bacarpenter
10-03-2015, 18:04
With that code, you're essentially taking a snapshot of the joystick button and the limit switch before the flat sequence begins, and not reading them again until it has ended.
You need to put the Joystick Get and the Switch Get Value functions inside their respective loops, so that you're repeatedly reading their current value.
Okay so I put it inside of the while loop and it works but it'll only work once.
Kevin Phan
10-03-2015, 18:21
I would suggest combining the first frames of your program, just to clean it up. It doesn't change any thing, but makes it neater. By once, do you mean it runs until it hits the limit switch?
bacarpenter
10-03-2015, 19:27
I would suggest combining the first frames of your program, just to clean it up. It doesn't change any thing, but makes it neater. By once, do you mean it runs until it hits the limit switch?
It runs once it'll stop when the limit switch is pressed but if you press the button again it won't work it says its not executed
Kevin Phan
10-03-2015, 19:40
Well since the limit switch is pressed, the loop will continue seeing true. What you need to do is to create a case structure that checks the button being pressed and when the limit is pressed. I suggest creating a truth table as you have 2 Boolean elements. There is a Boolean array to number express vi that will change the default case structure into a numeric structure. I have an examination to how to do this in a guide I made. Here's the link to it (http://www.chiefdelphi.com/forums/showthread.php?t=124145). This guide does not cover any new vis or changes made to LabVIEW for this season. LabVIEW's mechanics have not changed significantly and the examples shown will work. If you want to pursue this path, be attentive to the changes you made. Be aware of the states of your sensors before, during and after the action your robot will make after the button is pressed.
Alan Anderson
10-03-2015, 22:52
Okay so I put it inside of the while loop and it works but it'll only work once.
In order for the outer While to run again, everything inside it has to complete. You have three Flat Sequences there, each waiting for a joystick button and then a limit switch before they will finish. By putting all of those sequences in the same While, you have made it necessary to run all three of the lifts to the bottom before you can run any of them to the bottom again.
If your lifts are truly independent, put the code for each of them in its own While loop.
bacarpenter
11-03-2015, 11:44
Thanks for the help! I got it to work after putting the flat sequence inside of a case structure that executes whenever the button is pressed
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.