Go to Post On the contrary, you've had several helpful responses. You might be confusing "helpful" with "do my homework for me." - Rick TYler [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #46   Spotlight this post!  
Unread 02-07-2015, 10:33 AM
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: Limit Swtich Help

Quote:
Originally Posted by Jon Stratis View Post
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!
Okay so if I remember correctly I can use && for and so could I do something like this?
Code:
if(-axis > 0.5 && limitPressed2 == true) { //I am using true because the limit switch is off when open and on when closed
     victor1.set(1);
     victor2.set(1);
} else if(axis > 0.5 && limitPressed == false) {
     victor1.set(-1);
     victor2.set(-1);
}else {
     victor1.set(0);
     victor2.set(0);
} if(xbox.getRawButton(4) && limitPressed3 == true) {
     spike1.set(Relay.Value.kForward);
     spike2.set(Relay.Value.kForward);
} else if(xbox.getRawButton(1) && limitPressed 4 == true) {
     spike1.set(Relay.Value.kReverse);
     spike2.set(Relay.Value.kReverse); 
} else {
     spike1.set(Relay.Value.kOff);
     spike1.set(Relay.Value.kOff);
}

Last edited by curtis0gj : 02-07-2015 at 12:37 PM.
Reply With Quote
  #47   Spotlight this post!  
Unread 02-08-2015, 04:21 PM
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: Limit Swtich Help

Jon Stratis, does this look okay I feel as if I don't need to set my limit switches to true/false in the if statements also should I add any timer delays?

Code:
    public void operatorControl() {
    	
    	while (isOperatorControl() && isEnabled()) {
    	    double leftaxis = xbox.getRawAxis(1);
    	    double rightaxis = xbox.getRawAxis(4);
    	    double rightyaxis = xbox.getRawAxis(5);
            robot.arcadeDrive(stick.getY() * 0.5, stick.getX() * 0.5); //Change the 0.5 for sensitivity, I removed get throttle I may need it again.
            limitPressed = limit.get(); 
            limitPressed2 = limit2.get();
            limitPressed3 = limit3.get();
            limitPressed4 = limit4.get();
            
            /* REMINDER limitPressed is an opposite type of limit switch!
             * victor1 and victor2 will power the lead screw.
             * victor3 will open and close arms.
             * limitPressed will be the bottom of the lead screw.
             * limitPressed2 will be the top of the lead screw.
             * limitPressed3 will the for the left minimum arm distance.
             * limitPressed4 will be for the max arm distance.
             * The print lines are helpful for testing boolean states.
            //System.out.println("limitPressed=" + limitPressed); //Read the RoboRIO log for some values.
            //System.out.println("limitPressed2=" + limitPressed2);
            //System.out.println("limitPressed3=" + limitPressed3);
            //System.out.println("limitPressd4=" + limitPressed4);
            */

            if(-leftaxis > 0.5 && limitPressed2 == true) {
            	victor1.set(1);
            	victor2.set(1);
            } else if(leftaxis > 0.5 && limitPressed == false) {
            	victor1.set(-1);
            	victor2.set(-1);
            } else {
            	victor1.set(0);
            	victor2.set(0);
            }
            
            if(-rightyaxis > 0.5 && limitPressed4 == true) {
            	victor3.set(1);
            } else if(rightyaxis > 0.5 && limitPressed3 == true) {
            	victor3.set(-1);
            } else {
            	victor3.set(0);
            }
            
            if(-rightaxis > 0.5) {
            	spike1.set(Relay.Value.kForward);
            	spike2.set(Relay.Value.kForward);
            } else if(rightaxis > 0.5) {
            	spike1.set(Relay.Value.kReverse);
            	spike2.set(Relay.Value.kReverse);     
            } else {
            	spike1.set(Relay.Value.kOff);
            	spike2.set(Relay.Value.kOff);            	
            }
    	}
    }
Reply With Quote
  #48   Spotlight this post!  
Unread 02-08-2015, 05:38 PM
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,720
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

That looks great to me. I think it'll work great for you!
__________________
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
  #49   Spotlight this post!  
Unread 02-08-2015, 05:41 PM
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: Limit Swtich Help

Quote:
Originally Posted by Jon Stratis View Post
That looks great to me. I think it'll work great for you!
Alright awesome thanks for all the help I will try it out tomorrow.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 08:46 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi