Hi my team uses mag encoders that are connected to the talonSRX for the drivetrain , I want to get the value for the encode but it give me an error when I define the encoder heres my code:
public class DriveTrain extends Subsystem {
// Put methods for controlling this subsystem
// here. Call these from Commands.
public WPI_TalonSRX leftfront = new WPI_TalonSRX(22);
public WPI_TalonSRX leftback = new WPI_TalonSRX(10);
public WPI_TalonSRX rightfront = new WPI_TalonSRX(7);
public WPI_TalonSRX rightback = new WPI_TalonSRX(5);
leftfront.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative);
SpeedControllerGroup leftmotors = new SpeedControllerGroup(leftfront, leftback);
SpeedControllerGroup rightmotors = new SpeedControllerGroup(rightfront, rightback);
DifferentialDrive DriveTrain = new DifferentialDrive(leftmotors, rightmotors);
public void arcadeDrive(double move , double rotate){
DriveTrain.arcadeDrive(move, rotate);
}
public void tankDrive(double left , double right){
DriveTrain.tankDrive(left, right);
}
@Override
public void initDefaultCommand() {
// Set the default command for a subsystem here.
setDefaultCommand(new DriveArcade());
}
}
Are you getting an error here? Does the code refuse to compile, or does it just not do what it is expected to on your robot?
Also a little tip: Try to organize the CAN IDs of your motor controllers, and make them constant variables. It can help a lot when you organize your code. For example;
public WPI_TalonSRX frontLeft = new WPI_TalonSRX(10);
public WPI_TalonSRX backLeft = new WPI_TalonSRX(11);
public WPI_TalonSRX frontRight = new WPI_TalonSRX(12);
public WPI_TalonSRX backRight = new WPI_TalonSRX(13);