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

Commit

Permalink
Implement climber subsystem
Browse files Browse the repository at this point in the history
Resolves #3
  • Loading branch information
spacey-sooty committed May 16, 2024
1 parent 1a2880a commit ac43ec8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ public final class Constants {
public static final double shooterP = 0.02;
public static final double shooterI = 0.5;
public static final double shooterD = 0;
public static final int climberPort = 32;
public static final double climberP = 0.35;
public static final double climberI = 0;
public static final double climberD = 0;
}
7 changes: 7 additions & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import frc.robot.subsystems.Climber;
import frc.robot.subsystems.Shooter;

public class Robot extends TimedRobot {
private Command m_autonomousCommand;
private CommandXboxController m_driver;
private Shooter m_shooter;
private Climber m_climber;

private Command getAutonomousCommand() {
return null;
Expand All @@ -22,10 +24,15 @@ private void configureBindings() {}
@SuppressWarnings("removal")
public Robot() {
m_driver = new CommandXboxController(Constants.driverport);

m_shooter =
new Shooter(
new CANSparkMax(Constants.shooterPort, CANSparkMaxLowLevel.MotorType.kBrushless));

m_climber =
new Climber(
new CANSparkMax(Constants.climberPort, CANSparkMaxLowLevel.MotorType.kBrushless));

configureBindings();
}

Expand Down
35 changes: 35 additions & 0 deletions src/main/java/frc/robot/subsystems/Climber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package frc.robot.subsystems;

import com.revrobotics.CANSparkMax;
import com.revrobotics.RelativeEncoder;
import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import frc.robot.Constants;

/** Our Crescendo climber Subsystem */
public class Climber {
private PIDController m_pid;
private CANSparkMax m_motor;
private RelativeEncoder m_encoder;

/**
* Creates a new {@link Climber} {@link edu.wpi.first.wpilibj2.command.Subsystem}.
*
* @param motor The motor that the climber controls.
*/
public Climber(CANSparkMax motor) {
m_motor = motor;
m_encoder = m_motor.getEncoder();
m_pid = new PIDController(Constants.climberP, Constants.climberI, Constants.climberD);
m_pid.setTolerance(0.2, 0.5);
}

public Command climb() {
m_pid.setSetpoint(3.14159 / 2);
return Commands.run(
() ->
m_motor.setVoltage(m_pid.calculate(Units.rotationsToRadians(m_encoder.getPosition()))));
}
}

0 comments on commit ac43ec8

Please sign in to comment.