/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package frc.robot;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the TimedRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the build.gradle file in the
* project.
*/
public class Robot extends TimedRobot {
/**
* This function is run when the robot is first started up and should be used
* for any initialization code.
*/
DigitalInput forearm_LimitSwitchUp;
@Override
public void robotInit() {
forearm_LimitSwitchUp = new DigitalInput(0);
}
@Override
public void autonomousInit() {
}
@Override
public void autonomousPeriodic() {
}
@Override
public void teleopInit() {
}
@Override
public void teleopPeriodic() {
if (!forearm_LimitSwitchUp.get())
{
SmartDashboard.putBoolean("Forearm Limit Switch", forearm_LimitSwitchUp.get());
}
}
@Override
public void testInit() {
}
@Override
public void testPeriodic() {
}
}
How is is connected? I believe the Roborio is active low meaning you should be connected to the ground and signal. (Page 15) http://www.ni.com/pdf/manuals/374474a.pdf When switch is closed you will get a false and when open you get true.
Set the multimeter to continuity mode (aka beep mode). Touch one lead to signal (blue) and one to ground (black). If it beeps when the magnet is close and stops beeping when you remove the magnet, it’s working. The sensor should also have a light that turns on when the magnet is close and off when it’s removed.
Also, try unplugging the sensor from your cable and doing a continuity test between the ground and a signal pin (e.g. the two at the ends) and see if it beeps when the magnet is brought close. If it doesn’t beep, you have a bad switch. If it does beep, time to check the cable for continuity.
The Magnetic Limit Switch needs power to operate, so unplugging it completely won’t show you anything.
@Dacosta Can you confirm whether or not the LED is illuminated when the magnet is in range? The LED is part of the signal path so it is a reliable indicator if the sensor is working.
To use a multimeter you would need to keep the sensor plugged in to the DIO and measure the voltage between the GND pin and Signal Pin. You’ll measure 0V when triggered and 5V when not triggered. With a PWM extension, you can probably get your probes on the little bit of exposed metal on the connector housings.