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

Commit

Permalink
Implement shoulder subsystem (#16)
Browse files Browse the repository at this point in the history
* Finish shoulder subsystem

* Add second motor

---------

Co-authored-by: Chris <[email protected]>
  • Loading branch information
lechris07 and JelloSmello authored Aug 26, 2023
1 parent 400ab03 commit 9c40ce5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/main/java/frc/robot/shoulder/ShoulderSubsystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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 final CANSparkMax motorFollower;

private RelativeEncoder encoder;
private SparkMaxPIDController pid;
private double goalAngle = 0.0;

public ShoulderSubsystem(CANSparkMax motor, CANSparkMax motorFollower) {
super(SubsystemPriority.SHOULDER);
this.motor = motor;
this.motorFollower = motorFollower;
motorFollower.follow(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 @@ -13,6 +13,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 9c40ce5

Please sign in to comment.