View Single Post
  #17   Spotlight this post!  
Unread 27-01-2016, 16:17
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

PROGRESS! Sorry for doing a double post.

So I just enable autonomous and the robot drove backwards very quickly right. I guess I need to change the direction the robot drives, so going forwards instead of backwards and then make the leftPID mask the rightPID so it drives straight.

Code:
public class Robot extends IterativeRobot {
	double xThrottle = 0;

	RobotDrive tankDrive;

	Talon leftDrive = new Talon(0);
	Talon rightDrive = new Talon(1);

	Joystick joystick = new Joystick(0);

	Encoder rightEncoder = new Encoder(0, 1, true,
			EncodingType.k4X);

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

	public void robotInit() {
		rightEncoder.setPIDSourceType(PIDSourceType.kDisplacement);

		rightEncoder.setReverseDirection(true);
		rightDrive.setInverted(true); // only one side needs inversion

		rightEncoder.reset();

		rightPID.setOutputRange(-0.75, 0.75); // max speed it can set to motors

		rightPID.enable();
	}

	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.reset();
	}

	public void autonomousPeriodic() {
		rightPID.setSetpoint(20);
	}

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

	public void teleopPeriodic() {
		double throttle = joystick.getRawAxis(Defines.THROTTLE);
		xThrottle = (-throttle + 2) / 4;

		tankDrive.arcadeDrive(joystick.getX() * xThrottle, -joystick.getY() * xThrottle);
	}
}

Last edited by curtis0gj : 27-01-2016 at 16:20.
Reply With Quote