Using Limit Switches plugged into TalonSRX

My team has plugged a limit switch into the data port on a TalonSRX and I can’t find out how to get its value. Is there a method in CANTalon or something that we can use? Thank you.

Yes, there are methods to enable the limit switches and to read them back. They are particularly useful when you want to make sure the motor stops when the switch is hit.

Here’s a sample blurb of connecting them:


// Construct instance
CANTalon lift = new CANTalon(12);

// Make available in "Test" mode
LiveWindow.addActuator("Lift", "Motor", lift);

// Enable hardware limit switch at both ends of lift so lift stops
// Make sure you connect them correctly!
lift.enableLimitSwitch(true, true);

There are two limit switch connections (one for stopping the motors from driving forward and one for stopping them from driving in reverse). It is important to connect them correctly in order to get the hardware feature working properly.

Here’s a sample of checking in software if the switch has been hit


boolean atTop = lift.isFwdLimitSwitchClosed();
boolean atBottom = lift.isRevLimitSwitchClosed();

There are a bunch of methods available on the CANTalon speed controllers (they have many more features than most of the other speed controllers).

You should be able to find the javadoc for them on your system (comes with the WPIlib plugins). Look for the javadoc under (change YOUR_LOGIN_ID to the login you use on Windows):

file:///C:/Users/YOUR_LOGIN_ID/wpilib/java/current/javadoc/index.html

Beware of the “soft limit” functions. I’m not sure of the practical use, but we had some of the programmers set or enable both of the “soft limit” switches. This seemed to stick and prevented the CANTalon from working with other code that was not using the “soft limit” functions. Some of our team thought the CANTalon had gone bad and physically replaced them. We were lucky and pulled them from the trash and then discovered that the soft limits had been enabled on the ones mistaken for bad.

If it’s forward limit switch it should be

motor.isFwdLimitSwitchClosed()

for the reverse limit switch it should be

motor.isRevLimitSwitchClosed()

P.S Nice username

Thank you guys, this helped us greatly!