Done Test code

Co-Authored-By: 76842 <90875734+76842@users.noreply.github.com>
This commit is contained in:
aarav18
2022-01-25 17:17:07 -07:00
parent 9112c87156
commit f1f1de18bb
5 changed files with 46 additions and 37 deletions
+5 -5
View File
@@ -68,18 +68,18 @@ public final class Constants {
}
public static final class SerializerConstants {
public static final double SERIALIZER_BELT_SPEED = 1.0; // TODO (currently max power, DO NOT RUN)
public static final double SERIALIZER_SHOOTER_BELT_SPEED = 1.0; // TODO (currently max power, DO NOT RUN)
public static final double SERIALIZER_BELT_SPEED = 1.d; // TODO (currently max power, DO NOT RUN)
public static final double SERIALIZER_SHOOTER_BELT_SPEED = 1.d; // TODO (currently max power, DO NOT RUN)
// CAN IDs
public static final int SERIALIZER_BELT = 1; // TODO
public static final int SERIALIZER_SHOOTER_BELT = 2; // TODO
public static final int SERIALIZER_BELT = 2; // TODO
public static final int SERIALIZER_SHOOTER_BELT = 5; // TODO
public static final int SERIALIZER_BELT_BEAM = 3; // TODO
}
public static final class IntakeConstants {
// CAN IDs
public static final int INTAKE_MOTOR = 3;
public static final int EXTENDER_MOTOR = 4;
public static final int EXTENDER_MOTOR = 6;
}
public static final class LEDConstants {
public static final int LED_SPARK_ID = 0;
+10 -10
View File
@@ -29,7 +29,7 @@ public class RobotContainer {
/* RobotMap */
private final RobotMap m_robotMap = new RobotMap();
/* Subsystems */
/* Subsystems
private final SwerveDrive m_robotSwerveDrive = new SwerveDrive(
m_robotMap.leftFrontSteerMotor, m_robotMap.leftFrontWheelMotor,
m_robotMap.rightFrontSteerMotor, m_robotMap.rightFrontWheelMotor,
@@ -40,7 +40,7 @@ public class RobotContainer {
m_robotMap.leftBackEncoder,
m_robotMap.rightBackEncoder
);
*/
private final Intake m_robotIntake = new Intake(m_robotMap.intakeMotor, m_robotMap.extenderMotor);
private final Serializer m_robotSerializer = new Serializer(m_robotMap.serializerBelt, m_robotMap.serializerShooterBelt);
@@ -58,9 +58,9 @@ public class RobotContainer {
/* Default Commands */
// drives the swerve drive with a two-axis input from the driver controller
m_robotSwerveDrive.setDefaultCommand(
new RunCommand(() -> m_robotSwerveDrive.driveWithInput(-getDriverController().getLeftXAxis(),
getDriverController().getLeftYAxis(), -getDriverController().getRightXAxis(), false), m_robotSwerveDrive));
// m_robotSwerveDrive.setDefaultCommand(
// new RunCommand(() -> m_robotSwerveDrive.driveWithInput(-getDriverController().getLeftXAxis(),
// getDriverController().getLeftYAxis(), -getDriverController().getRightXAxis(), false), m_robotSwerveDrive));
m_robotIntake.setDefaultCommand(
new RunCommand(() -> m_robotIntake.runWithTriggers(
@@ -88,13 +88,13 @@ public class RobotContainer {
.whenReleased(() -> m_robotIntake.runExtender(false));
// activates "Lit Mode"
new JoystickButton(getOperatorJoystick(), XboxController.A_BUTTON)
.whenPressed(() -> m_robotLED.setPattern(LEDPatterns.LAVA_RAINBOW))
.whenReleased(() -> m_robotLED.setPattern(LEDConstants.DEFAULT_PATTERN));
// new JoystickButton(getOperatorJoystick(), XboxController.A_BUTTON)
// .whenPressed(() -> m_robotLED.setPattern(LEDPatterns.LAVA_RAINBOW))
// .whenReleased(() -> m_robotLED.setPattern(LEDConstants.DEFAULT_PATTERN));
new JoystickButton(getOperatorJoystick(), XboxController.B_BUTTON)
.whenPressed(() -> m_robotSerializer.setSerializerStateWithBeam(true, m_robotSerializer.getBeam()))
.whenReleased(() -> m_robotSerializer.setSerializerStateWithBeam(false, m_robotSerializer.getBeam()));
.whenPressed(() -> m_robotSerializer.setSerializerState(true))
.whenReleased(() -> m_robotSerializer.setSerializerState(false));
}
/**
+7 -5
View File
@@ -6,12 +6,14 @@ package frc4388.robot;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX;
import com.ctre.phoenix.sensors.CANCoder;
import com.revrobotics.CANSparkMax;
import edu.wpi.first.wpilibj.motorcontrol.Spark;
import frc4388.robot.Constants.IntakeConstants;
import frc4388.robot.Constants.LEDConstants;
import frc4388.robot.Constants.SerializerConstants;
import frc4388.robot.Constants.SwerveDriveConstants;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
/**
* Defines and holds all I/O objects on the Roborio. This is useful for unit
@@ -21,7 +23,7 @@ public class RobotMap {
public RobotMap() {
configureLEDMotorControllers();
configureSwerveMotorControllers();
//configureSwerveMotorControllers();
}
/* LED Subsystem */
@@ -31,7 +33,7 @@ public class RobotMap {
}
/* Swerve Subsystem */
/* Swerve Subsystem
public final WPI_TalonFX leftFrontSteerMotor = new WPI_TalonFX(SwerveDriveConstants.LEFT_FRONT_STEER_CAN_ID);
public final WPI_TalonFX leftFrontWheelMotor = new WPI_TalonFX(SwerveDriveConstants.LEFT_FRONT_WHEEL_CAN_ID);
public final WPI_TalonFX rightFrontSteerMotor = new WPI_TalonFX(SwerveDriveConstants.RIGHT_FRONT_STEER_CAN_ID);
@@ -96,10 +98,10 @@ public class RobotMap {
/* Serializer Subsystem */
public final Spark serializerBelt = new Spark(SerializerConstants.SERIALIZER_BELT);
public final Spark serializerShooterBelt = new Spark(SerializerConstants.SERIALIZER_SHOOTER_BELT);
public final CANSparkMax serializerBelt = new CANSparkMax(SerializerConstants.SERIALIZER_BELT, MotorType.kBrushless);
public final CANSparkMax serializerShooterBelt = new CANSparkMax(SerializerConstants.SERIALIZER_SHOOTER_BELT, MotorType.kBrushless);
/* Intake Subsytem */
public final WPI_TalonFX intakeMotor = new WPI_TalonFX(IntakeConstants.INTAKE_MOTOR);
public final Spark extenderMotor = new Spark(IntakeConstants.EXTENDER_MOTOR);
public final CANSparkMax extenderMotor = new CANSparkMax(IntakeConstants.EXTENDER_MOTOR, MotorType.kBrushless);
}
@@ -17,29 +17,27 @@ public class Intake extends SubsystemBase {
private WPI_TalonFX m_intakeMotor;
private CANSparkMax m_extenderMotor;
private SparkMaxLimitSwitch m_inLimit;
private SparkMaxLimitSwitch m_outLimit;
// private SparkMaxLimitSwitch m_inLimit;
// private SparkMaxLimitSwitch m_outLimit;
public boolean toggle;
/** Creates a new Intake. */
public Intake(WPI_TalonFX intakeMotor, Spark extenderMotor) {
public Intake(WPI_TalonFX intakeMotor, CANSparkMax extenderMotor) {
m_intakeMotor = intakeMotor;
//m_extenderMotor = extenderMotor;
m_extenderMotor = extenderMotor;
// m_intakeMotor.restoreFactoryDefaults();
// m_extenderMotor.restoreFactoryDefaults();
m_extenderMotor.restoreFactoryDefaults();
m_intakeMotor.setNeutralMode(NeutralMode.Brake);
m_extenderMotor.setIdleMode(IdleMode.kBrake);
m_intakeMotor.setInverted(false);
m_extenderMotor.setInverted(true);
m_inLimit = m_extenderMotor.getForwardLimitSwitch(SparkMaxLimitSwitch.Type.kNormallyOpen);
m_outLimit = m_extenderMotor.getForwardLimitSwitch(SparkMaxLimitSwitch.Type.kNormallyOpen);
m_inLimit.enableLimitSwitch(true);
m_outLimit.enableLimitSwitch(true);
// m_inLimit = m_extenderMotor.getForwardLimitSwitch(SparkMaxLimitSwitch.Type.kNormallyOpen);
// m_outLimit = m_extenderMotor.getForwardLimitSwitch(SparkMaxLimitSwitch.Type.kNormallyOpen);
// m_inLimit.enableLimitSwitch(true);
// m_outLimit.enableLimitSwitch(true);
}
@Override
@@ -52,7 +50,8 @@ public class Intake extends SubsystemBase {
}
public void runExtender(boolean extended) {
//m_extenderMotor.set(extended ? 1 : -1);
double extenderMotorSpeed = extended ? 0.25d : 0.d;
m_extenderMotor.set(extenderMotorSpeed);
}
public void toggleExtender() {
@@ -4,37 +4,45 @@ import edu.wpi.first.wpilibj.motorcontrol.Spark;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc4388.robot.Constants;
import edu.wpi.first.wpilibj.DigitalInput;
import com.revrobotics.CANSparkMax;
public class Serializer extends SubsystemBase{
private Spark m_serializerBelt;
private Spark m_serializerShooterBelt;
private CANSparkMax m_serializerBelt;
private CANSparkMax m_serializerShooterBelt;
private DigitalInput m_serializerBeam;
private boolean serializerState;
public Serializer(Spark serializerBelt, Spark serializerShooterBelt) {
public Serializer(CANSparkMax serializerBelt, CANSparkMax serializerShooterBelt) {
m_serializerBelt = serializerBelt;
m_serializerShooterBelt = serializerShooterBelt;
m_serializerBeam = new DigitalInput(Constants.SerializerConstants.SERIALIZER_BELT_BEAM);
//m_serializerBeam = new DigitalInput(Constants.SerializerConstants.SERIALIZER_BELT_BEAM);
serializerState = false;
setSerializerState(serializerState);
m_serializerBelt.set(0);
m_serializerShooterBelt.set(0);
}
public boolean getBeam() {
return m_serializerBeam.get();
System.out.println("oi");
return false;
}
public void setSerializerStateWithBeam(boolean ctrlbutter, boolean beambroken) {
boolean total = ctrlbutter || beambroken;
setSerializerState(total);
}
public void setSerializerState(boolean state) {
System.out.println(state);
setSerializerBeltState(state);
setSerializerShooterBeltState(state);
serializerState = state;
}
public void setSerializerBeltState(boolean state) {
System.out.println("oi");
double serializerBeltSpeed = state ? Constants.SerializerConstants.SERIALIZER_BELT_SPEED : 0.d;
m_serializerBelt.set(serializerBeltSpeed);
System.out.println("oi2");
}
public void setSerializerShooterBeltState(boolean state) {