Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
47a1806
restructuring to follow command based flow
samfreund Oct 13, 2023
79d4aa1
add x button to x mode command
samfreund Oct 13, 2023
373cb52
add documentation and format
samfreund Oct 13, 2023
ab26d80
adjust filteredButton to take a port input
samfreund Oct 13, 2023
7657cb5
formatting
samfreund Oct 13, 2023
40457fb
implement a method to reset the gyro
samfreund Oct 13, 2023
9e90d28
hard code rate limits
samfreund Oct 13, 2023
7dee6a6
fix whitespace
samfreund Oct 13, 2023
8d0e887
enforce consistency
samfreund Oct 13, 2023
ba87008
remove unneccessary declaration
samfreund Oct 13, 2023
96da67d
change slowing to percentage
samfreund Oct 13, 2023
e8e8f4e
update team number
MKECyberCheese Oct 14, 2023
1ed4330
abstract filtered controller
MKECyberCheese Oct 14, 2023
1bd5874
abstract auto into sequentialCommandGroup
samfreund Oct 15, 2023
ce8f037
add command to stop robot
samfreund Oct 15, 2023
f780f95
add binding
samfreund Oct 15, 2023
6b545f8
some good old documenting
samfreund Oct 15, 2023
1028e06
swerve drive is working!
MKECyberCheese Oct 21, 2023
8be571a
start filtered joystick class
samfreund Oct 21, 2023
9a5c9d8
update joystick class
MKECyberCheese Oct 28, 2023
1fd908f
update joystick stuff
MKECyberCheese Oct 28, 2023
95800c1
camera server
MKECyberCheese Oct 28, 2023
52620c8
change the way slow works and mess with inputs
MKECyberCheese Nov 1, 2023
88f868c
update comments and fix X-Mode
MKECyberCheese Nov 1, 2023
d7697b1
comments
MKECyberCheese Nov 1, 2023
8274513
different things are broken now
MKECyberCheese Nov 1, 2023
936907a
swap clamp statements
MKECyberCheese Nov 1, 2023
7501ae4
comment
samfreund Nov 2, 2023
7fadd59
fix x mode
MKECyberCheese Nov 4, 2023
bc63324
joystick is done
MKECyberCheese Nov 4, 2023
b4dcd01
remove import
MKECyberCheese Nov 4, 2023
4a80bdf
x-mode work
MKECyberCheese Nov 4, 2023
4d96f11
Merge branch 'development' into joystickTesting
samfreund Nov 6, 2023
eddbf9f
Merge pull request #4 from MilwaukeeCyberCheese/joystickTesting
samfreund Nov 6, 2023
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 .wpilib/wpilib_preferences.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"enableCppIntellisense": false,
"currentLanguage": "java",
"projectYear": "2023",
"teamNumber": 2714
"teamNumber": 8847
}
75 changes: 49 additions & 26 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

import com.kauailabs.navx.frc.AHRS;
import com.revrobotics.CANSparkMax.IdleMode;
import java.util.function.BooleanSupplier;

