Skip to content

Commit c136819

Browse files
authored
Merge pull request #8 from Ocebots/subsystems
drive code
2 parents 7cde87c + 35e0350 commit c136819

21 files changed

Lines changed: 314 additions & 167 deletions

.idea/modules.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#This file is generated by updateDaemonJvm
2+
toolchainVersion=17

src/main/java/frc/robot/Robot.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,26 @@
44

55
package frc.robot;
66

7+
import static frc.robot.config.VisionConfig.photonPoseEstimatorForward;
8+
import static frc.robot.config.VisionConfig.result;
9+
710
import edu.wpi.first.epilogue.Epilogue;
811
import edu.wpi.first.epilogue.Logged;
912
import edu.wpi.first.wpilibj.DataLogManager;
1013
import edu.wpi.first.wpilibj.DriverStation;
1114
import edu.wpi.first.wpilibj.TimedRobot;
1215
import edu.wpi.first.wpilibj2.command.Command;
1316
import edu.wpi.first.wpilibj2.command.CommandScheduler;
17+
import frc.robot.config.TunerConstants;
18+
import frc.robot.config.VisionConfig;
19+
import frc.robot.subsystems.CommandSwerveDrivetrain;
20+
import java.util.Optional;
21+
import org.photonvision.EstimatedRobotPose;
1422

