Could someone who has experience programming the Rev Through Bore Encoder please help me figure out how to get started? Does it have to be plugged into the RoboRIO for the encoder class to function? Also, does it program like any other encoder or are there specific through bore encoder classes that we have to use. We are trying to measure the rotation of an arm
REV’s docs here outline the different wiring options:
If you use it as a quadrature / relative encoder, use the Encoder
class.
If you use it as a duty cycle / absolute encoder, use the DutyCycleEncoder
class.
This is specifically relevant if it’s wired directly to the RoboRIO. @RoboticsMan10, since you asked IF it needed to be wired there, I’ll add that it could also be wired to the 10-pin sensor port on the top of a SparkMax if you’re using those.
If using on a SparkMax will I use the DutyCycleEncoder class?
Nope, you would get the value off of the SparkMax object itself. If the sparkmax is controlling a brushed motor, you would wire it into the A/B channel pins and use the getEncoder() method. If controlling a brushless motor (NEO/NEO550), you would need to wire it for Alternate Encoder Mode and use getAlternateEncoder()
is this good code?
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(0, 1);
}
public void robotPeriodic() {
ticks = throughBore.get();
rawTicks = throughBore.getRaw();
SmartDashboard.putNumber(“Encoder value”, ticks);
SmartDashboard.putNumber(“Raw encoder value”, rawTicks);
}
}
That’s an exceptionally subjective question. I’ll say it’s difficult-to-read code. In the future, please make sure to format pasted code properly (triple backticks (```) before and after the block of code), or simply link to github or something. If you don’t feel you need to share a whole project, you can create a gist with just the code you do need to share.
That said, is it good in what way? If you’re asking if it’ll be able to read values from the encoder, I’ll say yes it does appear that it would be able to do that. Be sure to read through the docs though, as you very likely don’t want to work directly with “ticks”