Skip to content

Commit

Permalink
refactored naming, changed modifiers, and reoganized a bit. configura…
Browse files Browse the repository at this point in the history
…tion and tuning methods still need to be written
  • Loading branch information
mattperls-code committed Jan 28, 2024
1 parent 996ae50 commit f1ac556
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 52 deletions.
10 changes: 7 additions & 3 deletions src/main/java/org/robolancers321/RobotContainer.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
/* (C) Robolancers 2024 */
package org.robolancers321;

import org.robolancers321.subsystem.Sucker;

import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import org.robolancers321.subsystem.Intake;

public class RobotContainer {

public Intake intake = new Intake();
private Sucker sucker;

public RobotContainer() {
this.sucker = Sucker.getInstance();

this.sucker.setDefaultCommand(this.sucker.tuneController());

configureBindings();
}

Expand Down
49 changes: 0 additions & 49 deletions src/main/java/org/robolancers321/subsystem/Intake.java

This file was deleted.

112 changes: 112 additions & 0 deletions src/main/java/org/robolancers321/subsystem/Sucker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/* (C) Robolancers 2024 */
package org.robolancers321.subsystem;

import com.revrobotics.CANSparkLowLevel.MotorType;
import com.revrobotics.CANSparkMax;
import com.revrobotics.RelativeEncoder;
import com.revrobotics.SparkPIDController;
import com.revrobotics.CANSparkBase.ControlType;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class Sucker extends SubsystemBase {
/*
* Singleton
*/

private static Sucker instance = null;

public static Sucker getInstance(){
if (instance == null) instance = new Sucker();

return instance;
}

/*
* Constants
*/

private static final int kMotorPort = 0;

private static final boolean kInvertMotor = false;
private static final int kCurrentLimit = 20;

private static final double kP = 0.0;
private static final double kI = 0.0;
private static final double kD = 0.0;
private static final double kFF = 0.01;

private static final double kInRPM = -2000;
private static final double kOutRPM = 1000;

/*
* Implementation
*/

private CANSparkMax motor;
private RelativeEncoder encoder;
private SparkPIDController controller;

private Sucker() {
this.motor = new CANSparkMax(kMotorPort, MotorType.kBrushless);
this.encoder = this.motor.getEncoder();
this.controller = this.motor.getPIDController();

this.configureMotor();
this.configureEncoder();
this.configureController();
}

private void configureMotor(){
// TODO: inversion, current limit, idle mode, voltage compensation
}

public void configureEncoder(){
// TODO: set velocity conversion factor to 1
}

public void configureController(){
// TODO: set kP, kI, kD, kFF on controller
}

public double getVelocityRPM(){
return this.encoder.getVelocity();
}

private void doSendables(){
SmartDashboard.putNumber("sucker velocity rpm", this.getVelocityRPM());
}

@Override
public void periodic() {
this.doSendables();
}

public void initTuning(){
// TODO: put default values for kP, kI, kD, kFF on SmartDashboard
}

public void tune(){
// TODO: read the values for kP, kI, kD, kFF from SmartDashboard and update your controller
}

public Command in() {
return run(() -> this.controller.setReference(kInRPM, ControlType.kVelocity));
}

public Command out(double power) {
return run(() -> this.controller.setReference(kOutRPM, ControlType.kVelocity));
}

public Command off() {
return runOnce(() -> this.controller.setReference(0.0, ControlType.kVelocity));
}

public Command tuneController(){
initTuning();

return run(this::tune);
}
}

0 comments on commit f1ac556

Please sign in to comment.