View Single Post
  #45   Spotlight this post!  
Unread 06-02-2015, 23:40
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Electrical/Programming Mentor
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,784
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: Limit Swtich Help

While the brake setting will help, it may not be your issue. It depends on what, exactly, the behavior is.

Take a look at this portion of the code:
Code:
            if(limitPressed || limitPressed2 == false || limitPressed3 == false || limitPressed4 == false) {
            	victor1.set(0);
            	victor2.set(0);
            } else if (-leftaxis > 0.5) {
            	victor1.set(1);
            	victor2.set(1);
            } else {
            	victor1.set(0);
            	victor2.set(0);
            }
            if(leftaxis > 0.5) {
            	victor1.set(-1);
            	victor2.set(-1);
            } else {
            	victor1.set(0);
            	victor2.set(0);
            }

There are two if/else blocks here. The first one controls going up, the second going down, I assume. However, your limit switch at the bottom of the lead screw is being checked in the first if statement. What this may be doing is telling your motors to stop in the first if statement, then in the second telling them to go down. So you end up with a fast oscillation between stop and down.

When I'm working with a motor, I try to combine all control of the motor into a single if/else block, or in a single set command, just to make sure I don't get into a situation where I'm telling it two different things every loop through.

For this situation, I might do something like:
Code:
if (operator says to go up AND I haven't hit the top limit switch yet)
{
  go up
}
else if (operator says to go down AND I haven't hit the bottom limit switch yet)
{
  go down
}
else
{
  stop
}
Obviously, that's pseudocode... its up to you to figure out how to translate that to real code

Also, check the third and fourth limit switches... your comments say they are for controlling left to right motion of the gripper, but in your code they're set up to work with the up/down motion of the elevator. Are you controlling the left/right motion with the relays? If so, you'll want to work those into the if/else block that deals with the relays!
__________________
2007 - Present: Mentor, 2177 The Robettes
LRI: North Star 2012-2016; Lake Superior 2013-2014; MN State Tournament 2013-2014, 2016; Galileo 2016; Iowa 2017
2015: North Star Regional Volunteer of the Year
2016: Lake Superior WFFA
Reply With Quote