Skip to content

Commit 18b9284

Browse files
authored
ACTUALLY added intake subsystem (#27)
I will add the intake stuff to the backup once it works.
2 parents 9f93c24 + f3c68ce commit 18b9284

8 files changed

Lines changed: 111 additions & 20 deletions

File tree

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Constants.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ public static class Drivetrain {
1010

1111
public static class Shooter {
1212
public static final String shooterMotorName = "shooterMotor";
13-
public static final double defaultSpeed = 1;
13+
public static final String rampMotorName = "rampMotor";
14+
public static final double shooterSpeed = 1;
15+
public static final double rampSpeed = 0.5;
16+
}
17+
18+
public static class Intake {
19+
public static final String intakeMotorName = "intakeMotor";
20+
public static final double defaultSpeed = 0.5;
1421
}
1522
}

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/OpModes/BackupOpMode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public void initialize() {
3434
drivetrain.setDefaultCommand(new UserDrive(drivetrain, driverOp));
3535
register(drivetrain);
3636

37-
shooter = new Shooter(hardwareMap, Constants.Shooter.shooterMotorName);
37+
shooter = new Shooter(hardwareMap, Constants.Shooter.shooterMotorName, Constants.Shooter.rampMotorName);
3838
register(shooter);
3939
coOp.getGamepadButton(GamepadKeys.Button.A).whileHeld(
40-
new RunShooter(shooter, Constants.Shooter.defaultSpeed));
40+
new RunShooter(shooter, Constants.Shooter.shooterSpeed, Constants.Shooter.rampSpeed));
4141
}
4242
}

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/OpModes/PrimaryOpMode.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
77

88
import org.firstinspires.ftc.teamcode.Constants;
9+
import org.firstinspires.ftc.teamcode.commands.RunIntake;
910
import org.firstinspires.ftc.teamcode.commands.RunShooter;
1011
import org.firstinspires.ftc.teamcode.commands.UserDrive;
1112
import org.firstinspires.ftc.teamcode.subsystems.Drivetrain;
13+
import org.firstinspires.ftc.teamcode.subsystems.Intake;
1214
import org.firstinspires.ftc.teamcode.subsystems.Shooter;
1315

1416
@TeleOp(name = "PrimaryOpMode", group = "NormalOpModes")
1517
public class PrimaryOpMode extends CommandOpMode {
1618
private Shooter shooter;
19+
private Intake intake;
1720
private Drivetrain drivetrain;
1821

1922
private GamepadEx driverOp;
@@ -33,9 +36,13 @@ public void initialize() {
3336
);
3437
drivetrain.setDefaultCommand(new UserDrive(drivetrain, driverOp));
3538
register(drivetrain);
36-
shooter = new Shooter(hardwareMap, Constants.Shooter.shooterMotorName);
39+
shooter = new Shooter(hardwareMap, Constants.Shooter.shooterMotorName, Constants.Shooter.rampMotorName);
3740
register(shooter);
41+
intake = new Intake(hardwareMap, Constants.Intake.intakeMotorName);
42+
register(intake);
3843
coOp.getGamepadButton(GamepadKeys.Button.A).whileHeld(
39-
new RunShooter(shooter, Constants.Shooter.defaultSpeed));
44+
new RunShooter(shooter, Constants.Shooter.shooterSpeed, Constants.Shooter.rampSpeed));
45+
coOp.getGamepadButton(GamepadKeys.Button.B).whileHeld(
46+
new RunIntake(intake, Constants.Intake.defaultSpeed));
4047
}
4148
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.firstinspires.ftc.teamcode.commands;
2+
3+
import com.arcrobotics.ftclib.command.CommandBase;
4+
5+
import org.firstinspires.ftc.teamcode.subsystems.Intake;
6+
7+
public class RunIntake extends CommandBase {
8+
private final Intake subsystem;
9+
10+
private final double speed;
11+
12+
public RunIntake(Intake _subsystem, double _speed) {
13+
subsystem = _subsystem;
14+
addRequirements(subsystem);
15+
speed = _speed;
16+
}
17+
18+
@Override
19+
public void initialize() {
20+
subsystem.run(speed);
21+
}
22+
23+
@Override
24+
public void end(boolean interrupted) {
25+
subsystem.stop();
26+
}
27+
}

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/commands/RunShooter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66

