Skip to content

Commit

Permalink
Dynamic auto new (#27)
Browse files Browse the repository at this point in the history
Co-authored-by: ihernandez3647 <[email protected]>
Co-authored-by: gvaldez7206 <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: Owen <[email protected]>
  • Loading branch information
5 people authored Jan 28, 2023
1 parent 71c8c98 commit 3c932d1
Show file tree
Hide file tree
Showing 21 changed files with 1,949 additions and 416 deletions.
1,306 changes: 1,306 additions & 0 deletions shuffleboard/shuffleboard.json

Large diffs are not rendered by default.

385 changes: 385 additions & 0 deletions src/main/java/frc/lib/util/FieldConstants.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package frc.robot;
package frc.lib.util.ctre;

import com.ctre.phoenix.motorcontrol.SupplyCurrentLimitConfiguration;
import com.ctre.phoenix.motorcontrol.can.TalonFXConfiguration;
import com.ctre.phoenix.sensors.AbsoluteSensorRange;
import com.ctre.phoenix.sensors.CANCoderConfiguration;
import com.ctre.phoenix.sensors.SensorInitializationStrategy;
import com.ctre.phoenix.sensors.SensorTimeBase;
import frc.robot.Constants;

/**
* CTRE config constants
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package frc.lib.util;
package frc.lib.util.ctre;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.kinematics.SwerveModuleState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package frc.robot;
package frc.lib.util.swerve;

import com.ctre.phoenix.motorcontrol.ControlMode;
import com.ctre.phoenix.motorcontrol.DemandType;
Expand All @@ -9,7 +9,9 @@
import edu.wpi.first.math.kinematics.SwerveModulePosition;
import edu.wpi.first.math.kinematics.SwerveModuleState;
import frc.lib.math.Conversions;
import frc.lib.util.CTREModuleState;
import frc.lib.util.ctre.CTREModuleState;
import frc.robot.Constants;
import frc.robot.Robot;

/**
* Base Swerve Module Class. Creates an instance of the swerve module
Expand All @@ -30,7 +32,7 @@ public class SwerveModule {
* @param moduleNumber Swerve Module ID. Must be unique
* @param constants Constants specific to the swerve module
*/
public SwerveModule(int moduleNumber, frc.lib.util.SwerveModuleConstants constants) {
public SwerveModule(int moduleNumber, frc.lib.util.swerve.SwerveModuleConstants constants) {
this.moduleNumber = moduleNumber;
angleOffset = constants.angleOffset;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package frc.lib.util;
package frc.lib.util.swerve;

/**
* Constants file used when creating swerve modules
Expand Down
55 changes: 46 additions & 9 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package frc.robot;

import com.ctre.phoenix.motorcontrol.NeutralMode;
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.geometry.Translation3d;
import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
import edu.wpi.first.math.util.Units;
import frc.lib.util.SwerveModuleConstants;
import frc.lib.util.swerve.SwerveModuleConstants;

/**
* Constants file.
Expand All @@ -13,6 +16,40 @@
public final class Constants {
public static final double stickDeadband = 0.1;

/**
* PID constants for Swerve Auto Holonomic Drive Controller
*/
public static class SwerveTransformPID {
public static final double pidXkP = 1.5;
public static final double pidXkI = 0.0;
public static final double pidXkD = 0.0;
public static final double pidYkP = 1.5;
public static final double pidYkI = 0.0;
public static final double pidYkD = 0.0;
public static final double pidTkP = 3.0;
public static final double pidTkI = 0.0;
public static final double pidTkD = 0.0;

public static final double maxAngularVelocity = 3.0;
public static final double maxAngularAcceleration = 3.0;
public static final double stdDevMod = 2.0;
}

/**
* Camera offset constants
*/
public static class CameraConstants {

public static final double pitch = 0 * Math.PI / 180;
public static final double roll = Math.PI;
public static final double yaw = 0.0;
public static final Transform3d kCameraToRobot =
new Transform3d(new Translation3d(Units.inchesToMeters(-10), Units.inchesToMeters(2),
Units.inchesToMeters(7.5)), new Rotation3d(roll, pitch, yaw));
public static final String cameraName = "pv2";
public static final double largestDistance = 0.1;
}

/**
* Swerve ID's
*/
Expand All @@ -22,9 +59,9 @@ public static final class Swerve {
public static final boolean invertGyro = false; // Always ensure Gyro is CCW+ CW-

/* Drivetrain Constants */
public static final double trackWidth = Units.inchesToMeters(27);
public static final double wheelBase = Units.inchesToMeters(27);
public static final double wheelDiameter = Units.inchesToMeters(3.94);
public static final double trackWidth = Units.inchesToMeters(14);
public static final double wheelBase = Units.inchesToMeters(14);
public static final double wheelDiameter = Units.inchesToMeters(4);
public static final double wheelCircumference = wheelDiameter * Math.PI;

public static final boolean isFieldRelative = true;
Expand All @@ -33,7 +70,7 @@ public static final class Swerve {
public static final double openLoopRamp = 0.25;
public static final double closedLoopRamp = 0.4;

public static final double driveGearRatio = (8.14 / 1.0); // 6.86:1
public static final double driveGearRatio = (8.14 / 1.0); // 8.14:1
public static final double angleGearRatio = (12.8 / 1.0); // 12.8:1

public static final SwerveDriveKinematics swerveKinematics =
Expand Down Expand Up @@ -94,19 +131,19 @@ public static final class Mod0 {
public static final int driveMotorID = 50;
public static final int angleMotorID = 8;
public static final int canCoderID = 3;
public static final double angleOffset = 138.867;
public static final double angleOffset = 139.043;
public static final SwerveModuleConstants constants =
new SwerveModuleConstants(driveMotorID, angleMotorID, canCoderID, angleOffset);
}

/**
* Front Right Module - Module 1.
* Front Right Module - Module 1. PROBLEM CHILD
*/
public static final class Mod1 {
public static final int driveMotorID = 51;
public static final int angleMotorID = 52;
public static final int canCoderID = 2;
public static final double angleOffset = 109.775;
public static final double angleOffset = 118.564;
public static final SwerveModuleConstants constants =
new SwerveModuleConstants(driveMotorID, angleMotorID, canCoderID, angleOffset);
}
Expand All @@ -118,7 +155,7 @@ public static final class Mod2 {
public static final int driveMotorID = 4;
public static final int angleMotorID = 2;
public static final int canCoderID = 1;
public static final double angleOffset = 259.541;
public static final double angleOffset = 259.805;
public static final SwerveModuleConstants constants =
new SwerveModuleConstants(driveMotorID, angleMotorID, canCoderID, angleOffset);
}
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 @@ -7,6 +7,7 @@
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import frc.lib.util.ctre.CTREConfigs;

/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

package frc.robot;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Transform2d;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
Expand All @@ -12,6 +15,7 @@
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import frc.robot.commands.TeleopSwerve;
import frc.robot.commands.TestTransform;
import frc.robot.subsystems.Swerve;

/**
Expand Down Expand Up @@ -48,6 +52,9 @@ public RobotContainer() {
private void configureButtonBindings() {
/* Driver Buttons */
driver.y().whileTrue(new InstantCommand(() -> s_Swerve.resetFieldRelativeOffset()));
driver.x().whileTrue(new TestTransform(s_Swerve,
new Transform2d(new Translation2d(1, 0), Rotation2d.fromDegrees(180)), 7));
driver.a().whileTrue(new InstantCommand(() -> s_Swerve.resetInitialized()));
}

/**
Expand Down
39 changes: 0 additions & 39 deletions src/main/java/frc/robot/commands/ExecUltrasonic.java

This file was deleted.

48 changes: 0 additions & 48 deletions src/main/java/frc/robot/commands/LimelightAlign.java

This file was deleted.

37 changes: 0 additions & 37 deletions src/main/java/frc/robot/commands/MoveNewMotor.java

This file was deleted.

73 changes: 0 additions & 73 deletions src/main/java/frc/robot/commands/SpinMotor.java

This file was deleted.

Loading

0 comments on commit 3c932d1

Please sign in to comment.