Go to Post But FIRST isn't FRC anymore. We need to make way for FTC and FLL. - Tetraman [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
  #1   Spotlight this post!  
Unread 15-02-2015, 15:03
Team 4939 Team 4939 is offline
Registered User
AKA: Anshul Shah
FRC #4939 (All spark 9)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Brampton
Posts: 52
Team 4939 is an unknown quantity at this point
Programming Limit Switches

Hello FRC Community,

We were putting some Limit Switches on our robot. I was trying some different interpretations of what I found here: https://wpilib.screenstepslive.com/s...ntrol-behavior

But I cant seem to understand it.

What I basically need to do is set a motor value to 0 when the switch is hit.

Any help would be appreciated.

Thanks in Advance.
Reply With Quote
  #2   Spotlight this post!  
Unread 15-02-2015, 15:51
legts legts is offline
Autonomous Queen
FRC #2399 (The Fighting Unicorns)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2012
Location: Ohio
Posts: 73
legts is an unknown quantity at this point
Re: Programming Limit Switches

What you want to do is use code that is sort of like the following:

if(limitSwitch.get() == true){
motorName.stopMotor();
}

This code waits for a limit switch to be pressed. When it is pressed it turns true, triggering the contents of the if statement. The contents call the WPI method stopMotor on the motor. Hopefully this helped.
Reply With Quote
  #3   Spotlight this post!  
Unread 15-02-2015, 22:35
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,654
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Programming Limit Switches

Unless you are making a one-shot device, you need to be a bit more subtle. For argument sake, and since it's the more common case for limit switches this year, I'll assume your actuator is moving up and down. I'll also assume that motion in the positive direction is up, and the negative direction is down.

If the top limit switch is set, you want to limit your applied force so that it can only be zero or negative; you may want to "come down" later.

If the bottom limit switch is set, you want to limit your applied force so that it can only be zero or positive; you may want to "go up" later.

Just doing the full initializer and the set() methods, it would look something like:
Code:
Class MyWinchController extends Talon {
    DigitalInput topLimitSwitch;
    DigitalInput bottomLimitSwitch;

    MyWinchController(int PWM, int topLimitDIO, int bottomLimitDIO) {
        super(PWM);
        topLimitSwitch = new DigitalInput (topLimitDIO);
        bottomLimitSwitch = new DigitalInput (bottomLimitDIO);
    }

    set(double speed) {
        if (topLimitSwitch.get() && (speed>0.0)) speed = 0.0;
        if (bottomLimitSwitch.get() && (speed<0.0)) speed = 0.0;
        super.set(speed);
    }
}
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #4   Spotlight this post!  
Unread 16-02-2015, 09:31
BrianAtlanta's Avatar
BrianAtlanta BrianAtlanta is offline
Registered User
FRC #1261
Team Role: Mentor
 
Join Date: Apr 2014
Rookie Year: 2012
Location: Atlanta, GA
Posts: 70
BrianAtlanta has a spectacular aura aboutBrianAtlanta has a spectacular aura about
Re: Programming Limit Switches

Also, be aware to check the limit switch before turning on a motor, not just when to turn it off. So, for example, button A raises a lift when held for example. When the lift hits a limit switch, it stops without having the operator releasing the button. Now the lift is at the top. But, if the operator presses the same button again the lift shouldn't move. This is one condition that our new programmers don't think about. They would start the motor and then check to limit switch in the IsFinished method. Which caused the lift to start slowly pulsing up. So, they learned to check the limit switch before starting the motor, and then check in the IsFinished.

This is a great learning experience for them. As I say at work "Programming the Happy path is easy. It's how you handle the unexpected is what makes it hard." Great way for them to learn to think beyond the requirements, to the undocumented requirements.

Brian
Reply With Quote
  #5   Spotlight this post!  
Unread 16-02-2015, 20:03
Team 4939 Team 4939 is offline
Registered User
AKA: Anshul Shah
FRC #4939 (All spark 9)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Brampton
Posts: 52
Team 4939 is an unknown quantity at this point
Re: Programming Limit Switches

Quote:
Originally Posted by GeeTwo View Post
Unless you are making a one-shot device, you need to be a bit more subtle. For argument sake, and since it's the more common case for limit switches this year, I'll assume your actuator is moving up and down. I'll also assume that motion in the positive direction is up, and the negative direction is down.

If the top limit switch is set, you want to limit your applied force so that it can only be zero or negative; you may want to "come down" later.

If the bottom limit switch is set, you want to limit your applied force so that it can only be zero or positive; you may want to "go up" later.

