Skip to content

Pivot #7

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

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d3e805f
Untested class
6kn4eakfr4s Jan 28, 2025
479507d
Untested Talon Class
6kn4eakfr4s Jan 28, 2025
367353f
Added methods to accomodate usages in existing branches
6kn4eakfr4s Jan 29, 2025
aa9bf85
Enable PIDF tuning through NT + Logging more things for spark max.
6kn4eakfr4s Jan 29, 2025
010458f
Allows changing talon pid through NT
6kn4eakfr4s Jan 29, 2025
92c20a3
fixed typo
6kn4eakfr4s Jan 29, 2025
ac86d8b
Added comments & allowed one spark max to follow another
6kn4eakfr4s Jan 30, 2025
8190463
Using optional int to represent the can ID to follow
6kn4eakfr4s Jan 30, 2025
1b00441
Allows to set the motor's position & differentiated setPosition and s…
6kn4eakfr4s Jan 31, 2025
dff12b3
allows to set a position reference with feedforward
6kn4eakfr4s Jan 31, 2025
2e3aaf5
Allow softlimit config
6kn4eakfr4s Jan 31, 2025
9232165
spark max now tracks speeds set through set()
6kn4eakfr4s Jan 31, 2025
69c869f
setangle
eerinn Jan 16, 2025
ae49536
setup basic pivot with pid no soft limits
CrolineCrois Jan 17, 2025
b4029d4
pivot ready for r1
CrolineCrois Jan 17, 2025
f1cec0a
update conversion factor
CrolineCrois Jan 17, 2025
c721ce0
update syntax in pivot, begin comands
CrolineCrois Jan 17, 2025
0908146
pivot commands
CrolineCrois Jan 18, 2025
5808699
init rollers
CrolineCrois Jan 18, 2025
b310c21
commands and basic test bindings in robocoantiner
CrolineCrois Jan 19, 2025
b54c602
update conversion factor, works intakeless
CrolineCrois Jan 20, 2025
3fa069b
tuned Kg in terms of giant metal block
CrolineCrois Jan 21, 2025
93440e7
added bindings
CrolineCrois Jan 29, 2025
93d56b9
renaming folders for conv
CrolineCrois Feb 2, 2025
dd33702
move config to constants
CrolineCrois Feb 3, 2025
dafd3b6
tune pvito r1
CrolineCrois Feb 12, 2025
75243b3
actual pivot branch this time
eerinn Feb 20, 2025
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@
"edu.wpi.first.math.**.struct.*",
],
"wpilib.autoStartRioLog": true,
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -Xlog:disable"
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx8G -Xms100m -Xlog:disable"
}
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/Commands/AutoAlignCommand.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package frc.robot.Commands;
package frc.robot.commands;
import frc.robot.subsystems.swerve.SwerveSubsystem;


Expand Down
64 changes: 63 additions & 1 deletion src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,32 @@

package frc.robot;

import org.photonvision.PhotonPoseEstimator.PoseStrategy;
import java.util.OptionalInt;
import java.util.Optional;

import com.revrobotics.spark.ClosedLoopSlot;
import com.revrobotics.spark.config.ClosedLoopConfig;
import com.revrobotics.spark.config.EncoderConfig;
import com.revrobotics.spark.config.MAXMotionConfig;
import com.revrobotics.spark.config.SoftLimitConfig;

import java.util.OptionalInt;
import java.util.Optional;
import com.revrobotics.spark.ClosedLoopSlot;
import com.revrobotics.spark.config.ClosedLoopConfig;
import com.revrobotics.spark.config.EncoderConfig;
import com.revrobotics.spark.config.MAXMotionConfig;
import com.revrobotics.spark.config.SoftLimitConfig;

import org.photonvision.PhotonPoseEstimator.PoseStrategy;
import edu.wpi.first.math.geometry.Pose3d;
import edu.wpi.first.math.geometry.Rotation3d;
import edu.wpi.first.math.geometry.Transform3d;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.util.Units;
import frc.robot.subsystems.Vision.CameraConfig;
import frc.robot.util.PolynomialRegression;
import frc.robot.util.Motors.LoggedSparkMaxConfig;

