Go to Post You can never have enough FIRST! :D - Koko Ed [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 27-10-2012, 15:16
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Limit switches on a lift -- best practice

So, I'm porting over our 2012 Robot to Java and I was wondering about how best to use limit switches within the confines of the command-based template. OI runs the raise/lower commands while a button is being held. Would it be best to put the limit switch code within the subsystem methods like so:

Code:
private CANJaguar liftMotor1;
    private CANJaguar liftMotor2;
    
    private DigitalInput upperLimitSwitch;
    private DigitalInput lowerLimitSwitch;

public void initDefaultCommand() {
        // Set the default command for a subsystem here.
        setDefaultCommand(new ArmDoNothing());
    }
    
    public Arm() {        
        initCAN();        
    }

.....

public void doNothing() throws CANTimeoutException {
        liftMotor1.setX(0.0);
        liftMotor2.setX(0.0);
    }
    
public void raiseArm() throws CANTimeoutException {
        while(!getTopLimit())
            {
                liftMotor1.setX(0.1);
                liftMotor2.setX(-0.1);
            }
    }
    
public void lowerArm() throws CANTimeoutException {
        while(!getBottomLimit())
            {
                liftMotor1.setX(0.1);
                liftMotor2.setX(-0.1);
            }
    }
    
public boolean getTopLimit() {
        if(upperLimitSwitch.get()) {
            return true;
        } else {
            return false;
        }
    }
    
    public boolean getBottomLimit() {
        if(lowerLimitSwitch.get()) {
            return true;
        } else {
            return false;
        }
    }
(and as an aside, I've tested none of this, and I'm sure I probably did something wrong, but you get the point)

Or, would it be best to put the limit switch code within the Commands under execute() or isFinished()? Which I assume would go something like:

Quote:
protected void execute() {
while(!arm.getTopLimit()) {
try {
arm.raiseArm();
} catch (CANTimeoutException ex) {
System.out.println(ex);
}
}
}
or

Code:
boolean stop;
    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        if(arm.getTopLimit()) {
            stop = true;
        } else {
            stop = false;
        }
        
        try {
            arm.raiseArm();
        } catch (CANTimeoutException ex) {
            System.out.println(ex);
        }
    }
    
    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return stop;
    }
Are they all more or less equivalent, or is there one way that has significant advantages over the others? Also, am I doing this completely wrong
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
  #2   Spotlight this post!  
Unread 27-10-2012, 21:24
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Limit switches on a lift -- best practice

To me, dealing with limit switches is a problem internal to the Subsystem - if it had to be dealt with by Commands, it would make every one of your Commands more complicated, which to me seems like insufficient abstraction. As for how to do it, I'd probably do something similar to how WPILibJ's PIDController works - use an internal TimerTask or Thread to handle the checking and overriding. That way, it doesn't matter what the Commands try to do - the Subsystem simply won't allow it to go beyond the limits.
  #3   Spotlight this post!  
Unread 28-10-2012, 15:20
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,102
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Limit switches on a lift -- best practice

A better way to do it is connect the limit switch directly to the Jaguar, so then you don't have to write any software to make it work
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
  #4   Spotlight this post!  
Unread 28-10-2012, 15:46
nighterfighter nighterfighter is offline
1771 Alum, 1771 Mentor
AKA: Matt B
FRC #1771 (1771)
Team Role: Mentor
 
Join Date: Sep 2009
Rookie Year: 2007
Location: Suwanee/Kennesaw, GA
Posts: 835
nighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant future
Re: Limit switches on a lift -- best practice

Quote:
Originally Posted by virtuald View Post
A better way to do it is connect the limit switch directly to the Jaguar, so then you don't have to write any software to make it work
We did this in 2011, and when it worked, it was GREAT.

