|
1 | 1 | package org.trigon.utilities.mechanisms; |
2 | 2 |
|
3 | | -import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d; |
4 | | -import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d; |
5 | | -import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d; |
6 | 3 | import edu.wpi.first.wpilibj.util.Color8Bit; |
7 | 4 | import org.littletonrobotics.junction.Logger; |
| 5 | +import org.littletonrobotics.junction.mechanism.LoggedMechanism2d; |
| 6 | +import org.littletonrobotics.junction.mechanism.LoggedMechanismLigament2d; |
| 7 | +import org.littletonrobotics.junction.mechanism.LoggedMechanismRoot2d; |
8 | 8 |
|
9 | 9 | /** |
10 | 10 | * A Mechanism2d object to display the current velocity and target velocity of a mechanism. |
11 | 11 | */ |
12 | 12 | public class SpeedMechanism2d { |
13 | 13 | private final String key; |
14 | | - private final Mechanism2d mechanism; |
15 | | - private final MechanismLigament2d |
| 14 | + private final LoggedMechanism2d mechanism; |
| 15 | + private final LoggedMechanismLigament2d |
16 | 16 | currentVelocityLigament, |
17 | 17 | currentVelocityTopArrowLigament, |
18 | 18 | currentVelocityBottomArrowLigament, |
@@ -40,15 +40,15 @@ public SpeedMechanism2d(String key, double maximumDisplayableVelocity) { |
40 | 40 | public SpeedMechanism2d(String name, double maximumDisplayableVelocity, double deadband) { |
41 | 41 | this.deadband = deadband; |
42 | 42 | this.key = "Mechanisms/" + name; |
43 | | - this.mechanism = new Mechanism2d(2 * maximumDisplayableVelocity, 2 * maximumDisplayableVelocity); |
44 | | - final MechanismRoot2d root = mechanism.getRoot("Root", maximumDisplayableVelocity, maximumDisplayableVelocity); |
45 | | - this.currentVelocityLigament = root.append(new MechanismLigament2d("ZCurrentVelocityLigament", 0, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.BLUE)); |
46 | | - this.currentVelocityTopArrowLigament = currentVelocityLigament.append(new MechanismLigament2d("ZCurrentVelocityTopArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_TOP_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.BLUE)); |
47 | | - this.currentVelocityBottomArrowLigament = currentVelocityLigament.append(new MechanismLigament2d("ZCurrentVelocityBottomArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_BOTTOM_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.BLUE)); |
| 43 | + this.mechanism = new LoggedMechanism2d(2 * maximumDisplayableVelocity, 2 * maximumDisplayableVelocity); |
| 44 | + final LoggedMechanismRoot2d root = mechanism.getRoot("Root", maximumDisplayableVelocity, maximumDisplayableVelocity); |
| 45 | + this.currentVelocityLigament = root.append(new LoggedMechanismLigament2d("ZCurrentVelocityLigament", 0, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.BLUE)); |
| 46 | + this.currentVelocityTopArrowLigament = currentVelocityLigament.append(new LoggedMechanismLigament2d("ZCurrentVelocityTopArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_TOP_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.BLUE)); |
| 47 | + this.currentVelocityBottomArrowLigament = currentVelocityLigament.append(new LoggedMechanismLigament2d("ZCurrentVelocityBottomArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_BOTTOM_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.BLUE)); |
48 | 48 |
|
49 | | - this.targetVelocityLigament = root.append(new MechanismLigament2d("TargetVelocityLigament", 0, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY)); |
50 | | - this.targetVelocityTopArrowLigament = targetVelocityLigament.append(new MechanismLigament2d("TargetVelocityTopArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_TOP_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY)); |
51 | | - this.targetVelocityBottomArrowLigament = targetVelocityLigament.append(new MechanismLigament2d("TargetVelocityBottomArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_BOTTOM_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY)); |
| 49 | + this.targetVelocityLigament = root.append(new LoggedMechanismLigament2d("TargetVelocityLigament", 0, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY)); |
| 50 | + this.targetVelocityTopArrowLigament = targetVelocityLigament.append(new LoggedMechanismLigament2d("TargetVelocityTopArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_TOP_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY)); |
| 51 | + this.targetVelocityBottomArrowLigament = targetVelocityLigament.append(new LoggedMechanismLigament2d("TargetVelocityBottomArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_BOTTOM_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY)); |
52 | 52 | } |
53 | 53 |
|
54 | 54 | /** |
@@ -114,7 +114,7 @@ else if (velocity < -deadband) |
114 | 114 | return MechanismConstants.BLUE; |
115 | 115 | } |
116 | 116 |
|
117 | | - private void setArrowAngle(double velocity, MechanismLigament2d topLigament, MechanismLigament2d bottomLigament) { |
| 117 | + private void setArrowAngle(double velocity, LoggedMechanismLigament2d topLigament, LoggedMechanismLigament2d bottomLigament) { |
118 | 118 | if (velocity > deadband) { |
119 | 119 | topLigament.setAngle(MechanismConstants.POSITIVE_TOP_ANGLE); |
120 | 120 | bottomLigament.setAngle(MechanismConstants.POSITIVE_BOTTOM_ANGLE); |
|
0 commit comments