/**
* The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean
Expand Down Expand Up @@ -78,8 +95,15 @@ public static class SwerveConstants {
public static final boolean STATE_DEBUG = false;
}

public static class DebugConstants{
public static final Boolean REV_DEBUG = false;
public static final Boolean CTRE_DEBUG = false;
}

public static class LoggingConstants{
public static final String SWERVE_TABLE = "SwerveStats";
public static final String REV_TABLE = "MotorStats";
public static final String CTRE_TABLE = "MotorStats";
}

public static class VisionConstants{
Expand Down Expand Up @@ -150,4 +174,42 @@ public static class VisionConstants{
public static final PolynomialRegression oStdDevModel = new PolynomialRegression(
VisionConstants.STD_DEV_DIST,VisionConstants.O_STD_DEV,1);
}

public static class IntakeConstants {
public static final int PIVOT_ID = 14;
public static final int ROLLER_ID = 16;
public static final int INTAKE_SENSOR_ID = 1;

public static final double PIVOT_CONVERSION_FACTOR = (2 * Math.PI) / 30.;

public static final double ZERO_POSITION = 0;
public static final double SOURCE_POSITION = Units.degreesToRadians(45); //TODO: change
public static final double OUTTAKE_POSITION = Units.degreesToRadians(-45); //TODO: change
public static final double VERTICAL_POSITION = Units.degreesToRadians(82); //TODO: change

public static final double PIVOT_TOLERANCE = .08; //TODO: change

public static final double PIVOT_KG = 3;
public static final double PIVOT_KS = 0;
public static final double PIVOT_KV = 0;

public static final double PIVOT_P = .3;
public static final double PIVOT_I = 0;
public static final double PIVOT_D = 0.3;

public static final LoggedSparkMaxConfig PivotMotorLoggedSparkMaxConfig = new LoggedSparkMaxConfig(
PIVOT_ID,
new ClosedLoopConfig().pid(PIVOT_P, PIVOT_I, PIVOT_D, ClosedLoopSlot.kSlot0),
new EncoderConfig().positionConversionFactor(PIVOT_CONVERSION_FACTOR),
OptionalInt.empty(),
Optional.of(
new SoftLimitConfig()
.forwardSoftLimitEnabled(true)
.forwardSoftLimit(Units.degreesToRadians(85))
.reverseSoftLimitEnabled(true)
.reverseSoftLimit(Units.degreesToRadians(-50))
)
);

}
}
92 changes: 76 additions & 16 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package frc.robot;

// import frc.robot.commands.pivot.SetPivotVerticalCommand;
// import frc.robot.commands.pivot.SetPivotZeroCommand;
import frc.robot.controllers.BaseDriveController;
import frc.robot.controllers.DualJoystickDriveController;
import frc.robot.controllers.PS5DriveController;
Expand All @@ -13,13 +15,25 @@

import edu.wpi.first.wpilibj.DataLogManager;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.PS5Controller;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.ConditionalCommand;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.button.CommandPS5Controller;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import frc.robot.subsystems.FieldManagementSubsystem.FieldManagementSubsystem;
import frc.robot.subsystems.Vision.VisionSubsystem;
import frc.robot.subsystems.intake.pivot.PivotState;
import frc.robot.subsystems.intake.pivot.PivotSubsystem;
import frc.robot.subsystems.intake.rollers.RollerSubsystem;
import frc.robot.subsystems.swerve.SwerveSubsystem;
import frc.robot.Constants.VisionConstants;
import frc.robot.commands.pivot.SetPivotOuttakeCommand;
import frc.robot.commands.pivot.SetPivotSourceCommand;
import frc.robot.commands.pivot.SetPivotVerticalCommand;
import frc.robot.commands.pivot.SetPivotZeroCommand;
/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
* "declarative" paradigm, very little robot logic should actually be handled in the {@link Robot}
Expand All @@ -31,6 +45,8 @@ public class RobotContainer {
private BaseDriveController driveController;

private final SwerveSubsystem swerveSubsystem = new SwerveSubsystem();
private final PivotSubsystem pivotSubsystem = new PivotSubsystem();
private final RollerSubsystem rollerSubsystem = new RollerSubsystem();
private final VisionSubsystem visionSubsystem2 = new VisionSubsystem(
VisionConstants.cameraConfigs[1]
);
Expand All @@ -41,8 +57,19 @@ public class RobotContainer {
VisionConstants.cameraConfigs[3]
);

private CommandPS5Controller mechController;
private Trigger aButton, lTrigger, rTrigger, lBumper, rBumper;

/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {
mechController = new CommandPS5Controller(1);
aButton = new Trigger(mechController.cross());
lTrigger = new Trigger(mechController.L2());
rTrigger = new Trigger(mechController.R2());

lBumper = new Trigger(mechController.L1());
rBumper = new Trigger(mechController.R1());

constructDriveController();
// startLog();
setVisionDataInterface();
Expand All @@ -63,25 +90,58 @@ private void configureBindings() {
* the robot is controlled along its own axes, otherwise controls apply to the field axes by default. If the
* swerve aim button is held down, the robot will rotate automatically to always face a target, and only
* translation will be manually controllable. */
swerveSubsystem.setDefaultCommand(
new RunCommand(() -> {
swerveSubsystem.setDrivePowers(
driveController.getForwardPower(),
driveController.getLeftPower(),
driveController.getRotatePower()
);
},
swerveSubsystem
)
// swerveSubsystem.setDefaultCommand(
// new RunCommand(() -> {
// swerveSubsystem.setDrivePowers(
// driveController.getForwardPower(),
// driveController.getLeftPower(),
// driveController.getRotatePower()
// );
// },
// swerveSubsystem
// )
// );

rBumper.onTrue(
new ConditionalCommand(
new SetPivotOuttakeCommand(pivotSubsystem),
new ConditionalCommand(
new SetPivotZeroCommand(pivotSubsystem).andThen(new SetPivotSourceCommand(pivotSubsystem)),
new SetPivotSourceCommand(pivotSubsystem),
() -> (pivotSubsystem.getCurrentAngle() < PivotState.ZERO.getTargetAngle())),
() -> (pivotSubsystem.getTargetState() == PivotState.SOURCE)
)
);

/* Pressing the button resets the field axes to the current robot axes. */
driveController.bindDriverHeadingReset(
() ->{
swerveSubsystem.resetDriverHeading();
},
swerveSubsystem
lBumper.onTrue(
new SetPivotVerticalCommand(pivotSubsystem).withTimeout(2.5)
);

rollerSubsystem.setDefaultCommand(new ConditionalCommand(
new InstantCommand( () -> {
//ps5 trigger's range is -1 to 1, with non-input position being -1. This maps the range -1 to 1 to 0 to 1.
rollerSubsystem.setRollerPower(.25 * (mechController.getR2Axis() + 1.) / 2.);
}, rollerSubsystem),
new InstantCommand( () -> {
rollerSubsystem.setRollerPower(.25 * (mechController.getR2Axis() - mechController.getL2Axis()));
}, rollerSubsystem),
() -> rollerSubsystem.getIntakeSensor()));

// aButton.onTrue(
// new SetPivotVerticalCommand(pivotSubsystem)
// );

// rollerSubsystem.setDefaultCommand(new InstantCommand( () -> {
// rollerSubsystem.setRollerPower(mechController.getL2Axis() - mechController.getR2Axis());
// }, rollerSubsystem));

// /* Pressing the button resets the field axes to the current robot axes. */
// driveController.bindDriverHeadingReset(
// () ->{
// swerveSubsystem.resetDriverHeading();
// },
// swerveSubsystem
// );
}

/**
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/frc/robot/commands/pivot/SetPivotOuttakeCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package frc.robot.commands.pivot;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.intake.pivot.PivotState;
import frc.robot.subsystems.intake.pivot.PivotSubsystem;

public class SetPivotOuttakeCommand extends Command{
private PivotSubsystem pivotSubsystem;

public SetPivotOuttakeCommand(PivotSubsystem pivotSubsystem) {
this.addRequirements(pivotSubsystem);
this.pivotSubsystem = pivotSubsystem;
}

@Override
public void execute() {
this.pivotSubsystem.setState(PivotState.OUTTAKE);
}

@Override
public boolean isFinished() {
return pivotSubsystem.atState(PivotState.OUTTAKE);
}
}
24 changes: 24 additions & 0 deletions src/main/java/frc/robot/commands/pivot/SetPivotSourceCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package frc.robot.commands.pivot;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.intake.pivot.PivotState;
import frc.robot.subsystems.intake.pivot.PivotSubsystem;

public class SetPivotSourceCommand extends Command{
private PivotSubsystem pivotSubsystem;

public SetPivotSourceCommand(PivotSubsystem pivotSubsystem) {
this.addRequirements(pivotSubsystem);
this.pivotSubsystem = pivotSubsystem;
}

@Override
public void execute() {
this.pivotSubsystem.setState(PivotState.SOURCE);
}

@Override
public boolean isFinished() {
return pivotSubsystem.atState(PivotState.SOURCE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package frc.robot.commands.pivot;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.intake.pivot.PivotState;
import frc.robot.subsystems.intake.pivot.PivotSubsystem;

public class SetPivotVerticalCommand extends Command{
private PivotSubsystem pivotSubsystem;

public SetPivotVerticalCommand(PivotSubsystem pivotSubsystem) {
this.addRequirements(pivotSubsystem);
this.pivotSubsystem = pivotSubsystem;
}

@Override
public void execute() {
this.pivotSubsystem.setState(PivotState.VERTICAL);
// System.out.println("vertical" + pivotSubsystem.getPositionError());
}

@Override
public boolean isFinished() {
return pivotSubsystem.atState(PivotState.VERTICAL);
}

@Override
public void end(boolean interrupted) {
pivotSubsystem.setSpeed(0);
}
}
30 changes: 30 additions & 0 deletions src/main/java/frc/robot/commands/pivot/SetPivotZeroCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package frc.robot.commands.pivot;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.intake.pivot.PivotState;
import frc.robot.subsystems.intake.pivot.PivotSubsystem;

public class SetPivotZeroCommand extends Command{
private PivotSubsystem pivotSubsystem;

public SetPivotZeroCommand(PivotSubsystem pivotSubsystem) {
this.addRequirements(pivotSubsystem);
this.pivotSubsystem = pivotSubsystem;
}

@Override
public void execute() {
this.pivotSubsystem.setState(PivotState.ZERO);
// System.out.println("horizontal" + pivotSubsystem.getPositionError());
}

@Override
public boolean isFinished() {
return pivotSubsystem.atState(PivotState.ZERO);
}

@Override
public void end(boolean interrupted) {
pivotSubsystem.setSpeed(0);
}
}
21 changes: 21 additions & 0 deletions src/main/java/frc/robot/subsystems/intake/pivot/PivotState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package frc.robot.subsystems.intake.pivot;

import frc.robot.Constants;

public enum PivotState {
ZERO(Constants.IntakeConstants.ZERO_POSITION),
OUTTAKE(Constants.IntakeConstants.OUTTAKE_POSITION),
SOURCE(Constants.IntakeConstants.SOURCE_POSITION),
VERTICAL(Constants.IntakeConstants.VERTICAL_POSITION);

private final double targetAngle;

private PivotState(double targetAngle) {
this.targetAngle = targetAngle;
}

public double getTargetAngle() {
return targetAngle;
}

}
Loading