View Single Post
  #15   Spotlight this post!  
Unread 27-01-2016, 15:52
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: Drive train PID control

Quote:
Originally Posted by techkid86 View Post
yes, just switch out the teleop init and periodic with the following.

Code:
RobotDrive drive;

public void teleopInit()
{
leftPID.disable(); rightPID.disable(); drive=new RobotDrive(leftDrive, rightDrive);
} public void teleopPeriodic() {
drive.arcadeDrive(//however you setup the stick);
}
Alright I've got that setup nicely next step is to actually add in the PID jazz.
Code:
public class Robot extends IterativeRobot {
	RobotDrive tankDrive;

	Talon leftDrive = new Talon(Defines.DRIVE_CHANNEL_ZERO);
	Talon rightDrive = new Talon(Defines.DRIVE_CHANNEL_ONE);

	Joystick joystick = new Joystick(Defines.JOYSTICK_CHANNEL);

	Encoder rightEncoder = new Encoder(Defines.ENCODER_CHANNEL_ZERO, Defines.ENCODER_CHANNEL_ONE, true,
			EncodingType.k4X);

	PIDController rightPID = new PIDController(0.1, 0, 0, rightEncoder, rightDrive);

	public void robotInit() {
	}

	public void autonomousInit() {
		final double distancePerPulse = Math.PI * Defines.WHEEL_DIAMETER / Defines.PULSE_PER_REVOLUTION
				/ Defines.ENCODER_GEAR_RATIO / Defines.GEAR_RATIO * Defines.FUDGE_FACTOR;

		rightEncoder.setDistancePerPulse(distancePerPulse);
		rightEncoder.get();
	}

	public void autonomousPeriodic() {
	}

	public void teleopInit() {
		rightPID.disable();
		tankDrive = new RobotDrive(leftDrive, rightDrive);
	}

	public void teleopPeriodic() {
		tankDrive.arcadeDrive(joystick.getY(), -joystick.getX());

	}
}
Reply With Quote