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

Commit

Permalink
Implement shooter subsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty committed May 14, 2024
1 parent 17d9825 commit 9fc16c1
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 64 deletions.
88 changes: 45 additions & 43 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,51 @@ plugins {
id 'com.diffplug.spotless' version '6.25.0'
}

spotless {
enforceCheck false

java {
target fileTree('.') {
include '**/*.java'
exclude '**/build/**', '**/build-*/**'
}
toggleOffOn()
googleJavaFormat()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
groovyGradle {
target fileTree('.') {
include '**/*.gradle'
exclude '**/build/**', '**/build-*/**'
}
greclipse()
indentWithSpaces(4)
trimTrailingWhitespace()
endWithNewline()
}
format 'xml', {
target fileTree('.') {
include '**/*.xml'
exclude '**/build/**', '**/build-*/**'
}
eclipseWtp('xml')
trimTrailingWhitespace()
indentWithSpaces(2)
endWithNewline()
}
format 'misc', {
target fileTree('.') {
include '**/*.md', '**/.gitignore'
exclude '**/build/**', '**/build-*/**'
}
trimTrailingWhitespace()
indentWithSpaces(2)
endWithNewline()
}
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down Expand Up @@ -104,46 +149,3 @@ wpi.java.configureTestTasks(test)
tasks.withType(JavaCompile) {
options.compilerArgs.add '-XDstringConcat=inline'
}

spotless {
java {
target fileTree('.') {
include '**/*.java'
exclude '**/build/**', '**/build-*/**'
}
toggleOffOn()
googleJavaFormat()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
groovyGradle {
target fileTree('.') {
include '**/*.gradle'
exclude '**/build/**', '**/build-*/**'
}
greclipse()
indentWithSpaces(4)
trimTrailingWhitespace()
endWithNewline()
}
format 'xml', {
target fileTree('.') {
include '**/*.xml'
exclude '**/build/**', '**/build-*/**'
}
eclipseWtp('xml')
trimTrailingWhitespace()
indentWithSpaces(2)
endWithNewline()
}
format 'misc', {
target fileTree('.') {
include '**/*.md', '**/.gitignore'
exclude '**/build/**', '**/build-*/**'
}
trimTrailingWhitespace()
indentWithSpaces(2)
endWithNewline()
}
}
8 changes: 8 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package frc.robot;

public final class Constants {
public static final int shooterPort = 99;
public static final double shooterP = 1;
public static final double shooterI = 1;
public static final double shooterD = 1;
}
20 changes: 15 additions & 5 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
package frc.robot;

import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMaxLowLevel;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import frc.robot.subsystems.Shooter;

public class Robot extends TimedRobot {
private Command m_autonomousCommand;
private Shooter m_shooter;

private RobotContainer m_robotContainer;
private Command getAutonomousCommand() {
return null;
}

@Override
public void robotInit() {
m_robotContainer = new RobotContainer();
private void configureBindings() {}

@SuppressWarnings("removal")
public Robot() {
m_shooter =
new Shooter(
new CANSparkMax(Constants.shooterPort, CANSparkMaxLowLevel.MotorType.kBrushless));
}

@Override
Expand All @@ -30,7 +40,7 @@ public void disabledExit() {}

@Override
public void autonomousInit() {
m_autonomousCommand = m_robotContainer.getAutonomousCommand();
m_autonomousCommand = getAutonomousCommand();

if (m_autonomousCommand != null) {
m_autonomousCommand.schedule();
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/frc/robot/RobotContainer.java

This file was deleted.

43 changes: 43 additions & 0 deletions src/main/java/frc/robot/subsystems/Shooter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package frc.robot.subsystems;

import com.revrobotics.CANSparkMax;
import com.revrobotics.RelativeEncoder;
import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import frc.robot.Constants;

public class Shooter extends SubsystemBase {
private PIDController m_pid;
private CANSparkMax m_motor;
private RelativeEncoder m_encoder;

public Shooter(CANSparkMax motor) {
m_motor = motor;
m_encoder = m_motor.getEncoder();
m_pid = new PIDController(Constants.shooterP, Constants.shooterI, Constants.shooterD);
}

public Command spinup(double speed) {
m_pid.setSetpoint(speed);
return Commands.run(
() -> {
double rads = m_encoder.getVelocity() * 2 * 3.14159;
m_motor.setVoltage(m_pid.calculate(rads));
});
}

public Command holdspeed() {
return Commands.run(
() -> {
double rads = m_encoder.getVelocity() * 2 * 3.14159;
m_motor.setVoltage(m_pid.calculate(rads));
});
}

public Trigger atSetpoint() {
return new Trigger(m_pid::atSetpoint);
}
}
74 changes: 74 additions & 0 deletions vendordeps/REVLib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"fileName": "REVLib.json",
"name": "REVLib",
"version": "2024.2.4",
"frcYear": "2024",
"uuid": "3f48eb8c-50fe-43a6-9cb7-44c86353c4cb",
"mavenUrls": [
"https://maven.revrobotics.com/"
],
"jsonUrl": "https://software-metadata.revrobotics.com/REVLib-2024.json",
"javaDependencies": [
{
"groupId": "com.revrobotics.frc",
"artifactId": "REVLib-java",
"version": "2024.2.4"
}
],
"jniDependencies": [
{
"groupId": "com.revrobotics.frc",
"artifactId": "REVLib-driver",
"version": "2024.2.4",
"skipInvalidPlatforms": true,
"isJar": false,
"validPlatforms": [
"windowsx86-64",
"windowsx86",
"linuxarm64",
"linuxx86-64",
"linuxathena",
"linuxarm32",
"osxuniversal"
]
}
],
"cppDependencies": [
{
"groupId": "com.revrobotics.frc",
"artifactId": "REVLib-cpp",
"version": "2024.2.4",
"libName": "REVLib",
"headerClassifier": "headers",
"sharedLibrary": false,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"windowsx86-64",
"windowsx86",
"linuxarm64",
"linuxx86-64",
"linuxathena",
"linuxarm32",
"osxuniversal"
]
},
{
"groupId": "com.revrobotics.frc",
"artifactId": "REVLib-driver",
"version": "2024.2.4",
"libName": "REVLibDriver",
"headerClassifier": "headers",
"sharedLibrary": false,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"windowsx86-64",
"windowsx86",
"linuxarm64",
"linuxx86-64",
"linuxathena",
"linuxarm32",
"osxuniversal"
]
}
]
}

0 comments on commit 9fc16c1

Please sign in to comment.