Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arm subystem fixes #25

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/LowestSeenAngleLeft", lowestSeenAngleLeft);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recording this as LowestSeenAngleLeft is redundant since it's already prefixed with Arm/Left/. same for the right motor too


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());
jonahsnider marked this conversation as resolved.
Show resolved Hide resolved
DogLog.log("Arm/Right/LowestSeenAngleRight", 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;
}
}
Loading