Go to Post The 2008 team is not the 2007 team and won't be the 2009 team. Every year is a new year and a new opportunity for growth and development as a FIRST team. It's very cool. - JaneYoung [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
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 17-02-2013, 17:47
Nyle's Avatar
Nyle Nyle is offline
Registered User
FRC #0422 (The Mech Tech Dragons)
Team Role: Leadership
 
Join Date: Feb 2013
Rookie Year: 2012
Location: Richmond, Virginia
Posts: 28
Nyle is just really niceNyle is just really niceNyle is just really niceNyle is just really nice
How to code limit switch to stop movement

Our robot's articulator for adjusting the vertical angle of the shooter has limit switches on the top and bottom to stop it from going too far in either direction. Currently our code has three methods in the shooter articulator subsystem used for moving it: moveUp(), moveDown(), and stop(). The moveUp() and moveDown() methods check if the limit switch they would be moving towards is pressed, if it is not sets the talon to 1.0 or -1.0, and if it is calls the stop() method, which sets the talon to 0. This makes sure that the articulator doesn't extend beyond where it is supposed to travel as long as one of the movement methods is being called continually (currently they are), but if they aren't being continually called the limit switches won't stop the articulator from moving (for instance, if moveUp() were to be called once, it would check the top limit switch, and if it isn't pressed, set the talon to 1.0. This unfortunately won't stop when the limit switch is pressed.). I have a feeling that there is a better way to do this, but I don't know what it is. Any suggestions?
Reply With Quote
  #2   Spotlight this post!  
Unread 17-02-2013, 18:39
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,089
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: How to code limit switch to stop movement

Quote:
Originally Posted by Nyle View Post
I have a feeling that there is a better way to do this, but I don't know what it is. Any suggestions?
This is one application where the Jag has an advantage. You can wire the limit switches directly to the Jag and it handles everything for you.


Reply With Quote
  #3   Spotlight this post!  
Unread 17-02-2013, 19:22
Nyle's Avatar
Nyle Nyle is offline
Registered User
FRC #0422 (The Mech Tech Dragons)
Team Role: Leadership
 
Join Date: Feb 2013
Rookie Year: 2012
Location: Richmond, Virginia
Posts: 28
Nyle is just really niceNyle is just really niceNyle is just really niceNyle is just really nice
Re: How to code limit switch to stop movement

Quote:
Originally Posted by Ether View Post
This is one application where the Jag has an advantage. You can wire the limit switches directly to the Jag and it handles everything for you.


Thanks, I'll keep that in mind for the future, it seems very useful, but we are looking for a software solution at the moment as we don't have the time or space to change to a Jag at this point.
Reply With Quote
  #4   Spotlight this post!  
Unread 17-02-2013, 23:09
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: How to code limit switch to stop movement

I have an idea for a small architectural change to make it work. Instead of setting the articulator's motor value directly, have your move() and stop() methods set a global variable. Then have a small piece of "main loop" code that continually reads the global and the limit switches then sets the motor appropriately.
Reply With Quote
  #5   Spotlight this post!  
Unread 18-02-2013, 01:13
VCEmblem VCEmblem is offline
Registered User
FRC #3880
 
Join Date: Feb 2013
Location: Kailua-Kona
Posts: 2
VCEmblem is an unknown quantity at this point
Smile Re: How to code limit switch to stop movement

You should post your code; this is what my team is using at the moment:

Code:
if(driveStick.GetRawButton(5) && topLimit.Get() == 1) //The arm will only move up if the limit switch is NOT pressed
{
         leftArm.Set(-1.0); //Moves the arm up
         rightArm.Set(-1.0);
}
else if(driveStick.GetRawButton(7) && bottomLimit.Get() == 1) //ditto ^
{
         leftArm.Set(0.5); //Moves the arm down
         rightArm.Set(0.5);
}
else
{
         leftArm.Set(0.0); //Stops moving the arm
         rightArm.Set(0.0);
}
The way we wired our limit switch makes it so then when the limit switch is pressed, it is equal to "0" and when it is not pressed, it is equal to "1"
Reply With Quote
  #6   Spotlight this post!  
Unread 19-02-2013, 18:55
garyk garyk is offline
Programming Mentor: 668, 972, 2643
FRC #0668 (Apes of Wrath)
Team Role: Mentor
 
Join Date: Dec 2006
Rookie Year: 2005
Location: Santa Clara (Silicon Valley) Calif.
Posts: 93
garyk is a jewel in the roughgaryk is a jewel in the roughgaryk is a jewel in the roughgaryk is a jewel in the rough
Re: How to code limit switch to stop movement

Generally we wire our limit switches to read 1 when they are pressed (the limit is hit) and 0 otherwise. That way if the switch gets disconnected it reads as though it's pushed, and the mechanism won't move toward the limit. Your team has to decide whether you want the mechanism to still work with a disconnected switch (risking damage) or stop if the switch is disconnected, rendering the mechanism not fully operational. This kind of design consideration is called "risk management."

Digital Inputs are "pulled up" through a resistor to +5v and will read 1 when there's no connection. The pneumatic pressure switch is wired in this manner, a disconnected switch reads the same as at full pressure. Therefore, the pump won't run with a disconnected pressure switch.
__________________

Silicon Valley Regional 2005, 2006 972
Silicon Valley Regional 2007 668 Xerox Creativity Award
Championship Event 2007 668
Portland Regional 2008 668
Silicon Valley Regional 2008 668, 972
Beta Test Team 2008 668 (with 100 & 254)
Silicon Valley Regional 2009 668 Regional Chairman's Award; 2643
Sacramento Regional 2009 668 Winning Alliance (thanks, 1717 & 2473!), 2010 Winning Alliance 3256
CalGames 2006, 2007, 2008, 2009, 2010, 2011 Field Tech
NorCal FTC Regional 2008, 2009 Inspector
Championship Event 2009
San Diego, Silicon Valley Regionals; Champ. Event 2010 668, 2643, 3256
Silicon Valley, Madera Regional 2012 2643
WRRF Programming Instructor 2006-2016
Regional Woodie Flowers Award 2014 2643 Utah Regional

Reply With Quote
  #7   Spotlight this post!  
Unread 20-02-2013, 17:44
Anyun Anyun is offline
Co-Captain Team 1308
FRC #1308 (Wildcats)
Team Role: Programmer
 
Join Date: Aug 2012
Rookie Year: 2009
Location: Cleveland
Posts: 13
Anyun is an unknown quantity at this point
Re: How to code limit switch to stop movement

We're actually doing something similar. Our launcher is lifted using two motors (LifterA and Lifter B), and we wired our limit switches so that the upper is 1 when depressed and the lower is 1 when open. The upper limit becomes open onces the ramp reaches the furthest up we want it to go, while the lower limit becomes closed when it goes the furthest down we want it to go. Our code looks something like this:

if(stick.GetRawButton(4) && UpperLimit.Get() == 1)
// if button 4 is pressed and upper limit is pressed, lifter goes up
{
LifterA.Set(0.4);
LifterB.Set(0.4);
}
else if(stick.GetRawButton(5) && LowerLimit.Get() == 1)
// if button 5 is pressed and lower limit is not pressed, lifter goes down
{
LifterA.Set(-0.4);
LifterB.Set(-0.4);
}
else
{
LifterA.Set(0.0);
LifterB.Set(0.0);
}
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 14:03.

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