Skip to content

Commit 619f952

Browse files
committed
Arm fixed, turned out it was a gearing conversion.
1 parent 9bb7fe6 commit 619f952

4 files changed

Lines changed: 23 additions & 18 deletions

File tree

src/main/java/frc/robot/subsystems/arm/Arm.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ public class Arm extends SubsystemBase {
1616
private final ArmIO io;
1717
private final ArmIOInputsAutoLogged replayedInputs = new ArmIOInputsAutoLogged();
1818

19-
private ArmPositions currentArmPosition = ArmPositions.NORTH;
20-
2119
public Arm(ArmIO io) {
2220
this.io = io;
2321
}

src/main/java/frc/robot/subsystems/arm/ArmIO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ArmIOInputs {
2323
public double intakeMotorVelocityRotsPerSecond;
2424
public double intakeMotorVoltage;
2525

26-
// Encoder inputs
26+
// Encoder inputs, should be the same as the arm position.
2727
public double encoderPositionDegrees;
2828
}
2929

src/main/java/frc/robot/subsystems/arm/ArmIOReal.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package frc.robot.subsystems.arm;
22

3-
import static edu.wpi.first.units.Units.Degrees;
3+
import static edu.wpi.first.units.Units.*;
44
import static frc.robot.Constants.*;
55
import static frc.robot.subsystems.arm.ArmConstants.*;
66

@@ -12,6 +12,7 @@
1212
import com.ctre.phoenix6.signals.SensorDirectionValue;
1313
import edu.wpi.first.units.measure.Angle;
1414
import edu.wpi.first.units.measure.Voltage;
15+
import org.littletonrobotics.junction.Logger;
1516

1617
// TODO: Test this class on LePrawn, ensure the arm won't rotate more than once in any direction.
1718
public class ArmIOReal implements ArmIO {
@@ -20,12 +21,9 @@ public class ArmIOReal implements ArmIO {
2021
TalonFX pivotMotor;
2122
TalonFXConfiguration pivotMotorConfig;
2223

23-
PositionVoltage pivotPositionControl = new PositionVoltage(0);
24-
2524
CANcoder armEncoder;
2625
CANcoderConfiguration armEncoderConfig;
2726

28-
2927
// Intake/Outtake motors & configurations
3028
TalonFX intakeMotor;
3129
TalonFXConfiguration intakeMotorConfig;
@@ -36,7 +34,7 @@ public ArmIOReal() {
3634

3735
armEncoderConfig = new CANcoderConfiguration();
3836
armEncoderConfig.withMagnetSensor(
39-
new MagnetSensorConfigs().withSensorDirection(SensorDirectionValue.CounterClockwise_Positive));
37+
new MagnetSensorConfigs().withSensorDirection(SensorDirectionValue.Clockwise_Positive));
4038

4139
armEncoder.getConfigurator().apply(armEncoderConfig);
4240

@@ -45,7 +43,13 @@ public ArmIOReal() {
4543

4644
// Set the current position of the arm to what the position of the absolute encoder.
4745
// Negates the encoder position because the encoder and motor are on different sides of the arm carriage.
48-
pivotMotor.setPosition(armEncoder.getAbsolutePosition().getValue().unaryMinus());
46+
Angle zeroPos = armEncoder
47+
.getAbsolutePosition()
48+
.getValue()
49+
.plus(Rotations.of(0.408691).plus(Degrees.of(90)));
50+
pivotMotor.setPosition(zeroPos.times(MOTOR_TO_ARM_GEARING));
51+
Logger.recordOutput("Arm/Encoder/ABS_VAL_Deg", zeroPos.in(Degrees));
52+
Logger.recordOutput("Arm/Encoder/ABS_VAL_Rot", zeroPos.in(Rotations));
4953

5054
// Start motor config.
5155
pivotMotorConfig = new TalonFXConfiguration();
@@ -79,22 +83,24 @@ public ArmIOReal() {
7983
public void updateState(ArmIOInputs inputs) {
8084
inputs.armPositionDegrees = pivotMotor.getPosition().getValue().in(Degrees) / MOTOR_TO_ARM_GEARING;
8185

82-
inputs.pivotMotorRotations = pivotMotor.getPosition().getValueAsDouble();
83-
inputs.pivotMotorVelocityRotsPerSecond = pivotMotor.getVelocity().getValueAsDouble();
84-
inputs.pivotMotorCurrent = pivotMotor.getStatorCurrent().getValueAsDouble();
85-
inputs.pivotMotorVoltage = pivotMotor.getMotorVoltage().getValueAsDouble();
86+
inputs.pivotMotorRotations = pivotMotor.getPosition().getValue().in(Rotations);
87+
inputs.pivotMotorVelocityRotsPerSecond =
88+
pivotMotor.getVelocity().getValue().in(RotationsPerSecond);
89+
inputs.pivotMotorCurrent = pivotMotor.getStatorCurrent().getValue().in(Amp);
90+
inputs.pivotMotorVoltage = pivotMotor.getMotorVoltage().getValue().in(Volts);
8691

87-
inputs.intakeMotorVelocityRotsPerSecond = intakeMotor.getVelocity().getValueAsDouble();
88-
inputs.intakeMotorVoltage = intakeMotor.getMotorVoltage().getValueAsDouble();
92+
inputs.intakeMotorVelocityRotsPerSecond =
93+
intakeMotor.getVelocity().getValue().in(RotationsPerSecond);
94+
inputs.intakeMotorVoltage = intakeMotor.getMotorVoltage().getValue().in(Volts);
8995

9096
inputs.encoderPositionDegrees = armEncoder.getPosition().getValue().in(Degrees);
9197
}
9298

9399
@Override
94100
public void setPivotMotorSetpoint(Angle setpoint) {
95101
// "0" in sim is facing to the east, while in real robot, it is north. No me gusta, but thus must be done.
96-
97-
pivotMotor.setControl(pivotPositionControl.withPosition(setpoint));
102+
Logger.recordOutput("Arm/PivotMotor/SetpointDeg", setpoint.in(Degrees));
103+
pivotMotor.setControl(new PositionVoltage(setpoint));
98104
}
99105

100106
@Override

src/main/java/frc/robot/subsystems/arm/ArmIOSim.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ private void updateSim() {
110110
intakeMotorSimState.setSupplyVoltage(Volts.of(12));
111111
armEncoderSimState.setSupplyVoltage(Volts.of(12));
112112

113-
armEncoder.setPosition(Radians.of(armSim.getAngleRads()));
113+
// negated because the arm and encoder are on opposite sides of the arm carriage.
114+
armEncoderSimState.setRawPosition(Radians.of(armSim.getAngleRads()).unaryMinus());
114115

115116
armSim.setInputVoltage(pivotMotorSimState.getMotorVoltage());
116117
armSim.update(0.02);

0 commit comments

Comments
 (0)