From 1c8615261ca8fdf19de29b2d71f6a84819964c0a Mon Sep 17 00:00:00 2001 From: EvelynCoolMop Date: Thu, 7 Dec 2023 17:14:11 -0800 Subject: [PATCH] buttons --- gradlew | 0 .../frc/robot/Commands/IntakeCommand.java | 42 +++++++++++++++++++ src/main/java/frc/robot/RobotContainer.java | 9 +++- .../frc/robot/subsystems/IntakeSubsystem.java | 33 +++++++++++++++ 4 files changed, 83 insertions(+), 1 deletion(-) mode change 100644 => 100755 gradlew create mode 100644 src/main/java/frc/robot/Commands/IntakeCommand.java create mode 100644 src/main/java/frc/robot/subsystems/IntakeSubsystem.java diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/frc/robot/Commands/IntakeCommand.java b/src/main/java/frc/robot/Commands/IntakeCommand.java new file mode 100644 index 0000000..e23aa81 --- /dev/null +++ b/src/main/java/frc/robot/Commands/IntakeCommand.java @@ -0,0 +1,42 @@ +// 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.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; +import frc.robot.subsystems.IntakeSubsystem; + +public class IntakeCommand extends CommandBase { + /** Creates a new IntakeCommand. */ + + public final IntakeSubsystem intakeSubsystem; + private double motorPower; + + public IntakeCommand(IntakeSubsystem intakeSubsystem, double motorPower) { + // Use addRequirements() here to declare subsystem dependencies. + this.intakeSubsystem = intakeSubsystem; + this.motorPower = motorPower; + + } + + // 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() { + intakeSubsystem.setIntakePower(motorPower); + } + + // 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/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index b992e09..1dde036 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -3,8 +3,11 @@ import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.InstantCommand; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; +import edu.wpi.first.wpilibj2.command.button.Trigger; import frc.robot.commands.ElevatorBaseCommand; +import frc.robot.commands.IntakeCommand; import frc.robot.subsystems.ElevatorSubsystem; +import frc.robot.subsystems.IntakeSubsystem; /** * This class is where the bulk of the robot should be declared. Since Command-based is a @@ -15,6 +18,7 @@ public class RobotContainer { // The robot's subsystems and commands are defined here... private final ElevatorSubsystem elevatorSubsystem = new ElevatorSubsystem(); + private final IntakeSubsystem intakeSubsystem = new IntakeSubsystem(); private final ElevatorBaseCommand ElevatorBaseCommand = new ElevatorBaseCommand(elevatorSubsystem, 0); @@ -39,7 +43,10 @@ public RobotContainer() { * 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() {} + private void configureButtonBindings() { + driverA.a().onTrue(new IntakeCommand(intakeSubsystem, 0.5)); + driverA.y().onTrue(new IntakeCommand(intakeSubsystem, 0)); + } /** * Use this to pass the autonomous command to the main {@link Robot} class. diff --git a/src/main/java/frc/robot/subsystems/IntakeSubsystem.java b/src/main/java/frc/robot/subsystems/IntakeSubsystem.java new file mode 100644 index 0000000..2cadce0 --- /dev/null +++ b/src/main/java/frc/robot/subsystems/IntakeSubsystem.java @@ -0,0 +1,33 @@ +// 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 edu.wpi.first.wpilibj2.command.SubsystemBase; +import frc.robot.Constants.Intake; + +import com.ctre.phoenix.motorcontrol.TalonFXControlMode; +import com.ctre.phoenix.motorcontrol.can.TalonFX; + +public class IntakeSubsystem extends SubsystemBase { + private double intakeMotorPower; + private TalonFX intake_motor; + /** Creates a new IntakeSubsystem. */ + public IntakeSubsystem() { + intake_motor = new TalonFX(Intake.MOTOR_PORT); + intakeMotorPower = 0; + + } + + public void setIntakePower(double intakeMotorPower) { + this.intakeMotorPower = intakeMotorPower; + + } + + @Override + public void periodic() { + // This method will be called once per scheduler run + intake_motor.set(TalonFXControlMode.PercentOutput, intakeMotorPower); + } +}