Skip to content

Commit

Permalink
Arm subystem fixes (#25)
Browse files Browse the repository at this point in the history
* Arm subystem fixes

* arm homing fix

* doglog name change
  • Loading branch information
ryanknj5 authored Sep 2, 2024
1 parent ed3fbe7 commit 86e5b6a
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions src/main/java/frc/robot/arm/ArmSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ArmSubsystem extends StateMachine<ArmState> {
private double distanceToSpeaker;
private double distanceToFeedSpot;
private double lowestSeenAngleLeft = Double.MAX_VALUE;
private double lowestSeenAngleRight = Double.MIN_VALUE;
private double lowestSeenAngleRight = Double.MAX_VALUE;
private InterpolatingDoubleTreeMap speakerDistanceToAngle = new InterpolatingDoubleTreeMap();
private InterpolatingDoubleTreeMap feedSpotDistanceToAngle = new InterpolatingDoubleTreeMap();
private final PositionVoltage positionRequest =
Expand Down Expand Up @@ -60,7 +60,7 @@ public void setState(ArmState newState) {
// public void disabledPeriodic()
// {
// rightMotor.setControl(staticBrake);
// rightMotor.setControl(staticBrake);
// leftMotor.setControl(staticBrake);
// }
// IF withOverrideBrakeDurNeutral DOESNT WORK
public boolean atGoal() {
Expand Down Expand Up @@ -166,40 +166,24 @@ public void robotPeriodic() {
DogLog.log("Arm/Left/SupplyCurrent", leftMotor.getSupplyCurrent().getValueAsDouble());
DogLog.log("Arm/Left/ArmAngle", leftMotor.getPosition().getValueAsDouble());
DogLog.log("Arm/Left/AppliedVoltage", leftMotor.getMotorVoltage().getValueAsDouble());
DogLog.log("Arm/Left/LowestSeenAngle", lowestSeenAngleLeft);

DogLog.log("Arm/Right/StatorCurrent", rightMotor.getStatorCurrent().getValueAsDouble());
DogLog.log("Arm/Right/SupplyCurrent", rightMotor.getSupplyCurrent().getValueAsDouble());
DogLog.log("Arm/Right/ArmAngle", rightMotor.getPosition().getValueAsDouble());
DogLog.log("Arm/Right/AppliedVoltage", rightMotor.getMotorVoltage().getValueAsDouble());
DogLog.log("Arm/Right/LowestSeenAngle", lowestSeenAngleRight);

if (DriverStation.isEnabled() && getState() == ArmState.PRE_MATCH_HOMING) {
Double homedAngle = getHomeAngleFromLowestSeen();

leftMotor.setPosition(Units.degreesToRotations(homedAngle));
rightMotor.setPosition(Units.degreesToRotations(homedAngle));
setState(ArmState.IDLE);
}

// We are enabled and still in pre match homing
// Reset the motor positions, and then transition to idle state
}

private double getHomeAngleFromLowestSeen() {
return RobotConfig.get().arm().minAngle() + (getAngle() - lowestSeenAngleLeft);
}

public double getAngle() {

return Units.rotationsToDegrees(leftMotor.getPosition().getValueAsDouble());
}

private static double clampAngle(double angle) {
if (angle < RobotConfig.get().arm().minAngle()) {
angle = RobotConfig.get().arm().minAngle();

} else if (angle > RobotConfig.get().arm().maxAngle()) {
angle = RobotConfig.get().arm().maxAngle();
// We are enabled and still in pre match homing
// Reset the motor positions, and then transition to idle state
leftMotor.setPosition(
Units.degreesToRotations(
RobotConfig.get().arm().minAngle() + (leftMotorAngle - lowestSeenAngleLeft)));
rightMotor.setPosition(
Units.degreesToRotations(
RobotConfig.get().arm().minAngle() + (rightMotorAngle - lowestSeenAngleRight)));
setStateFromRequest(ArmState.IDLE);
}
return angle;
}
}

0 comments on commit 86e5b6a

Please sign in to comment.