However there was a problem with the CAN software in 2011 where if a limit switch was pressed and connected to the jaguar when the robot was turned on, it would cause the scrolling CAN error. (Hundreds of error messages, resulting in a robot that couldn't move)

I'm not sure if this was fixed. It probably was.

And you might still need some software to prevent the lift from going full speed into the limit switch. Ouch.
  #5   Spotlight this post!  
Unread 28-10-2012, 18:08
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: Limit switches on a lift -- best practice

We haven't messed around with direct sensor-Jaguar control yet, so I don't know how it all works, but I'm not sure it would work for our situation. We used a screw-style lift (lead screw) which needs limit switches on both the top and the bottom. We also used two motors to drive the lift, which means two Jaguars because the GDC doesn't allow running two motors off of one controller. Correct me if I'm wrong but the Jaguar only allows input from one sensor at a time; and we need it to be able to accept from two. And since we have two Jaguars that also means we'd need 4 limit switches unless there's some way to split or duplicate the signal to both of them.
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
  #6   Spotlight this post!  
Unread 28-10-2012, 19:48
ebarker's Avatar
ebarker ebarker is offline
Registered User
AKA: Ed Barker
FRC #1311 (Kell Robotics)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Kennesaw GA
Posts: 1,437
ebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond repute
Re: Limit switches on a lift -- best practice

The best way is to wire them to the Jag inputs, but if you are doing this for a FIRST competition I think the rule book requires you to wire them to the cRio and do the work in software.
__________________
Ed Barker
  #7   Spotlight this post!  
Unread 28-10-2012, 19:56
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,125
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Limit switches on a lift -- best practice


2012 Rule R58-J:

Limit switch jumpers may be removed from a Jaguar speed controller and a custom limit switch circuit may be substituted.




Last edited by Ether : 28-10-2012 at 20:02.
  #8   Spotlight this post!  
Unread 28-10-2012, 20:18
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: Limit switches on a lift -- best practice

Quote:
Originally Posted by Ether View Post

2012 Rule R58-J:

Limit switch jumpers may be removed from a Jaguar speed controller and a custom limit switch circuit may be substituted.



At that point, it's probably easier just to write the 10-12 lines of code it takes to control it with software.

So the general consensus was to put it on the subsystem side as opposed to in execute()?
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional

Last edited by F22Rapture : 28-10-2012 at 20:23.
  #9   Spotlight this post!  
Unread 28-10-2012, 22:02
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,125
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Limit switches on a lift -- best practice

Quote:
Originally Posted by F22Rapture View Post
At that point, it's probably easier just to write the 10-12 lines of code it takes to control it with software.
I believe what Rule R58-J is saying is that you can simply connect the limit switch to the Jag. That is a "custom circuit".


  #10   Spotlight this post!  
Unread 28-10-2012, 22:59
ratdude747's Avatar
ratdude747 ratdude747 is offline
Official Scorekeeper
AKA: Larry Bolan
no team
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Madison, IN
Posts: 1,064
ratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond repute
Re: Limit switches on a lift -- best practice

Quote:
Originally Posted by Ether View Post
I believe what Rule R58-J is saying is that you can simply connect the limit switch to the Jag. That is a "custom circuit".


Correct.

The reason they said "custom" circuit is that in spirit of the rule, it could be anything from a simple limit switch to some crazy ultrasonic circuit. You could even pop in a toggle switch for the rule cares.

However, if the lift is like some I've seen/built, then you may have more than two switches involved (like one for each intermediate point used). In that case, then you would have to do at least some of the switches in software, as the jag is only good for two switches.

Generally those two are designed to be your high and low points; these are the points where if you were to overshoot it by a considerable margin very bad things would happen (like stripping a gearbox, breaking an arm joint, accidentally firing a ball, etc.) However, if you choose to split your switches between hardware and software, there is no "wrong" answer in terms of functionality.
__________________
Dean's List Semi-finalist 2010
1747 Harrison Boiler Robotics 2008-2010, 2783 Engineers of Tomorrow 2011, Event Volunteer 2012-current

DISCLAIMER: Any opinions/comments posted are solely my personal opinion and does not reflect the views/opinions of FIRST, IndianaFIRST, or any other organization.
  #11   Spotlight this post!  
Unread 28-10-2012, 23:26
AlexH AlexH is offline
Registered User
no team
Team Role: College Student
 
Join Date: Sep 2010
Rookie Year: 2010
Location: PA
Posts: 215
AlexH is a name known to allAlexH is a name known to allAlexH is a name known to allAlexH is a name known to allAlexH is a name known to allAlexH is a name known to all
Re: Limit switches on a lift -- best practice



i like limit switches like this where when the switch is tripped it kills power to the motor in one direction but allows you to power the motor in the other direction

http://www.radioshack.com/product/in... rValue=Diodes

i've used that diode with 550 china drill motor at 5s to lift 30lb robots
__________________
My Instructables
  #12   Spotlight this post!  
Unread 29-10-2012, 07:38
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,906
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Limit switches on a lift -- best practice

It should be noted that the previous custom circuit is not legal for FRC per R47.

It's okay for non FRC use, however you must make sure to use both switches and diodes rated for the current they will be passing.
Warning - potential fire hazard

Quote:
[R47]
Custom circuits shall not directly alter the power pathways between the battery, PD Board, speed controllers,
relays, motors, or other elements of the Robot control system (including the power pathways to other sensors or
circuits). Custom high impedance voltage monitoring or low impedance current monitoring circuitry connected to
the Robot’s electrical system is acceptable, if the effect on the Robot outputs is inconsequential.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 29-10-2012 at 07:40.
  #13   Spotlight this post!  
Unread 29-10-2012, 10:24
dyanoshak dyanoshak is offline
Registered User
AKA: David Yanoshak
FRC #2158 (ausTIN CANs)
Team Role: Mentor
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Austin, TX
Posts: 191
dyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond repute
Re: Limit switches on a lift -- best practice

Quote:
Originally Posted by F22Rapture View Post
Correct me if I'm wrong but the Jaguar only allows input from one sensor at a time; and we need it to be able to accept from two.
The Jaguar can definitely read two limit switches at the same time. This is regardless of the communication mode (CAN or PWM).

Quote:
Originally Posted by AlexH View Post


i like limit switches like this where when the switch is tripped it kills power to the motor in one direction but allows you to power the motor in the other direction
This is exactly how the limit switches are handled in Jaguar's firmware. There is one switch for Forward and one switch for Reverse (marked with an F and R). If only the R switch goes open-circuit, only the Reverse direction is stopped.

-David
  #14   Spotlight this post!  
Unread 29-10-2012, 13:05
jerry w's Avatar
jerry w jerry w is offline
Free Agent Mentor
no team (Team Krunch)
Team Role: Engineer
 
Join Date: Nov 2003
Rookie Year: 2002
Location: dunedin fl
Posts: 113
jerry w has much to be proud ofjerry w has much to be proud ofjerry w has much to be proud ofjerry w has much to be proud ofjerry w has much to be proud ofjerry w has much to be proud ofjerry w has much to be proud ofjerry w has much to be proud ofjerry w has much to be proud of
Re: Limit switches on a lift -- best practice

be careful with while loops. such as;
Code:
while(!getTopLimit())
Remember that the top level loop is controlling robot communication with the field. When you add lower level loops, everything waits for those loops to finish.
It is best to use "IF" statements and avoid loops.
__________________
Happiest when people tell the truth... However, I am blessed with many friends.
  #15   Spotlight this post!  
Unread 29-10-2012, 13:12
Andrew Schreiber Andrew Schreiber is offline
Joining the 900 Meme Team
FRC #0079
 
Join Date: Jan 2005
Rookie Year: 2000
Location: Misplaced Michigander
Posts: 4,080
Andrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond repute
Re: Limit switches on a lift -- best practice

Quote:
Originally Posted by jerry w View Post
be careful with while loops. such as;
Code:
while(!getTopLimit())
Remember that the top level loop is controlling robot communication with the field. When you add lower level loops, everything waits for those loops to finish.
It is best to use "IF" statements and avoid loops.
Not always true any more. With the old IFI system it was but now we have a real time operating system. If you spawn off your limit checking code into a new process this while(!getTopLimit()) will function as expected. However, you would need to create a new process for the bottom limit as well. Because of the cost associated with context switches it may not be the best approach.
__________________




.
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


All times are GMT -5. The time now is 01:36.

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