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

Commit

Permalink
refactor(superstructure): Improve superstructure mechanism renderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenheroux committed Apr 27, 2024
1 parent 566cc14 commit f9f4422
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/superstructure/Superstructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static Superstructure getInstance() {
public void periodic() {
measurement = new SuperstructureState(arm.getState(), intake.getState(), shooter.getState());

SuperstructureMechanism.getInstance().updateSuperstructure(measurement);
SuperstructureMechanism.getInstance().update(measurement);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,64 @@
/** Superstructure mechanism renderer. */
public class SuperstructureMechanism {

/** Superstructure mechanism renderer singleton. */
private static SuperstructureMechanism instance = null;

/** Superstructure mechanism. */
private final Mechanism2d mechanism;

/** Superstructure mechanism ligaments. */
private MechanismLigament2d shoulder, flywheel, serializer, rollers;

/** Superstructure mechanism width. */
private final double WIDTH =
2
* (RobotConstants.FRAME_PERIMETER_TO_ORIGIN_DISTANCE
+ RobotConstants.MAX_HORIZONTAL_EXTENSION_DISTANCE);

/** Superstructure mechanism height. */
private final double HEIGHT = RobotConstants.MAX_VERTICAL_EXTENSION_DISTANCE;

/** Superstructure mechanism origin (horizontally centered). */
private final Translation2d ORIGIN = new Translation2d(WIDTH / 2, 0);

/** Translation between the origin to shoulder base. */
private final Translation2d ORIGIN_TO_SHOULDER_BASE =
new Translation2d(Units.inchesToMeters(-7.5), Units.inchesToMeters(3.75));

/** Height of the shoulder member. */
private final double SHOULDER_BASE_HEIGHT = Units.inchesToMeters(18);

/** Distance from top of the shoulder member to shoulder pivot. */
private final double SHOULDER_BASE_TOP_TO_SHOULDER = Units.inchesToMeters(1.5);

/** Translation from shoulder base to shoulder pivot. */
private final Translation2d SHOULDER_BASE_TO_SHOULDER =
new Translation2d(0, SHOULDER_BASE_HEIGHT - SHOULDER_BASE_TOP_TO_SHOULDER);

/** Length of the flywheel segment of the shooter. */
private final double SHOOTER_LENGTH = Units.inchesToMeters(12);

/** Length of the serializer segment of the shooter. */
private final double SERIALIZER_LENGTH = Units.inchesToMeters(7.5);

/** Translation from origin to the intake rollers. */
private final Translation2d ORIGIN_TO_ROLLERS =
new Translation2d(Units.inchesToMeters(5.75), Units.inchesToMeters(2.5));

/** Superstructure mechanism default color. */
private final Color8Bit DEFAULT_COLOR = new Color8Bit(Color.kLightGray);

/** Superstructure mechanism flywheel color. */
private final Color8Bit FLYWHEEL_COLOR = new Color8Bit(Color.kSalmon);

/** Superstructure mechanism serializer color. */
private final Color8Bit SERIALIZER_COLOR = new Color8Bit(Color.kCornflowerBlue);

/** Superstructure mechanism rollers color. */
private final Color8Bit ROLLERS_COLOR = new Color8Bit(Color.kSpringGreen);

/** Initializes superstructure mechanism renderer. */
private SuperstructureMechanism() {
mechanism = new Mechanism2d(WIDTH, HEIGHT);

Expand Down Expand Up @@ -112,6 +130,11 @@ private SuperstructureMechanism() {
"framePerimeterRight_", HEIGHT, 90, framePerimeterThickness, DEFAULT_COLOR));
}

/**
* Returns the superstructure mechanism renderer instance.
*
* @return the superstructure mechanism renderer instance.
*/
public static SuperstructureMechanism getInstance() {
if (instance == null) {
instance = new SuperstructureMechanism();
Expand All @@ -120,11 +143,21 @@ public static SuperstructureMechanism getInstance() {
return instance;
}

/**
* Returns the superstructure mechanism renderer.
*
* @return the superstructure mechanism renderer.
*/
public Mechanism2d getMechanism() {
return mechanism;
}

public void updateSuperstructure(SuperstructureState state) {
/**
* Updates the superstructure mechanism renderer.
*
* @param state the state to render.
*/
public void update(SuperstructureState state) {
Rotation2d shoulderRotation =
Rotation2d.fromRotations(state.armState().shoulderRotations().position);

Expand Down

0 comments on commit f9f4422

Please sign in to comment.