Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes from testing week of 2/19 and 2/26 #7

Merged
merged 49 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
8006c1b
Created visionIO. Need to create methods
lncompetant Jan 20, 2024
359ca5a
"finished" vision.io
lncompetant Jan 23, 2024
fcdf6b3
Merge branch 'shooter' of https://github.com/FIRSTTeam102/robot2024 i…
lncompetant Jan 23, 2024
42e26e9
Began calculations for 2D odometry. Having issues with linking varia…
lncompetant Jan 30, 2024
086a8d0
Made vision subsystem
lncompetant Feb 3, 2024
5305eb0
Configured bindings for intake starting
RushaliBetala Feb 3, 2024
196a628
Fixed teensy startIntake command error
RushaliBetala Feb 3, 2024
215944b
Added odometry stuff
lncompetant Feb 6, 2024
3f592cd
Made gamepiece part of vision
lncompetant Feb 15, 2024
d4a99db
Merge branch 'arm' of https://github.com/FIRSTTeam102/robot2024 into arm
shinthebinn Feb 16, 2024
8148bbc
removing some stuff so branch actually resets
shinthebinn Feb 16, 2024
b55d3b4
configured arm to use smartmotion (requires tuning)
shinthebinn Feb 16, 2024
ac1abeb
Updated arm to use 2 motors and throughbore absolute encoder
shinthebinn Feb 16, 2024
4c25b03
added manual arm control and bindings for testcontroller
shinthebinn Feb 16, 2024
f8069ec
Updated CAN IDs to be correct (will have to adjust once wired)
shinthebinn Feb 16, 2024
0885a26
Final checks and revisions to piece and field vision. We need to tun…
lncompetant Feb 17, 2024
611ff74
Merge branch 'test' into vision
shinthebinn Feb 17, 2024
127d853
Merge pull request #5 from FIRSTTeam102/arm
carahegadorn Feb 17, 2024
9408f9d
Merge pull request #6 from FIRSTTeam102/vision
carahegadorn Feb 17, 2024
0b1198a
Fixed vision inputs bug, updated swerve offsets, added swerve voltage…
shinthebinn Feb 19, 2024
171191e
Tuning and stuff for testing
shinthebinn Feb 19, 2024
fd0620a
can ids of motors reassigned
carahegadorn Feb 20, 2024
34dce68
Arm fixes and manual control updates
shinthebinn Feb 22, 2024
c10a1fc
Arm changes from testing
shinthebinn Feb 24, 2024
5c29159
Added commands based on brayden's doc w/ comments for holes
shinthebinn Feb 24, 2024
0ad0d62
smart motion arm control :)
shinthebinn Feb 24, 2024
9a47420
added command to move arm w/ intake
shinthebinn Feb 24, 2024
6510f26
Rename setArmPosition.java to SetArmPosition.java
shinthebinn Feb 26, 2024
f6839c4
tuning and stuff 2/26
shinthebinn Feb 27, 2024
22f45f7
Made the temporary amp preset move arm also
shinthebinn Feb 27, 2024
0f7be41
make IntakeWithArm not run if there is a note
shinthebinn Feb 27, 2024
f94df8d
made temp arm command a onTrue instead of whileTrue
shinthebinn Feb 27, 2024
691c73a
2/28 tuning
shinthebinn Feb 29, 2024
a3c1782
Updated angle presets
shinthebinn Mar 2, 2024
917e55d
constructor called incorrectly -- removed auto-generated error method
shinthebinn Mar 2, 2024
ff51051
new offsets and arm max angle increase
shinthebinn Mar 2, 2024
6a4dec5
testing changes 3/4 (small stuff no big)
shinthebinn Mar 5, 2024
726bda7
added reset factory defaults to both lead & follower SparkMax's to gu…
carahegadorn Mar 7, 2024
953cd03
added gamepiece vision command and vision constants - using pinchy kP…
carahegadorn Mar 8, 2024
4ed4ec9
added driver left bumper binding for game piece vision
carahegadorn Mar 8, 2024
a7e543a
Made Auto align commands
lncompetant Mar 9, 2024
a50e2e1
prioritize speaker ID, change offsets, add filter to vision stuff
shinthebinn Mar 9, 2024
bb0aa1f
Made angle offsets
lncompetant Mar 9, 2024
bca583f
added methods to estimate scoring position via math and hashmap (need…
shinthebinn Mar 9, 2024
803c35c
Merge branch 'test' of https://github.com/FIRSTTeam102/robot2024 into…
shinthebinn Mar 9, 2024
9b87c25
merge conflicts incorrectly fixed
shinthebinn Mar 9, 2024
ec2c80d
AprilTagVision command - subsystems vision & swerve should be private…
carahegadorn Mar 11, 2024
30fb879
restore factory defaults & burnFlash our settings in SparkMax - make …
carahegadorn Mar 11, 2024
4bff607
gamepiece vision tuning and also climber!
shinthebinn Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* the package after creating this project, you must also update the build.gradle file in the
* project.
*/

public class Robot extends LoggedRobot {
private Command autonomousCommand;
private RobotContainer robotContainer;
Expand Down Expand Up @@ -155,6 +156,8 @@ public void teleopInit() {
if (autonomousCommand != null) {
autonomousCommand.cancel();
}

robotContainer.arm.setPosition(5);
}

/** This function is called periodically during operator control. */
Expand Down Expand Up @@ -185,4 +188,5 @@ public static boolean isBlue() {
// defaults to blue when unknown
return !DriverStation.getAlliance().isPresent() || DriverStation.getAlliance().get() != DriverStation.Alliance.Red;
}

}
70 changes: 57 additions & 13 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package frc.robot;

import static frc.robot.constants.Constants.tuningMode;
import static frc.robot.constants.Constants.OperatorConstants.*;

import frc.robot.constants.Constants;
import frc.robot.constants.Constants.OperatorConstants;
import frc.robot.constants.Constants.ShuffleboardConstants;
import frc.robot.constants.IntakeConstants;
import frc.robot.constants.ShooterConstants;
import frc.robot.io.GyroIO;
import frc.robot.io.GyroIOPigeon2;
import frc.robot.io.GyroIOSim;
Expand All @@ -14,16 +15,23 @@
import frc.robot.subsystems.Shooter;
import frc.robot.subsystems.Swerve;
import frc.robot.subsystems.SystemAlerter;
import frc.robot.subsystems.Vision;
import frc.robot.util.Alert;
import frc.robot.util.Alert.AlertType;

import frc.robot.commands.arm.ManualArmControl;
import frc.robot.commands.arm.SetArmPosition;
import frc.robot.commands.intake.IntakeWithArm;
import frc.robot.commands.intake.SetIntakeSpeed;
import frc.robot.commands.shooter.SetShooterVelocity;
import frc.robot.commands.shooter.StopShooter;
import frc.robot.commands.swerve.SwerveAngleOffsetCalibration;
import frc.robot.commands.swerve.TeleopSwerve;
import frc.robot.commands.swerve.XStance;
import frc.robot.commands.vision.GamePieceVision;

import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Relay.Value;
import edu.wpi.first.wpilibj.shuffleboard.BuiltInWidgets;
import edu.wpi.first.wpilibj.shuffleboard.SendableCameraWrapper;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
Expand Down Expand Up @@ -73,10 +81,10 @@ public static RobotContainer getInstance() {
: new GyroIOSim();

/* subsystems */
// public final Vision vision = new Vision();
public final Vision vision = new Vision();
public final Arm arm = new Arm();
public final Intake intake = new Intake();
public final Swerve swerve = new Swerve(gyro/* , vision */);
public final Swerve swerve = new Swerve(gyro, vision);
public final Shooter shooter = new Shooter();

/** The container for the robot. Contains subsystems, OI devices, and commands. */
Expand Down Expand Up @@ -122,6 +130,8 @@ public RobotContainer() {
autoChooser.addOption("sysid swerve drive", sysIdTestSet(swerve.driveSysIdRoutine));
autoChooser.addOption("sysid swerve angle", sysIdTestSet(swerve.angleSysIdRoutine));
autoChooser.addOption("sysid shooter", sysIdTestSet(shooter.sysIdRoutine));

vision.setPriorityId(7);
}

// shouldn't require tuningMode as we might run it randomly in comp
Expand All @@ -139,32 +149,55 @@ public RobotContainer() {
* joysticks}.
*/
private void configureBindings() {
// *DRIVER CONTROLS*
//
var teleopSwerve = new TeleopSwerve(
() -> -driverController.getLeftY(),
() -> -driverController.getLeftX(),
() -> -driverController.getRightX(),
driverController.getHID()::getLeftBumper, // override speed
() -> driverController.getLeftTriggerAxis() > OperatorConstants.boolTriggerThreshold, // preceise mode
() -> false, // no overdrive functionality
// driverController.getHID()::getLeftBumper, // override speed
() -> driverController.getLeftTriggerAxis() > OperatorConstants.boolTriggerThreshold, // precise mode
swerve);
swerve.setDefaultCommand(teleopSwerve);

driverController.rightTrigger(OperatorConstants.boolTriggerThreshold)
.whileTrue(teleopSwerve.holdToggleFieldRelative());
// driverController.rightBumper()
// .whileTrue(teleopSwerve.holdRotateAroundPiece());

// right bumper -> rotate to speaker apriltag
// driverController.rightBumper().whileTrue(new AprilTagVision(vision, swerve));
// left bumper -> rotate to note
driverController.leftBumper().whileTrue(new GamePieceVision(vision, swerve));
driverController.a().onTrue(teleopSwerve.toggleFieldRelative());
// b -> trap/climb align maybe?
driverController.x().whileTrue(new XStance(swerve));
driverController.y().onTrue(teleopSwerve.zeroYaw());

// operatorController.y().onTrue(new SetShooterVelocity(shooter, shooterVelocity));
// dpad left -> call for coopertition (lights)
// dpad right -> call for amplify (lights)

// *OPERATOR CONTROLS*
//
operatorController.a()
.onTrue(Commands.parallel(new SetArmPosition(arm, 84), new SetShooterVelocity(shooter, 1750)));
operatorController.b().onTrue(Commands.parallel(new SetArmPosition(arm, -1.5),
new SetShooterVelocity(shooter, ShooterConstants.subwooferVelocity_rpm)));
operatorController.x().onTrue(new StopShooter(shooter));
operatorController.rightBumper().whileTrue(new SetIntakeSpeed(intake, false));
// y -> set shooter speed and arm angle based on limelight
operatorController.leftBumper().onTrue(new SetArmPosition(arm, 4));
operatorController.rightBumper().onTrue(new SetArmPosition(arm, 84));
operatorController.leftTrigger(boolTriggerThreshold).whileTrue(new IntakeWithArm(intake, arm));
operatorController.rightTrigger(boolTriggerThreshold).whileTrue(new SetIntakeSpeed(intake, true));
// dpad up -> climber up
// dpad down -> climber down

operatorController.leftStick().whileTrue(new SetIntakeSpeed(intake, -IntakeConstants.intakeSpeed, true));
operatorController.rightStick().whileTrue(new ManualArmControl(arm, operatorController::getLeftY));

// *TESTING CONTROLS*
//
// When in tuning mode, create multiple testing options on shuffleboard as well as bind commands to a unique
// 'testing' controller
if (tuningMode) {
if (Constants.tuningMode) {
var indexSpeedEntry = Shuffleboard.getTab("Test").add("Index Speed", 0)
.withWidget(BuiltInWidgets.kNumberSlider)
.withProperties(Map.of("min", -1, "max", 1)).getEntry();
Expand All @@ -175,19 +208,30 @@ private void configureBindings() {
.withWidget(BuiltInWidgets.kNumberSlider)
.withProperties(Map.of("min", -1, "max", 1)).getEntry();
var shooterVelocityEntry = Shuffleboard.getTab("Test").add("Shooter Velocity", 0).getEntry();
var armPositionEntry = Shuffleboard.getTab("Test").add("Arm Position (degrees)", 0).getEntry();

testController.x().onTrue(new StopShooter(shooter));
testController.y()
.onTrue(Commands.runOnce(() -> arm.setPosition(armPositionEntry.getDouble(boolTriggerThreshold)), arm));
testController.b()
.onTrue(new InstantCommand(() -> shooter.setVelocity(shooterVelocityEntry.getDouble(0)), shooter));
testController.a()
.onTrue(new InstantCommand(() -> shooter.setPercentOutput(shooterSpeedEntry.getDouble(0)), shooter));

testController.rightBumper()
.whileTrue(Commands
.runEnd(() -> intake.setMotorVoltage(intakeSpeedEntry.getDouble(0) * 12), () -> intake.stopMotor(), intake)
.runEnd(() -> intake.setMotorSpeed(intakeSpeedEntry.getDouble(0)), () -> intake.stopMotor(), intake)
.until(() -> intake.inputs.noteSensor).unless(() -> intake.inputs.noteSensor));
testController.leftBumper().whileTrue(
new StartEndCommand(() -> intake.setMotorVoltage(indexSpeedEntry.getDouble(0) * 12), () -> intake.stopMotor(),
new StartEndCommand(() -> intake.setMotorSpeed(indexSpeedEntry.getDouble(0)), () -> intake.stopMotor(),
intake));

testController.leftStick().whileTrue(new SetIntakeSpeed(intake, -IntakeConstants.intakeSpeed, true));
testController.rightStick().whileTrue(new ManualArmControl(arm, testController::getLeftY));

testController.povDown().onTrue(Commands.runOnce(() -> arm.setClimberRelay(Value.kForward), arm));
testController.povUp().onTrue(Commands.runOnce(() -> arm.setClimberRelay(Value.kReverse), arm));
testController.povLeft().onTrue(Commands.runOnce(() -> arm.setClimberRelay(Value.kOff), arm));
}
}

Expand Down
56 changes: 56 additions & 0 deletions src/main/java/frc/robot/commands/arm/AutoAim.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot.commands.arm;

import frc.robot.constants.VisionConstants;
import frc.robot.io.FieldVisionIOInputsAutoLogged;
import frc.robot.subsystems.Arm;
import frc.robot.subsystems.Vision;

import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.DriverStation.Alliance;
import edu.wpi.first.wpilibj2.command.Command;

import java.util.Optional;

public class AutoAim extends Command {
private Arm arm;
private Vision vision; // needed just to set the priority tag to stare at
private FieldVisionIOInputsAutoLogged fieldvisionio; // the data we take from
Optional<Alliance> alliance = DriverStation.getAlliance();

/** Creates a new AutoAim. */
public AutoAim(Arm arm, Vision vision) {
this.arm = arm;
this.vision = vision;
}

// Called when the command is initially scheduled.
@Override
public void initialize() {
if (alliance.get() == Alliance.Blue) {
vision.setPriorityId(VisionConstants.blueSpeakerTag);
}
if (alliance.get() == Alliance.Red) {
vision.setPriorityId(VisionConstants.redSpeakerTag);
}
}

@Override
public void execute() {
if (vision.findDistance() > 1)
;
// add if statements for the range now
}

@Override
public void end(boolean interrupted) {}

// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}
53 changes: 53 additions & 0 deletions src/main/java/frc/robot/commands/arm/ManualArmControl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package frc.robot.commands.arm;

import frc.robot.constants.ArmConstants;
import frc.robot.subsystems.Arm;
import frc.robot.util.ControllerUtil;

import edu.wpi.first.wpilibj2.command.Command;

import java.util.function.DoubleSupplier;

public class ManualArmControl extends Command {
public DoubleSupplier speedSupplier;
public Arm arm;

/**
* Constructs a ManualArmControl command, using the provided function to supply speed numbers
* @param arm Arm subsystem to be passed in
* @param speedSupplier function that supplies the speed used to run the arm
*/
public ManualArmControl(Arm arm, DoubleSupplier speedSupplier) {
this.arm = arm;
this.speedSupplier = speedSupplier;
addRequirements(arm);
}

// Called when the command is initially scheduled.
@Override
public void initialize() {}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
// apply deadband to input. Run stationary feedforward ("stopped") if banded input is 0
double deadbandInput = ControllerUtil.scaleAxis(speedSupplier.getAsDouble());
if (deadbandInput == 0) {
arm.stop();
} else { // else, scale banded input by max manual output and then convert to volts (linearly with max of 12 V)
arm.setMotorVoltage(-(ArmConstants.manualMaxOutput * deadbandInput) * 12);
}
}

// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
arm.stop();
}

// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@

package frc.robot.commands.arm;

import frc.robot.constants.ArmConstants;
import frc.robot.subsystems.Arm;

import edu.wpi.first.wpilibj2.command.Command;

public class setArmPosition extends Command {
public class SetArmPosition extends Command {
private Arm arm;
protected double targetPosition_rad; // did I do this right?

/** Creates a new setArmPosition. */
public setArmPosition(Arm arm, double targetPosition_rad) {
/**
* Command to set the arm position, cancels the command and moves on
* after being within the range given by {@link ArmConstants#accuracyTolerance_deg accuracyTolerance}
* @param arm Arm subsystem
* @param targetPosition_deg Position in degrees to set the arm to (0 is horizontal to robot base)
*/
public SetArmPosition(Arm arm, double targetPosition_deg) {
this.arm = arm;
this.targetPosition_rad = targetPosition_rad;
this.targetPosition_rad = targetPosition_deg;
addRequirements(arm);
}

Expand All @@ -29,7 +35,10 @@ public void execute() {}

@Override
public void end(boolean interrupted) {
arm.stopArm();
// only stop if interrupted. Otherwise, continue adjusting arm position just move on to another command
if (interrupted) {
arm.stop();
}
}

// Returns true when the command should end.
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/frc/robot/commands/intake/IntakeWithArm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package frc.robot.commands.intake;

import frc.robot.constants.IntakeConstants;
import frc.robot.subsystems.Arm;
import frc.robot.subsystems.Intake;

import edu.wpi.first.wpilibj2.command.Command;

public class IntakeWithArm extends Command {
private Intake intake;
private Arm arm;

public IntakeWithArm(Intake intake, Arm arm) {
this.intake = intake;
this.arm = arm;
addRequirements(intake, arm);
}

// Called when the command is initially scheduled.
@Override
public void initialize() {
if (!intake.inputs.noteSensor) {
arm.setPosition(-1.5);
intake.setMotorSpeed(IntakeConstants.intakeSpeed);
}
}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {}

// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
arm.setPosition(4);
intake.stopMotor();
}

// Returns true when the command should end.
@Override
public boolean isFinished() {
return intake.inputs.noteSensor;
}
}
7 changes: 4 additions & 3 deletions src/main/java/frc/robot/commands/intake/SetIntakeSpeed.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public SetIntakeSpeed(Intake intake, boolean isIndexing) {
public void initialize() {
// Run motor only if we are either indexing or don't detect a note. Or, if we are intaking (not indexing) and we
// detect a note, don't run
if (isIndexing || !intake.detectNote())
intake.setMotorSpeed(speed);
if (isIndexing || !intake.isHoldingNote())
;
intake.setMotorSpeed(speed);
}

// Called every time the scheduler runs while the command is scheduled.
Expand All @@ -60,6 +61,6 @@ public void end(boolean interrupted) {
public boolean isFinished() {
// If we are intaking and we detect a note, cancel automatically. If we are indexing, the command will only be
// canceled on interrupt
return (!isIndexing && intake.detectNote());
return (!isIndexing && intake.inputs.noteSensor);
}
}
Loading