Go to Post The great thing about liking someone in your robotics team is that they've already seen you at your worst, and you cant shock them with ANYTHING anymore :D - SCROSSLEY-GCEC [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 18-02-2010, 00:47
Twisted eric's Avatar
Twisted eric Twisted eric is offline
Registered User
FRC #0581
 
Join Date: Jan 2010
Location: San Jose
Posts: 54
Twisted eric is an unknown quantity at this point
Limit Switch

In java I'm trying to code a limit switch to my single motor called hunt

Code:
package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Watchdog;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Jaguar;

public class Pup extends SimpleRobot {

    private static final long TIME_DELAY = 1000; // in milliseconds
    RobotDrive drive = new RobotDrive(1, 2);
    Joystick leftstick = new Joystick(1);
    Joystick rightstick = new Joystick(2);
    Jaguar hunt = new Jaguar(4);
    Joystick spot = new Joystick(4);
    Joystick kicker = new Joystick(3);
    Watchdog fenrir = Watchdog.getInstance();
    Compressor fluffy = new Compressor(1, 1);

    void setUpRobot() {
        fluffy.start();
        fenrir.feed();
    }
    
    public void autonomous() {
        setUpRobot();
        fenrir.setEnabled(false);
        while (true && isAutonomous() && isEnabled()) {
            drive.drive(1.0, 0.0);  // drive 100% fwd 0% turn
        }
    }

    public void operatorControl() {
        setUpRobot();
        while (true && isOperatorControl() && isEnabled()) // loop until change
        {
            drive.tankDrive(leftstick, rightstick);
            hunt.set(kicker.getY());
            Timer.delay(0.005);
            fenrir.feed();
        }    
    }
}
but i want it so that when it hits it, it will not go that way
  #2   Spotlight this post!  
Unread 18-02-2010, 09:36
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Limit Switch

Quote:
Originally Posted by Twisted eric View Post
but i want it so that when it hits it, it will not go that way
What does "it" mean?
  #3   Spotlight this post!  
Unread 19-02-2010, 13:59
Twisted eric's Avatar
Twisted eric Twisted eric is offline
Registered User
FRC #0581
 
Join Date: Jan 2010
Location: San Jose
Posts: 54
Twisted eric is an unknown quantity at this point
Re: Limit Switch

Quote:
Originally Posted by Alan Anderson View Post
What does "it" mean?
Sorry I want the limit switch to stop the motor from continuing when hit.
  #4   Spotlight this post!  
Unread 20-02-2010, 21:03
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Limit Switch

Programming for a limit switch is straightforward. You just need to read the value of the switch and test for "active". Sometimes a limit switch will return a True when it's inactive, and False when it's active; sometimes it will be the other way around. You also need to know whether the motor would be moving "forward" or "reverse" when it hits the switch.

When you see that the switch is active and the motor is being asked to travel in the direction you don't want it to go anymore, set the motor value to zero. That's it. If the switch is not active, don't do anything special; that will let the motor move normally. If the motor isn't being told to go in the direction you don't want it to go, don't do anything special; that will let the motor go back away from the limit.
  #5   Spotlight this post!  
Unread 20-02-2010, 22:11
KayyPii's Avatar
KayyPii KayyPii is offline
Registered User
FRC #1404 (SHOCKs)
Team Role: Programmer
 
Join Date: Oct 2008
Rookie Year: 2007
Location: Toronto
Posts: 45
KayyPii will become famous soon enough
Re: Limit Switch

In the API, theres a class called, DigitalInput. Once you create the class and specified with GPIO to keep track of, you can use the get() function to keep track of the state of the switch. Then you can use it as the boolean expression for the "if" statement.
__________________
=>"That hole you drilled is a little off."
=>"Don't panic, just make it bigger and put a washer on it!"

=>Eye ball once, and cut as many times as it takes

  #6   Spotlight this post!  
Unread 21-02-2010, 20:52
Twisted eric's Avatar
Twisted eric Twisted eric is offline
Registered User
FRC #0581
 
Join Date: Jan 2010
Location: San Jose
Posts: 54
Twisted eric is an unknown quantity at this point
Re: Limit Switch

Quote:
Originally Posted by KayyPii View Post
In the API, theres a class called, DigitalInput. Once you create the class and specified with GPIO to keep track of, you can use the get() function to keep track of the state of the switch. Then you can use it as the boolean expression for the "if" statement.


What is the "if" statement for the limit switch.
  #7   Spotlight this post!  
Unread 21-02-2010, 22:58
KayyPii's Avatar
KayyPii KayyPii is offline
Registered User
FRC #1404 (SHOCKs)
Team Role: Programmer
 
Join Date: Oct 2008
Rookie Year: 2007
Location: Toronto
Posts: 45
KayyPii will become famous soon enough
Re: Limit Switch

Say if you made a limit switch and named it switch.

DigitalInput switch = new DigitalInput ( 4, 1 ); //switch on digital side car channel 1

the if may look something like

if ( switch.get () )
//do something when the switch is not tripped
else
//do something when the switch is tripped
__________________
=>"That hole you drilled is a little off."
=>"Don't panic, just make it bigger and put a washer on it!"

=>Eye ball once, and cut as many times as it takes

  #8   Spotlight this post!  
Unread 21-02-2010, 23:23
Twisted eric's Avatar
Twisted eric Twisted eric is offline
Registered User
FRC #0581
 
Join Date: Jan 2010
Location: San Jose
Posts: 54
Twisted eric is an unknown quantity at this point
Re: Limit Switch

Quote:
Originally Posted by KayyPii View Post
Say if you made a limit switch and named it switch.

DigitalInput switch = new DigitalInput ( 4, 1 ); //switch on digital side car channel 1

the if may look something like

if ( switch.get () )
//do something when the switch is not tripped
else
//do something when the switch is tripped
Domo Arigato KayyPii-senpai and Alan-senpai
  #9   Spotlight this post!  
Unread 22-02-2010, 11:56
NullEntity's Avatar
NullEntity NullEntity is offline
Registered User
AKA: Bryce
FRC #0093 (N.E.W. Apple Corps Robotics)
Team Role: Scout
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Appleton
Posts: 108
NullEntity is an unknown quantity at this point
Re: Limit Switch

Slight tip:
Take out the true in
Code:
while (true && isAutonomous() && isEnabled()) {
.

It's not a biggy at all, but you only want while(true) when you want it to infinitly loop. With other conditionals, it's pointless.
__________________
FRC Team 93 Alumni
Closed Thread


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
limit switch solomason519 Programming 9 09-02-2010 08:50
Limit Switch Problem Boydean Programming 3 13-02-2008 16:32
Using a limit switch to limit motion ManicMechanic Programming 16 20-12-2007 00:54
limit switch wedellm Electrical 4 16-02-2007 13:01


All times are GMT -5. The time now is 23:25.

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