Skip to content

Commit ae949cd

Browse files
committed
feat: drive commands
1 parent 7fbc48a commit ae949cd

File tree

7 files changed

+114
-22
lines changed

7 files changed

+114
-22
lines changed

src/main/java/frc/team5115/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public static enum Mode {
4444

4545
public static final byte BLOCK_ACTUATOR_ID = 9;
4646

47+
public static final byte LUNITE_SENSOR = 0;
48+
4749
public static final byte LED_STRIP_PWM_ID = 0;
4850

4951
public static final double LOOP_PERIOD_SECS = 0.02;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package frc.team5115;
2+
3+
import edu.wpi.first.wpilibj2.command.Command;
4+
import edu.wpi.first.wpilibj2.command.Commands;
5+
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
6+
import frc.team5115.Constants.AutoConstants.Side;
7+
import frc.team5115.commands.DriveCommands;
8+
import frc.team5115.subsystems.drive.Drivetrain;
9+
10+
public class DriverController {
11+
private final CommandXboxController joyDrive;
12+
private final CommandXboxController joyManip;
13+
14+
private final Drivetrain drivetrain;
15+
16+
private boolean robotRelative = false;
17+
private boolean slowMode = false;
18+
19+
public DriverController(
20+
int port,
21+
Drivetrain drivetrain) {
22+
joyDrive = new CommandXboxController(port);
23+
joyManip = null;
24+
25+
this.drivetrain = drivetrain;
26+
27+
}
28+
29+
public DriverController(
30+
int drivePort,
31+
int manipPort,
32+
Drivetrain drivetrain) {
33+
joyDrive = new CommandXboxController(drivePort);
34+
joyManip = new CommandXboxController(manipPort);
35+
36+
this.drivetrain = drivetrain;
37+
38+
}
39+
40+
private Command offsetGyro() {
41+
return Commands.runOnce(() -> drivetrain.offsetGyro(), drivetrain).ignoringDisable(true);
42+
}
43+
44+
public boolean isConnected() {
45+
return joyDrive.isConnected() && (joyManip == null || joyManip.isConnected());
46+
}
47+
48+
private void configureSingleMode() {}
49+
private void configureDualMode() {}
50+
51+
52+
public void configureButtonBindings() {
53+
// drive control
54+
drivetrain.setDefaultCommand(
55+
DriveCommands.joystickDrive(
56+
drivetrain,
57+
() -> robotRelative,
58+
() -> slowMode,
59+
() -> -joyDrive.getLeftY(),
60+
() -> -joyDrive.getLeftX(),
61+
() -> -joyDrive.getRightX()));
62+
if (joyManip == null) {
63+
configureSingleMode();
64+
} else {
65+
configureDualMode();
66+
}
67+
}
68+
69+
private Command setRobotRelative(boolean state) {
70+
return Commands.runOnce(() -> robotRelative = state);
71+
}
72+
73+
private Command setSlowMode(boolean state) {
74+
return Commands.runOnce(() -> slowMode = state);
75+
}
76+
77+
public boolean getRobotRelative() {
78+
return robotRelative;
79+
}
80+
81+
public boolean getSlowMode() {
82+
return slowMode;
83+
}
84+
}

src/main/java/frc/team5115/commands/DriveCommands.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
import edu.wpi.first.math.kinematics.ChassisSpeeds;
99
import edu.wpi.first.wpilibj2.command.Command;
1010
import edu.wpi.first.wpilibj2.command.Commands;
11-
import frc.team5115.Constants;
1211
import frc.team5115.Constants.SwerveConstants;
1312
import frc.team5115.subsystems.arm.Arm;
1413
import frc.team5115.subsystems.drive.Drivetrain;
1514
import frc.team5115.subsystems.intakewheel.IntakeWheel;
16-
15+
import frc.team5115.subsystems.outtake.Outtake;
1716

1817
import java.util.function.BooleanSupplier;
1918
import java.util.function.DoubleSupplier;
@@ -74,17 +73,20 @@ public static Command joystickDrive(
7473
}
7574

7675
public static Command modeSwap(boolean intakeMode, IntakeWheel intakeWheel, Arm arm) {
77-
return Commands.run(
78-
() -> {
79-
if (intakeMode) {
80-
intakeWheel.intake().execute();
81-
arm.deploy().execute();
76+
return Commands.either(
77+
Commands.parallel(intakeWheel.intake(), arm.deploy()),
78+
Commands.parallel(intakeWheel.stop(), arm.stow()),
79+
() -> intakeMode);
80+
}
81+
82+
public static Command intakeMode(IntakeWheel intakeWheel, Arm arm) {
83+
return Commands.repeatingSequence(
84+
Commands.parallel(intakeWheel.intake(), arm.deploy()),
85+
(arm.waitForSensorState(true, Double.POSITIVE_INFINITY)),
86+
arm.stow());
87+
}
8288

83-
} else {
84-
intakeWheel.stop().execute();
85-
arm.stow().execute();
86-
}
87-
},
88-
intakeWheel);
89+
public static Command scoringMode(Outtake outtake) {
90+
return
8991
}
9092
}

