This repository has been archived by the owner on May 19, 2024. It is now read-only.
-
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.
feat(shooter): Add simulated hardware.
- Loading branch information
1 parent
aa8437c
commit 44c4be5
Showing
10 changed files
with
296 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package frc.robot.shooter; | ||
|
||
/** Beam break sensor hardware interface. */ | ||
public interface BeamBreakSensorIO { | ||
|
||
/** Values for the beam break sensor hardware interface. */ | ||
public static class BeamBreakSensorIOValues { | ||
/** If true, the beam break sensor is broken. */ | ||
public boolean isBroken = false; | ||
} | ||
|
||
/** | ||
* Updates the beam break sensor's values. | ||
* | ||
* @param values | ||
*/ | ||
public void update(BeamBreakSensorIOValues values); | ||
} |
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,27 @@ | ||
package frc.robot.shooter; | ||
|
||
import edu.wpi.first.networktables.BooleanTopic; | ||
import edu.wpi.first.networktables.NetworkTable; | ||
import edu.wpi.first.networktables.NetworkTableInstance; | ||
import java.util.function.BooleanSupplier; | ||
|
||
/** Simulated beam break sensor. */ | ||
public class BeamBreakSensorIOSim implements BeamBreakSensorIO { | ||
|
||
/** Supplies values for if the beam break sensor is broken. */ | ||
private final BooleanSupplier isBrokenSupplier; | ||
|
||
/** Creates a simulated beam break sensor. */ | ||
public BeamBreakSensorIOSim() { | ||
NetworkTable table = NetworkTableInstance.getDefault().getTable("shooter/beamBreakSensorSim"); | ||
|
||
BooleanTopic isBrokenTopic = table.getBooleanTopic("isBroken"); | ||
isBrokenTopic.publish().set(false); | ||
isBrokenSupplier = isBrokenTopic.subscribe(false); | ||
} | ||
|
||
@Override | ||
public void update(BeamBreakSensorIOValues values) { | ||
values.isBroken = isBrokenSupplier.getAsBoolean(); | ||
} | ||
} |
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,28 @@ | ||
package frc.robot.shooter; | ||
|
||
/** Flywheel motor hardware interface. */ | ||
public interface FlywheelMotorIO { | ||
|
||
/** Values for the flywheel motor hardware interface. */ | ||
public static class FlywheelMotorIOValues { | ||
/** Angular velocity of the flywheel in rotations per second. */ | ||
public double angularVelocityRotationsPerSecond = 0.0; | ||
|
||
/** Current drawn by the flywheel motor in amps. */ | ||
public double currentAmps = 0.0; | ||
} | ||
|
||
/** | ||
* Updates the flywheel motor's values. | ||
* | ||
* @param values | ||
*/ | ||
public void update(FlywheelMotorIOValues values); | ||
|
||
/** | ||
* Run the flywheel motor with the specified voltage. | ||
* | ||
* @param volts volts to apply to the flywheel motor. | ||
*/ | ||
public void setVoltage(double volts); | ||
} |
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,27 @@ | ||
package frc.robot.shooter; | ||
|
||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.wpilibj.simulation.FlywheelSim; | ||
import frc.robot.shooter.ShooterConstants.FlywheelConstants; | ||
|
||
/** Simulated flywheel motor. */ | ||
public class FlywheelMotorIOSim implements FlywheelMotorIO { | ||
|
||
/** Represents the motor used the drive the flywheel. */ | ||
private final DCMotor motorSim = DCMotor.getNeo550(1); | ||
|
||
/** Represents the flywheel driven by the motor. */ | ||
private final FlywheelSim flywheelSim = | ||
new FlywheelSim(motorSim, FlywheelConstants.GEARING, FlywheelConstants.MOI); | ||
|
||
@Override | ||
public void update(FlywheelMotorIOValues values) { | ||
values.angularVelocityRotationsPerSecond = flywheelSim.getAngularVelocityRPM() / 60.0; | ||
values.currentAmps = flywheelSim.getCurrentDrawAmps(); | ||
} | ||
|
||
@Override | ||
public void setVoltage(double volts) { | ||
flywheelSim.setInputVoltage(volts); | ||
} | ||
} |
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,28 @@ | ||
package frc.robot.shooter; | ||
|
||
/** Serializer motor hardware interface. */ | ||
public interface SerializerMotorIO { | ||
|
||
/** Values for the serializer motor hardware interface. */ | ||
public static class SerializerMotorIOValues { | ||
/** Angular velocity of the serializer in rotations per second. */ | ||
public double angularVelocityRotationsPerSecond = 0.0; | ||
|
||
/** Current drawn by the serializer motor in amps. */ | ||
public double currentAmps = 0.0; | ||
} | ||
|
||
/** | ||
* Updates the serializer motor's values. | ||
* | ||
* @param values | ||
*/ | ||
public void update(SerializerMotorIOValues values); | ||
|
||
/** | ||
* Run the serializer motor with the specified voltage. | ||
* | ||
* @param volts volts to apply to the serializer motor. | ||
*/ | ||
public void setVoltage(double volts); | ||
} |
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,27 @@ | ||
package frc.robot.shooter; | ||
|
||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.wpilibj.simulation.FlywheelSim; | ||
import frc.robot.shooter.ShooterConstants.SerializerConstants; | ||
|
||
/** Simulated serializer motor. */ | ||
public class SerializerMotorIOSim implements SerializerMotorIO { | ||
|
||
/** Represents the motor used the drive the serializer. */ | ||
private final DCMotor motorSim = DCMotor.getNeo550(1); | ||
|
||
/** Represents the serializer driven by the motor. */ | ||
private final FlywheelSim serializerSim = | ||
new FlywheelSim(motorSim, SerializerConstants.GEARING, SerializerConstants.MOI); | ||
|
||
@Override | ||
public void update(SerializerMotorIOValues values) { | ||
values.angularVelocityRotationsPerSecond = serializerSim.getAngularVelocityRPM() / 60.0; | ||
values.currentAmps = serializerSim.getCurrentDrawAmps(); | ||
} | ||
|
||
@Override | ||
public void setVoltage(double volts) { | ||
serializerSim.setInputVoltage(volts); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,50 @@ | ||
package frc.robot.shooter; | ||
|
||
import edu.wpi.first.math.util.Units; | ||
import frc.lib.CAN; | ||
|
||
/** Constants for the shooter subsystem. */ | ||
public class ShooterConstants { | ||
|
||
/** Constants for the sensors used in the shooter subsystem. */ | ||
public static class SensorConstants { | ||
/** The beam break sensor's DIO port number. */ | ||
/** Beam break sensor's DIO port number. */ | ||
public static final int BEAM_BREAK_PORT = 0; // TODO | ||
} | ||
|
||
/** Constants for the serializer motor used in the shooter subsystem. */ | ||
public static class SerializerConstants { | ||
/** The serializer motor controller's CAN identifier. */ | ||
/** Serializer motor controller's CAN identifier. */ | ||
public static final CAN ID = new CAN(0); // TODO | ||
|
||
/** If true, invert the serializer motor controller's direction. */ | ||
public static final boolean IS_INVERTED = false; // TODO | ||
|
||
/** Gearing between the serializer motor and the serializer wheel. */ | ||
public static final double GEARING = 1.0; // TODO | ||
|
||
/** Moment of interia of the serializer wheel in joules kilograms meters squared. */ | ||
public static final double MOI = 0.000125; // TODO | ||
|
||
/** Radius of the serializer wheel in meters. */ | ||
public static final double RADIUS = 0.5 * Units.inchesToMeters(4.0); | ||
} | ||
|
||
/** Constants for the flywheel motor used in the shooter subsystem. */ | ||
public static class FlywheelConstants { | ||
/** The flywheel motor controller's CAN identifier. */ | ||
/** Flywheel motor controller's CAN identifier. */ | ||
public static final CAN ID = new CAN(0); // TODO | ||
|
||
/** If true, invert the flywheel motor controller's direction. */ | ||
public static final boolean IS_INVERTED = false; // TODO | ||
|
||
/** Gearing between the flywheel motor and the flywheel wheel. */ | ||
public static final double GEARING = 1.0; // TODO | ||
|
||
/** Moment of interia of the flywheel wheel in joules kilograms meters squared. */ | ||
public static final double MOI = 0.000125; // TODO | ||
|
||
/** Radius of the flywheel wheel in meters. */ | ||
public static final double RADIUS = 0.5 * Units.inchesToMeters(4.0); | ||
} | ||
} |
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.shooter; | ||
|
||
import frc.robot.Robot; | ||
|
||
/** Helper class for creating hardware for the shooter subsystem. */ | ||
public class ShooterFactory { | ||
|
||
/** | ||
* Creates a beam break sensor. | ||
* | ||
* @return a beam break sensor. | ||
*/ | ||
public static BeamBreakSensorIO createBeamBreakSensor() { | ||
if (Robot.isReal()) return new BeamBreakSensorIOSim(); // TODO | ||
|
||
return new BeamBreakSensorIOSim(); | ||
} | ||
|
||
/** | ||
* Creates a serializer motor. | ||
* | ||
* @return a serializer motor. | ||
*/ | ||
public static SerializerMotorIO createSerializerMotor() { | ||
if (Robot.isReal()) return new SerializerMotorIOSim(); // TODO | ||
|
||
return new SerializerMotorIOSim(); | ||
} | ||
|
||
/** | ||
* Creates a flywheel motor. | ||
* | ||
* @return a flywheel motor. | ||
*/ | ||
public static FlywheelMotorIO createFlywheelMotor() { | ||
if (Robot.isReal()) return new FlywheelMotorIOSim(); // TODO | ||
|
||
return new FlywheelMotorIOSim(); | ||
} | ||
} |