From c0ead80055877053bfa8f08af4499c552eae5e08 Mon Sep 17 00:00:00 2001 From: KyraRivera <59713772+KyraRivera@users.noreply.github.com> Date: Thu, 6 Feb 2020 19:51:17 -0700 Subject: [PATCH 1/2] Added Leveler --- src/main/java/frc4388/robot/Constants.java | 3 ++ .../java/frc4388/robot/RobotContainer.java | 5 ++ .../commands/RunLevelerWithJoystick.java | 53 +++++++++++++++++++ .../java/frc4388/robot/subsystems/Intake.java | 1 + .../frc4388/robot/subsystems/Leveler.java | 44 +++++++++++++++ 5 files changed, 106 insertions(+) create mode 100644 src/main/java/frc4388/robot/commands/RunLevelerWithJoystick.java create mode 100644 src/main/java/frc4388/robot/subsystems/Leveler.java diff --git a/src/main/java/frc4388/robot/Constants.java b/src/main/java/frc4388/robot/Constants.java index 793ce5c..916ada6 100644 --- a/src/main/java/frc4388/robot/Constants.java +++ b/src/main/java/frc4388/robot/Constants.java @@ -29,6 +29,9 @@ public final class Constants { public static final class IntakeConstants { public static final int INTAKE_SPARK_ID = 1; } + public static final class LevelerConstants { + public static final int LEVELER_TALON_ID = 9; + } public static final class LEDConstants { public static final int LED_SPARK_ID = 0; diff --git a/src/main/java/frc4388/robot/RobotContainer.java b/src/main/java/frc4388/robot/RobotContainer.java index 4131d4b..e2fddb7 100644 --- a/src/main/java/frc4388/robot/RobotContainer.java +++ b/src/main/java/frc4388/robot/RobotContainer.java @@ -17,9 +17,11 @@ import edu.wpi.first.wpilibj2.command.button.JoystickButton; import frc4388.robot.Constants.*; import frc4388.robot.commands.DriveWithJoystick; import frc4388.robot.commands.RunIntakeWithTriggers; +import frc4388.robot.commands.RunLevelerWithJoystick; import frc4388.robot.subsystems.Drive; import frc4388.robot.subsystems.Intake; import frc4388.robot.subsystems.LED; +import frc4388.robot.subsystems.Leveler; import frc4388.utility.LEDPatterns; import frc4388.utility.controller.IHandController; import frc4388.utility.controller.XboxController; @@ -36,6 +38,7 @@ public class RobotContainer { private final Drive m_robotDrive = new Drive(); private final LED m_robotLED = new LED(); private final Intake m_robotIntake = new Intake(); + private final Leveler m_robotLeveler = new Leveler(); /* Controllers */ private final XboxController m_driverXbox = new XboxController(OIConstants.XBOX_DRIVER_ID); @@ -54,6 +57,8 @@ public class RobotContainer { m_robotIntake.setDefaultCommand(new RunIntakeWithTriggers(m_robotIntake, getOperatorController())); // continually sends updates to the Blinkin LED controller to keep the lights on m_robotLED.setDefaultCommand(new RunCommand(() -> m_robotLED.updateLED(), m_robotLED)); + // drives the robot with an axis input from the driver controller + m_robotLeveler.setDefaultCommand(new RunLevelerWithJoystick(m_robotLeveler, getDriverController())); } /** diff --git a/src/main/java/frc4388/robot/commands/RunLevelerWithJoystick.java b/src/main/java/frc4388/robot/commands/RunLevelerWithJoystick.java new file mode 100644 index 0000000..0b91068 --- /dev/null +++ b/src/main/java/frc4388/robot/commands/RunLevelerWithJoystick.java @@ -0,0 +1,53 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2019 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package frc4388.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; +import frc4388.robot.subsystems.Leveler; +import frc4388.utility.controller.IHandController; + +public class RunLevelerWithJoystick extends CommandBase { + private Leveler m_leveler; + private IHandController m_controller; + + /** + * Creates a new RunLevelerWithJoystick to control the leveler with an Xbox controller. + * @param subsystem pass the Drive subsystem from {@link frc4388.robot.RobotContainer#RobotContainer() RobotContainer} + * @param controller pass the Driver {@link frc4388.utility.controller.IHandController#getClass() IHandController} using the + * {@link frc4388.robot.RobotContainer#getDriverJoystick() getDriverJoystick()} method in + * {@link frc4388.robot.RobotContainer#RobotContainer() RobotContainer} + */ + public RunLevelerWithJoystick(Leveler subsystem, IHandController controller) { + m_leveler = subsystem; + m_controller = controller; + addRequirements(m_leveler); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + double input = m_controller.getLeftXAxis(); + m_leveler.runLeveler(input); + } + + // 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() { + return false; + } +} diff --git a/src/main/java/frc4388/robot/subsystems/Intake.java b/src/main/java/frc4388/robot/subsystems/Intake.java index ea2ba9c..a1c1a4c 100644 --- a/src/main/java/frc4388/robot/subsystems/Intake.java +++ b/src/main/java/frc4388/robot/subsystems/Intake.java @@ -18,6 +18,7 @@ public class Intake extends SubsystemBase { * Creates a new Intake. */ public Intake() { + m_intakeMotor.setInverted(false); } diff --git a/src/main/java/frc4388/robot/subsystems/Leveler.java b/src/main/java/frc4388/robot/subsystems/Leveler.java new file mode 100644 index 0000000..613a8cb --- /dev/null +++ b/src/main/java/frc4388/robot/subsystems/Leveler.java @@ -0,0 +1,44 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2019 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package frc4388.robot.subsystems; + +import com.ctre.phoenix.motorcontrol.NeutralMode; +import com.ctre.phoenix.motorcontrol.can.TalonSRX; +import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX; + +import edu.wpi.first.wpilibj.Talon; +import edu.wpi.first.wpilibj2.command.SubsystemBase; +import frc4388.robot.Constants.LevelerConstants; + +public class Leveler extends SubsystemBase { + WPI_TalonSRX m_levelerMotor = new WPI_TalonSRX(LevelerConstants.LEVELER_TALON_ID); + + /** + * Creates a new Leveler. + */ + public Leveler() { + m_levelerMotor.configFactoryDefault(); + + m_levelerMotor.setNeutralMode(NeutralMode.Brake); + + m_levelerMotor.setInverted(false); + } + + @Override + public void periodic() { + // This method will be called once per scheduler run + } + + /** + * Runs intake motor + * @param input the percent output to run motor at + */ + public void runLeveler(double input) { + m_levelerMotor.set(input); + } +} From 5ab2fce79bb2e4e4d7c4633e85d532c214726b16 Mon Sep 17 00:00:00 2001 From: KyraRivera <101209@psdschools.org> Date: Sat, 8 Feb 2020 14:49:16 -0700 Subject: [PATCH 2/2] Set up leveler motor so that it can be run. --- src/main/java/frc4388/robot/Constants.java | 4 ++-- src/main/java/frc4388/robot/RobotContainer.java | 2 +- src/main/java/frc4388/robot/subsystems/Leveler.java | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/frc4388/robot/Constants.java b/src/main/java/frc4388/robot/Constants.java index e9c899c..e788406 100644 --- a/src/main/java/frc4388/robot/Constants.java +++ b/src/main/java/frc4388/robot/Constants.java @@ -70,11 +70,11 @@ public final class Constants { } public static final class LevelerConstants { - public static final int LEVELER_TALON_ID = 9; + public static final int LEVELER_CAN_ID = 9; } public static final class StorageConstants { - public static final int STORAGE_CAN_ID = 9; + public static final int STORAGE_CAN_ID = -1; public static final int BEAM_SENSOR_DIO_0 = 0; public static final int BEAM_SENSOR_DIO_1 = 1; public static final int BEAM_SENSOR_DIO_2 = 2; diff --git a/src/main/java/frc4388/robot/RobotContainer.java b/src/main/java/frc4388/robot/RobotContainer.java index e7ae628..cf5b717 100644 --- a/src/main/java/frc4388/robot/RobotContainer.java +++ b/src/main/java/frc4388/robot/RobotContainer.java @@ -60,7 +60,7 @@ public class RobotContainer { m_robotIntake.setDefaultCommand(new RunIntakeWithTriggers(m_robotIntake, getOperatorController())); // continually sends updates to the Blinkin LED controller to keep the lights on m_robotLED.setDefaultCommand(new RunCommand(() -> m_robotLED.updateLED(), m_robotLED)); - // drives the robot with an axis input from the driver controller + // drives the leveler with an axis input from the driver controller m_robotLeveler.setDefaultCommand(new RunLevelerWithJoystick(m_robotLeveler, getDriverController())); // runs storage motor at 50 percent m_robotStorage.setDefaultCommand(new RunCommand(() -> m_robotStorage.runStorage(0.0), m_robotStorage)); diff --git a/src/main/java/frc4388/robot/subsystems/Leveler.java b/src/main/java/frc4388/robot/subsystems/Leveler.java index 613a8cb..02df406 100644 --- a/src/main/java/frc4388/robot/subsystems/Leveler.java +++ b/src/main/java/frc4388/robot/subsystems/Leveler.java @@ -10,22 +10,23 @@ package frc4388.robot.subsystems; import com.ctre.phoenix.motorcontrol.NeutralMode; import com.ctre.phoenix.motorcontrol.can.TalonSRX; import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX; +import com.revrobotics.CANSparkMax; +import com.revrobotics.CANSparkMax.IdleMode; +import com.revrobotics.CANSparkMaxLowLevel.MotorType; import edu.wpi.first.wpilibj.Talon; import edu.wpi.first.wpilibj2.command.SubsystemBase; import frc4388.robot.Constants.LevelerConstants; public class Leveler extends SubsystemBase { - WPI_TalonSRX m_levelerMotor = new WPI_TalonSRX(LevelerConstants.LEVELER_TALON_ID); + CANSparkMax m_levelerMotor = new CANSparkMax(LevelerConstants.LEVELER_CAN_ID, MotorType.kBrushless); /** * Creates a new Leveler. */ public Leveler() { - m_levelerMotor.configFactoryDefault(); - - m_levelerMotor.setNeutralMode(NeutralMode.Brake); - + m_levelerMotor.restoreFactoryDefaults(); + m_levelerMotor.setIdleMode(IdleMode.kCoast); m_levelerMotor.setInverted(false); }