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

Added IR Break Beam and autoIntake with Ada, and also synced stuff in Swerve #11

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 6 additions & 32 deletions src/main/java/frc/robot/RobotContainer.java
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These constants are outdated (names have been changed), please update your branch so it doesn't conflict with the latest code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the intake note method will do what it is supposed to do, it won't actually end the command. and there is no timeout so it could theoretically run forever in auto

Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import frc.robot.Constants.OperatorConstants;
import frc.robot.Constants.SwerveConstants;
import frc.robot.commands.TeleopSwerve;
import frc.robot.commands.arm.ArmHold;
import frc.robot.commands.arm.AutoShoot;
import frc.robot.subsystems.Arm;
import frc.robot.subsystems.Intake;
import frc.robot.subsystems.Swerve;
Expand Down Expand Up @@ -74,27 +72,15 @@ public RobotContainer() {
configureBatteryChooser();
configurePrematchChecklist();

NamedCommands.registerCommand("Start Intake", Commands.run(intake::intakeNote, intake));
NamedCommands.registerCommand("Stop Intake", intake.runOnce(intake::stopIntakeMotor));

NamedCommands.registerCommand(
"Arm to Pickup", arm.moveToPosition(ArmConstants.pickupAngle).withTimeout(3.0));
NamedCommands.registerCommand(
"Arm to Subwoofer", arm.moveToPosition(ArmConstants.subwooferAngle).withTimeout(3.0));
NamedCommands.registerCommand(
"Arm to Source Podium",
arm.moveToPosition(ArmConstants.autoSourcePodiumAngle).withTimeout(3.0));
NamedCommands.registerCommand(
"Arm to Amp Podium", arm.moveToPosition(ArmConstants.autoAmpPodiumAngle).withTimeout(3.0));
NamedCommands.registerCommand("Note Intake", Commands.run(intake::autoIntake, intake));
// NamedCommands.registerCommand("Stop Intake", Commands.run(intake::stopIntakeMotor, intake));

SmartDashboard.putData("Command Scheduler", CommandScheduler.getInstance());
SmartDashboard.putData("Power Distribution Panel", powerDistribution);

LogUtil.recordMetadata("Battery Number", batteryChooser.getSelectedName());
LogUtil.recordMetadata("Battery Nickname", batteryChooser.getSelected());

arm.setDefaultCommand(new ArmHold(arm));

swerve.setDefaultCommand(
new TeleopSwerve(
driverController::getLeftY,
Expand Down Expand Up @@ -180,31 +166,19 @@ private void configureIntakeBindings() {
private void configureArmBindings() {
operatorStick
.button(OperatorConstants.armToPickup)
.whileTrue(arm.moveToPosition(ArmConstants.pickupAngle));
.whileTrue(arm.moveToPosition(ArmConstants.pickupHeight));

operatorStick
.button(OperatorConstants.armToAmp)
.whileTrue(arm.moveToPosition(ArmConstants.ampAngle));
.whileTrue(arm.moveToPosition(ArmConstants.ampHeight));

operatorStick
.button(OperatorConstants.armShootSubwoofer)
.whileTrue(arm.moveToPosition(ArmConstants.subwooferAngle));
.whileTrue(arm.moveToPosition(ArmConstants.subwooferHeight));

operatorStick
.button(OperatorConstants.armShootPodium)
.whileTrue(arm.moveToPosition(ArmConstants.podiumAngle));

operatorStick
.button(OperatorConstants.armManualUp)
.whileTrue(arm.run(() -> arm.setSpeed(ArmConstants.manualSpeed)))
.onFalse(arm.runOnce(() -> arm.setSpeed(0.0)));

operatorStick
.button(OperatorConstants.armManualDown)
.whileTrue(arm.run(() -> arm.setSpeed(-ArmConstants.manualSpeed)))
.onFalse(arm.runOnce(() -> arm.setSpeed(0.0)));

operatorStick.button(OperatorConstants.armAutoShoot).whileTrue(new AutoShoot(arm, swerve));
.whileTrue(arm.moveToPosition(ArmConstants.podiumHeight));
}

private void configureAutoChooser() {
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/frc/robot/commands/PathFindToPose.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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;


import com.pathplanner.lib.auto.AutoBuilder;
import com.pathplanner.lib.path.PathConstraints;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.Constants.SwerveConstants;
import frc.robot.subsystems.Swerve;

public class PathFindToPose extends Command {
Swerve swerve;
double xCoordinate;
double yCoordinate;
double rotationSupplier;

/** Creates a new VisionCommand. */
public PathFindToPose(Swerve swerve, double xCoordinate,
double yCoordinate, double rotationSupplier) {
// Use addRequirements() here to declare subsystem dependencies.
this.xCoordinate = xCoordinate;
this.yCoordinate = yCoordinate;
this.rotationSupplier = rotationSupplier;
this.swerve = swerve;

addRequirements(swerve);
}

// 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() {

Pose2d targetPose = new Pose2d(xCoordinate, yCoordinate, Rotation2d.fromDegrees(rotationSupplier));

PathConstraints constraints = new PathConstraints(
SwerveConstants.maxTranslationalSpeed, SwerveConstants.maxTranslationalAcceleration,
Units.degreesToRadians(540), Units.degreesToRadians(720));

Command pathfindingCommand = AutoBuilder.pathfindToPose(
targetPose,
constraints,
0.0,
0.0
);
}

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

// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}
14 changes: 14 additions & 0 deletions src/main/java/frc/robot/subsystems/Intake.java
Copy link
Member

@Gold872 Gold872 Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the motor ID being used for the beam break DIO port number?

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@

import com.revrobotics.CANSparkLowLevel.MotorType;
import com.revrobotics.CANSparkMax;

import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction;
import frc.robot.Constants.IntakeConstants;

public class Intake extends SubsystemBase {
/** Creates a new Intake. */
CANSparkMax intakeMotor1 =
new CANSparkMax(IntakeConstants.intakeMotorOneID, MotorType.kBrushless);
DigitalInput irBreakBeam = new DigitalInput(IntakeConstants.intakeMotorOneID);

public Intake() {}

Expand All @@ -28,8 +34,16 @@ public void stopIntakeMotor() {
intakeMotor1.set(0.0);
}

public void autoIntake() {
intakeNote();
if (!irBreakBeam.get()) {
stopIntakeMotor();
}
}

@Override
public void periodic() {
// This method will be called once per scheduler run
SmartDashboard.putBoolean("Intake Note?", !irBreakBeam.get());
}
}
Loading
Loading