Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
worked on adding phoenix 6 swerve
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen756 committed Nov 29, 2023
1 parent 310dee0 commit ad12957
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 52 deletions.
39 changes: 6 additions & 33 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

package frc.robot;

import com.ctre.phoenix.sensors.CANCoder;
import com.ctre.phoenix.sensors.Pigeon2;
import com.ctre.phoenixpro.hardware.TalonFX;
import com.ctre.phoenix6.hardware.Pigeon2;
import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
import edu.wpi.first.wpilibj.PowerDistribution;
Expand All @@ -29,11 +27,11 @@
import frc.robot.intake.IntakeSubsystem;
import frc.robot.localization.LocalizationSubsystem;
import frc.robot.managers.AutoRotate;
import frc.robot.swerve.SwerveModule;
import frc.robot.swerve.SwerveSubsystem;
import frc.robot.util.scheduling.LifecycleSubsystemManager;
import frc.robot.wrist.Positions;
import frc.robot.wrist.WristSubsystem;
import frc.swerve.SwerveSubsystem;

import org.littletonrobotics.junction.LoggedRobot;
import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.networktables.NT4Publisher;
Expand All @@ -55,35 +53,11 @@ public class Robot extends LoggedRobot {
private final RumbleControllerSubsystem rumbleController =
new RumbleControllerSubsystem(new XboxController(1));

private final SwerveModule frontLeft =
new SwerveModule(
Config.SWERVE_FL_CONSTANTS,
new TalonFX(Config.SWERVE_FL_DRIVE_MOTOR_ID),
new TalonFX(Config.SWERVE_FL_STEER_MOTOR_ID),
new CANCoder(Config.SWERVE_FL_CANCODER_ID));
private final SwerveModule frontRight =
new SwerveModule(
Config.SWERVE_FR_CONSTANTS,
new TalonFX(Config.SWERVE_FR_DRIVE_MOTOR_ID),
new TalonFX(Config.SWERVE_FR_STEER_MOTOR_ID),
new CANCoder(Config.SWERVE_FR_CANCODER_ID));
private final SwerveModule backLeft =
new SwerveModule(
Config.SWERVE_BL_CONSTANTS,
new TalonFX(Config.SWERVE_BL_DRIVE_MOTOR_ID),
new TalonFX(Config.SWERVE_BL_STEER_MOTOR_ID),
new CANCoder(Config.SWERVE_BL_CANCODER_ID));
private final SwerveModule backRight =
new SwerveModule(
Config.SWERVE_BR_CONSTANTS,
new TalonFX(Config.SWERVE_BR_DRIVE_MOTOR_ID),
new TalonFX(Config.SWERVE_BR_STEER_MOTOR_ID),
new CANCoder(Config.SWERVE_BR_CANCODER_ID));


private final FmsSubsystem fmsSubsystem = new FmsSubsystem();
private final ImuSubsystem imu = new ImuSubsystem(new Pigeon2(Config.PIGEON_ID));
private final SwerveSubsystem swerve =
new SwerveSubsystem(imu, frontRight, frontLeft, backRight, backLeft);
private final SwerveSubsystem swerve = new SwerveSubsystem(imu);
private final IntakeSubsystem intake =
new IntakeSubsystem(new CANSparkMax(Config.INTAKE_MOTOR_ID, MotorType.kBrushless));
private final WristSubsystem wrist =
Expand Down Expand Up @@ -194,8 +168,7 @@ private void configureButtonBindings() {
() ->
driveController.getSidewaysPercentage() == 0
&& driveController.getForwardPercentage() == 0
&& driveController.getThetaPercentage() == 0)
.onFalse(swerve.disableXSwerveCommand());
&& driveController.getThetaPercentage() == 0);

// operator home wrist
operatorController.back().onTrue(wrist.getHomeCommand());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/autos/Autobalance.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import edu.wpi.first.wpilibj2.command.Commands;
import frc.robot.fms.FmsSubsystem;
import frc.robot.imu.ImuSubsystem;
import frc.robot.swerve.SwerveSubsystem;
import frc.robot.util.scheduling.LifecycleSubsystem;
import frc.robot.util.scheduling.SubsystemPriority;
import frc.swerve.SwerveSubsystem;

