diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/PrimaryOpMode.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/PrimaryOpMode.java index 33347058d842..e2ce412f609a 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/PrimaryOpMode.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/PrimaryOpMode.java @@ -8,7 +8,9 @@ import com.qualcomm.robotcore.eventloop.opmode.TeleOp; import com.qualcomm.robotcore.hardware.HardwareMap; +import org.firstinspires.ftc.teamcode.commands.RunIntake; import org.firstinspires.ftc.teamcode.commands.RunShooter; +import org.firstinspires.ftc.teamcode.subsystems.Intake; import org.firstinspires.ftc.teamcode.subsystems.Shooter; @TeleOp(name = "PrimaryOpMode", group= "NormalOpModes") @@ -16,6 +18,7 @@ public class PrimaryOpMode extends OpMode { private Motor fL, fR, bL, bR; private MecanumDrive drive; private Shooter shooter; + private Intake intake; private GamepadEx driverOp; private GamepadEx coOp; @@ -33,7 +36,10 @@ public void init() { shooter = new Shooter(hardwareMap, "shooterMotor"); + intake = new Intake(hardwareMap, "intakeMotor"); + coOp.getGamepadButton(GamepadKeys.Button.A).whileHeld(new RunShooter(shooter, 1)); + coOp.getGamepadButton(GamepadKeys.Button.B).whileHeld(new RunIntake(intake, 0.5)); } @Override diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/commands/RunIntake.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/commands/RunIntake.java new file mode 100644 index 000000000000..ac19f45ca52c --- /dev/null +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/commands/RunIntake.java @@ -0,0 +1,29 @@ +package org.firstinspires.ftc.teamcode.commands; + +import com.arcrobotics.ftclib.command.CommandBase; +import com.qualcomm.robotcore.hardware.HardwareMap; + +import org.firstinspires.ftc.teamcode.subsystems.Intake; + +public class RunIntake extends CommandBase { + + private Intake subsystem; + + private double speed; + + public RunIntake(Intake _subsystem, double _speed) { + subsystem = _subsystem; + addRequirements(subsystem); + speed = _speed; + } + + @Override + public void initialize() { + subsystem.run(speed); + } + + @Override + public void end(boolean interrupted) { + subsystem.stop(); + } +} diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/subsystems/Intake.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/subsystems/Intake.java new file mode 100644 index 000000000000..c02fc5ce1144 --- /dev/null +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/subsystems/Intake.java @@ -0,0 +1,23 @@ +package org.firstinspires.ftc.teamcode.subsystems; + +import com.arcrobotics.ftclib.command.SubsystemBase; +import com.arcrobotics.ftclib.hardware.motors.Motor; +import com.qualcomm.robotcore.hardware.HardwareMap; + +public class Intake extends SubsystemBase { + private Motor intakeMotor; + + public Intake(HardwareMap map, String motorName) { + intakeMotor = new Motor(map, motorName); + intakeMotor.setRunMode(Motor.RunMode.RawPower); + } + + public void run(double speed) { + double clampedSpeed = Math.max(-1.0, Math.min(1.0, speed)); + intakeMotor.set(clampedSpeed); + } + + public void stop() { + intakeMotor.stopMotor(); + } +}