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

Feature/intake phx6 alon #6

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
5 changes: 4 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ dependencies {

implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'

implementation 'com.github.galaxia5987:common:1181c49'
implementation 'com.github.galaxia5987:common:3580ac1cfd'
}

test {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import edu.wpi.first.wpilibj.PowerDistribution;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import frc.robot.subsystems.intake.Intake;
import org.littletonrobotics.junction.LogFileUtil;
import org.littletonrobotics.junction.LoggedRobot;
import org.littletonrobotics.junction.Logger;
Expand Down
38 changes: 12 additions & 26 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import frc.robot.commandgroups.PickUpCubeTeleop;
Expand All @@ -16,18 +17,26 @@
import frc.robot.subsystems.gripper.Gripper;
import frc.robot.subsystems.intake.Intake;
import frc.robot.subsystems.intake.commands.HoldIntakeInPlace;
import frc.robot.subsystems.intake.commands.IntakeKeyboardControl;
import frc.robot.subsystems.intake.commands.ProximitySensorDefaultCommand;
import frc.robot.subsystems.intake.commands.Retract;
import frc.robot.subsystems.leds.Leds;
import swerve.SwerveDrive;
import swerve.commands.XboxDrive;
import utils.Utils;


public class RobotContainer {
private static RobotContainer INSTANCE = null;
private final Arm arm = Arm.getINSTANCE();
private final Leds leds = Leds.getInstance();
private final SwerveDrive swerveDrive = SwerveDrive.getInstance(Robot.isReal());
static {
SwerveDrive.setInstance(Robot.isReal(),
Ports.SwerveDrive.DRIVE_IDS,
Ports.SwerveDrive.ANGLE_IDS,
Ports.SwerveDrive.ENCODER_IDS);
}
private final SwerveDrive swerveDrive = SwerveDrive.getInstance();
Copy link
Member

Choose a reason for hiding this comment

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

Why did you change this here? It's not related to this branch.

private final Intake intake = Intake.getInstance();
private final Gripper gripper = Gripper.getInstance();
private final XboxController xboxController = new XboxController(0);
Expand Down Expand Up @@ -77,35 +86,12 @@ private void configureDefaultCommands() {
new XboxDrive(swerveDrive, xboxController)
);
// arm.setDefaultCommand(new ArmXboxControl(xboxController));
intake.setDefaultCommand(new HoldIntakeInPlace());
intake.setDefaultCommand(new IntakeKeyboardControl());
leds.setDefaultCommand(new ProximitySensorDefaultCommand());
}

private void configureButtonBindings() {
leftJoystickTrigger.onTrue(new InstantCommand(swerveDrive::resetGyro));
y.whileTrue(new ArmWithSpline(ArmPosition.TOP_SCORING));
x.whileTrue(new ArmWithSpline(ArmPosition.MIDDLE_SCORING));
b.whileTrue(new ArmWithSpline(ArmPosition.FEEDER));
back.whileTrue(new ArmWithSpline(ArmPosition.FEEDER_CONE));
a.whileTrue(new ArmWithSpline(ArmPosition.NEUTRAL));

lb.onTrue(new InstantCommand(gripper::toggle));

start.onTrue(new InstantCommand(leds::toggle));

leftJoystickTopBottom.toggleOnTrue(
new InstantCommand(swerveDrive::lock, swerveDrive)
);
leftJoystickTopBottom.onTrue(
new InstantCommand(leds::toggleRainbow)
);

xboxLeftTrigger.whileTrue(new PickUpCubeTeleop())
.onFalse(new Retract(Retract.Mode.UP).andThen(new InstantCommand(() -> intake.setSpinMotorPower(0))));
xboxRightTrigger.whileTrue(new ReturnIntake());

rb.whileTrue(new ArmAxisControl(0.02, 0.02)
.until(() -> gripper.getDistance() < ArmConstants.FEEDER_DISTANCE));
Copy link
Member

Choose a reason for hiding this comment

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

Why did you delete all of that?

// a.whileTrue(new RunCommand(()-> intake.setAngleMotorAngle(Math.PI)));
Copy link
Member

Choose a reason for hiding this comment

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

...

}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/frc/robot/commandgroups/FeedTeleop.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package frc.robot.commandgroups;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj2.command.ParallelCommandGroup;
import edu.wpi.first.wpilibj2.command.RunCommand;
import frc.robot.subsystems.intake.Intake;
Expand All @@ -12,7 +13,7 @@ public FeedTeleop(boolean outtake) {

addCommands(
new Retract(Retract.Mode.DOWN)
.andThen(new RunCommand(() -> intake.setAngleMotorAngle(IntakeConstants.ANGLE_DOWN))),
.andThen(new RunCommand(() -> intake.setAngleMotorAngle(Rotation2d.fromDegrees(IntakeConstants.ANGLE_DOWN)))),
Copy link
Member

@katzuv katzuv Dec 16, 2023

Choose a reason for hiding this comment

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

Instead of creating a Rotation2d here, ANGLE_DOWN should already be a Rotation2d.

intake.run(outtake ? -IntakeConstants.INTAKE_POWER : IntakeConstants.INTAKE_POWER)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class CheckSwerve extends SequentialCommandGroup {
public CheckSwerve() {
SwerveDrive swerveDrive = SwerveDrive.getInstance(Robot.isReal());
SwerveDrive swerveDrive = SwerveDrive.getInstance();
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't be changed here. You can use interactive rebasing to remove this diff.

addCommands(
new RunCommand(swerveDrive::checkSwerve, swerveDrive).withTimeout(5),
new ZeroPositionSwerve().withTimeout(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.Arrays;

public class ZeroPositionSwerve extends Command {
private final SwerveDrive swerve = SwerveDrive.getInstance(Robot.isReal());
private final SwerveDrive swerve = SwerveDrive.getInstance();
private final Timer timer = new Timer();
private final SwerveModuleState[] zeroStates = new SwerveModuleState[4];

Expand Down
25 changes: 16 additions & 9 deletions src/main/java/frc/robot/subsystems/intake/Intake.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.ctre.phoenix.motorcontrol.ControlMode;
import edu.wpi.first.math.geometry.Pose3d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Rotation3d;
import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d;
Expand All @@ -14,6 +15,7 @@
import frc.robot.Robot;
import frc.robot.subsystems.intake.commands.HoldIntakeInPlace;
import org.littletonrobotics.junction.Logger;
import utils.Utils;

public class Intake extends SubsystemBase {
private static Intake INSTANCE;
Expand Down Expand Up @@ -70,26 +72,26 @@ public void setSpinMotorPower(double power) {
inputs.setpointSpinMotorPower = power;
}

public double getAngleMotorAngle() {
public Rotation2d getAngleMotorAngle() {
return inputs.angleMotorAngle;
}

/**
* Sets the angles position.
*
* @param angle is the angle of the retractor. [degrees]
* @param angleMotorAngle is the angle of the retractor. [degrees]
*/
public void setAngleMotorAngle(double angle) {
inputs.setpointAngleMotorAngle = Math.toRadians(angle);
public void setAngleMotorAngle(Rotation2d angleMotorAngle) {
inputs.setpointAngleMotorAngle = angleMotorAngle;
angleMode = ControlMode.Position;
}

private double getAngleMotorVelocity() {
private Rotation2d getAngleMotorVelocity() {
return inputs.angleMotorVelocity;
}

public double getCurrent() {
return inputs.angleMotorcurrent;
return inputs.angleMotorAppliedCurrent;
}

public void setAnglePower(double power) {
Expand All @@ -103,9 +105,12 @@ public void resetEncoder(double angle) {

public Command lowerIntake() {
return new InstantCommand(() -> resetEncoder(IntakeConstants.ANGLE_UP), this)
.andThen(new RunCommand(() -> setAngleMotorAngle(-40), this));
.andThen(new RunCommand(() -> setAngleMotorAngle(Rotation2d.fromDegrees(-40)), this));
}

// You Jerk :) 😎
// I'm gonna kill them all.
// All the juice must die
Comment on lines +111 to +113
Copy link
Member

Choose a reason for hiding this comment

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

Aren't you going to delete it?

public Command run(double power) {
return new RunCommand(() -> this.setSpinMotorPower(power));
}
Expand All @@ -127,9 +132,11 @@ public void periodic() {
!(lastCommand instanceof HoldIntakeInPlace);
lastCommand = currentCommand;

intakeP1.setAngle(Math.toDegrees(getAngleMotorAngle()) + IntakeConstants.INTAKE_MECH_OFFSET);
intakeP1.setAngle(getAngleMotorAngle().getDegrees() + IntakeConstants.INTAKE_MECH_OFFSET);
Copy link
Member

Choose a reason for hiding this comment

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

MechanismLigament2d can also receive Rotation2d objects.


Logger.recordOutput("IntakePose", getPose3d(getAngleMotorAngle() + IntakeConstants.INTAKE_SIM_ANGLE_OFFSET));

var intake3d = getPose3d(getAngleMotorAngle().getRadians() + Math.toRadians(IntakeConstants.INTAKE_SIM_ANGLE_OFFSET)); //TODO: ??!?!! check
Logger.recordOutput("IntakePose", Utils.pose3dToArray(intake3d));
Logger.processInputs("Intake", inputs);
SmartDashboard.putData("IntakeMech", mech);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package frc.robot.subsystems.intake;

import com.ctre.phoenix6.configs.Slot0Configs;
import edu.wpi.first.math.geometry.Translation2d;
import utils.units.Units;

public class IntakeConstants {
public static final double ANGLE_GEAR_RATIO = 35.26;
public static final double SPIN_GEAR_RATIO = 10; //Not a real value
public static final double kP = 2;
public static final double kP = 0.1*ANGLE_GEAR_RATIO;
public static final double kI = 0;
public static final double kD = 0.2;
public static final double kF = 0;
public static final double kD = 0;
public static final double kF = 0; // not relevant anymore
Copy link
Member

Choose a reason for hiding this comment

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

If that's not relevant, delete it. Why isn't it, though?

public static final Slot0Configs PIDGains = new Slot0Configs().withKP(IntakeConstants.kP).withKI(IntakeConstants.kI).withKD(IntakeConstants.kD);
Copy link
Member

@katzuv katzuv Dec 12, 2023

Choose a reason for hiding this comment

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

You don't need to create individual constants, just put the numbers on this line instead.


public static final double FALCON_TICKS_PER_ROTATION = 2048;
public static final double TICKS_PER_DEGREE = FALCON_TICKS_PER_ROTATION / 360 * ANGLE_GEAR_RATIO;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/frc/robot/subsystems/intake/IntakeIO.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package frc.robot.subsystems.intake;

import edu.wpi.first.math.geometry.Rotation2d;

public interface IntakeIO {
void updateInputs(IntakeLoggedInputs inputs);

void setSpinMotorPower(double power);

void setAngleMotorAngle(double angle);
void setAngleMotorAngle(Rotation2d angle);

void setAngleMotorPower(double power);

Expand Down
Loading