-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from bow4290/better-implementation
Signifigantly better version of GenericMotor.java, using interfaces and composing implementations with official APIs
- Loading branch information
Showing
4 changed files
with
97 additions
and
98 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
src/main/java/frc/robot/lib/GenericMotors/GenericMotor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package frc.robot.lib.GenericMotors; | ||
|
||
/** | ||
* An unofficial generic for motors, similiar to MotorController interface. Not entirely intended for every-day use cases. | ||
*/ | ||
public interface GenericMotor { | ||
|
||
void setSpeed(double speedPercentage); | ||
|
||
double getSpeed(); | ||
|
||
void setInverted(boolean isInverted); | ||
|
||
boolean getInverted(); | ||
|
||
|
||
|
||
|
||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/frc/robot/lib/GenericMotors/GenericSparkMax.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package frc.robot.lib.GenericMotors; | ||
|
||
import com.revrobotics.CANSparkMax; | ||
import com.revrobotics.CANSparkLowLevel.MotorType; | ||
|
||
public class GenericSparkMax implements GenericMotor { | ||
int motorID; | ||
|
||
CANSparkMax motorSparkMax; | ||
MotorType motorType; | ||
|
||
public GenericSparkMax(int motorID, MotorType motorType){ | ||
this.motorID = motorID; | ||
this.motorType = motorType; | ||
|
||
this.motorSparkMax = new CANSparkMax(this.motorID, this.motorType); | ||
System.out.printf("New CanSparkMax constructed with GenericSparkMax at motor ID: %d", this.motorID); | ||
} | ||
|
||
@Override | ||
public void setSpeed(double speedPercentage) { | ||
motorSparkMax.set(speedPercentage); | ||
} | ||
|
||
@Override | ||
public double getSpeed() { | ||
return motorSparkMax.get(); | ||
} | ||
|
||
@Override | ||
public void setInverted(boolean isInverted) { | ||
motorSparkMax.setInverted(isInverted); | ||
} | ||
|
||
@Override | ||
public boolean getInverted() { | ||
return motorSparkMax.getInverted(); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/frc/robot/lib/GenericMotors/GenericTalonFX.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package frc.robot.lib.GenericMotors; | ||
|
||
|
||
import com.ctre.phoenix6.hardware.TalonFX; | ||
|
||
public class GenericTalonFX implements GenericMotor{ | ||
TalonFX motorTalon; | ||
int motorID; | ||
|
||
public GenericTalonFX(int motorID){ | ||
this.motorID = motorID; | ||
|
||
this.motorTalon = new TalonFX(this.motorID); | ||
System.out.printf("New TalonFX constructed with GenericTalonFX at motor ID: %d", this.motorID); | ||
} | ||
|
||
@Override | ||
public void setSpeed(double speedPercentage) { | ||
motorTalon.set(speedPercentage); | ||
} | ||
|
||
@Override | ||
public double getSpeed() { | ||
return motorTalon.get(); | ||
} | ||
|
||
@Override | ||
public void setInverted(boolean isInverted) { | ||
motorTalon.setInverted(isInverted); | ||
} | ||
|
||
@Override | ||
public boolean getInverted() { | ||
return motorTalon.getInverted(); | ||
} | ||
|
||
} |