Skip to content

Commit 674c3a1

Browse files
committed
e
1 parent e9d07d7 commit 674c3a1

File tree

4 files changed

+73
-55
lines changed

4 files changed

+73
-55
lines changed

src/main/java/org/frc6423/robot/subsystems/superstructure/arm/Arm.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import static edu.wpi.first.units.Units.Radians;
1111

1212
import edu.wpi.first.epilogue.Logged;
13+
import edu.wpi.first.math.geometry.Rotation2d;
1314
import edu.wpi.first.units.measure.Angle;
1415
import edu.wpi.first.units.measure.AngularVelocity;
1516
import edu.wpi.first.wpilibj2.command.Command;
@@ -23,6 +24,37 @@
2324

2425
/** Arm Subsystem */
2526
public class Arm extends SubsystemBase {
27+
/** Represents a state the {@link Arm} subsystem can be in */
28+
// TODO CHECK ROLLER SPEEDS
29+
public static enum ArmState {
30+
/** Resting state */
31+
STOWED(Rotation2d.fromDegrees(90), 0.0),
32+
/** Avoidance state for preventing collisions */
33+
AVOIDING(Rotation2d.fromDegrees(65), 0.0),
34+
/** Flipped state for intaking */
35+
INTAKING(Rotation2d.fromDegrees(-90), 20.0),
36+
/** L2 pose but not scoring */
37+
L2_PRIMED(Rotation2d.fromDegrees(21.975), 0.0),
38+
/** L3 pose but not scoring */
39+
L3_PRIMED(Rotation2d.fromDegrees(21.975), 0.0),
40+
/** L4 pose but not scoring */
41+
L4_PRIMED(Rotation2d.fromDegrees(74.5), 0.0),
42+
/** L2 scoring */
43+
L2_SCORING(Rotation2d.fromDegrees(21.975), -40.0),
44+
/** L3 scoring */
45+
L3_SCORING(Rotation2d.fromDegrees(21.975), -40.0),
46+
/** L4 scoring */
47+
L4_SCORING(Rotation2d.fromDegrees(74.5), -40.0);
48+
49+
public final Rotation2d angle;
50+
public final double rollerSpeedRpm;
51+
52+
private ArmState(Rotation2d angle, double rollerSpeedRpm) {
53+
this.angle = angle;
54+
this.rollerSpeedRpm = rollerSpeedRpm;
55+
}
56+
}
57+
2658
@Logged(name = "Pivot Subsystem-Component")
2759
private final ArmPivot pivot;
2860

@@ -67,6 +99,13 @@ public boolean isNearSetpointAngle() {
6799
return pivot.isNearSetpointAngle();
68100
}
69101

102+
/**
103+
* @return {@link Rotation2d} representing the arm angle
104+
*/
105+
public Rotation2d getRotation2d() {
106+
return pivot.getRotation2d();
107+
}
108+
70109
/**
71110
* @return true if arm has vectored coral piece
72111
*/

src/main/java/org/frc6423/robot/subsystems/superstructure/arm/ArmPivot.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,28 @@
1010
import static edu.wpi.first.units.Units.Inches;
1111
import static edu.wpi.first.units.Units.KilogramSquareMeters;
1212
import 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

1416
import edu.wpi.first.epilogue.Logged;
1517
import edu.wpi.first.math.MathUtil;
1618
import edu.wpi.first.math.filter.LinearFilter;
19+
import edu.wpi.first.math.geometry.Rotation2d;
1720
import edu.wpi.first.units.measure.Angle;
21+
import edu.wpi.first.units.measure.AngularAcceleration;
22+
import edu.wpi.first.units.measure.AngularVelocity;
1823
import edu.wpi.first.units.measure.Distance;
1924
import edu.wpi.first.units.measure.MomentOfInertia;
2025
import edu.wpi.first.wpilibj2.command.Command;
2126
import edu.wpi.first.wpilibj2.command.SubsystemBase;
2227
import java.util.function.DoubleSupplier;
23-
import org.frc6423.robot.subsystems.superstructure.Visualizer;
2428

2529
/** Pivot subsystem-component of the {@link Arm} Subsystem */
2630
public 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) {

src/main/java/org/frc6423/robot/subsystems/superstructure/arm/ArmPivotIOReal.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66

77
package org.frc6423.robot.subsystems.superstructure.arm;
88

9-
import static edu.wpi.first.units.Units.MetersPerSecond;
10-
import static edu.wpi.first.units.Units.MetersPerSecondPerSecond;
119
import static edu.wpi.first.units.Units.Radians;
10+
import static edu.wpi.first.units.Units.RadiansPerSecond;
11+
import static edu.wpi.first.units.Units.RadiansPerSecondPerSecond;
12+
import static org.frc6423.robot.subsystems.superstructure.arm.ArmPivot.CANBUS;
13+
import static org.frc6423.robot.subsystems.superstructure.arm.ArmPivot.GEAR_REDUCTION;
14+
import static org.frc6423.robot.subsystems.superstructure.arm.ArmPivot.MAX_ACCELERATION;
1215
import static org.frc6423.robot.subsystems.superstructure.arm.ArmPivot.MAX_ANGLE;
16+
import static org.frc6423.robot.subsystems.superstructure.arm.ArmPivot.MAX_VELOCITY;
1317
import static org.frc6423.robot.subsystems.superstructure.arm.ArmPivot.MIN_ANGLE;
1418
import static org.frc6423.robot.subsystems.superstructure.arm.ArmPivot.MOTOR_ID;
15-
import static org.frc6423.robot.subsystems.superstructure.elevator.Elevator.*;
1619

1720
import com.ctre.phoenix6.BaseStatusSignal;
1821
import com.ctre.phoenix6.configs.TalonFXConfiguration;
@@ -62,8 +65,8 @@ public ArmPivotIOReal() {
6265
conf.Slot0.kI = 0.0;
6366
conf.Slot0.kD = 0.0;
6467

65-
conf.MotionMagic.MotionMagicCruiseVelocity = MAX_VELOCITY.in(MetersPerSecond);
66-
conf.MotionMagic.MotionMagicAcceleration = MAX_ACCELERATION.in(MetersPerSecondPerSecond);
68+
conf.MotionMagic.MotionMagicCruiseVelocity = MAX_VELOCITY.in(RadiansPerSecond);
69+
conf.MotionMagic.MotionMagicAcceleration = MAX_ACCELERATION.in(RadiansPerSecondPerSecond);
6770

6871
motor.getConfigurator().apply(conf);
6972

src/main/java/org/frc6423/robot/subsystems/superstructure/arm/ArmState.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)