77
public class RunShooter extends CommandBase {
88
private final Shooter subsystem;
9-
private final double speed;
9+
private final double shooterSpeed, rampSpeed;
1010

11-
public RunShooter(Shooter _subsystem, double _speed) {
11+
public RunShooter(Shooter _subsystem, double _shooterSpeed, double _rampSpeed) {
1212
subsystem = _subsystem;
1313
addRequirements(subsystem);
14-
speed = _speed;
14+
shooterSpeed = _shooterSpeed;
15+
rampSpeed = _rampSpeed;
1516
}
1617

1718
@Override
1819
public void initialize() {
19-
subsystem.run(speed);
20+
subsystem.run(shooterSpeed, rampSpeed);
2021
}
2122

2223
@Override

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/readme.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ Subsystem for driving
2929
- UserDrive
3030
- Drives with controls from gamepad
3131
- Stops moving when done
32-
- Controls
33-
- Left Stick
34-
- Y: Forward
35-
- X: Strafe
36-
- Right Stick: X: Turn
3732

3833
## Shooter
3934

@@ -42,4 +37,30 @@ Subsystem that runs launcher
4237
### Commands
4338

4439
- RunShooter
45-
- Runs shooter motors in raw mode with the specified power
40+
- Runs shooter motors in raw mode with the specified power
41+
- Runs ramp motors in raw mode with the specified power
42+
43+
## Intake
44+
45+
Subsystem that runs intake
46+
47+
### Commands
48+
49+
- RunIntake
50+
- Runs intake motor in raw mode with the specified power
51+
52+
# Controls
53+
54+
## Robot Driver
55+
56+
- Left Stick
57+
- Y: Forward
58+
- X: Strafe
59+
- Right Stick:
60+
- X: Turn
61+
62+
## Co-op Driver
63+
64+
- A: Ramp and Shooter
65+
- B: Intake
66+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.firstinspires.ftc.teamcode.subsystems;
2+
3+
import com.arcrobotics.ftclib.command.SubsystemBase;
4+
import com.arcrobotics.ftclib.hardware.motors.Motor;
5+
import com.qualcomm.robotcore.hardware.HardwareMap;
6+
7+
public class Intake extends SubsystemBase {
8+
private final Motor intakeMotor;
9+
10+
public Intake(HardwareMap map, String intakeMotorName) {
11+
intakeMotor = new Motor(map, intakeMotorName);
12+
intakeMotor.setRunMode(Motor.RunMode.RawPower);
13+
}
14+
15+
public void run(double speed) {
16+
double clampedSpeed = Math.max(1.0, Math.min(-1.0, speed));
17+
intakeMotor.set(clampedSpeed);
18+
}
19+
20+
public void stop() {
21+
intakeMotor.stopMotor();
22+
}
23+
}

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/subsystems/Shooter.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,25 @@
55
import com.qualcomm.robotcore.hardware.HardwareMap;
66

77
public class Shooter extends SubsystemBase {
8-
private final Motor shooterMotor;
8+
private final Motor shooterMotor, rampMotor;
99

10-
public Shooter(HardwareMap map, String motorName) {
11-
shooterMotor = new Motor(map, motorName);
10+
public Shooter(HardwareMap map, String shooterMotorName, String rampMotorName) {
11+
shooterMotor = new Motor(map, shooterMotorName);
1212
shooterMotor.setRunMode(Motor.RunMode.RawPower);
13+
rampMotor = new Motor(map, rampMotorName);
14+
rampMotor.setRunMode(Motor.RunMode.RawPower);
1315
}
1416

15-
public void run(double speed) {
17+
public void run(double shooterSpeed, double rampSpeed) {
1618
// Clamp speed to valid motor range [-1.0, 1.0]
17-
double clampedSpeed = Math.max(-1.0, Math.min(1.0, speed));
19+
double clampedSpeed = Math.max(-1.0, Math.min(1.0, shooterSpeed));
20+
double _rampSpeed = Math.max(-1.0, Math.min(1.0, rampSpeed));
1821
shooterMotor.set(clampedSpeed);
22+
rampMotor.set(_rampSpeed);
1923
}
2024

2125
public void stop() {
2226
shooterMotor.stopMotor();
27+
rampMotor.stopMotor();
2328
}
2429
}

0 commit comments

Comments
 (0)