public class Autobalance extends LifecycleSubsystem {
private final SwerveSubsystem swerve;
Expand Down
18 changes: 3 additions & 15 deletions src/main/java/frc/robot/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
package frc.robot.config;

import com.pathplanner.lib.auto.PIDConstants;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj.PowerDistribution.ModuleType;
import frc.robot.swerve.SwerveCorner;
import frc.robot.swerve.SwerveModuleConstants;

public class Config {
public static final String SERIAL_NUMBER = System.getenv("serialnum");
Expand Down Expand Up @@ -38,27 +35,18 @@ public class Config {
public static final int SWERVE_FL_DRIVE_MOTOR_ID = 2;
public static final int SWERVE_FL_STEER_MOTOR_ID = 3;
public static final int SWERVE_FL_CANCODER_ID = 10;
public static final SwerveModuleConstants SWERVE_FL_CONSTANTS =
new SwerveModuleConstants(
Rotation2d.fromDegrees(284.68), SwerveCorner.FRONT_LEFT, false, false);

public static final int SWERVE_FR_DRIVE_MOTOR_ID = 4;
public static final int SWERVE_FR_STEER_MOTOR_ID = 5;
public static final int SWERVE_FR_CANCODER_ID = 11;
public static final SwerveModuleConstants SWERVE_FR_CONSTANTS =
new SwerveModuleConstants(
Rotation2d.fromDegrees(259.89), SwerveCorner.FRONT_RIGHT, false, false);

public static final int SWERVE_BL_DRIVE_MOTOR_ID = 6;
public static final int SWERVE_BL_STEER_MOTOR_ID = 7;
public static final int SWERVE_BL_CANCODER_ID = 12;
public static final SwerveModuleConstants SWERVE_BL_CONSTANTS =
new SwerveModuleConstants(
Rotation2d.fromDegrees(35.60), SwerveCorner.BACK_LEFT, false, false);

public static final int SWERVE_BR_DRIVE_MOTOR_ID = 8;
public static final int SWERVE_BR_STEER_MOTOR_ID = 9;
public static final int SWERVE_BR_CANCODER_ID = 13;
public static final SwerveModuleConstants SWERVE_BR_CONSTANTS =
new SwerveModuleConstants(
Rotation2d.fromDegrees(116.37), SwerveCorner.BACK_RIGHT, false, false);

public static final int WRIST_MOTOR_ID = 16;
public static final double WRIST_GEARING = 1.0 / 96.0;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/frc/robot/imu/ImuSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

package frc.robot.imu;

import com.ctre.phoenix.sensors.Pigeon2;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import frc.robot.util.scheduling.LifecycleSubsystem;
import frc.robot.util.scheduling.SubsystemPriority;
import org.littletonrobotics.junction.Logger;

import com.ctre.phoenix6.hardware.Pigeon2;

public class ImuSubsystem extends LifecycleSubsystem {
private final Pigeon2 imu;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import edu.wpi.first.wpilibj2.command.Commands;
import frc.robot.fms.FmsSubsystem;
import frc.robot.imu.ImuSubsystem;
import frc.robot.swerve.SwerveSubsystem;
import frc.robot.util.scheduling.LifecycleSubsystem;
import frc.robot.util.scheduling.SubsystemPriority;
import frc.swerve.SwerveSubsystem;

import org.littletonrobotics.junction.Logger;

public class LocalizationSubsystem extends LifecycleSubsystem {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/frc/robot/managers/AutoRotate.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.fms.FmsSubsystem;
import frc.robot.swerve.SwerveSubsystem;
import frc.robot.util.scheduling.LifecycleSubsystem;
import frc.robot.util.scheduling.SubsystemPriority;
import frc.swerve.SwerveSubsystem;

import java.util.function.Supplier;
import org.littletonrobotics.junction.Logger;

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/frc/swerve/CustomSlotGains.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.swerve;

import com.ctre.phoenix6.configs.Slot0Configs;

public class CustomSlotGains extends Slot0Configs {
public CustomSlotGains(double kP, double kI, double kD, double kV, double kS) {
this.kP = kP;
this.kI = kI;
this.kD = kD;
this.kV = kV;
this.kS = kS;
}
}

0 comments on commit ad12957

Please sign in to comment.