Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 src/main/java/frc/robot/commands/Autos.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
// private Autos() {
// throw new UnsupportedOperationException("This is a utility class!");
// }
// }
// }
31 changes: 14 additions & 17 deletions src/main/java/frc/robot/subsystems/AlgaeArm/AlgaeArmIOCB.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

//if CB & PB IO files have equal values, remove from PB, which extends CB. Everything "private" must be "protected"
package frc.robot.subsystems.AlgaeArm;

import com.revrobotics.RelativeEncoder;
Expand All @@ -19,24 +19,21 @@

public class AlgaeArmIOCB implements AlgaeArmIO {

private final SparkMax armMotor =
new SparkMax(Constants.CompBotConstants.ALGAE_ARM_ID, MotorType.kBrushless); // placeholder
// // ID
private final RelativeEncoder encoder = armMotor.getEncoder();

private final double kP = 0.25;
private final double kI = 0.0;
private final double kD = 0.0;
protected final SparkMax armMotor = new SparkMax(Constants.CompBotConstants.ALGAE_ARM_ID, MotorType.kBrushless); // placeholder // ID
protected final RelativeEncoder encoder = armMotor.getEncoder();

protected final double kP = 0.025;
protected final double kI = 0.0;
protected final double kD = 0.0;

private final double POSITION_CONVERSION_FACTOR =
(1.0 / 5.0) * (1.0 / 5.0) * (18.0 / 36.0) * (360.0 / 1.0);
private final double VELOCITY_CONVERSION_FACTOR = POSITION_CONVERSION_FACTOR / 60.0;
protected final double POSITION_CONVERSION_FACTOR = (1.0 / 5.0) * (1.0 / 5.0) * (18.0 / 36.0) * (360.0 / 1.0);
protected final double VELOCITY_CONVERSION_FACTOR = POSITION_CONVERSION_FACTOR / 60.0;

private final double FORWARD_LIMIT = 180.0;
private final double REVERSE_LIMIT = -18.0;
private final SparkMaxConfig sparkMaxConfig = new SparkMaxConfig();
protected final double FORWARD_LIMIT = 150.0;
protected final double REVERSE_LIMIT = 10.0;
protected final SparkMaxConfig sparkMaxConfig = new SparkMaxConfig();

private final double MAX_OUTPUT = 0.5;
protected final double MAX_OUTPUT = 0.5;

/** Creates a new AlgaeArmIOPB. */
public AlgaeArmIOCB() {
Expand Down Expand Up @@ -94,4 +91,4 @@ public void enableReverseSoftLimit(boolean enabled) {
public void setEncoder(double value) {
encoder.setPosition(value);
}
}
}
92 changes: 3 additions & 89 deletions src/main/java/frc/robot/subsystems/AlgaeArm/AlgaeArmIOPB.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,94 +4,8 @@

package frc.robot.subsystems.AlgaeArm;

import com.revrobotics.RelativeEncoder;
import com.revrobotics.spark.SparkBase.ControlType;
import com.revrobotics.spark.SparkBase.PersistMode;
import com.revrobotics.spark.SparkBase.ResetMode;
import com.revrobotics.spark.SparkLowLevel.MotorType;
import com.revrobotics.spark.SparkMax;
import com.revrobotics.spark.config.ClosedLoopConfig;
import com.revrobotics.spark.config.EncoderConfig;
import com.revrobotics.spark.config.SoftLimitConfig;
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
import com.revrobotics.spark.config.SparkMaxConfig;
import frc.robot.Constants;

public class AlgaeArmIOPB implements AlgaeArmIO {

private final SparkMax armMotor =
new SparkMax(
Constants.PracticeBotConstants.ALGAE_ARM_ID, MotorType.kBrushless); // placeholder
// // ID
private final RelativeEncoder encoder = armMotor.getEncoder();

private final double kP = 0.025;
private final double kI = 0.0;
private final double kD = 0.0;

private final double POSITION_CONVERSION_FACTOR =
(1.0 / 5.0) * (1.0 / 5.0) * (18.0 / 36.0) * (360.0 / 1.0);
private final double VELOCITY_CONVERSION_FACTOR = POSITION_CONVERSION_FACTOR / 60.0;

private final double FORWARD_LIMIT = 150.0;
private final double REVERSE_LIMIT = -18.0;
private final SparkMaxConfig sparkMaxConfig = new SparkMaxConfig();

private final double MAX_OUTPUT = 0.5;

public class AlgaeArmIOPB extends AlgaeArmIOCB{
/** Creates a new AlgaeArmIOPB. */
public AlgaeArmIOPB() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to call super(); in the constructor

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the config code below is identical to the config code in the super class, delete this

sparkMaxConfig.idleMode(IdleMode.kBrake);
sparkMaxConfig.inverted(false);

ClosedLoopConfig closedLoopConfig = new ClosedLoopConfig();
closedLoopConfig.pid(kP, kI, kD);
closedLoopConfig.minOutput(-MAX_OUTPUT);
closedLoopConfig.maxOutput(MAX_OUTPUT);
sparkMaxConfig.apply(closedLoopConfig);

EncoderConfig encoderConfig = new EncoderConfig();
encoderConfig.positionConversionFactor(POSITION_CONVERSION_FACTOR);
encoderConfig.velocityConversionFactor(VELOCITY_CONVERSION_FACTOR);
sparkMaxConfig.apply(encoderConfig);

SoftLimitConfig softLimitConfig = new SoftLimitConfig();
softLimitConfig.forwardSoftLimit(FORWARD_LIMIT);
softLimitConfig.forwardSoftLimitEnabled(true);
softLimitConfig.reverseSoftLimit(REVERSE_LIMIT);
softLimitConfig.reverseSoftLimitEnabled(true);
sparkMaxConfig.apply(softLimitConfig);

armMotor.configure(
sparkMaxConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
}

public void updateInputs(AlgaeArmIOInputs inputs) {
inputs.algaeArmAngle = encoder.getPosition();
inputs.algaeArmVelocity = encoder.getVelocity();
inputs.algaeArmVoltage = armMotor.getBusVoltage() * armMotor.getAppliedOutput();
inputs.algaeArmCurrent = armMotor.getOutputCurrent();
inputs.algaeArmTemp = armMotor.getMotorTemperature();
}

public void setDutyCycle(double dutyCycle) {
armMotor.set(dutyCycle);
}

public void setPosition(double position) {
armMotor.getClosedLoopController().setReference(position, ControlType.kPosition);
}

public void enableReverseSoftLimit(boolean enabled) {
sparkMaxConfig.softLimit.reverseSoftLimitEnabled(enabled);
}

/**
* method for updating the encoder position
*
* @param value new encoder position in motor rotations
*/
public void setEncoder(double value) {
encoder.setPosition(value);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
import com.revrobotics.spark.SparkMax;
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
import com.revrobotics.spark.config.SparkMaxConfig;

import frc.robot.Constants;

public class AlgaeRollerIOCB implements AlgaeRollerIO {
private final SparkMax motor =
new SparkMax(Constants.CompBotConstants.ALGAE_ROLLER, MotorType.kBrushless);
private final SparkMaxConfig config = new SparkMaxConfig();
private final RelativeEncoder encoder = motor.getEncoder();
protected SparkMax motor;
protected SparkMaxConfig config = new SparkMaxConfig();
protected RelativeEncoder encoder;

/** Creates a new AlgaeIntakeRollerIOPB. */
public AlgaeRollerIOCB() {
motor = new SparkMax(Constants.CompBotConstants.ALGAE_ROLLER, MotorType.kBrushless);
encoder = motor.getEncoder();

config.inverted(true);
config.idleMode(IdleMode.kCoast);
config.smartCurrentLimit(20, 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,22 @@

package frc.robot.subsystems.AlgaeRoller;

import com.revrobotics.RelativeEncoder;
import com.revrobotics.spark.SparkBase.PersistMode;
import com.revrobotics.spark.SparkBase.ResetMode;
import com.revrobotics.spark.SparkLowLevel.MotorType;
import com.revrobotics.spark.SparkMax;
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
import com.revrobotics.spark.config.SparkMaxConfig;
import com.revrobotics.spark.SparkMax;
import frc.robot.Constants;

public class AlgaeRollerIOPB implements AlgaeRollerIO {
private final SparkMax motor =
new SparkMax(Constants.PracticeBotConstants.ALGAE_ROLLER, MotorType.kBrushless);
private final SparkMaxConfig config = new SparkMaxConfig();
private final RelativeEncoder encoder = motor.getEncoder();
public class AlgaeRollerIOPB extends AlgaeRollerIOCB {

/** Creates a new AlgaeIntakeRollerIOPB. */
public AlgaeRollerIOPB() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to include the super(); keyword

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I implement the keyword? Do I use it after extends and then state the class a second time (with IOCB layer)?

super();
motor = new SparkMax(Constants.PracticeBotConstants.ALGAE_ROLLER, MotorType.kBrushless);

config.inverted(true);
config.idleMode(IdleMode.kBrake);
motor.configure(config, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
}

public void setDutyCycle(double dutyCycle) {
motor.set(dutyCycle);
}

public void updateInputs(AlgaeRollerIOInputs inputs) {
inputs.rollerDutyCycle = motor.get();
inputs.rollerPosition = encoder.getPosition();
inputs.rollerVelocity = encoder.getVelocity();
inputs.rollerCurrent = motor.getAppliedOutput();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,26 @@

public class AlgaeShooterIOCB implements AlgaeShooterIO {

private final SparkFlex algaeShooterMotorFront =
new SparkFlex(
Constants.CompBotConstants.ALGAE_SHOOTER_FRONT_ID, MotorType.kBrushless); // no ID
private final SparkFlex algaeShooterMotorBack =
new SparkFlex(
Constants.CompBotConstants.ALGAE_SHOOTER_BACK_ID, MotorType.kBrushless); // no ID
protected final SparkFlex algaeShooterMotorFront;
protected final SparkFlex algaeShooterMotorBack;

private SparkFlexConfig frontConfig = new SparkFlexConfig();
private SparkFlexConfig backConfig = new SparkFlexConfig();
private final double positionConversionFactor = 1.0;
protected SparkFlexConfig frontConfig = new SparkFlexConfig();
protected SparkFlexConfig backConfig = new SparkFlexConfig();
protected final double positionConversionFactor = 1.0;

/** Creates a new AlgaeShooterIOWB. */
public AlgaeShooterIOCB() {
final double kP = 0.00035;
this(
new SparkFlex(Constants.CompBotConstants.ALGAE_SHOOTER_FRONT_ID, MotorType.kBrushless),
new SparkFlex(Constants.CompBotConstants.ALGAE_SHOOTER_BACK_ID, MotorType.kBrushless)
);
}

public AlgaeShooterIOCB(SparkFlex algaeShooterMotorFront, SparkFlex algaeShooterMotorBack) {
this.algaeShooterMotorFront = algaeShooterMotorFront;
this.algaeShooterMotorBack = algaeShooterMotorBack;

final double kP = 0.0;
final double kI = 0.0;
final double kD = 0.0;
final double kFF = 0.00015;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,25 @@

package frc.robot.subsystems.AlgaeShooter;

import com.revrobotics.spark.SparkBase.ControlType;
import com.revrobotics.spark.SparkBase.PersistMode;
import com.revrobotics.spark.SparkBase.ResetMode;
import com.revrobotics.spark.SparkFlex;
import com.revrobotics.spark.SparkLowLevel.MotorType;
import com.revrobotics.spark.config.ClosedLoopConfig;
import com.revrobotics.spark.config.EncoderConfig;
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
import com.revrobotics.spark.config.SparkFlexConfig;
import frc.robot.Constants;

public class AlgaeShooterIOPB implements AlgaeShooterIO {

private final SparkFlex algaeShooterMotorFront =
new SparkFlex(
Constants.PracticeBotConstants.ALGAE_SHOOTER_FRONT_ID, MotorType.kBrushless); // no ID
private final SparkFlex algaeShooterMotorBack =
new SparkFlex(
Constants.PracticeBotConstants.ALGAE_SHOOTER_BACK_ID, MotorType.kBrushless); // no ID

private SparkFlexConfig frontConfig = new SparkFlexConfig();
private SparkFlexConfig backConfig = new SparkFlexConfig();
private final double positionConversionFactor = 1.0;
import frc.robot.Constants;

public class AlgaeShooterIOPB extends AlgaeShooterIOCB {

/** Creates a new AlgaeShooterIOWB. */
public AlgaeShooterIOPB() {
super(
new SparkFlex(Constants.PracticeBotConstants.ALGAE_SHOOTER_FRONT_ID, MotorType.kBrushless),
new SparkFlex(Constants.PracticeBotConstants.ALGAE_SHOOTER_BACK_ID, MotorType.kBrushless)
);

// TODO: add values
final double kP = 0.0001;
final double kI = 0.0;
Expand All @@ -55,30 +48,4 @@ public AlgaeShooterIOPB() {
algaeShooterMotorBack.configure(
backConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
}

public void updateInputs(AlgaeShooterIOInputs inputs) {
inputs.algaeShooterFrontVoltage = algaeShooterMotorFront.getBusVoltage();
inputs.algaeShooterFrontPosition = algaeShooterMotorFront.getEncoder().getPosition();
inputs.algaeShooterFrontVelocity = algaeShooterMotorFront.getEncoder().getVelocity();
inputs.algaeShooterFrontCurrent = algaeShooterMotorFront.getOutputCurrent();
inputs.algaeShooterFrontTemperature = algaeShooterMotorFront.getMotorTemperature();

inputs.algaeShooterBackVoltage = algaeShooterMotorBack.getBusVoltage();
inputs.algaeShooterBackPosition = algaeShooterMotorBack.getEncoder().getPosition();
inputs.algaeShooterBackVelocity = algaeShooterMotorBack.getEncoder().getVelocity();
inputs.algaeShooterBackCurrent = algaeShooterMotorBack.getOutputCurrent();
inputs.algaeShooterBackTemperature = algaeShooterMotorBack.getMotorTemperature();
}

public void setDutyCycle(double dutyCycle) {
algaeShooterMotorFront.set(dutyCycle);
}

public void setVelocity(double velocity) {
algaeShooterMotorFront.getClosedLoopController().setReference(velocity, ControlType.kVelocity);
}

public void stop() {
algaeShooterMotorFront.stopMotor();
}
}
37 changes: 17 additions & 20 deletions src/main/java/frc/robot/subsystems/AlgaeTilt/AlgaeTiltIOCB.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,34 @@
import com.revrobotics.spark.config.EncoderConfig;
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
import com.revrobotics.spark.config.SparkMaxConfig;

import frc.robot.Constants;

public class AlgaeTiltIOCB implements AlgaeTiltIO {
private final SparkMax motor =
new SparkMax(Constants.CompBotConstants.ALGAE_TILT, MotorType.kBrushless);
private final AbsoluteEncoder absEncoder =
motor.getAbsoluteEncoder(); // TODO: make absolute when we get one!!
// private final RelativeEncoder encoder = motor.getEncoder(); // TODO: make absolute when we get
// one!!
protected SparkMax motor;
protected AbsoluteEncoder absEncoder;
// private final RelativeEncoder encoder = motor.getEncoder(); // TODO: make absolute when we get one!!

private final double kP = 4;
private final double kI = 0.0;
private final double kD = 0.0;
protected double kP;
protected final double kI = 0.0;
protected final double kD = 0.0;

private final double forwardLimit = 38.0;
private final double reverseLimit = -10.0;
protected final double forwardLimit = 38.0;
protected final double reverseLimit = -10.0;

private final double ZERO_OFFSET = 0.7170253;
protected final double ZERO_OFFSET = 0.7170253;
// 0.5551491; //0.7218491 + 0.833;

private final double positionConversionFactor = 1.0;
private final SparkMaxConfig sparkMaxConfig = new SparkMaxConfig();
protected final double positionConversionFactor = 1.0;
protected final SparkMaxConfig sparkMaxConfig = new SparkMaxConfig();

/** Creates a new AlgaeIntakeIOPB. */
public AlgaeTiltIOCB() {
motor = new SparkMax(Constants.CompBotConstants.ALGAE_TILT, MotorType.kBrushless);
absEncoder = motor.getAbsoluteEncoder(); // TODO: make absolute when we get one!!

kP = 4;

sparkMaxConfig.idleMode(IdleMode.kBrake);
sparkMaxConfig.inverted(true);
sparkMaxConfig.smartCurrentLimit(20, 5);
Expand Down Expand Up @@ -94,10 +97,4 @@ public void updateInputs(AlgaeTiltIOInputs inputs) {
inputs.armVelocityAbsolute = absEncoder.getVelocity();
inputs.armAmps = motor.getOutputCurrent();
}

// @Override
// public void setEncoder(double value) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'setEncoder'");
// }
}
Loading
Loading