Skip to content

Commit

Permalink
Cleaned up code a bit
Browse files Browse the repository at this point in the history
Got rid of unnecessary spaces, made it easier to look at
  • Loading branch information
Ith9 committed Dec 1, 2023
1 parent bba4c82 commit d29b983
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 46 deletions.
32 changes: 5 additions & 27 deletions src/main/java/frc/Subsystems/ElevatorSubsystem.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
// 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.Subsystems;




import com.ctre.phoenix.motorcontrol.NeutralMode;
import com.ctre.phoenix.motorcontrol.TalonFXControlMode;
import com.ctre.phoenix.motorcontrol.can.TalonFX;


import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.wpilibj.shuffleboard.BuiltInLayouts;
Expand All @@ -36,7 +17,6 @@
import frc.robot.Constants.Elevator;
import edu.wpi.first.wpilibj2.command.SubsystemBase;


public class ElevatorSubsystem extends SubsystemBase {
/** Creates a new ExampleSubsystem. */
private TalonFX left_motor;
Expand All @@ -58,18 +38,16 @@ public ElevatorSubsystem() {
right_motor.clearStickyFaults();
left_motor.clearStickyFaults();


right_motor.configForwardSoftLimitThreshold(
0, 0); // this is the bottom limit, we stop AT the bottom

// right_motor.configReverseSoftLimitThreshold(
// -heightToTicks(24), 0); // this is the top limit, we stop at the very top
right_motor.configForwardSoftLimitEnable(true, 0);
right_motor.configReverseSoftLimitEnable(true, 0);


right_motor.configOpenloopRamp(.5);


left_motor.setSelectedSensorPosition(0);
right_motor.setSelectedSensorPosition(0);

Expand All @@ -85,7 +63,9 @@ public ElevatorSubsystem() {
targetHeight = 0;

motorPower = 0;

pidController = new PIDController(0.34, 0, 0.02);

//pidController.setTolerance(0.7,0.001);
ElevatorTab.addNumber("Current Motor Power", () -> this.motorPower);
ElevatorTab.addNumber("Target Height", () -> this.targetHeight);
Expand All @@ -110,27 +90,25 @@ public static double inchesToTicks(double height) {
public static double ticksToInches(double ticks) {
return (ticks * Elevator.GEAR_CIRCUMFERENCE) / (Elevator.TICKS_PER_REVOLUTION * Elevator.GEAR_RATIO);
}



public void setTargetHeight(double targetHeight) {
this.targetHeight = targetHeight;
pidController.setSetpoint(targetHeight); }


public boolean nearTargetHeight(){
if(targetHeight -0.5 <= currentHeight && currentHeight <= targetHeight + 0.5){
return true;
}else{
return false;
}
}

@Override
public void periodic() {
// This method will be called once per scheduler run
motorPower = pidController.calculate(currentHeight);
left_motor.set(TalonFXControlMode.PercentOutput, -(MathUtil.clamp(motorPower + 0.02, -0.5,0.5)));
currentHeight = ticksToInches(-left_motor.getSelectedSensorPosition());

}
// left_motor.set(TalonFXControlMode.PercentOutput, -(0.1));

Expand Down
12 changes: 0 additions & 12 deletions src/main/java/frc/robot/Commands/ElevatorBaseCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@
// 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.Commands;


import frc.Subsystems.ElevatorSubsystem;
import edu.wpi.first.wpilibj2.command.CommandBase;


/** An example command that uses an example subsystem. */
public class ElevatorBaseCommand extends CommandBase {
@SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"})
private final ElevatorSubsystem elevatorSubsystem;
public double targetHeight;


/**
* Creates a new ExampleCommand.
*
Expand All @@ -29,28 +25,20 @@ public ElevatorBaseCommand(ElevatorSubsystem elevatorSubsystem, double targetHei
addRequirements(elevatorSubsystem);
}


// Called when the command is initially scheduled.
@Override
public void initialize() {
elevatorSubsystem.setTargetHeight(targetHeight);




}


// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {}


// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {}


// Returns true when the command should end.
@Override
public boolean isFinished() {
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import frc.Subsystems.ElevatorSubsystem;


/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
* "declarative" paradigm, very little robot logic should actually be handled in the {@link Robot}
Expand All @@ -17,14 +16,11 @@ public class RobotContainer {
// The robot's subsystems and commands are defined here...
private final ElevatorSubsystem elevatorSubsystem = new ElevatorSubsystem();


private ElevatorBaseCommand ElevatorBaseCommand = new ElevatorBaseCommand(elevatorSubsystem, 0);


private final CommandXboxController driverA = new CommandXboxController(0);
private double targetHeight;


/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {

Expand All @@ -36,16 +32,13 @@ public RobotContainer() {
driverA.a().onTrue(new ElevatorBaseCommand(elevatorSubsystem, 3));
}


/**
* Use this method to define your button->command mappings. Buttons can be created by
* instantiating a {@link GenericHID} or one of its subclasses ({@link
* edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a {@link
* edu.wpi.first.wpilibj2.command.button.JoystickButton}.
*/
private void configureButtonBindings() {}


/**
* Use this to pass the autonomous command to the main {@link Robot} class.
*
Expand Down

0 comments on commit d29b983

Please sign in to comment.