View Full Version : How to program a toggle switch to stop a motor from spinning..?
Team3763 Adam
17-02-2014, 18:52
Simple task, right?
I need a switch program that, when the PVC pipe hits the switch, it will stop powering the motor and prevent power in the same direction until the switch is depressed.
I also need to know how to wire the switch properly so it will function.
MathMaven
17-02-2014, 19:33
The programming is simple. The idea is that a switch will return either a true value or a false value corresponding to whether the switch is being pressed at the moment.
You want the motor to operate normally when the switch is returning false (is not being pressed), and to be allowed to move only backward when the switch is returning true (is being pressed).
I would implement this knowledge as follows:
if ( ![switch name here].Get() )
{
/* control the motor normally */
}
else
{
if ( [motor name here].Get() > 0 ) // or < 0; test to figure out!
{
[motor name here].Set(0); // necessary: otherwise motor will continue
// at whatever speed you left it at
}
}
Naturally, use the syntax of whatever programming language you're using.
I can't help you with the wiring, since I don't know too much about that stuff.
Mark McLeod
17-02-2014, 20:17
Here are two LabVIEW examples.
They are just two different styles, pick what you are most comfortable with.
When the limit switch is wired Normally Open (NO) it reads in the code as false when pressed.
Wired Normally Closed it reads in the code as true when pressed.
Wire to Ground (GND) and pick only one of the other two NC or NO.
If you look at the side of the limit switch, most of them have a diagram labeled GND, NO, and NC to show where the wires go.
If there is no label, then use a multimeter to figure out which is the ground and which is NC or NO.
http://team358.org/files/programming/ControlSystem2009-/sm_LimitSwitch.jpg
http://team358.org/files/programming/ControlSystem2009-/LabVIEW/LimitSwitch2.jpg
Team3763 Adam
18-02-2014, 15:30
Where would the switch wire into? The PD board or the Digital Sidecar?
Mark McLeod
18-02-2014, 15:35
Limit switches get wired to a Digital Input on the Digital Sidecar. Signal and ground pins only (NOT the +5v power pin).
Team3763 Adam
18-02-2014, 16:33
Alright I'll do that very soon, thanks.
Team3763 Adam
18-02-2014, 18:14
I don't think either of those examples would work with what I'm trytrying trying to do. Pretty much we have a pvc pipe that is extending and descending. While descending, I'd like a piece of metal to hit the switch to prevent the motor from pulling the pvc down further.
Mark McLeod
18-02-2014, 18:31
A team I'm mentoring is also moving a pvc pipe up and down, stopping the motor at both the top and the bottom with limit switches.
The right example is good for that.
I don't know what is complicating what you are doing differently.
Team3763 Adam
18-02-2014, 18:47
I think the main complication is how im using 2 true-false statements attached to two separate button.
I can't upload a picture because the photo exceeds size, but buttons 4 & 6 both connect into a true-false triangle. The true of 4 is -1 and the false is connected to the output of button 6. Button 6 has true 1 false 0. The output of the two connects to set motor output
Mark McLeod
18-02-2014, 19:07
Your button 4 Select output would replace "axis 2 (y)" in the example on the right.
Team3763 Adam
18-02-2014, 19:10
And leave button 6 as is?
Mark McLeod
18-02-2014, 19:16
The result of the Button 6 Select feeds the Button 4 Select.
Team3763 Adam
18-02-2014, 19:24
So now onto the wiring. We have switches similar to the one pictured above. But as for wiring into the DS and what wire is nrrdrd I dont know what to do
Mark McLeod
18-02-2014, 20:48
If you have a spare PWM cable, that could be used by cutting off the male end.
The black wire goes to the limit switch GND contact on the bottom of the photograph.
The white wire goes to either the NO or NC contact on the side of the limit switch
The red wire gets cut short and taped over with electrical tape (it's not used)The female end of the PWM cable plugs into a DIO on the Digital Sidecar.
Team3763 Adam
19-02-2014, 20:10
Thank you for this info. During our post-build season I'll wire up a mock where we can test the code and wiring. Thanks for your help!
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.