/* I’m moving this topic to programming, it looks like the wiring is okay
Greetings! I feel like as a 2003 rookie year team we should have posted here before, but the programming and electronics team is fairly new, so here goes out first post.
We’re having some trouble getting the Rev through bore encoder reading in either absolute or quadrature modes.
We plugged in a limit switch to the DIO to make sure that the pins were working and everything went swimmingly, but as soon as we try the encoder we get nothing. The programming team is new to encoders (and programming), so any help would be appreciated!
Looking at the SmartDashboard we aren’t even getting values from the encoders, so I want to make sure that we aren’t doing something wrong before sending it back to Rev.
Here is our quadrature wiring and code:
In the picture the motor controller is next to the RoboRio, but the through bore encoder is actually plugged directly in to the RoboRio via the jst->dupont adapter
package frc.robot;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
public class Robot extends TimedRobot {
private static final String kDefaultAuto = “Default”;
private static final String kCustomAuto = “My Auto”;
private String m_autoSelected;
private final SendableChooser m_chooser = new SendableChooser<>();
private Encoder throughBore;
private int ticks;
private int rawTicks;
public void robotInit() {
m_chooser.setDefaultOption("Default Auto", kDefaultAuto);
m_chooser.addOption("My Auto", kCustomAuto);
SmartDashboard.putData("Auto choices", m_chooser);
throughBore = new Encoder(7, 8, 9);
}
public void robotPeriodic() {
ticks = throughBore.get();
rawTicks = throughBore.getRaw();
SmartDashboard.putNumber("Encoder value", ticks);
SmartDashboard.putNumber("Raw encoder value", rawTicks);
}
// the rest of the code below is the normal timed robot
I can’t put another picture in, but imagine a pic of the white abs wire plugged into DIO 9 with the other three quad wires unplugged.
package frc.robot;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.DutyCycleEncoder;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
public class Robot extends TimedRobot {
private static final String kDefaultAuto = “Default”;
private static final String kCustomAuto = “My Auto”;
private String m_autoSelected;
private final SendableChooser m_chooser = new SendableChooser<>();
private DutyCycleEncoder throughBore;
private double ticks;
private double freq;
private boolean isConn;
private DigitalInput limit;
private Boolean limitGet;
public void robotInit() {
m_chooser.setDefaultOption("Default Auto", kDefaultAuto);
m_chooser.addOption("My Auto", kCustomAuto);
SmartDashboard.putData("Auto choices", m_chooser);
throughBore = new DutyCycleEncoder(9);
throughBore.setConnectedFrequencyThreshold(900);
limit = new DigitalInput(0);
}
public void robotPeriodic() {
ticks = throughBore.get();
freq = throughBore.getFrequency();
isConn = throughBore.isConnected();
limitGet = limit.get();
SmartDashboard.putNumber("Encoder value", ticks);
SmartDashboard.putNumber("Encoder frequency", freq);
SmartDashboard.putBoolean("Encoder is connected", isConn);
SmartDashboard.putBoolean("Limit is pressed", limitGet);
}
// The rest of the code below is the normal timed robot