Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: feat(motors): implement all standard FRC motors #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import com.revrobotics.SparkRelativeEncoder;
import edu.wpi.first.wpilibj.RobotBase;
import edu.wpi.first.wpilibj.motorcontrol.MotorController;

Check warning on line 5 in src/main/java/net/frc5183/librobot/hardware/motor/SparkMaxMotor.java

View workflow job for this annotation

GitHub Actions / pmd

Unused import 'edu.wpi.first.wpilibj.motorcontrol.MotorController'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. If some imports cannot be resolved, for instance because you run PMD with an incomplete auxiliary classpath, some imports may be conservatively marked as used even if they're not to avoid false positives. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.4.0/pmd_rules_java_codestyle.html#unnecessaryimport
import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkLowLevel.MotorType;
import net.frc5183.librobot.hardware.encoder.Encoder;
import net.frc5183.librobot.hardware.encoder.SparkMaxEncoder;

/**
* A wrapper class around CANSparkMax to make it compatible with other motor types
* Represents a Spark Max motor controller.
*/
public class SparkMaxMotor extends Motor implements EncodedMotor {
private final CANSparkMax motor;
Expand Down Expand Up @@ -68,12 +68,7 @@
motor.stopMotor();
}

@Override
public MotorController getRawMotor() {
return motor;
}

public CANSparkMax getTrueRawMotor() {
public CANSparkMax getRawMotor() {
return motor;
}

Expand Down
62 changes: 62 additions & 0 deletions src/main/java/net/frc5183/librobot/hardware/motor/SparkMotor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package net.frc5183.librobot.hardware.motor;

import edu.wpi.first.wpilibj.motorcontrol.Spark;

/**
* Represents a Spark motor controller.
*/
public class SparkMotor extends Motor {
private final Spark motor;

public SparkMotor(int port) {
this.motor = new Spark(port);
}

public SparkMotor(Spark motor) {
this.motor = motor;
}

@Override
public void set(double speed) {
motor.set(speed);
}

@Override
public void periodic() {
motor.feed();
}

@Override
public double get() {
return motor.get();
}

@Override
public void setSafety(boolean on) {
motor.setSafetyEnabled(on);
}

@Override
public void setInverted(boolean inverted) {
motor.setInverted(inverted);
}

@Override
public boolean getInverted() {
return motor.getInverted();
}

@Override
public void disable() {
motor.disable();
}

@Override
public void stopMotor() {
motor.stopMotor();
}

public Spark getRawMotor() {
return motor;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package net.frc5183.librobot.hardware.motor;

import com.ctre.phoenix6.hardware.TalonFX;
import edu.wpi.first.wpilibj.motorcontrol.MotorController;

Check warning on line 4 in src/main/java/net/frc5183/librobot/hardware/motor/TalonFXMotor.java

View workflow job for this annotation

GitHub Actions / pmd

Unused import 'edu.wpi.first.wpilibj.motorcontrol.MotorController'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. If some imports cannot be resolved, for instance because you run PMD with an incomplete auxiliary classpath, some imports may be conservatively marked as used even if they're not to avoid false positives. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.4.0/pmd_rules_java_codestyle.html#unnecessaryimport
Baconing marked this conversation as resolved.
Show resolved Hide resolved

/**
* Represents a TalonFX motor controller.
*/
public class TalonFXMotor extends Motor {
private final TalonFX motor;

public TalonFXMotor(int port) {
motor = new TalonFX(port);
}

public TalonFXMotor(TalonFX motor) {
this.motor = motor;
}

@Override
public void set(double speed) {
motor.set(speed);
}

@Override
public void periodic() {
motor.feed();
}

@Override
public double get() {
return motor.get();
}

@Override
public void setSafety(boolean on) {
motor.setSafetyEnabled(on);
}

@Override
public void setInverted(boolean inverted) {
motor.setInverted(inverted);
}

@Override
public boolean getInverted() {
return motor.getInverted();
}

@Override
public void disable() {
motor.disable();
}

@Override
public void stopMotor() {
motor.stopMotor();
}

public TalonFX getRawMotor() {
return motor;
}
}
Loading