Skip to content

Commit

Permalink
Basic ShooterIOSparkMax (#10)
Browse files Browse the repository at this point in the history
* added ShooterIOSparkMax

* spotless Apply

* updated gear ratio

* added ShooterIOSparkMax as io for tankBot

* Added Comments

* Spotless Apply

---------

Co-authored-by: Nilesh Agarwalla <[email protected]>
  • Loading branch information
StewardHail3433 and BrownGenius authored Jan 20, 2024
1 parent f58f702 commit bb4cc32
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import frc.robot.subsystems.intake.IntakeBase;
import frc.robot.subsystems.intake.IntakeIOSim;
import frc.robot.subsystems.shooter.ShooterIOSim;
import frc.robot.subsystems.shooter.ShooterIOSparkMax;
import frc.robot.subsystems.shooter.ShooterSubsystem;

public class RobotContainer {
Expand All @@ -25,13 +26,13 @@ public RobotContainer() {
controller = new CommandXboxController(0);

boolean swerveBot = false;
boolean tankBot = false;
boolean tankBot = true;

if (swerveBot) {
shooter = null;
intake = null;
} else if (tankBot) {
shooter = null;
shooter = new ShooterSubsystem(new ShooterIOSparkMax());
intake = null;
} else {
shooter = new ShooterSubsystem(new ShooterIOSim());
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/frc/robot/subsystems/shooter/ShooterIOSparkMax.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package frc.robot.subsystems.shooter;

import com.revrobotics.CANSparkLowLevel.MotorType;
import com.revrobotics.CANSparkMax;
import com.revrobotics.RelativeEncoder;
import edu.wpi.first.math.util.Units;

public class ShooterIOSparkMax implements ShooterIO {
// Gear ratio for the shooter mechanism
private static final double GEAR_RATIO = 5.0;

// define the 2 SparkMax Controllers. A leader, and a follower
private final CANSparkMax leader = new CANSparkMax(0, MotorType.kBrushless);
private final CANSparkMax follower = new CANSparkMax(1, MotorType.kBrushless);

// Gets the NEO encoder
private final RelativeEncoder encoder = leader.getEncoder();

public ShooterIOSparkMax() {
// leader motor is not inverted, and set follower motor to follow the leader
leader.setInverted(false);
follower.follow(leader, false);
}

@Override
public void updateInputs(ShooterIOInputs inputs) {
// Set velocityRadPerSec to the encoder velocity(rotationsPerMinute) divided by the gear ratio
// and converted into Radians Per Second
inputs.velocityRadPerSec =
Units.rotationsPerMinuteToRadiansPerSecond(encoder.getVelocity() / GEAR_RATIO);
// Get applied voltage from the leader motor
inputs.appliedVolts = leader.getAppliedOutput() * leader.getBusVoltage();
}

@Override
public void setVoltage(double volts) {
// Set the voltage output for the leader motor
leader.setVoltage(volts);
}
}
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.0",
"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.0"
}
],
"jniDependencies": [
{
"groupId": "com.revrobotics.frc",
"artifactId": "REVLib-driver",
"version": "2024.2.0",
"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.0",
"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.0",
"libName": "REVLibDriver",
"headerClassifier": "headers",
"sharedLibrary": false,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"windowsx86-64",
"windowsx86",
"linuxarm64",
"linuxx86-64",
"linuxathena",
"linuxarm32",
"osxuniversal"
]
}
]
}

0 comments on commit bb4cc32

Please sign in to comment.