Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
Finish shoulder subsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
JelloSmello committed Aug 26, 2023
1 parent 5f01aec commit c177bf8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/main/java/frc/robot/shoulder/ShoulderSubsystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package frc.robot.shoulder;
import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMax.ControlType;
import com.revrobotics.RelativeEncoder;
import com.revrobotics.SparkMaxPIDController;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.util.scheduling.LifecycleSubsystem;
import frc.robot.util.scheduling.SubsystemPriority;

public class ShoulderSubsystem extends LifecycleSubsystem {
private final CANSparkMax motor;
private RelativeEncoder encoder;
private SparkMaxPIDController pid;
private double goalAngle = 0.0;

public ShoulderSubsystem(CANSparkMax motor) {
super(SubsystemPriority.SHOULDER);

this.motor = motor;
encoder = motor.getEncoder();
pid = motor.getPIDController();

pid.setP(5);
pid.setI(0);
pid.setD(0);

encoder.setPosition(0);
encoder.setPositionConversionFactor(50);
}

@Override
public void enabledPeriodic() {
pid.setReference(goalAngle / 360.0, ControlType.kSmartMotion);
}

public void set(double angle) {
goalAngle = angle;
}

public Command setPositionCommand(double angle) {
return run(() -> {
set(angle);
})
.until(() -> atAngle(angle));
}

private boolean atAngle(double angle) {
return Math.abs(getWristAngle() - angle) < 1;
}

private double getWristAngle() {
return encoder.getPosition() * 360.0;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum SubsystemPriority {
SWERVE(10),
IMU(10),
INTAKE(10),
SHOULDER(10),
// Run localization after swerve & IMU
LOCALIZATION(9),

Expand Down

0 comments on commit c177bf8

Please sign in to comment.