-
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.
Nitay - made roller into a polymorphism system
- Loading branch information
Showing
18 changed files
with
159 additions
and
29 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
13 changes: 13 additions & 0 deletions
13
src/main/java/training/subsystems/ArmSubsystems/roller/IRoller.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,13 @@ | ||
package training.subsystems.ArmSubsystems.roller; | ||
|
||
import training.subsystems.ArmSubsystems.elbow.ElbowInputsAutoLogged; | ||
|
||
public interface IRoller { | ||
|
||
public void setPower(double power); | ||
|
||
public void setVoltage(double voltage); | ||
|
||
public void updateInputs(RollerInputsAutoLogged inputs); | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/training/subsystems/ArmSubsystems/roller/NeoRoller/NeoConstants.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,8 @@ | ||
package training.subsystems.ArmSubsystems.roller.NeoRoller; | ||
|
||
|
||
public class NeoConstants { | ||
|
||
protected static final int ID = 22; | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/training/subsystems/ArmSubsystems/roller/NeoRoller/NeoRoller.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,31 @@ | ||
package training.subsystems.ArmSubsystems.roller.NeoRoller; | ||
|
||
import com.revrobotics.CANSparkLowLevel; | ||
import com.revrobotics.CANSparkMax; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import training.subsystems.ArmSubsystems.roller.IRoller; | ||
import training.subsystems.ArmSubsystems.roller.RollerInputsAutoLogged; | ||
|
||
public class NeoRoller implements IRoller { | ||
|
||
private final CANSparkMax motor; | ||
|
||
|
||
public NeoRoller() { | ||
this.motor = new CANSparkMax(NeoConstants.ID, CANSparkLowLevel.MotorType.kBrushless); | ||
} | ||
|
||
public void setPower(double power) { | ||
motor.set(power); | ||
} | ||
|
||
public void setVoltage(double voltage) { | ||
motor.setVoltage(voltage); | ||
} | ||
|
||
public void updateInputs(RollerInputsAutoLogged inputs) { | ||
inputs.position= Rotation2d.fromRotations(motor.getEncoder().getPosition()); | ||
inputs.velocity=Rotation2d.fromRotations(motor.getEncoder().getVelocity()); | ||
} | ||
|
||
} |
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
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
16 changes: 16 additions & 0 deletions
16
src/main/java/training/subsystems/ArmSubsystems/roller/RollerFactory.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,16 @@ | ||
package training.subsystems.ArmSubsystems.roller; | ||
|
||
import training.Robot; | ||
import training.subsystems.ArmSubsystems.roller.NeoRoller.NeoRoller; | ||
import training.subsystems.ArmSubsystems.roller.simulationRoller.SimulationRoller; | ||
|
||
public class RollerFactory { | ||
|
||
public static IRoller create() { | ||
return switch (Robot.ROBOT_TYPE) { | ||
case SYNCOPA -> new NeoRoller(); | ||
case SIMULATION -> new SimulationRoller(); | ||
}; | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/training/subsystems/ArmSubsystems/roller/RollerInputs.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,13 @@ | ||
package training.subsystems.ArmSubsystems.roller; | ||
|
||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
@AutoLog | ||
public class RollerInputs { | ||
|
||
public Rotation2d position; | ||
public Rotation2d velocity; | ||
public double voltage; | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...n/java/training/subsystems/ArmSubsystems/roller/simulationRoller/SimulationConstants.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,13 @@ | ||
package training.subsystems.ArmSubsystems.roller.simulationRoller; | ||
|
||
public class SimulationConstants { | ||
|
||
protected static final int ID = 22; | ||
public static final int NUMBER_OF_MOTORS = 1; | ||
|
||
public static final double GEAR_RATIO = 1; | ||
|
||
public static final double MOMENT_OF_INERTIA = 1; | ||
|
||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...main/java/training/subsystems/ArmSubsystems/roller/simulationRoller/SimulationRoller.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,39 @@ | ||
package training.subsystems.ArmSubsystems.roller.simulationRoller; | ||
|
||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.wpilibj.simulation.DCMotorSim; | ||
import training.GlobalConstants; | ||
import training.subsystems.ArmSubsystems.elbow.ElbowInputsAutoLogged; | ||
import training.subsystems.ArmSubsystems.roller.IRoller; | ||
import training.subsystems.ArmSubsystems.roller.RollerInputsAutoLogged; | ||
|
||
public class SimulationRoller implements IRoller { | ||
|
||
private final DCMotorSim motor; | ||
|
||
|
||
public SimulationRoller() { | ||
this.motor = new DCMotorSim( | ||
DCMotor.getNEO(SimulationConstants.NUMBER_OF_MOTORS), | ||
SimulationConstants.GEAR_RATIO, | ||
SimulationConstants.MOMENT_OF_INERTIA | ||
); | ||
} | ||
|
||
public void setPower(double power) { | ||
setVoltage(power * GlobalConstants.MAX_BATTERY_VOLTAGE); | ||
} | ||
|
||
public void setVoltage(double voltage) { | ||
motor.setInputVoltage(voltage); | ||
} | ||
|
||
@Override | ||
public void updateInputs(RollerInputsAutoLogged inputs) { | ||
inputs.position= Rotation2d.fromRotations(motor.getAngularPositionRotations()); | ||
inputs.velocity=Rotation2d.fromRadians(motor.getAngularVelocityRadPerSec()); | ||
} | ||
|
||
|
||
} |