mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[examples] Remove old command-based templates and examples (#3263)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
committed by
GitHub
parent
689e9ccfb5
commit
67df469c58
@@ -257,17 +257,6 @@
|
||||
"mainclass": "Main",
|
||||
"commandversion": 2
|
||||
},
|
||||
{
|
||||
"name": "PacGoat",
|
||||
"description": "A fully functional example CommandBased program for FRC Team 190's 2014 robot. This code can run on your computer if it supports simulation.",
|
||||
"tags": [
|
||||
"Complete Robot"
|
||||
],
|
||||
"foldername": "pacgoat",
|
||||
"gradlebase": "java",
|
||||
"mainclass": "Main",
|
||||
"commandversion": 1
|
||||
},
|
||||
{
|
||||
"name": "Simple Vision",
|
||||
"description": "Demonstrate the use of the CameraServer class to stream from a USB Webcam without processing the images.",
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat;
|
||||
|
||||
import edu.wpi.first.wpilibj.RobotBase;
|
||||
|
||||
/**
|
||||
* Do NOT add any static variables to this class, or any initialization at all. Unless you know what
|
||||
* you are doing, do not modify this file except to change the parameter class to the startRobot
|
||||
* call.
|
||||
*/
|
||||
public final class Main {
|
||||
private Main() {}
|
||||
|
||||
/**
|
||||
* Main initialization function. Do not perform any initialization here.
|
||||
*
|
||||
* <p>If you change your main robot class, change the parameter type.
|
||||
*/
|
||||
public static void main(String... args) {
|
||||
RobotBase.startRobot(Robot::new);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat;
|
||||
|
||||
import edu.wpi.first.wpilibj.Joystick;
|
||||
import edu.wpi.first.wpilibj.buttons.JoystickButton;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.commands.Collect;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.commands.DriveForward;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.commands.LowGoal;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.commands.SetCollectionSpeed;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.commands.SetPivotSetpoint;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.commands.Shoot;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Collector;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Pivot;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.triggers.DoubleButton;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
/**
|
||||
* The operator interface of the robot, it has been simplified from the real robot to allow control
|
||||
* with a single PS3 joystick. As a result, not all functionality from the real robot is available.
|
||||
*/
|
||||
public class OI {
|
||||
public Joystick m_joystick = new Joystick(0);
|
||||
|
||||
/** Create a new OI and all of the buttons on it. */
|
||||
public OI() {
|
||||
new JoystickButton(m_joystick, 12).whenPressed(new LowGoal());
|
||||
new JoystickButton(m_joystick, 10).whenPressed(new Collect());
|
||||
|
||||
new JoystickButton(m_joystick, 11).whenPressed(new SetPivotSetpoint(Pivot.kShoot));
|
||||
new JoystickButton(m_joystick, 9).whenPressed(new SetPivotSetpoint(Pivot.kShootNear));
|
||||
|
||||
new DoubleButton(m_joystick, 2, 3).whenActive(new Shoot());
|
||||
|
||||
// SmartDashboard Buttons
|
||||
SmartDashboard.putData("Drive Forward", new DriveForward(2.25));
|
||||
SmartDashboard.putData("Drive Backward", new DriveForward(-2.25));
|
||||
SmartDashboard.putData("Start Rollers", new SetCollectionSpeed(Collector.kForward));
|
||||
SmartDashboard.putData("Stop Rollers", new SetCollectionSpeed(Collector.kStop));
|
||||
SmartDashboard.putData("Reverse Rollers", new SetCollectionSpeed(Collector.kReverse));
|
||||
}
|
||||
|
||||
public Joystick getJoystick() {
|
||||
return m_joystick;
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat;
|
||||
|
||||
import edu.wpi.first.wpilibj.TimedRobot;
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.command.Scheduler;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.commands.DriveAndShootAutonomous;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.commands.DriveForward;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Collector;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Drivetrain;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Pivot;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Pneumatics;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Shooter;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
/**
|
||||
* This is the main class for running the PacGoat code.
|
||||
*
|
||||
* <p>The VM is configured to automatically run this class, and to call the functions corresponding
|
||||
* to each mode, as described in the TimedRobot documentation. If you change the name of this class
|
||||
* or the package after creating this project, you must also update the manifest file in the
|
||||
* resource directory.
|
||||
*/
|
||||
public class Robot extends TimedRobot {
|
||||
Command m_autonomousCommand;
|
||||
public static OI oi;
|
||||
|
||||
// Initialize the subsystems
|
||||
public static final Drivetrain drivetrain = new Drivetrain();
|
||||
public static final Collector collector = new Collector();
|
||||
public static final Shooter shooter = new Shooter();
|
||||
public static final Pneumatics pneumatics = new Pneumatics();
|
||||
public static final Pivot pivot = new Pivot();
|
||||
|
||||
public SendableChooser<Command> m_autoChooser;
|
||||
|
||||
// This function is run when the robot is first started up and should be
|
||||
// used for any initialization code.
|
||||
@Override
|
||||
public void robotInit() {
|
||||
SmartDashboard.putData(drivetrain);
|
||||
SmartDashboard.putData(collector);
|
||||
SmartDashboard.putData(shooter);
|
||||
SmartDashboard.putData(pneumatics);
|
||||
SmartDashboard.putData(pivot);
|
||||
|
||||
// This MUST be here. If the OI creates Commands (which it very likely
|
||||
// will), constructing it during the construction of CommandBase (from
|
||||
// which commands extend), subsystems are not guaranteed to be
|
||||
// yet. Thus, their requires() statements may grab null pointers. Bad
|
||||
// news. Don't move it.
|
||||
oi = new OI();
|
||||
|
||||
// instantiate the command used for the autonomous period
|
||||
m_autoChooser = new SendableChooser<>();
|
||||
m_autoChooser.setDefaultOption("Drive and Shoot", new DriveAndShootAutonomous());
|
||||
m_autoChooser.addOption("Drive Forward", new DriveForward());
|
||||
SmartDashboard.putData("Auto Mode", m_autoChooser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autonomousInit() {
|
||||
m_autonomousCommand = m_autoChooser.getSelected();
|
||||
m_autonomousCommand.start();
|
||||
}
|
||||
|
||||
// This function is called periodically during autonomous
|
||||
@Override
|
||||
public void autonomousPeriodic() {
|
||||
Scheduler.getInstance().run();
|
||||
log();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleopInit() {
|
||||
// This makes sure that the autonomous stops running when
|
||||
// teleop starts running. If you want the autonomous to
|
||||
// continue until interrupted by another command, remove
|
||||
// this line or comment it out.
|
||||
if (m_autonomousCommand != null) {
|
||||
m_autonomousCommand.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
// This function is called periodically during operator control
|
||||
@Override
|
||||
public void teleopPeriodic() {
|
||||
Scheduler.getInstance().run();
|
||||
log();
|
||||
}
|
||||
|
||||
// This function called periodically during test mode
|
||||
@Override
|
||||
public void testPeriodic() {}
|
||||
|
||||
@Override
|
||||
public void disabledInit() {
|
||||
Robot.shooter.unlatch();
|
||||
}
|
||||
|
||||
// This function is called periodically while disabled
|
||||
@Override
|
||||
public void disabledPeriodic() {
|
||||
log();
|
||||
}
|
||||
|
||||
/** Log interesting values to the SmartDashboard. */
|
||||
private void log() {
|
||||
Robot.pneumatics.writePressure();
|
||||
SmartDashboard.putNumber("Pivot Pot Value", Robot.pivot.getAngle());
|
||||
SmartDashboard.putNumber("Left Distance", drivetrain.getLeftEncoder().getDistance());
|
||||
SmartDashboard.putNumber("Right Distance", drivetrain.getRightEncoder().getDistance());
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
|
||||
/**
|
||||
* This command looks for the hot goal and waits until it's detected or timed out. The timeout is
|
||||
* because it's better to shoot and get some autonomous points than get none. When called
|
||||
* sequentially, this command will block until the hot goal is detected or until it is timed out.
|
||||
*/
|
||||
public class CheckForHotGoal extends Command {
|
||||
public CheckForHotGoal(double time) {
|
||||
setTimeout(time);
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
@Override
|
||||
protected boolean isFinished() {
|
||||
return isTimedOut() || Robot.shooter.goalIsHot();
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.InstantCommand;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
|
||||
/**
|
||||
* Close the claw.
|
||||
*
|
||||
* <p>NOTE: It doesn't wait for the claw to close since there is no sensor to detect that.
|
||||
*/
|
||||
public class CloseClaw extends InstantCommand {
|
||||
public CloseClaw() {
|
||||
requires(Robot.collector);
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
@Override
|
||||
protected void initialize() {
|
||||
Robot.collector.close();
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.CommandGroup;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Collector;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Pivot;
|
||||
|
||||
/** Get the robot set to collect balls. */
|
||||
public class Collect extends CommandGroup {
|
||||
/** Create a new collect command. */
|
||||
public Collect() {
|
||||
addSequential(new SetCollectionSpeed(Collector.kForward));
|
||||
addParallel(new CloseClaw());
|
||||
addSequential(new SetPivotSetpoint(Pivot.kCollect));
|
||||
addSequential(new WaitForBall());
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.CommandGroup;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
|
||||
/**
|
||||
* Drive over the line and then shoot the ball. If the hot goal is not detected, it will wait
|
||||
* briefly.
|
||||
*/
|
||||
public class DriveAndShootAutonomous extends CommandGroup {
|
||||
/** Create a new drive and shoot autonomous. */
|
||||
public DriveAndShootAutonomous() {
|
||||
addSequential(new CloseClaw());
|
||||
addSequential(new WaitForPressure(), 2);
|
||||
if (Robot.isReal()) {
|
||||
// NOTE: Simulation doesn't currently have the concept of hot.
|
||||
addSequential(new CheckForHotGoal(2));
|
||||
}
|
||||
addSequential(new SetPivotSetpoint(45));
|
||||
addSequential(new DriveForward(8, 0.3));
|
||||
addSequential(new Shoot());
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
|
||||
/**
|
||||
* This command drives the robot over a given distance with simple proportional control This command
|
||||
* will drive a given distance limiting to a maximum speed.
|
||||
*/
|
||||
public class DriveForward extends Command {
|
||||
private final double m_driveForwardSpeed;
|
||||
private final double m_distance;
|
||||
private double m_error;
|
||||
private static final double kTolerance = 0.1;
|
||||
private static final double kP = -1.0 / 5.0;
|
||||
|
||||
public DriveForward() {
|
||||
this(10, 0.5);
|
||||
}
|
||||
|
||||
public DriveForward(double dist) {
|
||||
this(dist, 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new drive forward command.
|
||||
*
|
||||
* @param dist The distance to drive
|
||||
* @param maxSpeed The maximum speed to drive at
|
||||
*/
|
||||
public DriveForward(double dist, double maxSpeed) {
|
||||
requires(Robot.drivetrain);
|
||||
m_distance = dist;
|
||||
m_driveForwardSpeed = maxSpeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initialize() {
|
||||
Robot.drivetrain.getRightEncoder().reset();
|
||||
setTimeout(2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute() {
|
||||
m_error = m_distance - Robot.drivetrain.getRightEncoder().getDistance();
|
||||
if (m_driveForwardSpeed * kP * m_error >= m_driveForwardSpeed) {
|
||||
Robot.drivetrain.tankDrive(m_driveForwardSpeed, m_driveForwardSpeed);
|
||||
} else {
|
||||
Robot.drivetrain.tankDrive(
|
||||
m_driveForwardSpeed * kP * m_error, m_driveForwardSpeed * kP * m_error);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isFinished() {
|
||||
return Math.abs(m_error) <= kTolerance || isTimedOut();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void end() {
|
||||
Robot.drivetrain.stop();
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
|
||||
/**
|
||||
* This command allows PS3 joystick to drive the robot. It is always running except when interrupted
|
||||
* by another command.
|
||||
*/
|
||||
public class DriveWithJoystick extends Command {
|
||||
public DriveWithJoystick() {
|
||||
requires(Robot.drivetrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute() {
|
||||
Robot.drivetrain.tankDrive(Robot.oi.getJoystick());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isFinished() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void end() {
|
||||
Robot.drivetrain.stop();
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.TimedCommand;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
|
||||
/** Extend the shooter and then retract it after a second. */
|
||||
public class ExtendShooter extends TimedCommand {
|
||||
public ExtendShooter() {
|
||||
super(1);
|
||||
requires(Robot.shooter);
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
@Override
|
||||
protected void initialize() {
|
||||
Robot.shooter.extendBoth();
|
||||
}
|
||||
|
||||
// Called once after isFinished returns true
|
||||
@Override
|
||||
protected void end() {
|
||||
Robot.shooter.retractBoth();
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.CommandGroup;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Collector;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Pivot;
|
||||
|
||||
/** Spit the ball out into the low goal assuming that the robot is in front of it. */
|
||||
public class LowGoal extends CommandGroup {
|
||||
/** Create a new low goal command. */
|
||||
public LowGoal() {
|
||||
addSequential(new SetPivotSetpoint(Pivot.kLowGoal));
|
||||
addSequential(new SetCollectionSpeed(Collector.kReverse));
|
||||
addSequential(new ExtendShooter());
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
|
||||
/** Opens the claw. */
|
||||
public class OpenClaw extends Command {
|
||||
public OpenClaw() {
|
||||
requires(Robot.collector);
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
@Override
|
||||
protected void initialize() {
|
||||
Robot.collector.open();
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
@Override
|
||||
protected boolean isFinished() {
|
||||
return Robot.collector.isOpen();
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.InstantCommand;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
|
||||
/**
|
||||
* This command sets the collector rollers spinning at the given speed. Since there is no sensor for
|
||||
* detecting speed, it finishes immediately. As a result, the spinners may still be adjusting their
|
||||
* speed.
|
||||
*/
|
||||
public class SetCollectionSpeed extends InstantCommand {
|
||||
private final double m_speed;
|
||||
|
||||
public SetCollectionSpeed(double speed) {
|
||||
requires(Robot.collector);
|
||||
this.m_speed = speed;
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
@Override
|
||||
protected void initialize() {
|
||||
Robot.collector.setSpeed(m_speed);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
|
||||
/**
|
||||
* Moves the pivot to a given angle. This command finishes when it is within the tolerance, but
|
||||
* leaves the PID loop running to maintain the position. Other commands using the pivot should make
|
||||
* sure they disable PID!
|
||||
*/
|
||||
public class SetPivotSetpoint extends Command {
|
||||
private final double m_setpoint;
|
||||
|
||||
public SetPivotSetpoint(double setpoint) {
|
||||
this.m_setpoint = setpoint;
|
||||
requires(Robot.pivot);
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
@Override
|
||||
protected void initialize() {
|
||||
Robot.pivot.enable();
|
||||
Robot.pivot.setSetpoint(m_setpoint);
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
@Override
|
||||
protected boolean isFinished() {
|
||||
return Robot.pivot.onTarget();
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.CommandGroup;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Collector;
|
||||
|
||||
/** Shoot the ball at the current angle. */
|
||||
public class Shoot extends CommandGroup {
|
||||
/** Create a new shoot command. */
|
||||
public Shoot() {
|
||||
addSequential(new WaitForPressure());
|
||||
addSequential(new SetCollectionSpeed(Collector.kStop));
|
||||
addSequential(new OpenClaw());
|
||||
addSequential(new ExtendShooter());
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
|
||||
/**
|
||||
* Wait until the collector senses that it has the ball. This command does nothing and is intended
|
||||
* to be used in command groups to wait for this condition.
|
||||
*/
|
||||
public class WaitForBall extends Command {
|
||||
public WaitForBall() {
|
||||
requires(Robot.collector);
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
@Override
|
||||
protected boolean isFinished() {
|
||||
return Robot.collector.hasBall();
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
|
||||
/**
|
||||
* Wait until the pneumatics are fully pressurized. This command does nothing and is intended to be
|
||||
* used in command groups to wait for this condition.
|
||||
*/
|
||||
public class WaitForPressure extends Command {
|
||||
public WaitForPressure() {
|
||||
requires(Robot.pneumatics);
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
@Override
|
||||
protected boolean isFinished() {
|
||||
return Robot.pneumatics.isPressurized();
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.subsystems;
|
||||
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj.PneumaticsModuleType;
|
||||
import edu.wpi.first.wpilibj.Solenoid;
|
||||
import edu.wpi.first.wpilibj.command.Subsystem;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.MotorController;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.Victor;
|
||||
|
||||
/**
|
||||
* The Collector subsystem has one motor for the rollers, a limit switch for ball detection, a
|
||||
* piston for opening and closing the claw, and a reed switch to check if the piston is open.
|
||||
*/
|
||||
public class Collector extends Subsystem {
|
||||
// Constants for some useful speeds
|
||||
public static final double kForward = 1;
|
||||
public static final double kStop = 0;
|
||||
public static final double kReverse = -1;
|
||||
|
||||
// Subsystem devices
|
||||
private final MotorController m_rollerMotor = new Victor(6);
|
||||
private final DigitalInput m_ballDetector = new DigitalInput(10);
|
||||
private final DigitalInput m_openDetector = new DigitalInput(6);
|
||||
private final Solenoid m_piston = new Solenoid(PneumaticsModuleType.CTREPCM, 1);
|
||||
|
||||
/** Create a new collector subsystem. */
|
||||
public Collector() {
|
||||
// Put everything to the LiveWindow for testing.
|
||||
addChild("Roller Motor", (Victor) m_rollerMotor);
|
||||
addChild("Ball Detector", m_ballDetector);
|
||||
addChild("Claw Open Detector", m_openDetector);
|
||||
addChild("Piston", m_piston);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the robot has the ball.
|
||||
*
|
||||
* <p>NOTE: The current simulation model uses the the lower part of the claw since the limit
|
||||
* switch wasn't exported. At some point, this will be updated.
|
||||
*
|
||||
* @return Whether or not the robot has the ball.
|
||||
*/
|
||||
public boolean hasBall() {
|
||||
return m_ballDetector.get(); // TODO: prepend ! to reflect real robot
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the speed to spin the collector rollers.
|
||||
*
|
||||
* @param speed The speed to spin the rollers.
|
||||
*/
|
||||
public void setSpeed(double speed) {
|
||||
m_rollerMotor.set(-speed);
|
||||
}
|
||||
|
||||
/** Stop the rollers from spinning. */
|
||||
public void stop() {
|
||||
m_rollerMotor.set(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wether or not the claw is open.
|
||||
*
|
||||
* @return Whether or not the claw is open.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
return m_openDetector.get(); // TODO: prepend ! to reflect real robot
|
||||
}
|
||||
|
||||
/** Open the claw up (For shooting). */
|
||||
public void open() {
|
||||
m_piston.set(true);
|
||||
}
|
||||
|
||||
/** Close the claw (For collecting and driving). */
|
||||
@Override
|
||||
public void close() {
|
||||
m_piston.set(false);
|
||||
}
|
||||
|
||||
/** No default command. */
|
||||
@Override
|
||||
protected void initDefaultCommand() {}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.subsystems;
|
||||
|
||||
import edu.wpi.first.wpilibj.AnalogGyro;
|
||||
import edu.wpi.first.wpilibj.CounterBase.EncodingType;
|
||||
import edu.wpi.first.wpilibj.Encoder;
|
||||
import edu.wpi.first.wpilibj.Joystick;
|
||||
import edu.wpi.first.wpilibj.command.Subsystem;
|
||||
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.commands.DriveWithJoystick;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.MotorController;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.Victor;
|
||||
|
||||
/**
|
||||
* The Drivetrain subsystem controls the robot's chassis and reads in information about it's speed
|
||||
* and position.
|
||||
*/
|
||||
public class Drivetrain extends Subsystem {
|
||||
// Subsystem devices
|
||||
private final MotorController m_frontLeftCIM = new Victor(1);
|
||||
private final MotorController m_frontRightCIM = new Victor(2);
|
||||
private final MotorController m_rearLeftCIM = new Victor(3);
|
||||
private final MotorController m_rearRightCIM = new Victor(4);
|
||||
private final MotorControllerGroup m_leftCIMs =
|
||||
new MotorControllerGroup(m_frontLeftCIM, m_rearLeftCIM);
|
||||
private final MotorControllerGroup m_rightCIMs =
|
||||
new MotorControllerGroup(m_frontRightCIM, m_rearRightCIM);
|
||||
private final DifferentialDrive m_drive;
|
||||
private final Encoder m_rightEncoder = new Encoder(1, 2, true, EncodingType.k4X);
|
||||
private final Encoder m_leftEncoder = new Encoder(3, 4, false, EncodingType.k4X);
|
||||
private final AnalogGyro m_gyro = new AnalogGyro(0);
|
||||
|
||||
/** Create a new drivetrain subsystem. */
|
||||
public Drivetrain() {
|
||||
// Configure drive motors
|
||||
addChild("Front Left CIM", (Victor) m_frontLeftCIM);
|
||||
addChild("Front Right CIM", (Victor) m_frontRightCIM);
|
||||
addChild("Back Left CIM", (Victor) m_rearLeftCIM);
|
||||
addChild("Back Right CIM", (Victor) m_rearRightCIM);
|
||||
|
||||
// Configure the DifferentialDrive to reflect the fact that all motors
|
||||
// are wired backwards (right is inverted in DifferentialDrive).
|
||||
m_leftCIMs.setInverted(true);
|
||||
m_rightCIMs.setInverted(true);
|
||||
m_drive = new DifferentialDrive(m_leftCIMs, m_rightCIMs);
|
||||
m_drive.setSafetyEnabled(true);
|
||||
m_drive.setExpiration(0.1);
|
||||
m_drive.setMaxOutput(1.0);
|
||||
|
||||
if (Robot.isReal()) { // Converts to feet
|
||||
m_rightEncoder.setDistancePerPulse(0.0785398);
|
||||
m_leftEncoder.setDistancePerPulse(0.0785398);
|
||||
} else {
|
||||
// Circumference = diameter in feet * pi. 360 tick simulated encoders.
|
||||
m_rightEncoder.setDistancePerPulse((4.0 /* in */ * Math.PI) / (360.0 * 12.0 /* in/ft */));
|
||||
m_leftEncoder.setDistancePerPulse((4.0 /* in */ * Math.PI) / (360.0 * 12.0 /* in/ft */));
|
||||
}
|
||||
|
||||
addChild("Right Encoder", m_rightEncoder);
|
||||
addChild("Left Encoder", m_leftEncoder);
|
||||
|
||||
// Configure gyro
|
||||
if (Robot.isReal()) {
|
||||
m_gyro.setSensitivity(0.007); // TODO: Handle more gracefully?
|
||||
}
|
||||
addChild("Gyro", m_gyro);
|
||||
}
|
||||
|
||||
/** When other commands aren't using the drivetrain, allow tank drive with the joystick. */
|
||||
@Override
|
||||
public void initDefaultCommand() {
|
||||
setDefaultCommand(new DriveWithJoystick());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tank drive using a PS3 joystick.
|
||||
*
|
||||
* @param joy PS3 style joystick to use as the input for tank drive.
|
||||
*/
|
||||
public void tankDrive(Joystick joy) {
|
||||
m_drive.tankDrive(joy.getY(), joy.getRawAxis(4));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tank drive using individual joystick axes.
|
||||
*
|
||||
* @param leftAxis Left sides value
|
||||
* @param rightAxis Right sides value
|
||||
*/
|
||||
public void tankDrive(double leftAxis, double rightAxis) {
|
||||
m_drive.tankDrive(leftAxis, rightAxis);
|
||||
}
|
||||
|
||||
/** Stop the drivetrain from moving. */
|
||||
public void stop() {
|
||||
m_drive.tankDrive(0, 0);
|
||||
}
|
||||
|
||||
/** The encoder getting the distance and speed of left side of the drivetrain. */
|
||||
public Encoder getLeftEncoder() {
|
||||
return m_leftEncoder;
|
||||
}
|
||||
|
||||
/** The encoder getting the distance and speed of right side of the drivetrain. */
|
||||
public Encoder getRightEncoder() {
|
||||
return m_rightEncoder;
|
||||
}
|
||||
|
||||
/** The current angle of the drivetrain as measured by the Gyro. */
|
||||
public double getAngle() {
|
||||
return m_gyro.getAngle();
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.subsystems;
|
||||
|
||||
import edu.wpi.first.wpilibj.AnalogPotentiometer;
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj.command.PIDSubsystem;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.MotorController;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.Victor;
|
||||
|
||||
/**
|
||||
* The Pivot subsystem contains the Van-door motor and the pot for PID control of angle of the pivot
|
||||
* and claw.
|
||||
*/
|
||||
public class Pivot extends PIDSubsystem {
|
||||
// Constants for some useful angles
|
||||
public static final double kCollect = 105;
|
||||
public static final double kLowGoal = 90;
|
||||
public static final double kShoot = 45;
|
||||
public static final double kShootNear = 30;
|
||||
|
||||
// Sensors for measuring the position of the pivot.
|
||||
private final DigitalInput m_upperLimitSwitch = new DigitalInput(13);
|
||||
private final DigitalInput m_lowerLimitSwitch = new DigitalInput(12);
|
||||
|
||||
// 0 degrees is vertical facing up.
|
||||
// Angle increases the more forward the pivot goes.
|
||||
private final AnalogPotentiometer m_pot = new AnalogPotentiometer(1);
|
||||
|
||||
// Motor to move the pivot.
|
||||
private final MotorController m_motor = new Victor(5);
|
||||
|
||||
/** Create a new pivot subsystem. */
|
||||
public Pivot() {
|
||||
super("Pivot", 7.0, 0.0, 8.0);
|
||||
setAbsoluteTolerance(0.005);
|
||||
getPIDController().setContinuous(false);
|
||||
if (Robot.isSimulation()) { // PID is different in simulation.
|
||||
getPIDController().setPID(0.5, 0.001, 2);
|
||||
setAbsoluteTolerance(5);
|
||||
}
|
||||
|
||||
// Put everything to the LiveWindow for testing.
|
||||
addChild("Upper Limit Switch", m_upperLimitSwitch);
|
||||
addChild("Lower Limit Switch", m_lowerLimitSwitch);
|
||||
addChild("Pot", (AnalogPotentiometer) m_pot);
|
||||
addChild("Motor", (Victor) m_motor);
|
||||
addChild("PIDSubsystem Controller", getPIDController());
|
||||
}
|
||||
|
||||
/** No default command, if PID is enabled, the current setpoint will be maintained. */
|
||||
@Override
|
||||
public void initDefaultCommand() {}
|
||||
|
||||
/** The angle read in by the potentiometer. */
|
||||
@Override
|
||||
protected double returnPIDInput() {
|
||||
return m_pot.get();
|
||||
}
|
||||
|
||||
/** Set the motor speed based off of the PID output. */
|
||||
@Override
|
||||
protected void usePIDOutput(double output) {
|
||||
m_motor.set(output);
|
||||
}
|
||||
|
||||
/** If the pivot is at its upper limit. */
|
||||
public boolean isAtUpperLimit() {
|
||||
// TODO: inverted from real robot (prefix with !)
|
||||
return m_upperLimitSwitch.get();
|
||||
}
|
||||
|
||||
/** If the pivot is at its lower limit. */
|
||||
public boolean isAtLowerLimit() {
|
||||
// TODO: inverted from real robot (prefix with !)
|
||||
return m_lowerLimitSwitch.get();
|
||||
}
|
||||
|
||||
/** The current angle of the pivot. */
|
||||
public double getAngle() {
|
||||
return m_pot.get();
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.subsystems;
|
||||
|
||||
import edu.wpi.first.wpilibj.AnalogInput;
|
||||
import edu.wpi.first.wpilibj.command.Subsystem;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
/**
|
||||
* The Pneumatics subsystem contains a pressure sensor.
|
||||
*
|
||||
* <p>NOTE: The simulator currently doesn't support the compressor or pressure sensors.
|
||||
*/
|
||||
public class Pneumatics extends Subsystem {
|
||||
AnalogInput m_pressureSensor = new AnalogInput(3);
|
||||
|
||||
private static final double kMaxPressure = 2.55;
|
||||
|
||||
public Pneumatics() {
|
||||
addChild("Pressure Sensor", m_pressureSensor);
|
||||
}
|
||||
|
||||
/** No default command. */
|
||||
@Override
|
||||
public void initDefaultCommand() {}
|
||||
|
||||
/** Whether or not the system is fully pressurized. */
|
||||
public boolean isPressurized() {
|
||||
if (Robot.isReal()) {
|
||||
return kMaxPressure <= m_pressureSensor.getVoltage();
|
||||
} else {
|
||||
return true; // NOTE: Simulation always has full pressure
|
||||
}
|
||||
}
|
||||
|
||||
/** Puts the pressure on the SmartDashboard. */
|
||||
public void writePressure() {
|
||||
SmartDashboard.putNumber("Pressure", m_pressureSensor.getVoltage());
|
||||
}
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.subsystems;
|
||||
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj.DoubleSolenoid;
|
||||
import edu.wpi.first.wpilibj.PneumaticsModuleType;
|
||||
import edu.wpi.first.wpilibj.Solenoid;
|
||||
import edu.wpi.first.wpilibj.command.Subsystem;
|
||||
|
||||
/**
|
||||
* The Shooter subsystem handles shooting. The mechanism for shooting is slightly complicated
|
||||
* because it has to pneumatic cylinders for shooting, and a third latch to allow the pressure to
|
||||
* partially build up and reduce the effect of the airflow. For shorter shots, when full power isn't
|
||||
* needed, only one cylinder fires.
|
||||
*
|
||||
* <p>NOTE: Simulation currently approximates this as as single pneumatic cylinder and ignores the
|
||||
* latch.
|
||||
*/
|
||||
public class Shooter extends Subsystem {
|
||||
// Devices
|
||||
DoubleSolenoid m_piston1 = new DoubleSolenoid(PneumaticsModuleType.CTREPCM, 3, 4);
|
||||
DoubleSolenoid m_piston2 = new DoubleSolenoid(PneumaticsModuleType.CTREPCM, 5, 6);
|
||||
Solenoid m_latchPiston = new Solenoid(PneumaticsModuleType.CTREPCM, 2);
|
||||
DigitalInput m_piston1ReedSwitchFront = new DigitalInput(9);
|
||||
DigitalInput m_piston1ReedSwitchBack = new DigitalInput(11);
|
||||
// NOTE: currently ignored in simulation
|
||||
DigitalInput m_hotGoalSensor = new DigitalInput(7);
|
||||
|
||||
/** Create a new shooter subsystem. */
|
||||
public Shooter() {
|
||||
// Put everything to the LiveWindow for testing.
|
||||
addChild("Hot Goal Sensor", m_hotGoalSensor);
|
||||
addChild("Piston1 Reed Switch Front ", m_piston1ReedSwitchFront);
|
||||
addChild("Piston1 Reed Switch Back ", m_piston1ReedSwitchBack);
|
||||
addChild("Latch Piston", m_latchPiston);
|
||||
}
|
||||
|
||||
/** No default command. */
|
||||
@Override
|
||||
public void initDefaultCommand() {}
|
||||
|
||||
/** Extend both solenoids to shoot. */
|
||||
public void extendBoth() {
|
||||
m_piston1.set(DoubleSolenoid.Value.kForward);
|
||||
m_piston2.set(DoubleSolenoid.Value.kForward);
|
||||
}
|
||||
|
||||
/** Retract both solenoids to prepare to shoot. */
|
||||
public void retractBoth() {
|
||||
m_piston1.set(DoubleSolenoid.Value.kReverse);
|
||||
m_piston2.set(DoubleSolenoid.Value.kReverse);
|
||||
}
|
||||
|
||||
/** Extend solenoid 1 to shoot. */
|
||||
public void extend1() {
|
||||
m_piston1.set(DoubleSolenoid.Value.kForward);
|
||||
}
|
||||
|
||||
/** Retract solenoid 1 to prepare to shoot. */
|
||||
public void retract1() {
|
||||
m_piston1.set(DoubleSolenoid.Value.kReverse);
|
||||
}
|
||||
|
||||
/** Extend solenoid 2 to shoot. */
|
||||
public void extend2() {
|
||||
m_piston2.set(DoubleSolenoid.Value.kReverse);
|
||||
}
|
||||
|
||||
/** Retract solenoid 2 to prepare to shoot. */
|
||||
public void retract2() {
|
||||
m_piston2.set(DoubleSolenoid.Value.kForward);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns off the piston1 double solenoid. This won't actuate anything because double solenoids
|
||||
* preserve their state when turned off. This should be called in order to reduce the amount of
|
||||
* time that the coils are powered.
|
||||
*/
|
||||
public void off1() {
|
||||
m_piston1.set(DoubleSolenoid.Value.kOff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns off the piston2 double solenoid. This won't actuate anything because double solenoids
|
||||
* preserve their state when turned off. This should be called in order to reduce the amount of
|
||||
* time that the coils are powered.
|
||||
*/
|
||||
public void off2() {
|
||||
m_piston2.set(DoubleSolenoid.Value.kOff);
|
||||
}
|
||||
|
||||
/** Release the latch so that we can shoot. */
|
||||
public void unlatch() {
|
||||
m_latchPiston.set(true);
|
||||
}
|
||||
|
||||
/** Latch so that pressure can build up and we aren't limited by air flow. */
|
||||
public void latch() {
|
||||
m_latchPiston.set(false);
|
||||
}
|
||||
|
||||
/** Toggles the latch postions. */
|
||||
public void toggleLatchPosition() {
|
||||
m_latchPiston.set(!m_latchPiston.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Piston 1 extended (after shooting).
|
||||
*
|
||||
* @return Whether or not piston 1 is fully extended.
|
||||
*/
|
||||
public boolean piston1IsExtended() {
|
||||
return !m_piston1ReedSwitchFront.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Piston 1 retracted (before shooting).
|
||||
*
|
||||
* @return Whether or not piston 1 is fully retracted.
|
||||
*/
|
||||
public boolean piston1IsRetracted() {
|
||||
return !m_piston1ReedSwitchBack.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns off all double solenoids. Double solenoids hold their position when they are turned off.
|
||||
* We should turn them off whenever possible to extend the life of the coils.
|
||||
*/
|
||||
public void offBoth() {
|
||||
m_piston1.set(DoubleSolenoid.Value.kOff);
|
||||
m_piston2.set(DoubleSolenoid.Value.kOff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the goal is hot as read by the banner sensor.
|
||||
*
|
||||
* <p>NOTE: doesn't work in simulation.
|
||||
*
|
||||
* @return Whether or not the goal is hot
|
||||
*/
|
||||
public boolean goalIsHot() {
|
||||
return m_hotGoalSensor.get();
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.triggers;
|
||||
|
||||
import edu.wpi.first.wpilibj.GenericHID;
|
||||
import edu.wpi.first.wpilibj.buttons.Trigger;
|
||||
|
||||
/** A custom button that is triggered when TWO buttons on a Joystick are simultaneously pressed. */
|
||||
public class DoubleButton extends Trigger {
|
||||
private final GenericHID m_joy;
|
||||
private final int m_button1;
|
||||
private final int m_button2;
|
||||
|
||||
/**
|
||||
* Create a new double button trigger.
|
||||
*
|
||||
* @param joy The joystick
|
||||
* @param button1 The first button
|
||||
* @param button2 The second button
|
||||
*/
|
||||
public DoubleButton(GenericHID joy, int button1, int button2) {
|
||||
this.m_joy = joy;
|
||||
this.m_button1 = button1;
|
||||
this.m_button2 = button2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean get() {
|
||||
return m_joy.getRawButton(m_button1) && m_joy.getRawButton(m_button2);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.templates.oldcommandbased;
|
||||
|
||||
import edu.wpi.first.wpilibj.RobotBase;
|
||||
|
||||
/**
|
||||
* Do NOT add any static variables to this class, or any initialization at all. Unless you know what
|
||||
* you are doing, do not modify this file except to change the parameter class to the startRobot
|
||||
* call.
|
||||
*/
|
||||
public final class Main {
|
||||
private Main() {}
|
||||
|
||||
/**
|
||||
* Main initialization function. Do not perform any initialization here.
|
||||
*
|
||||
* <p>If you change your main robot class, change the parameter type.
|
||||
*/
|
||||
public static void main(String... args) {
|
||||
RobotBase.startRobot(Robot::new);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.templates.oldcommandbased;
|
||||
|
||||
/**
|
||||
* This class is the glue that binds the controls on the physical operator interface to the commands
|
||||
* and command groups that allow control of the robot.
|
||||
*/
|
||||
public class OI {
|
||||
//// CREATING BUTTONS
|
||||
// One type of button is a joystick button which is any button on a
|
||||
//// joystick.
|
||||
// You create one by telling it which joystick it's on and which button
|
||||
// number it is.
|
||||
// Joystick stick = new Joystick(port);
|
||||
// Button button = new JoystickButton(stick, buttonNumber);
|
||||
|
||||
// There are a few additional built in buttons you can use. Additionally,
|
||||
// by subclassing Button you can create custom triggers and bind those to
|
||||
// commands the same as any other Button.
|
||||
|
||||
//// TRIGGERING COMMANDS WITH BUTTONS
|
||||
// Once you have a button, it's trivial to bind it to a button in one of
|
||||
// three ways:
|
||||
|
||||
// Start the command when the button is pressed and let it run the command
|
||||
// until it is finished as determined by it's isFinished method.
|
||||
// button.whenPressed(new ExampleCommand());
|
||||
|
||||
// Run the command while the button is being held down and interrupt it once
|
||||
// the button is released.
|
||||
// button.whileHeld(new ExampleCommand());
|
||||
|
||||
// Start the command when the button is released and let it run the command
|
||||
// until it is finished as determined by it's isFinished method.
|
||||
// button.whenReleased(new ExampleCommand());
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.templates.oldcommandbased;
|
||||
|
||||
import edu.wpi.first.wpilibj.TimedRobot;
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.command.Scheduler;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
import edu.wpi.first.wpilibj.templates.oldcommandbased.commands.ExampleCommand;
|
||||
import edu.wpi.first.wpilibj.templates.oldcommandbased.subsystems.ExampleSubsystem;
|
||||
|
||||
/**
|
||||
* The VM is configured to automatically run this class, and to call the functions corresponding to
|
||||
* each mode, as described in the TimedRobot documentation. If you change the name of this class or
|
||||
* the package after creating this project, you must also update the build.gradle file in the
|
||||
* project.
|
||||
*/
|
||||
public class Robot extends TimedRobot {
|
||||
public static final ExampleSubsystem m_subsystem = new ExampleSubsystem();
|
||||
public static OI m_oi;
|
||||
|
||||
Command m_autonomousCommand;
|
||||
SendableChooser<Command> m_chooser = new SendableChooser<>();
|
||||
|
||||
/**
|
||||
* This function is run when the robot is first started up and should be used for any
|
||||
* initialization code.
|
||||
*/
|
||||
@Override
|
||||
public void robotInit() {
|
||||
m_oi = new OI();
|
||||
m_chooser.setDefaultOption("Default Auto", new ExampleCommand());
|
||||
// chooser.addOption("My Auto", new MyAutoCommand());
|
||||
SmartDashboard.putData("Auto mode", m_chooser);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called every robot packet, no matter the mode. Use this for items like
|
||||
* diagnostics that you want ran during disabled, autonomous, teleoperated and test.
|
||||
*
|
||||
* <p>This runs after the mode specific periodic functions, but before LiveWindow and
|
||||
* SmartDashboard integrated updating.
|
||||
*/
|
||||
@Override
|
||||
public void robotPeriodic() {}
|
||||
|
||||
/**
|
||||
* This function is called once each time the robot enters Disabled mode. You can use it to reset
|
||||
* any subsystem information you want to clear when the robot is disabled.
|
||||
*/
|
||||
@Override
|
||||
public void disabledInit() {}
|
||||
|
||||
@Override
|
||||
public void disabledPeriodic() {
|
||||
Scheduler.getInstance().run();
|
||||
}
|
||||
|
||||
/**
|
||||
* This autonomous (along with the chooser code above) shows how to select between different
|
||||
* autonomous modes using the dashboard. The sendable chooser code works with the Java
|
||||
* SmartDashboard. If you prefer the LabVIEW Dashboard, remove all of the chooser code and
|
||||
* uncomment the getString code to get the auto name from the text box below the Gyro
|
||||
*
|
||||
* <p>You can add additional auto modes by adding additional commands to the chooser code above
|
||||
* (like the commented example) or additional comparisons to the switch structure below with
|
||||
* additional strings & commands.
|
||||
*/
|
||||
@Override
|
||||
public void autonomousInit() {
|
||||
m_autonomousCommand = m_chooser.getSelected();
|
||||
|
||||
/*
|
||||
* String autoSelected = SmartDashboard.getString("Auto Selector",
|
||||
* "Default"); switch(autoSelected) { case "My Auto": autonomousCommand
|
||||
* = new MyAutoCommand(); break; case "Default Auto": default:
|
||||
* autonomousCommand = new ExampleCommand(); break; }
|
||||
*/
|
||||
|
||||
// schedule the autonomous command (example)
|
||||
if (m_autonomousCommand != null) {
|
||||
m_autonomousCommand.start();
|
||||
}
|
||||
}
|
||||
|
||||
/** This function is called periodically during autonomous. */
|
||||
@Override
|
||||
public void autonomousPeriodic() {
|
||||
Scheduler.getInstance().run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleopInit() {
|
||||
// This makes sure that the autonomous stops running when
|
||||
// teleop starts running. If you want the autonomous to
|
||||
// continue until interrupted by another command, remove
|
||||
// this line or comment it out.
|
||||
if (m_autonomousCommand != null) {
|
||||
m_autonomousCommand.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/** This function is called periodically during operator control. */
|
||||
@Override
|
||||
public void teleopPeriodic() {
|
||||
Scheduler.getInstance().run();
|
||||
}
|
||||
|
||||
/** This function is called periodically during test mode. */
|
||||
@Override
|
||||
public void testPeriodic() {}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.templates.oldcommandbased;
|
||||
|
||||
/**
|
||||
* The RobotMap is a mapping from the ports sensors and actuators are wired into to a variable name.
|
||||
* This provides flexibility changing wiring, makes checking the wiring easier and significantly
|
||||
* reduces the number of magic numbers floating around.
|
||||
*/
|
||||
public class RobotMap {
|
||||
// For example to map the left and right motors, you could define the
|
||||
// following variables to use with your drivetrain subsystem.
|
||||
// public static int leftMotor = 1;
|
||||
// public static int rightMotor = 2;
|
||||
|
||||
// If you are using multiple modules, make sure to define both the port
|
||||
// number and the module. For example you with a rangefinder:
|
||||
// public static int rangefinderPort = 1;
|
||||
// public static int rangefinderModule = 1;
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.templates.oldcommandbased.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.templates.oldcommandbased.Robot;
|
||||
|
||||
/** An example command. You can replace me with your own command. */
|
||||
public class ExampleCommand extends Command {
|
||||
public ExampleCommand() {
|
||||
// Use requires() here to declare subsystem dependencies
|
||||
requires(Robot.m_subsystem);
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
@Override
|
||||
protected void initialize() {}
|
||||
|
||||
// Called repeatedly when this Command is scheduled to run
|
||||
@Override
|
||||
protected void execute() {}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
@Override
|
||||
protected boolean isFinished() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Called once after isFinished returns true
|
||||
@Override
|
||||
protected void end() {}
|
||||
|
||||
// Called when another command which requires one or more of the same
|
||||
// subsystems is scheduled to run
|
||||
@Override
|
||||
protected void interrupted() {}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.templates.oldcommandbased.subsystems;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.Subsystem;
|
||||
|
||||
/** An example subsystem. You can replace with me with your own subsystem. */
|
||||
public class ExampleSubsystem extends Subsystem {
|
||||
// Put methods for controlling this subsystem
|
||||
// here. Call these from Commands.
|
||||
|
||||
@Override
|
||||
protected void initDefaultCommand() {
|
||||
// Set the default command for a subsystem here.
|
||||
// setDefaultCommand(new MySpecialCommand());
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
"foldername": "timed",
|
||||
"gradlebase": "java",
|
||||
"mainclass": "Main",
|
||||
"commandversion": 1
|
||||
"commandversion": 2
|
||||
},
|
||||
{
|
||||
"name": "Timed Skeleton (Advanced)",
|
||||
@@ -19,7 +19,7 @@
|
||||
"foldername": "timedskeleton",
|
||||
"gradlebase": "java",
|
||||
"mainclass": "Main",
|
||||
"commandversion": 1
|
||||
"commandversion": 2
|
||||
},
|
||||
{
|
||||
"name": "RobotBase Skeleton (Advanced)",
|
||||
@@ -30,7 +30,7 @@
|
||||
"foldername": "robotbaseskeleton",
|
||||
"gradlebase": "java",
|
||||
"mainclass": "Main",
|
||||
"commandversion": 1
|
||||
"commandversion": 2
|
||||
},
|
||||
{
|
||||
"name": "Command Robot",
|
||||
@@ -43,17 +43,6 @@
|
||||
"mainclass": "Main",
|
||||
"commandversion": 2
|
||||
},
|
||||
{
|
||||
"name": "Old Command Robot",
|
||||
"description": "Old-command style (deprecated)",
|
||||
"tags": [
|
||||
"Command"
|
||||
],
|
||||
"foldername": "oldcommandbased",
|
||||
"gradlebase": "java",
|
||||
"mainclass": "Main",
|
||||
"commandversion": 1
|
||||
},
|
||||
{
|
||||
"name": "Romi - Timed Robot",
|
||||
"description": "Romi - Timed style",
|
||||
|
||||
Reference in New Issue
Block a user