Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
chore: Format.
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenheroux committed Mar 4, 2024
1 parent 69952b1 commit 1340888
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 52 deletions.
33 changes: 16 additions & 17 deletions src/main/java/frc/lib/InterpolatableColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@

public class InterpolatableColor {

private final Color zero, one;
private final Color zero, one;

public InterpolatableColor(Color zero, Color one) {
this.zero = zero;
this.one = one;
}
public InterpolatableColor(Color zero, Color one) {
this.zero = zero;
this.one = one;
}

public Color sample(double t) {
t = MathUtil.clamp(t, 0, 1);
public Color sample(double t) {
t = MathUtil.clamp(t, 0, 1);

double r = zero.red * (1 - t) + one.red * t;
double g = zero.green * (1 - t) + one.green * t;
double b = zero.blue * (1 - t) + one.blue * t;

return new Color(r, g, b);
}
double r = zero.red * (1 - t) + one.red * t;
double g = zero.green * (1 - t) + one.green * t;
double b = zero.blue * (1 - t) + one.blue * t;

public Color sample(double x, double min, double max) {
double t = x / (max - min);
return new Color(r, g, b);
}

return sample(t);
}
public Color sample(double x, double min, double max) {
double t = x / (max - min);

return sample(t);
}
}
56 changes: 23 additions & 33 deletions src/main/java/frc/robot/RobotMechanisms.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj.util.Color8Bit;
import frc.robot.arm.ArmConstants.ShoulderMotorConstants;
import frc.lib.InterpolatableColor;
import frc.robot.arm.ArmConstants.ShoulderMotorConstants;
import frc.robot.arm.ArmState;
import frc.robot.intake.IntakeConstants.PivotMotorConstants;
import frc.robot.intake.IntakeConstants.RollerMotorConstants;
Expand All @@ -36,9 +36,12 @@ public class RobotMechanisms {

private final Color8Bit DEFAULT_COLOR = new Color8Bit(Color.kLightGray);

private final InterpolatableColor shooterColor = new InterpolatableColor(Color.kLightGray, Color.kSalmon);
private final InterpolatableColor serializerColor = new InterpolatableColor(Color.kLightGray, Color.kCornflowerBlue);
private final InterpolatableColor intakeColor = new InterpolatableColor(Color.kLightGray, Color.kPaleGreen);
private final InterpolatableColor shooterColor =
new InterpolatableColor(Color.kLightGray, Color.kSalmon);
private final InterpolatableColor serializerColor =
new InterpolatableColor(Color.kLightGray, Color.kCornflowerBlue);
private final InterpolatableColor intakeColor =
new InterpolatableColor(Color.kLightGray, Color.kPaleGreen);

private RobotMechanisms() {
mechanism = new Mechanism2d(WIDTH, HEIGHT);
Expand Down Expand Up @@ -67,20 +70,12 @@ private void initializeArmMechanism() {
shooter =
shoulder.append(
new MechanismLigament2d(
"wrist",
Units.inchesToMeters(4.321),
0,
armThickness,
DEFAULT_COLOR));
"wrist", Units.inchesToMeters(4.321), 0, armThickness, DEFAULT_COLOR));

serializer =
shoulder.append(
new MechanismLigament2d(
"serializer",
Units.inchesToMeters(8.771),
0,
armThickness,
DEFAULT_COLOR));
"serializer", Units.inchesToMeters(8.771), 0, armThickness, DEFAULT_COLOR));
}

private void initializeFramePerimeterMechanisms() {
Expand All @@ -93,11 +88,7 @@ private void initializeFramePerimeterMechanisms() {
0)
.append(
new MechanismLigament2d(
"framePerimeterLeft_",
HEIGHT,
90,
framePerimeterThickness,
DEFAULT_COLOR));
"framePerimeterLeft_", HEIGHT, 90, framePerimeterThickness, DEFAULT_COLOR));

