View Single Post
  #7   Spotlight this post!  
Unread 20-02-2013, 17:44
Anyun Anyun is offline
Co-Captain Team 1308
FRC #1308 (Wildcats)
Team Role: Programmer
 
Join Date: Aug 2012
Rookie Year: 2009
Location: Cleveland
Posts: 13
Anyun is an unknown quantity at this point
Re: How to code limit switch to stop movement

We're actually doing something similar. Our launcher is lifted using two motors (LifterA and Lifter B), and we wired our limit switches so that the upper is 1 when depressed and the lower is 1 when open. The upper limit becomes open onces the ramp reaches the furthest up we want it to go, while the lower limit becomes closed when it goes the furthest down we want it to go. Our code looks something like this:

if(stick.GetRawButton(4) && UpperLimit.Get() == 1)
// if button 4 is pressed and upper limit is pressed, lifter goes up
{
LifterA.Set(0.4);
LifterB.Set(0.4);
}
else if(stick.GetRawButton(5) && LowerLimit.Get() == 1)
// if button 5 is pressed and lower limit is not pressed, lifter goes down
{
LifterA.Set(-0.4);
LifterB.Set(-0.4);
}
else
{
LifterA.Set(0.0);
LifterB.Set(0.0);
}
Reply With Quote