1010import static edu .wpi .first .units .Units .Inches ;
1111import static edu .wpi .first .units .Units .KilogramSquareMeters ;
1212import static edu .wpi .first .units .Units .Radians ;
13+ import static edu .wpi .first .units .Units .RadiansPerSecond ;
14+ import static edu .wpi .first .units .Units .RadiansPerSecondPerSecond ;
1315
1416import edu .wpi .first .epilogue .Logged ;
1517import edu .wpi .first .math .MathUtil ;
1618import edu .wpi .first .math .filter .LinearFilter ;
19+ import edu .wpi .first .math .geometry .Rotation2d ;
1720import edu .wpi .first .units .measure .Angle ;
21+ import edu .wpi .first .units .measure .AngularAcceleration ;
22+ import edu .wpi .first .units .measure .AngularVelocity ;
1823import edu .wpi .first .units .measure .Distance ;
1924import edu .wpi .first .units .measure .MomentOfInertia ;
2025import edu .wpi .first .wpilibj2 .command .Command ;
2126import edu .wpi .first .wpilibj2 .command .SubsystemBase ;
2227import java .util .function .DoubleSupplier ;
23- import org .frc6423 .robot .subsystems .superstructure .Visualizer ;
2428
2529/** Pivot subsystem-component of the {@link Arm} Subsystem */
2630public class ArmPivot extends SubsystemBase implements AutoCloseable {
27- // * CONSTANTS
31+ /** Name of the CAN bus hardware is on */
2832 public static final String CANBUS = "RIO" ;
33+
34+ /** Pivot motor CAN ID */
2935 public static final int MOTOR_ID = 14 ;
3036
3137 /** Gear ratio of the pivot gearbox */
@@ -46,18 +52,22 @@ public class ArmPivot extends SubsystemBase implements AutoCloseable {
4652 /** The max allowable angle error */
4753 public static final Angle TOLERANCE = Degrees .of (1.5 );
4854
55+ /** The velocity limit of the arm's trapezoid profile */
56+ public static final AngularVelocity MAX_VELOCITY = RadiansPerSecond .of (5.5 );
57+
58+ /** The acceleration of the arm's trapezoid profile */
59+ public static final AngularAcceleration MAX_ACCELERATION = RadiansPerSecondPerSecond .of (17 );
60+
4961 @ Logged (name = "Arm Pivot Hardware Loggables" )
5062 private final ArmPivotIO hardware ;
5163
52- private final LinearFilter pivotCurrentFilter = LinearFilter .movingAverage (5 );
64+ private final LinearFilter currentFilter = LinearFilter .movingAverage (5 );
5365
5466 @ Logged (name = "Filted Pivot Motor Stator Current (Amps)" )
55- private double filteredPivotCurrent ;
67+ private double filteredCurrent ;
5668
5769 private boolean isZeroed = false ;
5870
59- private final Visualizer visualizer = Visualizer .getInstance ();
60-
6171 public ArmPivot (ArmPivotIO hardware ) {
6272 this .hardware = hardware ;
6373 }
@@ -66,9 +76,7 @@ public ArmPivot(ArmPivotIO hardware) {
6676 public void periodic () {
6777 hardware .periodic ();
6878
69- filteredPivotCurrent = pivotCurrentFilter .calculate (hardware .getStatorCurrentAmps ());
70-
71- visualizer .setArmAngle (hardware .getAngleRads ());
79+ filteredCurrent = currentFilter .calculate (hardware .getStatorCurrentAmps ());
7280 }
7381
7482 /**
@@ -88,6 +96,14 @@ public boolean isNearSetpointAngle() {
8896 hardware .getSetpointAngleRads (), hardware .getAngleRads (), TOLERANCE .in (Radians ));
8997 }
9098
99+ /**
100+ * @return {@link Rotation2d} representing the pivot angle
101+ */
102+ @ Logged (name = "Angle (Rotation2d)" )
103+ public Rotation2d getRotation2d () {
104+ return Rotation2d .fromRadians (hardware .getAngleRads ());
105+ }
106+
91107 /**
92108 * Run arm into hardstop to determine home (aka, zero)
93109 *
@@ -96,7 +112,7 @@ public boolean isNearSetpointAngle() {
96112 // TODO CHECK VALUES
97113 public Command runCurrentHoming () {
98114 return this .run (() -> hardware .setVolts (-2.5 ))
99- .until (() -> Math .abs (filteredPivotCurrent ) > 50.0 )
115+ .until (() -> Math .abs (filteredCurrent ) > 50.0 )
100116 .finallyDo (
101117 (interupted ) -> {
102118 if (!interupted ) {
0 commit comments