Skip to content

Commit

Permalink
buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
EvLyn17 committed Dec 8, 2023
1 parent 1c44b3c commit 1c86152
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
Empty file modified gradlew
100644 → 100755
Empty file.
42 changes: 42 additions & 0 deletions src/main/java/frc/robot/Commands/IntakeCommand.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
9 changes: 8 additions & 1 deletion src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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.
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/frc/robot/subsystems/IntakeSubsystem.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 1c86152

Please sign in to comment.