1523
@Logged
1624
public class Robot extends TimedRobot {
1725
private Command m_autonomousCommand;
26+
private final CommandSwerveDrivetrain drivetrain = TunerConstants.createDrivetrain();
1827

1928
private final RobotContainer m_robotContainer;
2029

@@ -28,6 +37,19 @@ public Robot() {
2837
@Override
2938
public void robotPeriodic() {
3039
CommandScheduler.getInstance().run();
40+
Optional<EstimatedRobotPose> visionEst =
41+
VisionConfig.photonPoseEstimatorForward.estimateCoprocMultiTagPose(result);
42+
if (visionEst.isEmpty()) {
43+
visionEst = VisionConfig.photonPoseEstimatorForward.estimateLowestAmbiguityPose(result);
44+
} else {
45+
drivetrain.addVisionMeasurement(
46+
photonPoseEstimatorForward
47+
.estimateAverageBestTargetsPose(result)
48+
.get()
49+
.estimatedPose
50+
.toPose2d(),
51+
visionEst.get().timestampSeconds);
52+
}
3153
}
3254

3355
@Override

src/main/java/frc/robot/RobotContainer.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
1414
import frc.robot.commands.*;
1515
import frc.robot.config.CANMappings;
16+
import frc.robot.config.HopperConfig;
1617
import frc.robot.config.TunerConstants;
1718
import frc.robot.subsystems.*;
1819

@@ -24,18 +25,26 @@ public class RobotContainer {
2425
private Climb climb = new Climb();
2526
private Intake intake = new Intake();
2627
private Kicker kicker = new Kicker();
27-
private CommandXboxController controller = new CommandXboxController(0);
28+
private CommandXboxController controller = new CommandXboxController(1);
2829
private SwerveDriveState driveState = new SwerveDriveState();
30+
public static boolean isExtended = false;
2931

3032
private Command shootGroup =
3133
Commands.parallel(
3234
new KickerCommand(kicker, KickerCommand.Position.INTAKE),
33-
new HopperCommand(hopper, HopperCommand.Position.SHOOT_RETRACT),
35+
Commands.runEnd(
36+
() -> hopper.slowMove(HopperConfig.HOPPER_RETRACT_ROTATION),
37+
() -> hopper.stop(),
38+
hopper).withDeadline(Commands.waitSeconds(2)),
3439
new IntakeCommand(intake, IntakeCommand.Position.SLOW_INTAKE))
3540
.finallyDo(
3641
interrupt ->
3742
CommandScheduler.getInstance()
38-
.schedule(new HopperCommand(hopper, HopperCommand.Position.SHOOT_EXTEND)));
43+
.schedule(
44+
Commands.runEnd(
45+
() -> hopper.move(HopperConfig.HOPPER_EXTEND_ROTATION),
46+
() -> hopper.stop(),
47+
hopper).withDeadline(Commands.waitSeconds(2))));
3948

4049
public RobotContainer() {
4150
configureBindings();
@@ -63,12 +72,22 @@ private void configureBindings() {
6372
.x()
6473
.and(() -> !shootGroup.isScheduled())
6574
.toggleOnTrue(new IntakeCommand(intake, IntakeCommand.Position.INTAKE));
75+
76+
controller
77+
.povRight()
78+
.and(() -> !shootGroup.isScheduled())
79+
.toggleOnTrue(new IntakeCommand(intake, IntakeCommand.Position.OUTTAKE));
6680
// Right Stick Down = Extend/Retract Hopper
6781
controller
6882
.rightStick()
6983
.and(() -> !shootGroup.isScheduled())
70-
.onTrue(new HopperCommand(hopper, HopperCommand.Position.EXTEND_RETRACT));
71-
// Right Trigger = Climb Retract
84+
.onTrue(
85+
Commands.runEnd(
86+
() -> hopper.move(Hopper.getRotation(isExtended)), () -> hopper.stop(), hopper)
87+
.withDeadline(Commands.waitSeconds(2))
88+
.andThen(Commands.runOnce(() -> isExtended = !isExtended)));
89+
90+
// // Right Trigger = Climb Retract
7291
controller
7392
.rightTrigger()
7493
.whileTrue(new ClimbCommand(climb, ClimbCommand.Position.DIRECTIONAL_CLIMB));
@@ -92,6 +111,7 @@ private void configureBindings() {
92111
.a()
93112
.toggleOnTrue(
94113
new FlywheelCommand(flywheel, FlywheelCommand.Position.CALCULATED_SHOT, drivetrain));
114+
controller.povDown().onTrue(Commands.runOnce(() -> hopper.zero(), hopper));
95115
}
96116

97117
public Command getAutonomousCommand() {

src/main/java/frc/robot/commands/DrivetrainCommand.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,21 @@ public void execute() {
7070

7171
// Default driving mode
7272
case TELEOP:
73-
subsystem.applyRequest(
74-
() ->
75-
drive
76-
.withVelocityX(
77-
-leftY.getAsDouble() * MaxSpeed) // Drive forward with negative Y (forward)
78-
.withVelocityY(-leftX.getAsDouble() * MaxSpeed) // Drive left with negative X
79-
.withRotationalRate(
80-
-rightX.getAsDouble()
81-
* MaxAngularRate)); // Drive counterclockwise with negative X
82-
// System.out.println("Drivetrain: Teleop");
73+
subsystem.setControl(
74+
drive
75+
.withVelocityX(
76+
-leftY.getAsDouble() * MaxSpeed) // Drive forward with negative Y (forward)
77+
.withVelocityY(-leftX.getAsDouble() * MaxSpeed) // Drive left with negative X
78+
.withRotationalRate(
79+
-rightX.getAsDouble()
80+
* MaxAngularRate)); // Drive counterclockwise with negative X
8381
break;
8482

8583
// (Needs check) Mode for when shots are from a still position
8684
case STILL_SHOT:
8785
// make X with wheels, set wheels to brake mode
8886
applyRequest.ModuleStates = states;
8987
subsystem.setControl(applyRequest);
90-
subsystem.setControl(brakeRequest);
9188
System.out.println("Drivetrain: Still Shot Configuration");
9289
break;
9390

src/main/java/frc/robot/commands/HopperCommand.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import edu.wpi.first.epilogue.Logged;
44
import edu.wpi.first.wpilibj2.command.Command;
5+
import frc.robot.RobotContainer;
56
import frc.robot.config.HopperConfig;
67
import frc.robot.subsystems.Hopper;
78

@@ -15,11 +16,12 @@ public static enum Position {
1516

1617
private Hopper subsystem;
1718
private HopperCommand.Position pose;
18-
private static boolean isExtended = false;
19+
private boolean isExtended;
1920

20-
public HopperCommand(Hopper subsystem, HopperCommand.Position pose) {
21+
public HopperCommand(Hopper subsystem, HopperCommand.Position pose, boolean isExtended) {
2122
this.pose = pose;
2223
this.subsystem = subsystem;
24+
this.isExtended = isExtended;
2325

2426
addRequirements(subsystem);
2527
}
@@ -31,13 +33,15 @@ public void initialize() {
3133
// (Needs check) If hopper already extended, retract, and if hopper retracted, extend
3234
case EXTEND_RETRACT:
3335
if (isExtended) {
34-
// System.out.println("Hopper: Retracting");
36+
System.out.println("Hopper: Retracting");
3537
subsystem.move(HopperConfig.HOPPER_RETRACT_ROTATION);
36-
isExtended = false;
38+
RobotContainer.isExtended = false;
39+
System.out.println(RobotContainer.isExtended);
3740
} else {
38-
// System.out.println("Hopper: Extending");
41+
System.out.println("Hopper: Extending");
3942
subsystem.move(HopperConfig.HOPPER_EXTEND_ROTATION);
40-
isExtended = true;
43+
RobotContainer.isExtended = true;
44+
System.out.println(RobotContainer.isExtended);
4145
}
4246
break;
4347

src/main/java/frc/robot/config/FlywheelConfig.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ public class FlywheelConfig {
2222
// Set
2323
public static final double FLYWHEEL_LEFT_MAX_CRUISE_VELOCITY = 3000;
2424
public static final double FLYWHEEL_LEFT_TARGET_ACCELERATION = 500;
25-
public static final double FLYWHEEL_LEFT_P = 10;
25+
public static final double FLYWHEEL_LEFT_P = 0.5;
2626
public static final double FLYWHEEL_LEFT_I = 0;
2727
public static final double FLYWHEEL_LEFT_D = 0;
28-
public static final double FLYWHEEL_LEFT_S = 0;
29-
public static final double FLYWHEEL_LEFT_V = 0;
28+
public static final double FLYWHEEL_LEFT_S = 0.18;
29+
public static final double FLYWHEEL_LEFT_V = 0.115;
3030
public static final double FLYWHEEL_LEFT_A = 0;
3131

3232
// Set
3333
public static final double FLYWHEEL_OUTTAKE_SPEED = 0;
34-
public static final double FLYWHEEL_HUB_SHOT_SPEED = 0;
34+
public static final double FLYWHEEL_HUB_SHOT_SPEED = 40;
3535
public static final double FLYWHEEL_TOWER_SHOT_SPEED = 0;
36-
public static final double FLYWHEEL_DEFAULT_SHOT_SPEED = 0;
36+
public static final double FLYWHEEL_DEFAULT_SHOT_SPEED = 40;
3737
public static final double FLYWHEEL_TOLERANCE = 5;
3838
}

src/main/java/frc/robot/config/HopperConfig.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ public class HopperConfig {
88
// Set
99
public static final double HOPPER_MAX_CRUISE_VELOCITY = 3000;
1010
public static final double HOPPER_TARGET_ACCELERATION = 500;
11-
public static final double HOPPER_P = 0;
11+
public static final double HOPPER_P = 1.5;
1212
public static final double HOPPER_I = 0;
1313
public static final double HOPPER_D = 0;
14+
public static final double HOPPER_S = 0;
15+
public static final double HOPPER_V = 0;
16+
public static final double HOPPER_A = 0;
1417

15-
public static final double SLOW_HOPPER_P = 0;
18+
public static final double SLOW_HOPPER_P = 1;
1619
public static final double SLOW_HOPPER_I = 0;
1720
public static final double SLOW_HOPPER_D = 0;
1821

19-
public static final double HOPPER_TOLERANCE = 0.01;
22+
public static final double HOPPER_TOLERANCE = 0.2;
2023

2124
// Set
22-
public static final double HOPPER_EXTEND_ROTATION = 0.0;
23-
public static final double HOPPER_RETRACT_ROTATION = 0.0;
25+
public static final double HOPPER_EXTEND_ROTATION = 4.1;
26+
public static final double HOPPER_RETRACT_ROTATION = 0.1;
2427
}

src/main/java/frc/robot/config/IntakeConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class IntakeConfig {
66
public static final double INTAKE_GEAR_RATIO = 1;
77

88
// Set
9-
public static final double INTAKE_INTAKE_SPEED = 0;
10-
public static final double INTAKE_OUTTAKE_SPEED = 0;
9+
public static final double INTAKE_INTAKE_SPEED = 4;
10+
public static final double INTAKE_OUTTAKE_SPEED = 4;
1111
public static final double INTAKE_SLOW_SPEED = 0;
1212
}

src/main/java/frc/robot/config/KickerConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public class KickerConfig {
1616
public static final double KICKER_V = 0;
1717
public static final double KICKER_A = 0;
1818

19-
public static final double KICKER_INTAKE_SPEED = 0;
20-
public static final double KICKER_OUTTAKE_SPEED = 0;
19+
public static final double KICKER_INTAKE_SPEED = 11;
20+
public static final double KICKER_OUTTAKE_SPEED = 11;
2121

2222
public static final double KICKER_FRONT_INTAKE_SPEED = 0;
2323
public static final double KICKER_FRONT_OUTTAKE_SPEED = 0;

0 commit comments

Comments
 (0)