Hey I am a programmer on 4085 and we are having a ton of struggle with the new encoders. We have an encoder hooked up directly to the pins on our Talon SR's. We are currently getting position and I have spent 3 hours working on a dry board trying to get it to move forward for 4' and stop. Simple right? But there's a catch! There is no reset encoder position command. So we have no way of making it "zero" at the beginning of autonomous. Now you understand why I had 3 hours at the dry board. Our "get encoder position" command returns a number that doesn't start a "zero". Our "get velocity" command returns a largely changing number so we are calling it "dead" and bugged. We do have the breakout board plugged into the encoders before we plug them into the Talon. What are you guise using this year? We want to know that the pin out on the speed controllers don't work before we just rewire it back to the analog ports. Can you help?
Code:
package org.usfirst.frc.team4085.robot;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.Scheduler;
import org.usfirst.frc.team4085.robot.commands.ExampleCommand;
import org.usfirst.frc.team4085.robot.subsystems.ExampleSubsystem;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.CANTalon;
import edu.wpi.first.wpilibj.smartdashboard.*;
import edu.wpi.first.wpilibj.Encoder;
public class Robot extends IterativeRobot {
CANTalon ldrive = new CANTalon(5);
CANTalon rdrive = new CANTalon(6);
Joystick lstick = new Joystick(1);
Joystick rstick = new Joystick(0);
RobotDrive moving = new RobotDrive(ldrive, rdrive);
SmartDashboard smart = new SmartDashboard();
int d;
int y;
int z;
int b;
Encoder lenc1 = new Encoder(2);
public static final ExampleSubsystem exampleSubsystem = new ExampleSubsystem();
public static OI oi;
Command autonomousCommand;
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {
oi = new OI();
// instantiate the command used for the autonomous period
autonomousCommand = new ExampleCommand();
}
public void disabledPeriodic() {
Scheduler.getInstance().run();
}
public void autonomousInit() {
// schedule the autonomous command (example)
if (autonomousCommand != null) autonomousCommand.start();
}
/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
Scheduler.getInstance().run();
}
public void teleopInit() {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
if (autonomousCommand != null) autonomousCommand.cancel();
}
/**
* This function is called when the disabled button is hit.
* You can use it to reset subsystems before shutting down.
*/
public void disabledInit(){
}
/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
Scheduler.getInstance().run();
moving.tankDrive(rstick,lstick);
// moving1.tankDrive(rstick, lstick)
smart.putString("ldrive Position", Integer.toString(ldrive.getEncPosition()));
smart.putString("rdrive Position", Integer.toString(rdrive.getEncPosition()));
smart.putString("ldrive Velocity", Integer.toString(ldrive.getEncVelocity()));
smart.putString("rdrive Velocity", Integer.toString(rdrive.getEncVelocity()));
}
public void testPeriodic() {
}
}