src/main/java/frc/team5115/subsystems/arm/Arm.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public class Arm extends SubsystemBase {
1818
private final ArmFeedforward feedforward;
1919
private final PIDController pid;
2020
private final double ks;
21-
22-
private boolean frozen = false;
2321

2422
public Arm(ArmIO io) {
2523
this.io = io;
@@ -69,7 +67,7 @@ public void periodic() {
6967

7068
io.setArmVoltage(voltage);
7169
}
72-
//meow meow meow, meowwww
70+
// meow meow meow, meowwww
7371

7472
public Command waitForSetpoint(double timeout) {
7573
return Commands.waitUntil(() -> pid.atSetpoint()).withTimeout(timeout);
@@ -87,12 +85,12 @@ public Command stow() {
8785
return setAngle(Rotation2d.fromDegrees(Constants.ARM_STOW_ANGLE_DEG));
8886
}
8987

90-
public Command deploy(){
88+
public Command deploy() {
9189
return setAngle(Rotation2d.fromDegrees(Constants.ARM_DEPLOY_ANGLE_DEG));
9290
}
9391

94-
public void freeze(){
95-
frozen = true;
92+
public Command waitForSensorState(boolean state, double timeout) {
93+
return Commands.waitUntil(() -> inputs.luniteDetected == state).withTimeout(timeout);
9694
}
9795

9896
public void stop() {

src/main/java/frc/team5115/subsystems/arm/ArmIO.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public static class ArmIOInputs {
1212
public double armVelocityRPM = 0;
1313
public double currentAmps = 0;
1414
public double appliedVolts = 0;
15+
16+
public boolean luniteDetected = true;
1517
}
1618

1719
public default void updateInputs(ArmIOInputs inputs) {}

src/main/java/frc/team5115/subsystems/arm/ArmIOSparkMax.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
99
import com.revrobotics.spark.config.SparkMaxConfig;
1010
import edu.wpi.first.math.geometry.Rotation2d;
11+
import edu.wpi.first.wpilibj.DigitalInput;
1112
import frc.team5115.Constants;
1213
import java.util.ArrayList;
1314

1415
public class ArmIOSparkMax implements ArmIO {
1516
private final SparkMax motor;
16-
;
17+
1718
private final AbsoluteEncoder absoluteEncoder;
1819

20+
private final DigitalInput sensor;
21+
1922
public ArmIOSparkMax() {
23+
sensor = new DigitalInput(Constants.LUNITE_SENSOR);
2024
motor = new SparkMax(Constants.ARM_MOTOR_ID, MotorType.kBrushless);
2125
absoluteEncoder = motor.getAbsoluteEncoder();
2226
final SparkMaxConfig motorConfig = new SparkMaxConfig();
@@ -46,5 +50,6 @@ public void updateInputs(ArmIOInputs inputs) {
4650
}
4751
inputs.currentAmps = motor.getOutputCurrent();
4852
inputs.appliedVolts = motor.getAppliedOutput() * motor.getBusVoltage();
53+
inputs.luniteDetected = sensor.get();
4954
}
5055
}

src/main/java/frc/team5115/subsystems/intakewheel/IntakeWheel.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import edu.wpi.first.wpilibj2.command.Commands;
66
import edu.wpi.first.wpilibj2.command.SubsystemBase;
77
import frc.team5115.Constants;
8-
98
import java.util.ArrayList;
109
import java.util.function.BooleanSupplier;
1110
import org.littletonrobotics.junction.Logger;
@@ -52,7 +51,7 @@ public Command intakeIf(BooleanSupplier supplier) {
5251
if (inputs.currentAmps > 25.0) {
5352
io.setPercent(-0.22);
5453
} else {
55-
io.setPercent(INTAKE_SPEED);
54+
io.setPercent(Constants.INTAKE_SPEED);
5655
}
5756
} else {
5857
io.setPercent(0);

0 commit comments

Comments
 (0)