|
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?
|