astronautlevel
01-03-2016, 08:23
Hi, our team has been having a lot of trouble using the PIDController class to move an arm on our robot based on an angle sensor. We're not really sure how to use the PIDController, for example, what methods are necessary to initialize the PIDController for it for set motor values correctly? We are using Java and the Command-based Architecture.
Here is what our code is doing (within a Subsystem class):
public static Double setpoint;
private final CANTalon angleMotor = new CANTalon(Ports.SHOOTER_ANGLE_PORT);
PIDController controller;
PIDSource source;
public AnglePIDControllerSubsystem() {
source = new PIDSource() {
@Override
public void setPIDSourceType(PIDSourceType pidSource) {
}
@Override
public double pidGet() {
System.out.println("Getting value: " + currentAngle);
return currentAngle;
}
@Override
public PIDSourceType getPIDSourceType() {
return PIDSourceType.kDisplacement;
}
};
controller = new PIDController(10, 0 ,0, source, angleMotor);
controller.setContinuous(false);
controller.setAbsoluteTolerance(3);
controller.setInputRange(-90, 90);
controller.setOutputRange(-1, 1);
angleMotor.changeControlMode(CANTalon.TalonControl Mode.PercentVbus);
angleMotor.ConfigFwdLimitSwitchNormallyOpen(true);
angleMotor.ConfigRevLimitSwitchNormallyOpen(true);
angleMotor.enableForwardSoftLimit(false);
angleMotor.enableReverseSoftLimit(false);
controller.enable();
}
void setSetpoint(double val) {
controller.setSetpoint(val*10);
System.out.println("Voltage: " + controller.get());
System.out.println("Error: " + controller.getError());
System.out.println("Setpoint: " + controller.getSetpoint());
System.out.println("On target: " + controller.onTarget());
}
The default command for this subsystem is calling setSetpoint each cycle.
Has anyone else had success with the PIDController?
Here is what our code is doing (within a Subsystem class):
public static Double setpoint;
private final CANTalon angleMotor = new CANTalon(Ports.SHOOTER_ANGLE_PORT);
PIDController controller;
PIDSource source;
public AnglePIDControllerSubsystem() {
source = new PIDSource() {
@Override
public void setPIDSourceType(PIDSourceType pidSource) {
}
@Override
public double pidGet() {
System.out.println("Getting value: " + currentAngle);
return currentAngle;
}
@Override
public PIDSourceType getPIDSourceType() {
return PIDSourceType.kDisplacement;
}
};
controller = new PIDController(10, 0 ,0, source, angleMotor);
controller.setContinuous(false);
controller.setAbsoluteTolerance(3);
controller.setInputRange(-90, 90);
controller.setOutputRange(-1, 1);
angleMotor.changeControlMode(CANTalon.TalonControl Mode.PercentVbus);
angleMotor.ConfigFwdLimitSwitchNormallyOpen(true);
angleMotor.ConfigRevLimitSwitchNormallyOpen(true);
angleMotor.enableForwardSoftLimit(false);
angleMotor.enableReverseSoftLimit(false);
controller.enable();
}
void setSetpoint(double val) {
controller.setSetpoint(val*10);
System.out.println("Voltage: " + controller.get());
System.out.println("Error: " + controller.getError());
System.out.println("Setpoint: " + controller.getSetpoint());
System.out.println("On target: " + controller.onTarget());
}
The default command for this subsystem is calling setSetpoint each cycle.
Has anyone else had success with the PIDController?