View Full Version : Limit Switch Help
nickphowell
06-11-2014, 19:04
Our programming team is having some issues with setting up two limit switches. After button 4 is pressed, our first limit switch, Limit Switch, is supposed to stop our motors. After button 5 is pressed, the second limit switch, Limit Switch 2, is supposed to stop the motors once again.
When we run the code, the upper portion works properly (see picture), but our motors seem to fight each other.
Any help or input would be welcomed, and we are open to try everything.
Thank you
http://imgur.com/EvqRgHi
nickphowell
06-11-2014, 19:05
In case the picture did not show, the link is here:
http://imgur.com/EvqRgHi
Mark McLeod
06-11-2014, 19:35
You really don't want to be addressing one motor from two conflicting places at the same time. That's why they fight each other. Are you also setting the same motors in both False cases? That would be telling it to go and stop at the same time.
You need a Wait (say 10ms) in your loops otherwise you threaten to overload and lock up your CPU.Instead, make all your decisions about what you want the motor to do, then set the motor only once.
Here's an example for a Relay. Just replace the Relay with your motor in the sequence you want.
Since you are keying off two different limit switches you can also select and pass in the corresponding limit switch name or reference.
nickphowell
15-11-2014, 12:40
You really don't want to be addressing one motor from two conflicting places at the same time. That's why they fight each other. Are you also setting the same motors in both False cases? That would be telling it to go and stop at the same time.
You need a Wait (say 10ms) in your loops otherwise you threaten to overload and lock up your CPU.Instead, make all your decisions about what you want the motor to do, then set the motor only once.
Here's an example for a Relay. Just replace the Relay with your motor in the sequence you want.
Since you are keying off two different limit switches you can also select and pass in the corresponding limit switch name or reference.
How do you wire and use a relay? We are a brand new programming team, so we do not know everything there is to know......yet.
We went ahead and tried a new chunk of code, and that is not working either. However, it worked better than previously. What went wrong is our "Up" case would not work properly. The motors would not work when this case was triggered, but the "Default" and the "Down" cases worked perfectly. The "Default" case just sets the motor output to 0.
Here are pictures of what the code looks like right now.
http://imgur.com/yLUmJ8J
http://imgur.com/f80i1KW
nickphowell
15-11-2014, 16:49
Alright, so we have figured out our problem. Thank you all for the help
Iaquinto.Joe
19-11-2014, 06:30
An additional tip:
Every time you call the reference VI, it will get a joystick reference twice. It's better practice to make a habit to only get references once if you can manage it. It will marginally make you code faster and increase readability.
Greg McKaskle
19-11-2014, 07:10
An additional tip:
In other words, if the code will return the same value as you already have, you can just wire the value to two or more places.
Greg McKaskle
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.