1313public class ArmCalibrationCommand extends Command {
1414 //Find the gravity offset, kG, and kS
1515 private final TalonFXMotor motor ;
16+ private static final double VOLTAGE_INCREMENT = 0.001 ;
1617 private Rotation2d gravityOffset ;
1718 private double kG , kS , currentVoltage , minimumVoltage , maximumVoltage ;
18- private boolean isCalculationFinished ;
19+ private boolean isCalculationFinished = false ;
1920 private double previousVelocity ;
2021 HashMap <Double , Rotation2d > name = new HashMap <>();
2122
2223
2324 public ArmCalibrationCommand (TalonFXMotor motor , SubsystemBase ... requirements ) {
2425 this .motor = motor ;
25-
2626 addRequirements (requirements );
2727 }
2828
2929 @ Override
3030 public void initialize () {
31-
3231 }
3332
33+
3434 @ Override
3535 public void execute () {
3636 runCalculateGravityOffset ();
37+ System .out .println (isVelocityIncreasing () + "\n current velocity: " + motor .getSignal (TalonFXSignal .VELOCITY ) + " \n previous velocity: " + previousVelocity );
38+ System .out .println ("\n maximumPosition: " + gravityOffset .getRotations () + "\n minimumPosition: " + name .get (minimumVoltage ).getRotations ());
3739 }
3840
3941 @ Override
@@ -43,6 +45,7 @@ public boolean isFinished() {
4345
4446 @ Override
4547 public void end (boolean interrupted ) {
48+ System .out .println (interrupted );
4649 calculateKG ();
4750 calculateKS ();
4851 logValues ();
@@ -59,16 +62,18 @@ private void printResults() {
5962 System .out .println ("GravityOffset: " + gravityOffset );
6063 System .out .println ("kG: " + kG );
6164 System .out .println ("kS: " + kS );
65+ System .out .println ("Maximum Voltage: " + maximumVoltage );
66+ System .out .println ("Minimum Voltage: " + minimumVoltage );
6267 }
6368
6469 private void runCalculateGravityOffset () {
6570 if (isArmStoppedMoving ()) {
66- currentVoltage += 0.01 ;
71+ currentVoltage += VOLTAGE_INCREMENT ;
6772 motor .setControl (new VoltageOut (currentVoltage ));
6873 logMotorSignalsToHashmap ();
6974 }
7075 if (isVelocityIncreasing ()) {
71- maximumVoltage = currentVoltage - 0.01 ;
76+ maximumVoltage = currentVoltage - VOLTAGE_INCREMENT ;
7277 gravityOffset = name .get (maximumVoltage );
7378 getMinimumVoltage ();
7479 isCalculationFinished = true ;
@@ -77,13 +82,13 @@ private void runCalculateGravityOffset() {
7782
7883 private void getMinimumVoltage () {
7984 minimumVoltage = maximumVoltage ;
80- while (! (Math .abs (gravityOffset .getRotations () - name .get (minimumVoltage ).getRotations ()) > 0.001 )) {
81- minimumVoltage -= 0.01 ;
85+ while ((Math .abs (gravityOffset .getRotations () - name .get (minimumVoltage ).getRotations ()) > 0.0001 )) {
86+ minimumVoltage -= VOLTAGE_INCREMENT ;
8287 }
8388 }
8489
8590 private boolean isVelocityIncreasing () {
86- return motor .getSignal (TalonFXSignal .VELOCITY ) > previousVelocity ;
91+ return Math . abs ( motor .getSignal (TalonFXSignal .VELOCITY ) - previousVelocity ) > 0.001 ;
8792 }
8893
8994 private boolean isArmStoppedMoving () {
0 commit comments