-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all subsystems base code (yet to test)
- Loading branch information
1 parent
405f330
commit c550ccc
Showing
5 changed files
with
267 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// 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.subsystems; | ||
|
||
import com.revrobotics.spark.ClosedLoopSlot; | ||
import com.revrobotics.spark.SparkClosedLoopController; | ||
import com.revrobotics.spark.SparkMax; | ||
import com.revrobotics.spark.SparkBase.ControlType; | ||
import com.revrobotics.spark.config.SparkMaxConfig; | ||
import com.revrobotics.spark.config.ClosedLoopConfig.FeedbackSensor; | ||
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc.robot.Constants; | ||
|
||
public class Elevator extends SubsystemBase { | ||
private final SparkMax leftMotor; | ||
private final SparkMax rightMotor; | ||
|
||
private final SparkMaxConfig leftMotorConfig; | ||
private final SparkMaxConfig rightMotorConfig; | ||
|
||
private SparkClosedLoopController leftController; | ||
private SparkClosedLoopController rightController; | ||
|
||
/** Creates a new Elevator. */ | ||
public Elevator() { | ||
leftMotor = new SparkMax(Constants.ElevatorConstants.leftSparkMax, SparkMax.MotorType.kBrushless); | ||
leftMotorConfig = new SparkMaxConfig(); | ||
|
||
leftMotorConfig | ||
.inverted(Constants.ElevatorConstants.leftInverted) | ||
.smartCurrentLimit(Constants.ElevatorConstants.leftCurrentLimit) | ||
.idleMode(IdleMode.kBrake) | ||
.encoder.positionConversionFactor(1/12); | ||
|
||
leftMotorConfig.closedLoop | ||
.feedbackSensor(FeedbackSensor.kPrimaryEncoder) | ||
.outputRange(-1, 1) | ||
.pid(Constants.ElevatorConstants.leftKP, Constants.ElevatorConstants.leftKI, Constants.ElevatorConstants.leftKD); | ||
|
||
leftController = leftMotor.getClosedLoopController(); | ||
|
||
rightMotor = new SparkMax(Constants.ElevatorConstants.rightSparkMax, SparkMax.MotorType.kBrushless); | ||
rightMotorConfig = new SparkMaxConfig(); | ||
|
||
rightMotorConfig | ||
.inverted(Constants.ElevatorConstants.rightInverted) | ||
.smartCurrentLimit(Constants.ElevatorConstants.rightCurrentLimit) | ||
.idleMode(IdleMode.kBrake) | ||
.encoder.positionConversionFactor(1/12); | ||
|
||
rightMotorConfig.closedLoop | ||
.feedbackSensor(FeedbackSensor.kPrimaryEncoder) | ||
.outputRange(-1, 1) | ||
.pid(Constants.ElevatorConstants.rightKP, Constants.ElevatorConstants.rightKI, Constants.ElevatorConstants.rightKD); | ||
|
||
rightController = rightMotor.getClosedLoopController(); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
// This method will be called once per scheduler run | ||
} | ||
|
||
public void setElevatorPosition(double position) { | ||
leftController.setReference(position, ControlType.kPosition, ClosedLoopSlot.kSlot0); | ||
rightController.setReference(position, ControlType.kPosition, ClosedLoopSlot.kSlot0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// 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.subsystems; | ||
|
||
import com.revrobotics.spark.ClosedLoopSlot; | ||
import com.revrobotics.spark.SparkClosedLoopController; | ||
import com.revrobotics.spark.SparkMax; | ||
import com.revrobotics.spark.SparkBase.ControlType; | ||
import com.revrobotics.spark.SparkBase.ResetMode; | ||
import com.revrobotics.spark.SparkLowLevel.MotorType; | ||
import com.revrobotics.spark.config.SparkMaxConfig; | ||
import com.revrobotics.spark.config.ClosedLoopConfig.FeedbackSensor; | ||
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc.robot.Constants; | ||
|
||
public class Intake extends SubsystemBase { | ||
private final SparkMax wristMotor; | ||
private final SparkMax spinnerMotor; | ||
|
||
private final SparkMaxConfig wristConfig; | ||
private final SparkMaxConfig spinnerConfig; | ||
|
||
private SparkClosedLoopController wristController; | ||
|
||
/** Creates a new Intake. */ | ||
public Intake() { | ||
wristMotor = new SparkMax(Constants.IntakeConstants.wristSparkMax, MotorType.kBrushless); | ||
wristConfig = new SparkMaxConfig(); | ||
|
||
wristConfig | ||
.inverted(Constants.IntakeConstants.wristInverted) | ||
.smartCurrentLimit(Constants.IntakeConstants.wristCurrentLimit) | ||
.idleMode(IdleMode.kBrake) | ||
.encoder.positionConversionFactor(1/12); | ||
|
||
wristConfig.closedLoop | ||
.feedbackSensor(FeedbackSensor.kPrimaryEncoder) | ||
.outputRange(-1, 1) | ||
.pid(Constants.IntakeConstants.wristKP, Constants.IntakeConstants.wristKI, Constants.IntakeConstants.wristKD); | ||
|
||
wristMotor.configure(wristConfig, ResetMode.kResetSafeParameters, null); | ||
wristController = wristMotor.getClosedLoopController(); | ||
|
||
spinnerMotor = new SparkMax(Constants.IntakeConstants.spinnerSparkMax, MotorType.kBrushless); | ||
spinnerConfig = new SparkMaxConfig(); | ||
|
||
spinnerConfig | ||
.inverted(Constants.IntakeConstants.spinnerInverted) | ||
.smartCurrentLimit(Constants.IntakeConstants.spinnerCurrentLimit) | ||
.idleMode(IdleMode.kBrake); | ||
|
||
spinnerMotor.configure(spinnerConfig, ResetMode.kResetSafeParameters, null); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
// This method will be called once per scheduler run | ||
} | ||
|
||
public void setWristPosition(double position) { | ||
wristController.setReference(position, ControlType.kPosition, ClosedLoopSlot.kSlot0); | ||
} | ||
|
||
public void setSpinnerPower(double power) { | ||
spinnerMotor.set(power); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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.subsystems; | ||
|
||
import com.revrobotics.spark.SparkMax; | ||
import com.revrobotics.spark.SparkBase.ResetMode; | ||
import com.revrobotics.spark.SparkLowLevel.MotorType; | ||
import com.revrobotics.spark.config.SparkMaxConfig; | ||
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc.robot.Constants; | ||
|
||
public class Outtake extends SubsystemBase { | ||
private final SparkMax spinnerMotor; | ||
|
||
private final SparkMaxConfig spinnerConfig; | ||
/** Creates a new Outtake. */ | ||
public Outtake() { | ||
spinnerMotor = new SparkMax(Constants.OuttakeConstants.spinnerSparkMax, MotorType.kBrushless); | ||
spinnerConfig = new SparkMaxConfig(); | ||
|
||
spinnerConfig | ||
.inverted(Constants.OuttakeConstants.spinnerInverted) | ||
.smartCurrentLimit(Constants.OuttakeConstants.spinnerCurrentLimit) | ||
.idleMode(IdleMode.kBrake); | ||
|
||
spinnerMotor.configure(spinnerConfig, ResetMode.kResetSafeParameters, null); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
// This method will be called once per scheduler run | ||
} | ||
|
||
public void setOuttakeSpeed(double speed) { | ||
spinnerMotor.set(speed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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.subsystems; | ||
|
||
import com.revrobotics.spark.SparkMax; | ||
import com.revrobotics.spark.SparkBase.ResetMode; | ||
import com.revrobotics.spark.config.SparkMaxConfig; | ||
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc.robot.Constants; | ||
|
||
public class Passage extends SubsystemBase { | ||
private final SparkMax spinnerMotor; | ||
|
||
private final SparkMaxConfig spinnerConfig; | ||
|
||
/** Creates a new Passage. */ | ||
public Passage() { | ||
spinnerMotor = new SparkMax(Constants.PassageConstants.spinnerSparkMax, SparkMax.MotorType.kBrushless); | ||
spinnerConfig = new SparkMaxConfig(); | ||
|
||
spinnerConfig | ||
.inverted(Constants.PassageConstants.spinnerInverted) | ||
.smartCurrentLimit(Constants.PassageConstants.spinnerCurrentLimit) | ||
.idleMode(IdleMode.kCoast); | ||
|
||
spinnerMotor.configure(spinnerConfig, ResetMode.kResetSafeParameters, null); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
// This method will be called once per scheduler run | ||
} | ||
|
||
public void setSpinnerSpeed(double speed) { | ||
spinnerMotor.set(speed); | ||
} | ||
} |