1010import edu .wpi .first .wpilibj .util .Color8Bit ;
1111import frc .lib .InterpolatableColor ;
1212import frc .robot .arm .ArmConstants .ShoulderMotorConstants ;
13- import frc .robot .arm .ArmState ;
1413import frc .robot .intake .IntakeConstants .PivotMotorConstants ;
1514import frc .robot .intake .IntakeConstants .RollerMotorConstants ;
1615import frc .robot .shooter .ShooterConstants .FlywheelConstants ;
1716import frc .robot .shooter .ShooterConstants .SerializerConstants ;
17+ import frc .robot .superstructure .SuperstructureState ;
1818
1919/** Helper class for rendering robot mechanisms. */
2020public class RobotMechanisms {
@@ -23,7 +23,7 @@ public class RobotMechanisms {
2323
2424 private final Mechanism2d mechanism ;
2525
26- private MechanismLigament2d shoulder , shooter , serializer , intake ;
26+ private MechanismLigament2d shoulder , flywheel , serializer , pivot ;
2727
2828 private final double WIDTH =
2929 2
@@ -34,9 +34,12 @@ public class RobotMechanisms {
3434
3535 private final Translation2d ORIGIN = new Translation2d (WIDTH / 2 , 0 );
3636
37+ public static final Translation2d SHOULDER_TO_ORIGIN =
38+ new Translation2d (Units .inchesToMeters (-11.361 ), Units .inchesToMeters (7.721 ));
39+
3740 private final Color8Bit DEFAULT_COLOR = new Color8Bit (Color .kLightGray );
3841
39- private final InterpolatableColor shooterColor =
42+ private final InterpolatableColor flywheelColor =
4043 new InterpolatableColor (Color .kLightGray , Color .kSalmon );
4144 private final InterpolatableColor serializerColor =
4245 new InterpolatableColor (Color .kLightGray , Color .kCornflowerBlue );
@@ -47,12 +50,13 @@ private RobotMechanisms() {
4750 mechanism = new Mechanism2d (WIDTH , HEIGHT );
4851
4952 initializeArmMechanism ();
50- initializeFramePerimeterMechanisms ();
5153 initializeIntakeMechanism ();
54+
55+ initializeFramePerimeterMechanisms ();
5256 }
5357
5458 private void initializeArmMechanism () {
55- Translation2d armRootTranslation = ORIGIN .plus (ShoulderMotorConstants . SHOULDER_TO_ORIGIN );
59+ Translation2d armRootTranslation = ORIGIN .plus (SHOULDER_TO_ORIGIN );
5660
5761 double armThickness = Units .inchesToMeters (2 ) * 100 ;
5862
@@ -67,7 +71,7 @@ private void initializeArmMechanism() {
6771 0 ,
6872 armThickness ,
6973 DEFAULT_COLOR ));
70- shooter =
74+ flywheel =
7175 shoulder .append (
7276 new MechanismLigament2d (
7377 "wrist" , Units .inchesToMeters (4.321 ), 0 , armThickness , DEFAULT_COLOR ));
@@ -103,7 +107,7 @@ private void initializeFramePerimeterMechanisms() {
103107 private void initializeIntakeMechanism () {
104108 double intakeThickness = Units .inchesToMeters (3 ) * 100 ;
105109
106- intake =
110+ pivot =
107111 mechanism
108112 .getRoot (
109113 "intake" ,
@@ -126,9 +130,9 @@ public Mechanism2d getMechanism() {
126130 return mechanism ;
127131 }
128132
129- public void updateArm ( ArmState state ) {
130- Rotation2d shoulderRotation = Rotation2d .fromRotations (state .shoulder ().position );
131- Rotation2d wristRotation = Rotation2d .fromRotations (state .wrist ().position );
133+ public void updateSuperstructure ( SuperstructureState state ) {
134+ Rotation2d shoulderRotation = Rotation2d .fromRotations (state .shoulderAngleRotations ().position );
135+ Rotation2d wristRotation = Rotation2d .fromRotations (state .wristAngleRotations ().position );
132136
133137 shoulder .setAngle (shoulderRotation );
134138
@@ -138,32 +142,28 @@ public void updateArm(ArmState state) {
138142 Rotation2d shooterRotation = offsetWristRotation ;
139143 Rotation2d serializerRotation = offsetWristRotation .plus (Rotation2d .fromDegrees (180 ));
140144
141- shooter .setAngle (shooterRotation );
142- serializer .setAngle (serializerRotation );
143- }
144-
145- public void updateIntake (Rotation2d pivotAngle , double rollerVelocityRotationsPerSecond ) {
146- Color color =
147- intakeColor .sample (
148- Math .abs (rollerVelocityRotationsPerSecond ), 0 , RollerMotorConstants .MAXIMUM_SPEED );
149-
150- intake .setAngle (pivotAngle );
151- intake .setColor (new Color8Bit (color ));
152- }
153-
154- public void updateShooter (double velocityMetersPerSecond ) {
155- Color color =
156- shooterColor .sample (
157- Math .abs (velocityMetersPerSecond ), 0 , FlywheelConstants .MAXIMUM_TANGENTIAL_SPEED );
158-
159- shooter .setColor (new Color8Bit (color ));
160- }
145+ pivot .setAngle (Rotation2d .fromRotations (state .pivotAngleRotations ().position ));
146+ pivot .setColor (
147+ new Color8Bit (
148+ intakeColor .sample (
149+ Math .abs (state .rollerVelocityRotationsPerSecond ()),
150+ 0 ,
151+ RollerMotorConstants .MAXIMUM_SPEED )));
161152
162- public void updateSerializer (double velocityMetersPerSecond ) {
163- Color color =
164- serializerColor .sample (
165- Math .abs (velocityMetersPerSecond ), 0 , SerializerConstants .MAXIMUM_TANGENTIAL_SPEED );
153+ flywheel .setAngle (shooterRotation );
154+ flywheel .setColor (
155+ new Color8Bit (
156+ flywheelColor .sample (
157+ Math .abs (state .flywheelVelocityRotationsPerSecond ()),
158+ 0 ,
159+ FlywheelConstants .MAXIMUM_TANGENTIAL_SPEED )));
166160
167- serializer .setColor (new Color8Bit (color ));
161+ serializer .setAngle (serializerRotation );
162+ serializer .setColor (
163+ new Color8Bit (
164+ serializerColor .sample (
165+ Math .abs (state .serializerVelocityRotationsPerSecond ()),
166+ 0 ,
167+ SerializerConstants .MAXIMUM_TANGENTIAL_SPEED )));
168168 }
169169}
0 commit comments