Log in

View Full Version : PID Controller help


josephno1
18-11-2015, 20:24
So I followed the example on here.

http://wpilib.screenstepslive.com/s/3120/m/7912/l/79828-operating-the-robot-with-feedback-from-sensors-pid-control

So this is what I got so far.

The PID Controller is plugged in on PWM port 0 and AnalogInput 2

How do I call this in the Robot.java and what do I do next?
I am using IterativeRobot


import edu.wpi.first.wpilibj.command.PIDSubsystem;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.AnalogInput;
import edu.wpi.first.wpilibj.*;
/**
*
*/
public class PIDWheel extends PIDSubsystem {
SpeedController motor = new Talon(0);
AnalogInput pot = new AnalogInput(2);

// Initialize your subsystem here
public PIDWheel() {
super("Wheel", 1.0, 0.0, 0.0);
setAbsoluteTolerance(0.2);
getPIDController().setContinuous(false);
LiveWindow.addActuator("Wheel", "PIDSubsystem Controller", getPIDController());
// Use these to get going:
// setSetpoint() - Sets where the PID controller should move the system
// to
// enable() - Enables the PID controller.
}

public void initDefaultCommand() {
// Set the default command for a subsystem here.
//setDefaultCommand(new MySpecialCommand());
}

protected double returnPIDInput() {
// Return your input value for the PID loop
// e.g. a sensor, like a potentiometer:
// yourPot.getAverageVoltage() / kYourMaxVoltage;
return pot.getAverageVoltage();
}

protected void usePIDOutput(double output) {
motor.pidWrite(output);
// Use output to drive your system, like a motor
// e.g. yourMotor.set(output);
}
}