package first.robot.utilities; import java.util.function.DoubleSupplier; import org.wpilib.command2.Command; import org.wpilib.command2.SubsystemBase; import org.wpilib.hardware.bus.CANPort; import com.revrobotics.spark.SparkLowLevel.MotorType; import com.revrobotics.spark.SparkMax; /** * A simple subsystem that can be used to test a single SparkMax and associated NEO motor */ public class SparkMAXTester extends SubsystemBase { private SparkMax spark; /** * Constructor * * @param deviceID The CAN ID of the SparkMAX that needs testing */ public SparkMAXTester(CANPort canPort, int deviceID) { spark = new SparkMax(canPort, deviceID, MotorType.kBrushless); } /** * Sets the speed of the motor * * @param speed A method or lambda which returns a double between -1 and 1 * @return A Command object that runs indefinitely to control motor speed */ public Command setSpeed(DoubleSupplier speed) { return run(() -> { spark.setThrottle(speed.getAsDouble()); }); } }