import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.math.controller.ProfiledPIDController;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
import edu.wpi.first.math.trajectory.TrajectoryConfig;
import edu.wpi.first.math.trajectory.TrapezoidProfile;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj.SerialPort;
Expand All @@ -26,18 +30,20 @@
* constants are needed, to reduce verbosity.
*/
public final class Constants {
public static final class Sensors{
public static final class Sensors {
public static final AHRS gyro = new AHRS(SerialPort.Port.kUSB);
}

public static final class DriveConstants {
// Rate limits on or off
public static final BooleanSupplier kRateLimitsEnabled = () -> true;

// Driving Parameters - Note that these are not the maximum capable speeds of
// the robot, rather the allowed maximum speeds
public static final double kMaxSpeedMetersPerSecond = 4.8;
public static final double kMaxAngularSpeed = 2 * Math.PI; // radians per second

//Maximum allowed speeds for slow mode
public static final double kMaxSpeedMetersPerSecondSlow = 1.2;
public static final double kMaxAngularSpeedSlow = 0.5 * Math.PI; // radians per second
public static final double kSlowModifier = 0.7;

public static final double kDirectionSlewRate = 1.2; // radians per second
public static final double kMagnitudeSlewRate = 1.8; // percent per second (1 = 100%)
Expand All @@ -49,47 +55,52 @@ public static final class DriveConstants {
public static final double kWheelBase = Units.inchesToMeters(26.5);
// Distance between front and back wheels on robot
public static final SwerveDriveKinematics kDriveKinematics = new SwerveDriveKinematics(
new Translation2d(kWheelBase / 2, kTrackWidth / 2),
new Translation2d(kWheelBase / 2, -kTrackWidth / 2),
new Translation2d(-kWheelBase / 2, kTrackWidth / 2),
new Translation2d(-kWheelBase / 2, -kTrackWidth / 2));
new Translation2d(kWheelBase / 2, kTrackWidth / 2),
new Translation2d(-kWheelBase / 2, -kTrackWidth / 2),
new Translation2d(kWheelBase / 2, -kTrackWidth / 2));

// Angular offsets of the modules relative to the chassis in radians
public static final double kFrontLeftChassisAngularOffset = -Math.PI / 2;
public static final double kFrontRightChassisAngularOffset = 0;
public static final double kBackLeftChassisAngularOffset = Math.PI;
public static final double kBackRightChassisAngularOffset = Math.PI / 2;
//ccw is positive
public static final double kFrontLeftChassisAngularOffset = Math.PI;
public static final double kFrontRightChassisAngularOffset = -Math.PI / 2;
public static final double kBackLeftChassisAngularOffset = Math.PI / 2;
public static final double kBackRightChassisAngularOffset = 0;

// SPARK MAX CAN IDs
public static final int kFrontLeftDrivingCanId = 11;
public static final int kRearLeftDrivingCanId = 13;
public static final int kFrontRightDrivingCanId = 15;
public static final int kRearRightDrivingCanId = 17;
public static final int kFrontLeftDrivingCanId = 1;
public static final int kRearLeftDrivingCanId = 3;
public static final int kFrontRightDrivingCanId = 5;
public static final int kRearRightDrivingCanId = 7;

public static final int kFrontLeftTurningCanId = 10;
public static final int kRearLeftTurningCanId = 12;
public static final int kFrontRightTurningCanId = 14;
public static final int kRearRightTurningCanId = 16;
public static final int kFrontLeftTurningCanId = 2;
public static final int kRearLeftTurningCanId = 4;
public static final int kFrontRightTurningCanId = 6;
public static final int kRearRightTurningCanId = 8;

public static final boolean kGyroReversed = false;
public static final boolean kGyroReversed = true;
}

public static final class ModuleConstants {
// The MAXSwerve module can be configured with one of three pinion gears: 12T, 13T, or 14T.
// This changes the drive speed of the module (a pinion gear with more teeth will result in a
// The MAXSwerve module can be configured with one of three pinion gears: 12T,
// 13T, or 14T.
// This changes the drive speed of the module (a pinion gear with more teeth
// will result in a
// robot that drives faster).
// Currently 12T is installed on the robot
public static final int kDrivingMotorPinionTeeth = 12;

// Invert the turning encoder, since the output shaft rotates in the opposite direction of
// Invert the turning encoder, since the output shaft rotates in the opposite
// direction of
// the steering motor in the MAXSwerve Module.
public static final boolean kTurningEncoderInverted = true;

// Calculations required for driving motor conversion factors and feed forward
public static final double kDrivingMotorFreeSpeedRps = NeoMotorConstants.kFreeSpeedRpm / 60;
public static final double kWheelDiameterMeters = 0.0762;
public static final double kWheelCircumferenceMeters = kWheelDiameterMeters * Math.PI;
// 45 teeth on the wheel's bevel gear, 22 teeth on the first-stage spur gear, 15 teeth on the bevel pinion
// 45 teeth on the wheel's bevel gear, 22 teeth on the first-stage spur gear, 15
// teeth on the bevel pinion
public static final double kDrivingMotorReduction = (45.0 * 22) / (kDrivingMotorPinionTeeth * 15);
public static final double kDriveWheelFreeSpeedRps = (kDrivingMotorFreeSpeedRps * kWheelCircumferenceMeters)
/ kDrivingMotorReduction;
Expand Down Expand Up @@ -119,7 +130,7 @@ public static final class ModuleConstants {
public static final double kTurningMinOutput = -1;
public static final double kTurningMaxOutput = 1;

public static final IdleMode kDrivingMotorIdleMode = IdleMode.kBrake;
public static final IdleMode kDrivingMotorIdleMode = IdleMode.kCoast;
public static final IdleMode kTurningMotorIdleMode = IdleMode.kBrake;

public static final int kDrivingMotorCurrentLimit = 50; // amps
Expand All @@ -128,7 +139,8 @@ public static final class ModuleConstants {

public static final class OIConstants {
public static final int kDriverControllerPort = 0;
public static final double kDriveDeadband = 0.2;
public static final int kButtonPort = 2;
public static final double kDriveDeadband = 0.1;
}

public static final class AutoConstants {
Expand All @@ -144,6 +156,17 @@ public static final class AutoConstants {
// Constraint for the motion profiled robot angle controller
public static final TrapezoidProfile.Constraints kThetaControllerConstraints = new TrapezoidProfile.Constraints(
kMaxAngularSpeedRadiansPerSecond, kMaxAngularSpeedRadiansPerSecondSquared);

public static final TrajectoryConfig config = new TrajectoryConfig(AutoConstants.kMaxSpeedMetersPerSecond,
AutoConstants.kMaxAccelerationMetersPerSecondSquared)
// Add kinematics to ensure max speed is actually obeyed
.setKinematics(DriveConstants.kDriveKinematics);

public static final ProfiledPIDController thetaController = new ProfiledPIDController(
AutoConstants.kPThetaController, 0, 0, AutoConstants.kThetaControllerConstraints);

public static final PIDController xController = new PIDController(AutoConstants.kPXController, 0, 0);
public static final PIDController yController = new PIDController(AutoConstants.kPYController, 0, 0);
}

public static final class NeoMotorConstants {
Expand Down
60 changes: 44 additions & 16 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,80 @@
package frc.robot;

import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import frc.robot.autos.AutoTest;

/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
* each mode, as described in the TimedRobot documentation. If you change the name of this class or
* the package after creating this project, you must also update the build.gradle file in the
* The VM is configured to automatically run this class, and to call the
* functions corresponding to
* each mode, as described in the TimedRobot documentation. If you change the
* name of this class or
* the package after creating this project, you must also update the
* build.gradle file in the
* project.
*/
public class Robot extends TimedRobot {
// creates sendable chooser for autos
public static final SendableChooser<SequentialCommandGroup> m_autoChooser = new SendableChooser<>();

private Command m_autonomousCommand;

private RobotContainer m_robotContainer;

/**
* This function is run when the robot is first started up and should be used for any
* This function is run when the robot is first started up and should be used
* for any
* initialization code.
*/
@Override
public void robotInit() {
// Instantiate our RobotContainer. This will perform all our button bindings, and put our
// add autos
m_autoChooser.setDefaultOption("Zilch", null);
m_autoChooser.addOption("Test", new AutoTest(RobotContainer.m_robotDrive));
// Instantiate our RobotContainer. This will perform all our button bindings,
// and put our
// autonomous chooser on the dashboard.
m_robotContainer = new RobotContainer();
}

/**
* This function is called every 20 ms, no matter the mode. Use this for items like diagnostics
* This function is called every 20 ms, no matter the mode. Use this for items
* like diagnostics
* that you want ran during disabled, autonomous, teleoperated and test.
*
* <p>This runs after the mode specific periodic functions, but before LiveWindow and
* <p>
* This runs after the mode specific periodic functions, but before LiveWindow
* and
* SmartDashboard integrated updating.
*/
@Override
public void robotPeriodic() {
// Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled
// commands, running already-scheduled commands, removing finished or interrupted commands,
// and running subsystem periodic() methods. This must be called from the robot's periodic
// Runs the Scheduler. This is responsible for polling buttons, adding
// newly-scheduled
// commands, running already-scheduled commands, removing finished or
// interrupted commands,
// and running subsystem periodic() methods. This must be called from the
// robot's periodic
// block in order for anything in the Command-based framework to work.
CommandScheduler.getInstance().run();
}

/** This function is called once each time the robot enters Disabled mode. */
@Override
public void disabledInit() {}
public void disabledInit() {
}

@Override
public void disabledPeriodic() {}
public void disabledPeriodic() {
}

/** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */
/**
* This autonomous runs the autonomous command selected by your
* {@link RobotContainer} class.
*/
@Override
public void autonomousInit() {
m_autonomousCommand = m_robotContainer.getAutonomousCommand();
Expand All @@ -73,7 +98,8 @@ public void autonomousInit() {

/** This function is called periodically during autonomous. */
@Override
public void autonomousPeriodic() {}
public void autonomousPeriodic() {
}

@Override
public void teleopInit() {
Expand All @@ -88,7 +114,8 @@ public void teleopInit() {

/** This function is called periodically during operator control. */
@Override
public void teleopPeriodic() {}
public void teleopPeriodic() {
}

@Override
public void testInit() {
Expand All @@ -98,5 +125,6 @@ public void testInit() {

/** This function is called periodically during test mode. */
@Override
public void testPeriodic() {}
public void testPeriodic() {
}
}
Loading