Skip to content

Commit dbd237c

Browse files
committed
changed logic and added command to subsystem
1 parent 808395f commit dbd237c

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/main/java/frc/trigon/robot/subsystems/armelevator/ArmElevatorCommands.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import frc.trigon.robot.subsystems.endeffector.EndEffectorCommands;
1111
import frc.trigon.robot.subsystems.endeffector.EndEffectorConstants;
1212
import frc.trigon.robot.subsystems.swerve.SwerveCommands;
13+
import lib.commands.ArmCalibrationCommand;
1314
import lib.commands.ExecuteEndCommand;
1415
import lib.commands.GearRatioCalculationCommand;
1516
import lib.commands.NetworkTablesCommand;
@@ -31,6 +32,13 @@ public static Command getDebuggingCommand(boolean ignoreConstraints) {
3132
);
3233
}
3334

35+
public static Command getArmCalibrationCommand() {
36+
return new ArmCalibrationCommand(
37+
ArmElevatorConstants.ARM_MASTER_MOTOR,
38+
RobotContainer.ARM_ELEVATOR
39+
);
40+
}
41+
3442
public static Command getArmGearRatioCalulationCommand() {
3543
return new GearRatioCalculationCommand(
3644
ArmElevatorConstants.ARM_MASTER_MOTOR,

src/main/java/lib/commands/ArmCalibrationCommand.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,29 @@
1313
public 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() + "\ncurrent velocity: " + motor.getSignal(TalonFXSignal.VELOCITY) + " \nprevious velocity: " + previousVelocity);
38+
System.out.println("\nmaximumPosition: " + gravityOffset.getRotations() + "\nminimumPosition: " + 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

Comments
 (0)