2 Commits

8 changed files with 180 additions and 218 deletions

View File

@@ -8,6 +8,7 @@ import frc.robot.constants.ManipulatorPivotConstants;
import frc.robot.constants.ClimberPivotConstants;
import frc.robot.constants.ElevatorConstants;
import frc.robot.constants.OIConstants;
import frc.robot.constants.ElevatorConstants.ElevatorPositions;
import frc.robot.subsystems.ManipulatorPivot;
import frc.robot.subsystems.Vision;
import frc.robot.subsystems.ClimberPivot;
@@ -26,7 +27,9 @@ import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.WaitUntilCommand;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.Trigger;
public class RobotContainer {
private ClimberPivot climberPivot;
@@ -53,15 +56,14 @@ public class RobotContainer {
climberRollers = new ClimberRollers();
manipulator = new Manipulator();
//vision = new Vision(drivetrain::getGyroValue);
drivetrain = new Drivetrain();
vision = new Vision(drivetrain::getGyroValue);
elevator = new Elevator();
elevator = new Elevator(manipulator::getAlgaePhotoswitch);
//elevator = new ElevatorSysID();
manipulator = new Manipulator();
manipulatorPivot = new ManipulatorPivot();
driver = new CommandXboxController(OIConstants.kDriverControllerPort);
@@ -105,11 +107,6 @@ public class RobotContainer {
)
);
elevator.setDefaultCommand(
elevator.maintainPosition()
);
manipulatorPivot.setDefaultCommand(
manipulatorPivot.maintainPosition()
);
@@ -138,8 +135,6 @@ public class RobotContainer {
driver.start().and(driver.back()).onTrue(
startingConfig()
);
driver.y().onTrue(drivetrain.zeroHeading());
driver.povDown().whileTrue(climberPivot.runPivot(-0.5));
driver.povUp().whileTrue(climberPivot.runPivot(0.5));
@@ -150,28 +145,28 @@ public class RobotContainer {
//Operator inputs
operator.povUp().onTrue(
safeMoveManipulator(
ElevatorConstants.kL4Position,
ElevatorPositions.kL4,
ManipulatorPivotConstants.kL4Position
)
);
operator.povRight().onTrue(
safeMoveManipulator(
ElevatorConstants.kL3Position,
ElevatorPositions.kL3,
ManipulatorPivotConstants.kL3Position
)
);
operator.povLeft().onTrue(
safeMoveManipulator(
ElevatorConstants.kL2Position,
ElevatorPositions.kL2,
ManipulatorPivotConstants.kL2Position
)
);
operator.povDown().onTrue(
safeMoveManipulator(
ElevatorConstants.kL1Position,
ElevatorPositions.kL1,
ManipulatorPivotConstants.kL1Position
)
);
@@ -188,10 +183,15 @@ public class RobotContainer {
algaeIntakeRoutine(false)
);
operator.y().whileTrue(
elevator.goToSetpoint(() -> ElevatorConstants.kL2Position)
operator.y().onTrue(
elevator.setTargetPosition(ElevatorPositions.kL2)
);
new Trigger(() -> Math.abs(MathUtil.applyDeadband(operator.getLeftY(), .05)) > .05).onTrue(
elevator.runManualElevator(operator::getLeftY)
);
}
private void configureNamedCommands() {
@@ -246,22 +246,12 @@ public class RobotContainer {
sensorTab.addDouble("ElevMotor2", elevator::getMotor2)
.withWidget(BuiltInWidgets.kGraph);
sensorTab.addDouble("Elevator setpoint up", elevator::getPIDUpSetpoint)
sensorTab.addDouble("Elevator setpoint", elevator::getPIDSetpoint)
.withSize(1, 1)
.withPosition(5, 0)
.withWidget(BuiltInWidgets.kTextView);
sensorTab.addDouble("Elevator error up", elevator::getPIDUpError)
.withSize(1, 1)
.withPosition(5, 1)
.withWidget(BuiltInWidgets.kTextView);
sensorTab.addDouble("Elevator setpoint down", elevator::getPIDDownSetpoint)
.withSize(1, 1)
.withPosition(5, 0)
.withWidget(BuiltInWidgets.kTextView);
sensorTab.addDouble("Elevator error down", elevator::getPIDDownError)
sensorTab.addDouble("Elevator error", elevator::getPIDError)
.withSize(1, 1)
.withPosition(5, 1)
.withWidget(BuiltInWidgets.kTextView);
@@ -284,7 +274,7 @@ public class RobotContainer {
@SuppressWarnings("unused")
private Command coralIntakeRoutine() {
return moveManipulator(
ElevatorConstants.kCoralIntakePosition,
ElevatorPositions.kCoralIntake,
ManipulatorPivotConstants.kCoralIntakePosition
)
.andThen(manipulator.runUntilCollected(() -> .5));
@@ -299,7 +289,7 @@ public class RobotContainer {
@SuppressWarnings("unused")
private Command algaeIntakeRoutine(boolean l2) {
return moveManipulator(
l2 ? ElevatorConstants.kL2AlgaePosition : ElevatorConstants.kL3AlgaePosition,
l2 ? ElevatorPositions.kL2Algae : ElevatorPositions.kL3Algae,
l2 ? ManipulatorPivotConstants.kL2AlgaePosition : ManipulatorPivotConstants.kL3AlgaePosition
)
.andThen(manipulator.runUntilCollected(() -> 1));
@@ -312,10 +302,10 @@ public class RobotContainer {
* @param armPosition The target rotation of the arm
* @return Moves the elevator and arm to the setpoints using the most efficient path
*/
private Command moveManipulator(double elevatorPosition, double armPosition) {
private Command moveManipulator(ElevatorPositions elevatorPosition, double armPosition) {
// If the elevator current and target positions are above the brace, or the arm current and target position is in
// front of the brace, move together
if ((elevator.isMotionSafe() && elevator.isMotionSafe(elevatorPosition)) || (manipulatorPivot.isMotionSafe() && manipulatorPivot.isMotionSafe(armPosition))) {
if ((elevator.isMotionSafe() && elevator.isMotionSafe(elevatorPosition.getPosition())) || (manipulatorPivot.isMotionSafe() && manipulatorPivot.isMotionSafe(armPosition))) {
return moveManipulatorUtil(elevatorPosition, armPosition, false, false);
// If the target position is behind the brace, and the arm is not behind the brace, move the arm to a safe position first,
// then the elevator, then the arm again
@@ -344,7 +334,7 @@ public class RobotContainer {
* @param sequential Does the elevator and arm move separately? (True = .andThen, False = .alongWith)
* @return Moves the elevator and arm to the setpoints
*/
private Command moveManipulatorUtil(double elevatorPosition, double armPosition, boolean elevatorFirst, boolean sequential) {
private Command moveManipulatorUtil(ElevatorPositions elevatorPosition, double armPosition, boolean elevatorFirst, boolean sequential) {
/*if (elevatorPosition <= ElevatorConstants.kBracePosition || elevatorPosition == 0) {
armPosition = MathUtil.clamp(
@@ -356,13 +346,16 @@ public class RobotContainer {
return Commands.either(
Commands.either(
elevator.goToSetpoint(() -> elevatorPosition).andThen(manipulatorPivot.goToSetpoint(() -> armPosition)),
elevator.goToSetpoint(() -> elevatorPosition).alongWith(manipulatorPivot.goToSetpoint(() -> armPosition)),
elevator.setTargetPosition(elevatorPosition).andThen(
new WaitUntilCommand(elevator::atSetpoint),
manipulatorPivot.goToSetpoint(() -> armPosition)
),
elevator.setTargetPosition(elevatorPosition).alongWith(manipulatorPivot.goToSetpoint(() -> armPosition)),
() -> sequential
),
Commands.either(
manipulatorPivot.goToSetpoint(() -> armPosition).andThen(elevator.goToSetpoint(() -> elevatorPosition)),
manipulatorPivot.goToSetpoint(() -> armPosition).alongWith(elevator.goToSetpoint(() -> elevatorPosition)),
manipulatorPivot.goToSetpoint(() -> armPosition).andThen(elevator.setTargetPosition(elevatorPosition)),
manipulatorPivot.goToSetpoint(() -> armPosition).alongWith(elevator.setTargetPosition(elevatorPosition)),
() -> sequential
),
() -> elevatorFirst
@@ -370,18 +363,24 @@ public class RobotContainer {
}
@SuppressWarnings("unused")
private Command manipulatorSafeTravel(double elevatorPosition, double armPosition, boolean isL4){
private Command manipulatorSafeTravel(ElevatorPositions elevatorPosition, double armPosition, boolean isL4){
if(!isL4){
return Commands.sequence(
manipulatorPivot.goToSetpoint(() -> ManipulatorPivotConstants.kPivotSafeStowPosition),
elevator.goToSetpoint(() -> elevatorPosition),
elevator.setTargetPosition(elevatorPosition),
new WaitUntilCommand(elevator::atSetpoint),
manipulatorPivot.goToSetpoint(() -> armPosition));
}else{
return Commands.sequence(
manipulatorPivot.goToSetpoint(() -> ManipulatorPivotConstants.kPivotSafeStowPosition),
elevator.goToSetpoint(() -> elevatorPosition).until(() -> elevator.getEncoderPosition() > ElevatorConstants.kL4TransitionPosition),
Commands.parallel( manipulatorPivot.goToSetpoint(() -> armPosition)), elevator.goToSetpoint(() -> elevatorPosition));
elevator.setTargetPosition(elevatorPosition),
new WaitUntilCommand(() -> elevator.getEncoderPosition() > ElevatorPositions.kL4Transition.getPosition()),
Commands.parallel(
manipulatorPivot.goToSetpoint(() -> armPosition),
elevator.setTargetPosition(elevatorPosition).andThen(new WaitUntilCommand(elevator::atSetpoint))
)
);
}
}
@@ -393,18 +392,15 @@ public class RobotContainer {
* @param armPosition The target rotation of the arm
* @return Moves the elevator and arm to the setpoints
*/
private Command safeMoveManipulator(double elevatorPosition, double armPosition) {
/*return moveManipulatorUtil(elevatorPosition, ManipulatorPivotConstants.kPivotSafeStowPosition, false, true)
.deadlineFor(manipulatorPivot.goToSetpoint(() -> armPosition),
elevator.maintainPosition());*/
return manipulatorPivot.goToSetpoint(() -> ManipulatorPivotConstants.kPivotSafeStowPosition)
.andThen(elevator.goToSetpoint(() -> elevatorPosition))
.andThen(manipulatorPivot.goToSetpoint(() -> armPosition));
@SuppressWarnings("unused")
private Command safeMoveManipulator(ElevatorPositions elevatorPosition, double armPosition) {
return moveManipulatorUtil(elevatorPosition, ManipulatorPivotConstants.kPivotSafeStowPosition, false, true)
.andThen(manipulatorPivot.goToSetpoint(() -> armPosition));
}
@SuppressWarnings("unused")
private Command startingConfig() {
return moveManipulatorUtil(0, 0, false, true)
return moveManipulatorUtil(ElevatorPositions.kStartingPosition, 0, false, true)
.alongWith(climberPivot.climb(ClimberPivotConstants.kClimberStartingPosition, .1));
}
}

View File

@@ -11,6 +11,34 @@ import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Config;
public class ElevatorConstants {
public enum ElevatorControlMode {
kPID,
kManualMaintain
}
public enum ElevatorPositions {
kStartingPosition(0),
kCoralIntake(0),
kL1(0),
kL2(14.5),
kL2Algae(22),
kL3(29),
kL3Algae(39),
kL4(53),
kL4Transition(40),
kProcessor(4);
private double position;
private ElevatorPositions(double position) {
this.position = position;
}
public double getPosition() {
return position;
}
}
public static final int kElevatorMotor1ID = 8;
public static final int kElevatorMotor2ID = 6;
@@ -36,21 +64,16 @@ public class ElevatorConstants {
public static final double kFeedForwardG = (0.95 + 0.2)/2; /* kG too high + kG too low / 2 */ // calculated value 0.6
public static final double kFeedForwardV = 0.12; // calculated value 0.12
public static final double kFeedForwardAlgaeHeldS = 0;
public static final double kFeedForwardAlgaeHeldG = 0;
public static final double kFeedForwardAlgaeHeldV = 0;
public static final double kMaxVelocity = 150.0; // 120 inches per second (COOKING) calculated max is 184 in/s
public static final double kMaxAcceleration = 240; // 400 inches per second^2 (also COOKING) calculated max is 600 in/s^2
public static final double kCoralIntakePosition = 0;
public static final double kL1Position = 0;
public static final double kL2Position = 14.5;
public static final double kL3Position = 29.0;
public static final double kL4Position = 52.0;
public static final double kL4TransitionPosition = 40.0;
public static final double kL2AlgaePosition = 22.0;
public static final double kL3AlgaePosition = 39.0;
public static final double kProcessorPosition = 4.0;
/**The position of the top of the elevator brace */
public static final double kBracePosition = 0;
public static final double kMaxHeight = 52.0; //actual is 52
public static final double kMaxHeight = 47.5; //actual is 53
// 1, 7, 10 are the defaults for these, change as necessary
public static final double kSysIDRampRate = .25;

View File

@@ -4,7 +4,9 @@ import com.revrobotics.spark.config.SparkMaxConfig;
public class ManipulatorConstants {
public static final int kManipulatorMotorID = 12;
public static final int kCoralBeamBreakID = 2;
public static final int kAlgaePhotoswitchID = 3;
public static final SparkMaxConfig motorConfig = new SparkMaxConfig();
}

View File

@@ -248,12 +248,9 @@ public class Drivetrain extends SubsystemBase {
m_rearRight.resetEncoders();
}
/** Zeroes the heading of the robot.
* @return */
public Command zeroHeading() {
return run(() -> {
gyro.reset();
});
/** Zeroes the heading of the robot. */
public void zeroHeading() {
gyro.reset();
}
public double getGyroValue() {

View File

@@ -1,5 +1,6 @@
package frc.robot.subsystems;
import java.util.function.BooleanSupplier;
import java.util.function.DoubleSupplier;
import com.revrobotics.RelativeEncoder;
@@ -15,6 +16,8 @@ import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.constants.ElevatorConstants;
import frc.robot.constants.ElevatorConstants.ElevatorControlMode;
import frc.robot.constants.ElevatorConstants.ElevatorPositions;
public class Elevator extends SubsystemBase {
protected SparkMax elevatorMotor1;
@@ -22,14 +25,20 @@ public class Elevator extends SubsystemBase {
protected RelativeEncoder encoder;
private BooleanSupplier hasAlgae;
private DigitalInput bottomLimitSwitch;
private PIDController pidControllerUp;
private PIDController pidControllerDown;
private PIDController pidController;
private ElevatorFeedforward feedForward;
private ElevatorFeedforward algaeHeldFeedForward;
private ElevatorControlMode mode;
private ElevatorPositions currentTargetPosition;
public Elevator() {
public Elevator(BooleanSupplier hasAlgae) {
elevatorMotor1 = new SparkMax(
ElevatorConstants.kElevatorMotor1ID,
MotorType.kBrushless
@@ -54,33 +63,36 @@ public class Elevator extends SubsystemBase {
encoder = elevatorMotor1.getEncoder();
this.hasAlgae = hasAlgae;
bottomLimitSwitch = new DigitalInput(
ElevatorConstants.kBottomLimitSwitchID
);
pidControllerDown = new PIDController(
pidController = new PIDController(
ElevatorConstants.kDownControllerP,
ElevatorConstants.kDownControllerI,
ElevatorConstants.kDownControllerD
);
pidControllerDown.setSetpoint(0);
pidController.setSetpoint(0);
pidControllerDown.setTolerance(ElevatorConstants.kAllowedError);
pidControllerUp = new PIDController(
ElevatorConstants.kUpControllerP,
ElevatorConstants.kUpControllerI,
ElevatorConstants.kUpControllerD
);
pidControllerUp.setSetpoint(0);
pidControllerUp.setTolerance(ElevatorConstants.kAllowedError);
pidController.setTolerance(ElevatorConstants.kAllowedError);
feedForward = new ElevatorFeedforward(
ElevatorConstants.kFeedForwardS,
ElevatorConstants.kFeedForwardG,
ElevatorConstants.kFeedForwardV
);
algaeHeldFeedForward = new ElevatorFeedforward(
ElevatorConstants.kFeedForwardAlgaeHeldS,
ElevatorConstants.kFeedForwardAlgaeHeldG,
ElevatorConstants.kFeedForwardAlgaeHeldV
);
mode = ElevatorControlMode.kPID;
currentTargetPosition = ElevatorPositions.kCoralIntake;
}
@Override
@@ -88,6 +100,27 @@ public class Elevator extends SubsystemBase {
if (!getBottomLimitSwitch()) {
encoder.setPosition(0);
}
if(mode == ElevatorControlMode.kPID) {
if (!pidController.atSetpoint()) {
elevatorMotor1.setVoltage(
pidController.calculate(
encoder.getPosition(),
currentTargetPosition.getPosition()
) + (hasAlgae.getAsBoolean() ? algaeHeldFeedForward.calculate(0) : feedForward.calculate(0))
);
} else {
if (hasAlgae.getAsBoolean()) {
elevatorMotor1.setVoltage(
algaeHeldFeedForward.calculate(0)
);
} else {
elevatorMotor1.setVoltage(
feedForward.calculate(0)
);
}
}
}
}
/**
@@ -118,7 +151,10 @@ public class Elevator extends SubsystemBase {
* @return Sets motor voltage to translate the elevator and maintain position
*/
public Command runManualElevator(DoubleSupplier speed) {
return run(() -> {
return startRun(() -> {
mode = ElevatorControlMode.kManualMaintain;
},
() -> {
double desired = speed.getAsDouble();
if(Math.abs(MathUtil.applyDeadband(desired, .05)) > 0) {
@@ -126,128 +162,33 @@ public class Elevator extends SubsystemBase {
speed.getAsDouble()
);
} else {
elevatorMotor1.setVoltage(feedForward.calculate(0));
}
});
}
/**
* A command that will use the feed forward to hold up the elevator.
* Used for feed forward tuning.
*
* @return Sets motor voltage based on feed forward calculation.
*/
public Command maintainPosition() {
return startRun(() -> {
},
() -> {
/*
if (!pidControllerUp.atSetpoint()) {
if(encoder.getPosition()>pidControllerUp.getSetpoint()){
if (hasAlgae.getAsBoolean()) {
elevatorMotor1.setVoltage(
pidControllerUp.calculate(
encoder.getPosition()
) + feedForward.calculate(0)
algaeHeldFeedForward.calculate(0)
);
}else{
} else {
elevatorMotor1.setVoltage(
pidControllerDown.calculate(
encoder.getPosition()
) + feedForward.calculate(0)
feedForward.calculate(0)
);
}
} else {
elevatorMotor1.setVoltage(
feedForward.calculate(0)
);
}*/
elevatorMotor1.setVoltage(
feedForward.calculate(0)
);
}
});
}
/**
* Moves the elevator to a target destination (setpoint).
*
* @param setpoint Target destination of the subsystem
* @param timeout Time to achieve the setpoint before quitting
* @return Sets motor voltage to achieve the target destination
*/
public Command goToSetpoint(DoubleSupplier setpoint) {
return startRun(() -> {
pidControllerUp.setSetpoint(setpoint.getAsDouble());
pidControllerDown.setSetpoint(setpoint.getAsDouble());
pidControllerUp.reset();
pidControllerDown.reset();
},
() -> {
double upOutput = pidControllerUp.calculate(getEncoderPosition());
double downOutput = pidControllerDown.calculate(getEncoderPosition());
if(setpoint.getAsDouble()>encoder.getPosition())
elevatorMotor1.setVoltage(
upOutput + feedForward.calculate(0)
);
else{
elevatorMotor1.setVoltage(
downOutput + feedForward.calculate(0)
);
public Command setTargetPosition(ElevatorPositions position) {
return runOnce(() -> {
if (mode == ElevatorControlMode.kManualMaintain) {
pidController.reset();
mode = ElevatorControlMode.kPID;
}
}).until(() -> pidControllerUp.atSetpoint() || pidControllerDown.atSetpoint());
/*
elevatorMotor1.setVoltage(
pidController.calculate(
encoder.getPosition(),
clampedSetpoint
) + feedForward.calculate(0)
);
*/
/*
if (!pidController.atSetpoint()) {
elevatorMotor1.setVoltage(
pidController.calculate(
encoder.getPosition(),
clampedSetpoint
) + feedForward.calculate(0)
);
} else {
elevatorMotor1.setVoltage(
feedForward.calculate(0)
);
}
});*/
currentTargetPosition = position;
});
}
public boolean atSetpoint() {
return pidController.atSetpoint();
}
/*
if(encoder.getPosition() >= setpoint.getAsDouble()){
elevatorMotor1.setVoltage(
pidControllerUp.calculate(
encoder.getPosition(),
clampedSetpoint
) + feedForward.calculate(pidControllerUp.getSetpoint().velocity)
);
}else if(encoder.getPosition() <= setpoint.getAsDouble()){
elevatorMotor1.setVoltage(
pidControllerDown.calculate(
encoder.getPosition(),
clampedSetpoint
) + feedForward.calculate(pidControllerDown.getSetpoint().velocity)
);
}
*/
/**
* Returns the current encoder position
@@ -286,19 +227,11 @@ public class Elevator extends SubsystemBase {
return elevatorMotor2.getAppliedOutput()*elevatorMotor2.getBusVoltage();
}
public double getPIDUpSetpoint() {
return pidControllerUp.getSetpoint();
public double getPIDSetpoint() {
return pidController.getSetpoint();
}
public double getPIDUpError() {
return pidControllerUp.getError();
}
public double getPIDDownSetpoint() {
return pidControllerDown.getSetpoint();
}
public double getPIDDownError() {
return pidControllerDown.getError();
public double getPIDError() {
return pidController.getError();
}
}

View File

@@ -16,6 +16,7 @@ public class Manipulator extends SubsystemBase {
private SparkMax manipulatorMotor;
private DigitalInput coralBeamBreak;
private DigitalInput algaePhotoswitch;
public Manipulator() {
manipulatorMotor = new SparkMax(
@@ -30,6 +31,7 @@ public class Manipulator extends SubsystemBase {
);
coralBeamBreak = new DigitalInput(ManipulatorConstants.kCoralBeamBreakID);
algaePhotoswitch = new DigitalInput(ManipulatorConstants.kAlgaePhotoswitchID);
}
/**
@@ -90,4 +92,8 @@ public class Manipulator extends SubsystemBase {
public boolean getCoralBeamBreak() {
return coralBeamBreak.get();
}
public boolean getAlgaePhotoswitch() {
return algaePhotoswitch.get();
}
}

View File

@@ -40,9 +40,9 @@ public class Vision{
NetworkTable blackVisionTable = inst.getTable("black_Fiducial");
NetworkTable orangeVisionTable = inst.getTable("orange_Fiducial");
blackRobotRelativeX = blackVisionTable.getDoubleTopic("blackRelativeX").subscribe(0.0);
blackRobotRelativeY = blackVisionTable.getDoubleTopic("blackRelativeY").subscribe(0.0);
blackRobotRelativeZ = blackVisionTable.getDoubleTopic("blackRelativeZ").subscribe(0.0);
blackRobotRelativeX = orangeVisionTable.getDoubleTopic("blackRelativeX").subscribe(0.0);
blackRobotRelativeY = orangeVisionTable.getDoubleTopic("blackRelativeY").subscribe(0.0);
blackRobotRelativeZ = orangeVisionTable.getDoubleTopic("blackRelativeZ").subscribe(0.0);
blackClosestTag = blackVisionTable.getDoubleTopic("blackClosestTag").subscribe(0.0);
blackTagDetected = blackVisionTable.getBooleanTopic("blackTagDetected").subscribe(false);
@@ -59,23 +59,24 @@ public class Vision{
orangeFramerate = orangeVisionTable.getDoubleTopic("orangeFPS").subscribe(0.0);
}
public Pose2d relativeToGlobalPose2d(int tagID, Translation2d relativeCoords){
public Pose2d relativeToGlobalPose2d(int tagID, Translation2d relativeCoords, Rotation2d gyroAngle){
Pose2d tag2dPose = new Pose2d(VisionConstants.globalTagCoords[tagID][0],
VisionConstants.globalTagCoords[tagID][1],
new Rotation2d());
Pose2d relative = new Pose2d(relativeCoords, new Rotation2d(gyroAngle.getAsDouble()));
Pose2d relative = new Pose2d(relativeCoords, gyroAngle);
Transform2d relative2dTransformation = new Transform2d(relative.getTranslation(), relative.getRotation());
Pose2d globalPose = tag2dPose.transformBy(relative2dTransformation.inverse());
return new Pose2d(globalPose.getTranslation(), new Rotation2d(gyroAngle.getAsDouble()));
return new Pose2d(globalPose.getTranslation(), gyroAngle);
}
public Pose2d getBlackGlobalPose(){
return relativeToGlobalPose2d(getBlackClosestTag(),
new Translation2d(getBlackRelativeX(), getBlackRelativeY()));
new Translation2d(getBlackRelativeX(), getBlackRelativeY()),
new Rotation2d(gyroAngle.getAsDouble()));
}
public double getBlackRelativeX(){
@@ -108,7 +109,8 @@ public class Vision{
public Pose2d getOrangeGlobalPose(){
return relativeToGlobalPose2d(getOrangeClosestTag(),
new Translation2d(getOrangeRelativeX(), getOrangeRelativeY()));
new Translation2d(getOrangeRelativeX(), getOrangeRelativeY()),
new Rotation2d(gyroAngle.getAsDouble()));
}
public double getOrangeRelativeX(){

View File

@@ -2,6 +2,9 @@ package frc.robot.subsystems.sysid;
import static edu.wpi.first.units.Units.Inches;
import static edu.wpi.first.units.Units.Volts;
import java.util.function.BooleanSupplier;
import static edu.wpi.first.units.Units.InchesPerSecond;
import edu.wpi.first.units.measure.MutDistance;
@@ -22,8 +25,8 @@ public class ElevatorSysID extends Elevator {
private SysIdRoutine routine;
public ElevatorSysID() {
super();
public ElevatorSysID(BooleanSupplier hasAlgae) {
super(hasAlgae);
appliedVoltage = Volts.mutable(0);
@@ -38,7 +41,7 @@ public class ElevatorSysID extends Elevator {
(log) -> {
log.motor("elevatorMotor1")
.voltage(appliedVoltage.mut_replace(
elevatorMotor1.get() * RobotController.getBatteryVoltage(), Volts
getMotor1(), Volts
))
.linearPosition(elevatorPosition.mut_replace(
encoder.getPosition(), Inches