Just doing the full initializer and the set() methods, it would look something like:
Code:
Class MyWinchController extends Talon {
    DigitalInput topLimitSwitch;
    DigitalInput bottomLimitSwitch;

    MyWinchController(int PWM, int topLimitDIO, int bottomLimitDIO) {
        super(PWM);
        topLimitSwitch = new DigitalInput (topLimitDIO);
        bottomLimitSwitch = new DigitalInput (bottomLimitDIO);
    }

    set(double speed) {
        if (topLimitSwitch.get() && (speed>0.0)) speed = 0.0;
        if (bottomLimitSwitch.get() && (speed<0.0)) speed = 0.0;
        super.set(speed);
    }
}
If I am using a simple motor for my elevator system, would I need the && statements for speed?

If I wanted the elevator to go in the opposite direction for about 1 second based on which switch is pressed, what would that look like?

And what is 'super(PWM)' represent?
Reply With Quote
  #6   Spotlight this post!  
Unread 17-02-2015, 11:42
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,654
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Programming Limit Switches

Quote:
Originally Posted by Team 4939 View Post
If I am using a simple motor for my elevator system, would I need the && statements for speed?
I'm not sure what you mean. This does not have "warning track" switches as I described earlier in the thread. I was assuming a simple motor, so probably yes. If you only have one limit switch, you can remove the if statement for the switch you don't have. The reason for the && part of the test is that you don't want to set the speed to zero if your speed moves you away from the limit switch.

Quote:
Originally Posted by Team 4939 View Post
If I wanted the elevator to go in the opposite direction for about 1 second based on which switch is pressed, what would that look like?
Within the timeout loop, using the same sense of switches and directions as the example, and assuming fulll speed:
Code:
motor.set(TopLimitSwitch.get() ? -1 : BottomLimitSwitch.get() ? 1 : 0);
or in long form:
Code:
if (TopLimitSwitch.get() {
    motor.set(-1);
} else if (BottomLimitSwitch.get() {
    motor.set(1);
} else {
    motor.set(0);
}

Quote:
Originally Posted by Team 4939 View Post
And what is 'super(PWM)' represent?
This calls the initiator Talon(), but does not create a separate object; it is the beginning of creating this one. Also, super.set() calls the talon set() function.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #7   Spotlight this post!  
Unread 17-02-2015, 11:45
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,654
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Programming Limit Switches

Quote:
Originally Posted by BrianAtlanta View Post
Also, be aware to check the limit switch before turning on a motor, not just when to turn it off.
This is why overriding the set() method as I did above is really the best object-oriented way to do this. Every call to set() for that object will automatically include the limit switch check. Write it once, test it, then forget about it.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #8   Spotlight this post!  
Unread 30-03-2015, 12:23
WillNess's Avatar
WillNess WillNess is offline
Programmer
AKA: Will Ness
FRC #4944 (The Hi Fives)
Team Role: Programmer
 
Join Date: Apr 2014
Rookie Year: 2014
Location: United States
Posts: 90
WillNess is just really niceWillNess is just really niceWillNess is just really niceWillNess is just really nice
Re: Programming Limit Switches

Just a FYI: The limit switches I have return true when not pressed, and false when pressed.
__________________

Outreach Lead // Lead Programmer // Junior

2014 FRC:
Rookie Allstar, Highest Rookie Seed & Semifinalist @ Utah
Rookie Allstar, Highest Rookie Seed & Semifinalist @ Colorado
2015 FRC:
Creativity In Engineering & Semifinalist @ Arizona West
Reply With Quote
  #9   Spotlight this post!  
Unread 30-03-2015, 13:32
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,654
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Programming Limit Switches

Quote:
Originally Posted by WillNess View Post
Just a FYI: The limit switches I have return true when not pressed, and false when pressed.
Simply replace the TopLimitSwitch.get() calls with !TopLimitSwitch.get() and the BottomLimitSwitch.get() with !BottomLimitSwitch.get(). I also assumed that moving up required a positive setting on the motor; you may need to negate the motor speeds.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #10   Spotlight this post!  
Unread 30-03-2015, 17:36
dawonn's Avatar
dawonn dawonn is offline
Mentor
AKA: Dereck
FRC #2586 (Calumet Copperbots)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Auburn Hills, Mi
Posts: 53
dawonn is an unknown quantity at this point
Re: Programming Limit Switches

Always add an option to your drivers station to remotely disable all limit switches. If a switch is damaged in a match you might want to override them so you can keep playing and your drivers will just need ro be more careful than usual for that march.
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 12:32.

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