11package frc .robot .subsystems .arm ;
22
3- import static edu .wpi .first .units .Units .Degrees ;
3+ import static edu .wpi .first .units .Units .* ;
44import static frc .robot .Constants .*;
55import static frc .robot .subsystems .arm .ArmConstants .*;
66
1212import com .ctre .phoenix6 .signals .SensorDirectionValue ;
1313import edu .wpi .first .units .measure .Angle ;
1414import 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.
1718public 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
0 commit comments