mechanism
.getRoot(
Expand All @@ -106,11 +97,7 @@ private void initializeFramePerimeterMechanisms() {
0)
.append(
new MechanismLigament2d(
"framePerimeterRight_",
HEIGHT,
90,
framePerimeterThickness,
DEFAULT_COLOR));
"framePerimeterRight_", HEIGHT, 90, framePerimeterThickness, DEFAULT_COLOR));
}

private void initializeIntakeMechanism() {
Expand All @@ -124,11 +111,7 @@ private void initializeIntakeMechanism() {
ORIGIN.getY() + Units.inchesToMeters(6.283))
.append(
new MechanismLigament2d(
"intake_",
PivotMotorConstants.DISTANCE,
0.0,
intakeThickness,
DEFAULT_COLOR));
"intake_", PivotMotorConstants.DISTANCE, 0.0, intakeThickness, DEFAULT_COLOR));
}

public static RobotMechanisms getInstance() {
Expand All @@ -149,7 +132,8 @@ public void updateArm(ArmState state) {

shoulder.setAngle(shoulderRotation);

// Offset the rendered wrist rotation so that zero degrees is perpendicular to the shoulder, rather than parallel with the shoulder
// Offset the rendered wrist rotation so that zero degrees is perpendicular to the shoulder,
// rather than parallel with the shoulder
Rotation2d offsetWristRotation = wristRotation.plus(Rotation2d.fromDegrees(90));
Rotation2d shooterRotation = offsetWristRotation;
Rotation2d serializerRotation = offsetWristRotation.plus(Rotation2d.fromDegrees(180));
Expand All @@ -159,20 +143,26 @@ public void updateArm(ArmState state) {
}

public void updateIntake(Rotation2d pivotAngle, double rollerVelocityRotationsPerSecond) {
Color color = intakeColor.sample(Math.abs(rollerVelocityRotationsPerSecond), 0, RollerMotorConstants.MAXIMUM_SPEED);
Color color =
intakeColor.sample(
Math.abs(rollerVelocityRotationsPerSecond), 0, RollerMotorConstants.MAXIMUM_SPEED);

intake.setAngle(pivotAngle);
intake.setColor(new Color8Bit(color));
}

public void updateShooter(double velocityMetersPerSecond) {
Color color = shooterColor.sample(Math.abs(velocityMetersPerSecond), 0, FlywheelConstants.MAXIMUM_TANGENTIAL_SPEED);
Color color =
shooterColor.sample(
Math.abs(velocityMetersPerSecond), 0, FlywheelConstants.MAXIMUM_TANGENTIAL_SPEED);

shooter.setColor(new Color8Bit(color));
}

public void updateSerializer(double velocityMetersPerSecond) {
Color color = serializerColor.sample(Math.abs(velocityMetersPerSecond), 0, SerializerConstants.MAXIMUM_TANGENTIAL_SPEED);
Color color =
serializerColor.sample(
Math.abs(velocityMetersPerSecond), 0, SerializerConstants.MAXIMUM_TANGENTIAL_SPEED);

serializer.setColor(new Color8Bit(color));
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/frc/robot/arm/ShoulderMotorIOSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public void configure() {}
public void update(ShoulderMotorIOValues values) {
values.positionRotations = this.positionRotations;
values.velocityRotationsPerSecond = this.velocityRotationsPerSecond;
values.accelerationRotationsPerSecondPerSecond = accelerationCalculator.calculate(velocityRotationsPerSecond);
values.accelerationRotationsPerSecondPerSecond =
accelerationCalculator.calculate(velocityRotationsPerSecond);

values.inputVoltage = inputVoltage;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/frc/robot/intake/Intake.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public void periodic() {

rollerMotorCurrentFilter.calculate(rollerMotorValues.currentAmps);

mechanism.updateIntake(Rotation2d.fromRotations(pivotMotorValues.positionRotations), getRollerVelocity());
mechanism.updateIntake(
Rotation2d.fromRotations(pivotMotorValues.positionRotations), getRollerVelocity());
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/java/frc/robot/intake/PivotMotorIOSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class PivotMotorIOSim implements PivotMotorIO {

private double positionRotations;

// private double velocityRotationsPerSecond;

@Override
Expand Down

0 comments on commit 1340888

Please sign in to comment.