Skip to content

Commit

Permalink
Merge pull request #180 from StuyPulse/robot/nyny
Browse files Browse the repository at this point in the history
Changes for / from NYC Regional
  • Loading branch information
anivanchen authored Apr 10, 2023
2 parents b546132 + 8cee43b commit d9781cf
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 77 deletions.
10 changes: 5 additions & 5 deletions src/main/deploy/pathplanner/2 Piece + Dock.path
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@
{
"anchorPoint": {
"x": 2.18,
"y": 4.06
"y": 4.26
},
"prevControl": {
"x": 2.1355417497355624,
"y": 4.0781910527110625
"y": 4.278191052711063
},
"nextControl": {
"x": 2.990760937761192,
"y": 3.7282596623312907
"y": 3.928259662331291
},
"holonomicAngle": 0,
"isReversal": false,
Expand All @@ -74,11 +74,11 @@
},
{
"anchorPoint": {
"x": 3.6,
"x": 3.9000000000000004,
"y": 2.9668705600756398
},
"prevControl": {
"x": 1.9600286499779123,
"x": 2.2600286499779125,
"y": 2.866211202507875
},
"nextControl": null,
Expand Down
16 changes: 8 additions & 8 deletions src/main/deploy/pathplanner/2 Piece Wire.path
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@
{
"anchorPoint": {
"x": 7.5,
"y": 0.8240000000000001
"y": 1.4200000000000002
},
"prevControl": {
"x": 5.811700742388826,
"y": 0.756067081855683
"x": 5.986422913016767,
"y": 0.7879226014862292
},
"nextControl": {
"x": 7.520579845087765,
"y": 0.824828081233506
"x": 7.519005814510022,
"y": 1.4279369236594843
},
"holonomicAngle": 0,
"isReversal": false,
Expand All @@ -75,15 +75,15 @@
{
"anchorPoint": {
"x": 7.5,
"y": 1.004
"y": 1.3
},
"prevControl": {
"x": 7.524864538684214,
"y": 1.010041827491513
"y": 1.306041827491513
},
"nextControl": {
"x": 6.542296228896253,
"y": 0.7712878211629955
"y": 1.0672878211629957
},
"holonomicAngle": 0,
"isReversal": false,
Expand Down
8 changes: 4 additions & 4 deletions src/main/deploy/pathplanner/3 Piece.path
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@
"y": 4.5
},
"prevControl": {
"x": 4.838784774793751,
"y": 4.858894672949488
"x": 6.043518753704174,
"y": 5.298494015791451
},
"nextControl": {
"x": 4.838784774793751,
"y": 4.858894672949488
"x": 6.043518753704174,
"y": 5.298494015791451
},
"holonomicAngle": 10.0,
"isReversal": true,
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/stuypulse/robot/RobotContainer.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/************************ PROJECT JIM *************************/
/************************ PROJECT JIM *************************/
/* Copyright (c) 2023 StuyPulse Robotics. All rights reserved.*/
/* This work is licensed under the terms of the MIT license. */
/**************************************************************/
Expand Down Expand Up @@ -126,14 +126,16 @@ private void configureDriverBindings() {
driver.getBottomButton()
.whileTrue(new RobotScore());
driver.getLeftBumper()
.whileTrue(new RobotRelease());
.whileTrue(new RobotRelease())
.onFalse(new WaitCommand(0.5).andThen(new IntakeStop()));
driver.getRightTriggerButton()
.whileTrue(new RobotRelease());
.whileTrue(new RobotRelease())
.onFalse(new WaitCommand(0.5).andThen(new IntakeStop()));

driver.getTopButton()
.onTrue(new ManagerValidateState())
.onTrue(new ManagerChooseScoreNode())
.whileTrue(new RobotAlignThenScore());
.whileTrue(new RobotAlignThenScoreCubes());

// swerve
driver.getLeftButton().whileTrue(new SwerveDriveAlignThenBalance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.stuypulse.robot.constants.ArmTrajectories;
import com.stuypulse.robot.constants.Settings;
import com.stuypulse.robot.subsystems.LEDController;
import com.stuypulse.robot.constants.Settings.Alignment;
import com.stuypulse.robot.constants.Settings.Alignment.Rotation;
import com.stuypulse.robot.constants.Settings.Alignment.Translation;
Expand All @@ -23,6 +24,7 @@
import com.stuypulse.robot.subsystems.odometry.Odometry;
import com.stuypulse.robot.subsystems.swerve.SwerveDrive;
import com.stuypulse.robot.util.HolonomicController;
import com.stuypulse.robot.util.LEDColor;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
Expand Down Expand Up @@ -87,6 +89,8 @@ public void initialize() {
movingWhileScoring = false;
intake.enableBreak();
Odometry.USE_VISION_ANGLE.set(true);

LEDController.getInstance().setColor(LEDColor.BLUE, 694000000);
}

@Override
Expand Down Expand Up @@ -146,6 +150,8 @@ public void end(boolean interupted) {
swerve.stop();
intake.stop();
targetPose2d.setPose(Double.NaN, Double.NaN, new Rotation2d(Double.NaN));

LEDController.getInstance().setColor(LEDController.getInstance().getDefaultColor(), 0);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/************************ PROJECT JIM *************************/
/* Copyright (c) 2023 StuyPulse Robotics. All rights reserved.*/
/* This work is licensed under the terms of the MIT license. */
/**************************************************************/

package com.stuypulse.robot.commands;

import com.stuypulse.stuylib.control.angle.feedback.AnglePIDController;
import com.stuypulse.stuylib.control.feedback.PIDController;
import com.stuypulse.stuylib.streams.booleans.BStream;
import com.stuypulse.stuylib.streams.booleans.filters.BDebounceRC;

import com.stuypulse.robot.constants.ArmTrajectories;
import com.stuypulse.robot.constants.Settings;
import com.stuypulse.robot.subsystems.LEDController;
import com.stuypulse.robot.constants.Settings.Alignment;
import com.stuypulse.robot.constants.Settings.Alignment.Rotation;
import com.stuypulse.robot.constants.Settings.Alignment.Translation;
import com.stuypulse.robot.subsystems.Manager;
import com.stuypulse.robot.subsystems.Manager.GamePiece;
import com.stuypulse.robot.subsystems.Manager.NodeLevel;
import com.stuypulse.robot.subsystems.arm.Arm;
import com.stuypulse.robot.subsystems.intake.*;
import com.stuypulse.robot.subsystems.odometry.Odometry;
import com.stuypulse.robot.subsystems.swerve.SwerveDrive;
import com.stuypulse.robot.util.HolonomicController;
import com.stuypulse.robot.util.LEDColor;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj.smartdashboard.FieldObject2d;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase;

public class RobotAlignThenScoreCubes extends CommandBase {

// Subsystems
private final SwerveDrive swerve;
private final Arm arm;
private final Intake intake;

private final Manager manager;

// Holonomic control
private final HolonomicController controller;
private final BStream aligned;
private boolean movingWhileScoring; // when we have aligned and ready to score and move back

// Logging
private final FieldObject2d targetPose2d;

public RobotAlignThenScoreCubes(){
this.swerve = SwerveDrive.getInstance();
this.arm = Arm.getInstance();
this.intake = Intake.getInstance();
manager = Manager.getInstance();

controller = new HolonomicController(
new PIDController(Translation.P,Translation.I,Translation.D),
new PIDController(Translation.P, Translation.I, Translation.D),
new AnglePIDController(Rotation.P, Rotation.I, Rotation.D));

SmartDashboard.putData("Alignment/Controller", controller);

aligned = BStream.create(this::isAligned).filtered(new BDebounceRC.Rising(Alignment.DEBOUNCE_TIME));

targetPose2d = Odometry.getInstance().getField().getObject("Target Pose");
addRequirements(swerve, arm, intake);
}

private boolean isAligned() {
if (Manager.getInstance().getGamePiece().isCone()) {
return controller.isDone(
Alignment.ALIGNED_CONE_THRESHOLD_X.get(),
Alignment.ALIGNED_CONE_THRESHOLD_Y.get(),
Alignment.ALIGNED_CONE_THRESHOLD_ANGLE.get());
} else {
return controller.isDone(
Alignment.ALIGNED_CUBE_THRESHOLD_X.get(),
Alignment.ALIGNED_CUBE_THRESHOLD_Y.get(),
Alignment.ALIGNED_CUBE_THRESHOLD_ANGLE.get());
}
}

@Override
public void initialize() {
movingWhileScoring = false;
intake.enableBreak();
Odometry.USE_VISION_ANGLE.set(true);

LEDController.getInstance().setColor(LEDColor.BLUE, 694000000);
}

@Override
public void execute() {
Pose2d currentPose = Odometry.getInstance().getPose();
Pose2d targetPose = Manager.getInstance().getScorePose();
targetPose2d.setPose(targetPose);

controller.update(targetPose, currentPose);

if (aligned.get() || movingWhileScoring) {
// simply outtake when low
if (manager.getNodeLevel() == NodeLevel.LOW) {
intake.deacquire();
}


// or do scoring motion based on the game piece
else {

// only score for cubes
if (manager.getGamePiece().isCube()) {
intake.deacquire();
}
}

} else {
swerve.setChassisSpeeds(controller.getOutput());
}
}

@Override
public boolean isFinished(){
return false;
}

public void end(boolean interupted) {
intake.enableBreak();
Odometry.USE_VISION_ANGLE.set(false);
swerve.stop();
intake.stop();
targetPose2d.setPose(Double.NaN, Double.NaN, new Rotation2d(Double.NaN));

LEDController.getInstance().setColor(LEDController.getInstance().getDefaultColor(), 0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public boolean isFinished() {

@Override
public void end(boolean i) {
intake.stop();
// intake.stop();
intake.enableBreak();
swerve.stop();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/stuypulse/robot/commands/RobotScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public RobotScore() {
arm = Arm.getInstance();
intake = Intake.getInstance();
manager = Manager.getInstance();

addRequirements(swerve, arm, intake);
}

Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/stuypulse/robot/commands/auton/ThreePiece.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public AutonReady() {
}
});
}

@Override
protected ArmTrajectory getTrajectory(ArmState src, ArmState dest) {
double wristSafeAngle = Wrist.WRIST_SAFE_ANGLE.get();
Expand All @@ -65,7 +65,7 @@ protected ArmTrajectory getTrajectory(ArmState src, ArmState dest) {
.addState(new ArmState(src.getShoulderDegrees(), wristSafeAngle)
.setWristTolerance(45))
.addState(new ArmState(dest.getShoulderState(), dest.getWristState())
.setWristTolerance(30).setShoulderTolerance(20));
.setWristTolerance(7).setShoulderTolerance(25));
}
}
static class ArmIntakeFirst extends ArmRoutine {
Expand Down Expand Up @@ -134,7 +134,7 @@ protected ArmTrajectory getTrajectory(ArmState src, ArmState dest) {


private static final double INTAKE_DEACQUIRE_TIME = 0.3;
private static final double INTAKE_STOP_WAIT_TIME = 0.5;
private static final double INTAKE_STOP_WAIT_TIME = 1;
private static final double INTAKE_WAIT_TIME = 1.0;
private static final double ACQUIRE_WAIT_TIME = 0.02;
private static final double WIGGLE_PERIOD = 0.6;
Expand Down Expand Up @@ -174,12 +174,11 @@ public ThreePiece() {
addCommands(
new LEDSet(LEDColor.BLUE),
new IntakeScore(),
new WaitCommand(INTAKE_DEACQUIRE_TIME)
new WaitCommand(0.8)
);

// intake second piece
addCommands(
new ManagerSetGamePiece(GamePiece.CUBE),

new LEDSet(LEDColor.GREEN),

Expand All @@ -189,8 +188,10 @@ public ThreePiece() {
.withStop(),
// .until(Intake.getInstance()::hasGamePiece), // interrupting IntakeScore? idk one time the intake just stopped early

new WaitCommand(INTAKE_STOP_WAIT_TIME)
new IntakeScore()
.andThen(new WaitCommand(INTAKE_STOP_WAIT_TIME))
.andThen(new IntakeStop())
.andThen(new ManagerSetGamePiece(GamePiece.CUBE))
.andThen(new IntakeAcquire()),

new ArmIntakeFirst()
Expand Down
Loading

0 comments on commit d9781cf

Please sign in to comment.