Skip to content

Commit

Permalink
Add Unfinished Climber Code
Browse files Browse the repository at this point in the history
  • Loading branch information
taj-maharj08 committed Jan 30, 2024
1 parent a67fec6 commit 1265d28
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import edu.wpi.first.wpilibj2.command.RepeatCommand;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
import frc.robot.climber.Rev_2Climber;
import frc.robot.drivetrain.Drivetrain;
import frc.robot.intake.Intake;
import frc.robot.shooter.Shooter;
Expand All @@ -31,6 +32,7 @@ public class Robot extends LoggedRobot {
private final Intake m_intake = new Intake();
private final Shooter m_shooter = new Shooter();
private TimeOfFlight mytimeofflight = new TimeOfFlight(12);
private final Rev_2Climber m_climber = new Rev_2Climber();

private final CommandXboxController m_driverController = new CommandXboxController(0);

Expand Down Expand Up @@ -111,6 +113,7 @@ public Robot() {
// m_driverController.rightBumper().onTrue(m_shooter.Feeder());
// m_driverController.b().onTrue(m_shooter.Stop());
// SmartDashboard.putNumber("StopDistance", defaultStopDistance);
m_driverController.a().onTrue(m_climber.raiseElevator());

// m_driverController
// .a()
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/frc/robot/climber/Rev_2Climber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot.climber;

import com.revrobotics.CANSparkMax;
import com.revrobotics.RelativeEncoder;
import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.PIDCommand;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class Rev_2Climber extends SubsystemBase {
/** Creates a new Rev_2Climber. */
private CANSparkMax LeftHook = new CANSparkMax(10, CANSparkMax.MotorType.kBrushless);

private RelativeEncoder leftEnc = LeftHook.getEncoder();
// private CANSparkMax RightHook = new CANSparkMax(11,
// com.revrobotics.CANSparkLowLevel.MotorType.kBrushless);

public Rev_2Climber() {
// RightHook.follow(LeftHook);
}

@Override
public void periodic() {
SmartDashboard.putNumber("Left Elevator Enc Value", leftEnc.getPosition());
}

public Command Stop() {
return new InstantCommand(
() -> {
LeftHook.set(0);
});
}

public Command raiseElevator() {
PIDController leftController = new PIDController(0.05, 0, 0);
leftController.setTolerance(10);
return new PIDCommand(
leftController,
() -> leftEnc.getPosition(),
() -> 2,
(leftSpeed) -> LeftHook.set(leftSpeed),
this);
}

public Command lowerElevator() {
PIDController leftController = new PIDController(0.05, 0, 0);
leftController.setTolerance(1);
return new PIDCommand(
leftController,
() -> leftEnc.getPosition(),
() -> 0,
(leftSpeed) -> LeftHook.set(leftSpeed),
this);
}
}

0 comments on commit 1265d28

Please sign in to comment.