Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   How to code limit switch to stop movement (http://www.chiefdelphi.com/forums/showthread.php?t=113799)

Nyle 17-02-2013 17:47

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?

Ether 17-02-2013 18:39

Re: How to code limit switch to stop movement
 
Quote:

Originally Posted by Nyle (Post 1235147)
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.



Nyle 17-02-2013 19:22

Re: How to code limit switch to stop movement
 
Quote:

Originally Posted by Ether (Post 1235197)
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.

Alan Anderson 17-02-2013 23:09

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.

VCEmblem 18-02-2013 01:13

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"

garyk 19-02-2013 18:55

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.

Anyun 20-02-2013 17:44

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);
}


All times are GMT -5. The time now is 18:21.

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