pid gain scheduling
This commit is contained in:
parent
3dafb3c269
commit
a145c290fd
@ -139,6 +139,8 @@ public class RobotContainer {
|
|||||||
startingConfig()
|
startingConfig()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
driver.y().onTrue(drivetrain.zeroHeading());
|
||||||
|
|
||||||
driver.povDown().whileTrue(climberPivot.runPivot(-0.5));
|
driver.povDown().whileTrue(climberPivot.runPivot(-0.5));
|
||||||
driver.povUp().whileTrue(climberPivot.runPivot(0.5));
|
driver.povUp().whileTrue(climberPivot.runPivot(0.5));
|
||||||
|
|
||||||
@ -190,7 +192,6 @@ public class RobotContainer {
|
|||||||
elevator.goToSetpoint(() -> ElevatorConstants.kL2Position)
|
elevator.goToSetpoint(() -> ElevatorConstants.kL2Position)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureNamedCommands() {
|
private void configureNamedCommands() {
|
||||||
@ -245,12 +246,12 @@ public class RobotContainer {
|
|||||||
sensorTab.addDouble("ElevMotor2", elevator::getMotor2)
|
sensorTab.addDouble("ElevMotor2", elevator::getMotor2)
|
||||||
.withWidget(BuiltInWidgets.kGraph);
|
.withWidget(BuiltInWidgets.kGraph);
|
||||||
|
|
||||||
sensorTab.addDouble("Elevator setpoint", elevator::getPIDSetpoint)
|
sensorTab.addDouble("Elevator setpoint", elevator::getPIDUpSetpoint)
|
||||||
.withSize(1, 1)
|
.withSize(1, 1)
|
||||||
.withPosition(5, 0)
|
.withPosition(5, 0)
|
||||||
.withWidget(BuiltInWidgets.kTextView);
|
.withWidget(BuiltInWidgets.kTextView);
|
||||||
|
|
||||||
sensorTab.addDouble("Elevator error", elevator::getPIDError)
|
sensorTab.addDouble("Elevator error", elevator::getPIDUpError)
|
||||||
.withSize(1, 1)
|
.withSize(1, 1)
|
||||||
.withPosition(5, 1)
|
.withPosition(5, 1)
|
||||||
.withWidget(BuiltInWidgets.kTextView);
|
.withWidget(BuiltInWidgets.kTextView);
|
||||||
@ -382,7 +383,6 @@ public class RobotContainer {
|
|||||||
* @param armPosition The target rotation of the arm
|
* @param armPosition The target rotation of the arm
|
||||||
* @return Moves the elevator and arm to the setpoints
|
* @return Moves the elevator and arm to the setpoints
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private Command safeMoveManipulator(double elevatorPosition, double armPosition) {
|
private Command safeMoveManipulator(double elevatorPosition, double armPosition) {
|
||||||
return moveManipulatorUtil(elevatorPosition, ManipulatorPivotConstants.kPivotSafeStowPosition, false, true)
|
return moveManipulatorUtil(elevatorPosition, ManipulatorPivotConstants.kPivotSafeStowPosition, false, true)
|
||||||
.andThen(manipulatorPivot.goToSetpoint(() -> armPosition));
|
.andThen(manipulatorPivot.goToSetpoint(() -> armPosition));
|
||||||
|
@ -43,14 +43,14 @@ public class ElevatorConstants {
|
|||||||
public static final double kL1Position = 0;
|
public static final double kL1Position = 0;
|
||||||
public static final double kL2Position = 14.5;
|
public static final double kL2Position = 14.5;
|
||||||
public static final double kL3Position = 29.0;
|
public static final double kL3Position = 29.0;
|
||||||
public static final double kL4Position = 53.0;
|
public static final double kL4Position = 52.0;
|
||||||
public static final double kL4TransitionPosition = 40.0;
|
public static final double kL4TransitionPosition = 40.0;
|
||||||
public static final double kL2AlgaePosition = 22.0;
|
public static final double kL2AlgaePosition = 22.0;
|
||||||
public static final double kL3AlgaePosition = 39.0;
|
public static final double kL3AlgaePosition = 39.0;
|
||||||
public static final double kProcessorPosition = 4.0;
|
public static final double kProcessorPosition = 4.0;
|
||||||
/**The position of the top of the elevator brace */
|
/**The position of the top of the elevator brace */
|
||||||
public static final double kBracePosition = 0;
|
public static final double kBracePosition = 0;
|
||||||
public static final double kMaxHeight = 47.5; //actual is 53
|
public static final double kMaxHeight = 52.0; //actual is 52
|
||||||
|
|
||||||
// 1, 7, 10 are the defaults for these, change as necessary
|
// 1, 7, 10 are the defaults for these, change as necessary
|
||||||
public static final double kSysIDRampRate = .25;
|
public static final double kSysIDRampRate = .25;
|
||||||
|
@ -248,9 +248,12 @@ public class Drivetrain extends SubsystemBase {
|
|||||||
m_rearRight.resetEncoders();
|
m_rearRight.resetEncoders();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Zeroes the heading of the robot. */
|
/** Zeroes the heading of the robot.
|
||||||
public void zeroHeading() {
|
* @return */
|
||||||
|
public Command zeroHeading() {
|
||||||
|
return run(() -> {
|
||||||
gyro.reset();
|
gyro.reset();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getGyroValue() {
|
public double getGyroValue() {
|
||||||
|
@ -24,7 +24,8 @@ public class Elevator extends SubsystemBase {
|
|||||||
|
|
||||||
private DigitalInput bottomLimitSwitch;
|
private DigitalInput bottomLimitSwitch;
|
||||||
|
|
||||||
private PIDController pidController;
|
private PIDController pidControllerUp;
|
||||||
|
private PIDController pidControllerDown;
|
||||||
|
|
||||||
private ElevatorFeedforward feedForward;
|
private ElevatorFeedforward feedForward;
|
||||||
|
|
||||||
@ -57,14 +58,23 @@ public class Elevator extends SubsystemBase {
|
|||||||
ElevatorConstants.kBottomLimitSwitchID
|
ElevatorConstants.kBottomLimitSwitchID
|
||||||
);
|
);
|
||||||
|
|
||||||
pidController = new PIDController(
|
pidControllerDown = new PIDController(
|
||||||
ElevatorConstants.kDownControllerP,
|
ElevatorConstants.kDownControllerP,
|
||||||
ElevatorConstants.kDownControllerI,
|
ElevatorConstants.kDownControllerI,
|
||||||
ElevatorConstants.kDownControllerD
|
ElevatorConstants.kDownControllerD
|
||||||
);
|
);
|
||||||
pidController.setSetpoint(0);
|
pidControllerDown.setSetpoint(0);
|
||||||
|
|
||||||
pidController.setTolerance(ElevatorConstants.kAllowedError);
|
pidControllerDown.setTolerance(ElevatorConstants.kAllowedError);
|
||||||
|
|
||||||
|
pidControllerUp = new PIDController(
|
||||||
|
ElevatorConstants.kUpControllerP,
|
||||||
|
ElevatorConstants.kUpControllerI,
|
||||||
|
ElevatorConstants.kUpControllerD
|
||||||
|
);
|
||||||
|
pidControllerUp.setSetpoint(0);
|
||||||
|
|
||||||
|
pidControllerUp.setTolerance(ElevatorConstants.kAllowedError);
|
||||||
|
|
||||||
feedForward = new ElevatorFeedforward(
|
feedForward = new ElevatorFeedforward(
|
||||||
ElevatorConstants.kFeedForwardS,
|
ElevatorConstants.kFeedForwardS,
|
||||||
@ -132,53 +142,30 @@ public class Elevator extends SubsystemBase {
|
|||||||
|
|
||||||
return startRun(() -> {
|
return startRun(() -> {
|
||||||
|
|
||||||
//pidController.reset();
|
|
||||||
// pidController.setSetpoint(encoder.getPosition());
|
|
||||||
},
|
},
|
||||||
() -> {
|
() -> {
|
||||||
/*if (!pidController.atSetpoint()) {
|
if (!pidControllerUp.atSetpoint()) {
|
||||||
|
if(encoder.getPosition()>pidControllerUp.getSetpoint()){
|
||||||
elevatorMotor1.setVoltage(
|
elevatorMotor1.setVoltage(
|
||||||
pidController.calculate(
|
pidControllerUp.calculate(
|
||||||
encoder.getPosition()
|
encoder.getPosition()
|
||||||
) + feedForward.calculate(0)
|
) + feedForward.calculate(0)
|
||||||
);
|
);
|
||||||
}else{
|
}else{
|
||||||
elevatorMotor1.setVoltage(
|
elevatorMotor1.setVoltage(
|
||||||
feedForward.calculate(0)
|
pidControllerDown.calculate(
|
||||||
);
|
encoder.getPosition()
|
||||||
}*/
|
|
||||||
|
|
||||||
elevatorMotor1.setVoltage(
|
|
||||||
feedForward.calculate(0)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
elevatorMotor1.setVoltage(
|
|
||||||
pidController.calculate(
|
|
||||||
encoder.getPosition(),
|
|
||||||
clampedSetpoint
|
|
||||||
) + feedForward.calculate(0)
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
if (!pidController.atSetpoint()) {
|
|
||||||
elevatorMotor1.setVoltage(
|
|
||||||
pidController.calculate(
|
|
||||||
encoder.getPosition(),
|
|
||||||
clampedSetpoint
|
|
||||||
) + feedForward.calculate(0)
|
) + feedForward.calculate(0)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
elevatorMotor1.setVoltage(
|
elevatorMotor1.setVoltage(
|
||||||
feedForward.calculate(0)
|
feedForward.calculate(0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -192,25 +179,27 @@ public class Elevator extends SubsystemBase {
|
|||||||
|
|
||||||
return startRun(() -> {
|
return startRun(() -> {
|
||||||
|
|
||||||
pidController.setSetpoint(setpoint.getAsDouble());
|
pidControllerUp.setSetpoint(setpoint.getAsDouble());
|
||||||
pidController.reset();
|
pidControllerDown.setSetpoint(setpoint.getAsDouble());
|
||||||
|
pidControllerUp.reset();
|
||||||
|
pidControllerDown.reset();
|
||||||
},
|
},
|
||||||
() -> {
|
() -> {
|
||||||
if (!pidController.atSetpoint()) {
|
if(setpoint.getAsDouble()>encoder.getPosition())
|
||||||
elevatorMotor1.setVoltage(
|
elevatorMotor1.setVoltage(
|
||||||
pidController.calculate(
|
pidControllerUp.calculate(
|
||||||
encoder.getPosition(),
|
encoder.getPosition()
|
||||||
setpoint.getAsDouble()
|
|
||||||
) + feedForward.calculate(0)
|
) + feedForward.calculate(0)
|
||||||
);
|
);
|
||||||
} else {
|
else{
|
||||||
elevatorMotor1.setVoltage(
|
elevatorMotor1.setVoltage(
|
||||||
feedForward.calculate(0)
|
pidControllerDown.calculate(
|
||||||
|
encoder.getPosition()
|
||||||
|
) + feedForward.calculate(0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}).until(() -> pidController.atSetpoint());
|
|
||||||
|
|
||||||
|
|
||||||
|
}).until(() -> pidControllerUp.atSetpoint());
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -293,11 +282,19 @@ public class Elevator extends SubsystemBase {
|
|||||||
return elevatorMotor2.getAppliedOutput()*elevatorMotor2.getBusVoltage();
|
return elevatorMotor2.getAppliedOutput()*elevatorMotor2.getBusVoltage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPIDSetpoint() {
|
public double getPIDUpSetpoint() {
|
||||||
return pidController.getSetpoint();
|
return pidControllerUp.getSetpoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPIDError() {
|
public double getPIDUpError() {
|
||||||
return pidController.getError();
|
return pidControllerUp.getError();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPIDDownSetpoint() {
|
||||||
|
return pidControllerDown.getSetpoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPIDDownError() {
|
||||||
|
return pidControllerDown.getError();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user