Skip to content

Commit

Permalink
Added controls for the intake and conveyor system
Browse files Browse the repository at this point in the history
  • Loading branch information
tgurlik committed Jan 6, 2020
1 parent d27e4ca commit 4684855
Show file tree
Hide file tree
Showing 8 changed files with 393 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .wpilib/wpilib_preferences.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"enableCppIntellisense": false,
"currentLanguage": "java",
"projectYear": "2020",
"teamNumber": null
"teamNumber": 9001
}
5 changes: 5 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
* constants are needed, to reduce verbosity.
*/
public final class Constants {
public static final int kIntake = 5;
public static final int kConveyor = 6;
public static final int kFlywheel = 7;

public static final double kConveyorSpeed = 0.5;
}
45 changes: 37 additions & 8 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@

import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.XboxController;
import frc.robot.commands.ExampleCommand;
import frc.robot.subsystems.ExampleSubsystem;
import frc.robot.commands.ConveyorDown;
import frc.robot.commands.ConveyorUp;
import frc.robot.subsystems.Conveyor;
import frc.robot.subsystems.Intake;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.button.Trigger;

/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
Expand All @@ -20,19 +24,26 @@
* (including subsystems, commands, and button mappings) should be declared here.
*/
public class RobotContainer {
// The robot's subsystems and commands are defined here...
private final ExampleSubsystem m_exampleSubsystem = new ExampleSubsystem();

private final ExampleCommand m_autoCommand = new ExampleCommand(m_exampleSubsystem);

// Subsystems
private final Intake m_intake = new Intake();
private final Conveyor m_conveyor = new Conveyor();

// Controllers
private final XboxController m_driver = new XboxController(0);
private final XboxController m_manip = new XboxController(1);

/**
* The container for the robot. Contains subsystems, OI devices, and commands.
*/
public RobotContainer() {
// Configure the button bindings
configureButtonBindings();

m_intake.setDefaultCommand(new RunCommand(() -> m_intake.runIntake(
m_manip.getTriggerAxis(GenericHID.Hand.kLeft),
m_manip.getTriggerAxis(GenericHID.Hand.kRight)),
m_intake
));
}

/**
Expand All @@ -42,6 +53,8 @@ public RobotContainer() {
* {@link edu.wpi.first.wpilibj2.command.button.JoystickButton}.
*/
private void configureButtonBindings() {
new DPadUp().whileActiveContinuous(new ConveyorUp(m_conveyor));
new DPadDown().whileActiveContinuous(new ConveyorDown(m_conveyor));
}


Expand All @@ -52,6 +65,22 @@ private void configureButtonBindings() {
*/
public Command getAutonomousCommand() {
// An ExampleCommand will run in autonomous
return m_autoCommand;
return null;
}

private class DPadUp extends Trigger {
@Override
public boolean get() {
int pov = m_manip.getPOV();
return pov == 315 || pov <= 45;
}
}

private class DPadDown extends Trigger {
@Override
public boolean get() {
int pov = m_manip.getPOV();
return pov >= 135 && pov <= 225;
}
}
}
53 changes: 53 additions & 0 deletions src/main/java/frc/robot/commands/ConveyorDown.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

package frc.robot.commands;

import frc.robot.subsystems.Conveyor;
import edu.wpi.first.wpilibj2.command.CommandBase;

/**
* An example command that uses an example subsystem.
*/
public class ConveyorDown extends CommandBase {
@SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"})
private final Conveyor m_conveyor;

/**
* Creates a new ConveyorDown Command.
*
* @param subsystem The subsystem used by this command.
*/
public ConveyorDown(Conveyor conveyor) {
m_conveyor = conveyor;
// Use addRequirements() here to declare subsystem dependencies.
addRequirements(conveyor);
}

// Called when the command is initially scheduled.
@Override
public void initialize() {
}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
m_conveyor.lowerConveyor();
}

// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
m_conveyor.stopConveyor();
}

// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}
53 changes: 53 additions & 0 deletions src/main/java/frc/robot/commands/ConveyorUp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

package frc.robot.commands;

import frc.robot.subsystems.Conveyor;
import edu.wpi.first.wpilibj2.command.CommandBase;

/**
* An example command that uses an example subsystem.
*/
public class ConveyorUp extends CommandBase {
@SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"})
private final Conveyor m_conveyor;

/**
* Creates a new ConveyorUp.
*
* @param subsystem The subsystem used by this command.
*/
public ConveyorUp(Conveyor conveyor) {
m_conveyor = conveyor;
// Use addRequirements() here to declare subsystem dependencies.
addRequirements(conveyor);
}

// Called when the command is initially scheduled.
@Override
public void initialize() {
}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
m_conveyor.raiseConveyor();
}

// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
m_conveyor.stopConveyor();
}

// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}
38 changes: 38 additions & 0 deletions src/main/java/frc/robot/subsystems/Conveyor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

package frc.robot.subsystems;

import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX;

import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants;

public class Conveyor extends SubsystemBase {
private final WPI_VictorSPX m_conveyor = new WPI_VictorSPX(Constants.kConveyor);

/**
* Runs conveyor up
*/
public void raiseConveyor() {
m_conveyor.set(Constants.kConveyorSpeed);
}

/**
* Runs conveyor down
*/
public void lowerConveyor() {
m_conveyor.set(-Constants.kConveyorSpeed);
}

/**
* Stops conveyor
*/
public void stopConveyor() {
m_conveyor.stopMotor();
}
}
26 changes: 26 additions & 0 deletions src/main/java/frc/robot/subsystems/Intake.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

package frc.robot.subsystems;

import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX;

import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants;

public class Intake extends SubsystemBase {
private final WPI_VictorSPX m_intake = new WPI_VictorSPX(Constants.kIntake);

/**
* Runs the intake motor
* @param left Value of left trigger
* @param right Value of right trigger
*/
public void runIntake(double left, double right) {
m_intake.set(right - left);
}
}
Loading

0 comments on commit 4684855

Please sign in to comment.