mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Moves C++ templates and examples to match gradle setup (#1065)
This commit is contained in:
committed by
Peter Johnson
parent
d564e19ef3
commit
cff475c1fc
@@ -0,0 +1,22 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
class CheckForHotGoal : public frc::Command {
|
||||
public:
|
||||
explicit CheckForHotGoal(double time);
|
||||
bool IsFinished() override;
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/InstantCommand.h>
|
||||
|
||||
/**
|
||||
* Close the claw.
|
||||
*
|
||||
* NOTE: It doesn't wait for the claw to close since there is no sensor to
|
||||
* detect that.
|
||||
*/
|
||||
class CloseClaw : public frc::InstantCommand {
|
||||
public:
|
||||
CloseClaw();
|
||||
void Initialize() override;
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/CommandGroup.h>
|
||||
|
||||
/**
|
||||
* Get the robot set to collect balls.
|
||||
*/
|
||||
class Collect : public frc::CommandGroup {
|
||||
public:
|
||||
Collect();
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/CommandGroup.h>
|
||||
|
||||
/**
|
||||
* Drive over the line and then shoot the ball. If the hot goal is not detected,
|
||||
* it will wait briefly.
|
||||
*/
|
||||
class DriveAndShootAutonomous : public frc::CommandGroup {
|
||||
public:
|
||||
DriveAndShootAutonomous();
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
class DriveForward : public frc::Command {
|
||||
public:
|
||||
DriveForward();
|
||||
explicit DriveForward(double dist);
|
||||
DriveForward(double dist, double maxSpeed);
|
||||
void Initialize() override;
|
||||
void Execute() override;
|
||||
bool IsFinished() override;
|
||||
void End() override;
|
||||
|
||||
private:
|
||||
double m_driveForwardSpeed;
|
||||
double m_distance;
|
||||
double m_error = 0;
|
||||
static constexpr double kTolerance = 0.1;
|
||||
static constexpr double kP = -1.0 / 5.0;
|
||||
|
||||
void init(double dist, double maxSpeed);
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* This command allows PS3 joystick to drive the robot. It is always running
|
||||
* except when interrupted by another command.
|
||||
*/
|
||||
class DriveWithJoystick : public frc::Command {
|
||||
public:
|
||||
DriveWithJoystick();
|
||||
void Execute() override;
|
||||
bool IsFinished() override;
|
||||
void End() override;
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/TimedCommand.h>
|
||||
|
||||
/**
|
||||
* Extend the shooter and then retract it after a second.
|
||||
*/
|
||||
class ExtendShooter : public frc::TimedCommand {
|
||||
public:
|
||||
ExtendShooter();
|
||||
void Initialize() override;
|
||||
void End() override;
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/CommandGroup.h>
|
||||
|
||||
/**
|
||||
* Spit the ball out into the low goal assuming that the robot is in front of
|
||||
* it.
|
||||
*/
|
||||
class LowGoal : public frc::CommandGroup {
|
||||
public:
|
||||
LowGoal();
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* Opens the claw
|
||||
*/
|
||||
class OpenClaw : public frc::Command {
|
||||
public:
|
||||
OpenClaw();
|
||||
void Initialize() override;
|
||||
bool IsFinished() override;
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/InstantCommand.h>
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
class SetCollectionSpeed : public frc::InstantCommand {
|
||||
public:
|
||||
explicit SetCollectionSpeed(double speed);
|
||||
void Initialize() override;
|
||||
|
||||
private:
|
||||
double m_speed;
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* 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!
|
||||
*/
|
||||
class SetPivotSetpoint : public frc::Command {
|
||||
public:
|
||||
explicit SetPivotSetpoint(double setpoint);
|
||||
void Initialize() override;
|
||||
bool IsFinished() override;
|
||||
|
||||
private:
|
||||
double m_setpoint;
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/CommandGroup.h>
|
||||
|
||||
/**
|
||||
* Shoot the ball at the current angle.
|
||||
*/
|
||||
class Shoot : public frc::CommandGroup {
|
||||
public:
|
||||
Shoot();
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
class WaitForBall : public frc::Command {
|
||||
public:
|
||||
WaitForBall();
|
||||
bool IsFinished() override;
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
class WaitForPressure : public frc::Command {
|
||||
public:
|
||||
WaitForPressure();
|
||||
bool IsFinished() override;
|
||||
};
|
||||
29
wpilibcExamples/src/main/cpp/examples/PacGoat/include/OI.h
Normal file
29
wpilibcExamples/src/main/cpp/examples/PacGoat/include/OI.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Buttons/JoystickButton.h>
|
||||
#include <Joystick.h>
|
||||
|
||||
#include "Triggers/DoubleButton.h"
|
||||
|
||||
class OI {
|
||||
public:
|
||||
OI();
|
||||
frc::Joystick& GetJoystick();
|
||||
|
||||
private:
|
||||
frc::Joystick m_joystick{0};
|
||||
|
||||
frc::JoystickButton m_l1{&m_joystick, 11};
|
||||
frc::JoystickButton m_l2{&m_joystick, 9};
|
||||
frc::JoystickButton m_r1{&m_joystick, 12};
|
||||
frc::JoystickButton m_r2{&m_joystick, 10};
|
||||
|
||||
DoubleButton m_sticks{&m_joystick, 2, 3};
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/Command.h>
|
||||
#include <IterativeRobot.h>
|
||||
#include <SmartDashboard/SendableChooser.h>
|
||||
|
||||
#include "Commands/DriveAndShootAutonomous.h"
|
||||
#include "Commands/DriveForward.h"
|
||||
#include "OI.h"
|
||||
#include "Subsystems/Collector.h"
|
||||
#include "Subsystems/DriveTrain.h"
|
||||
#include "Subsystems/Pivot.h"
|
||||
#include "Subsystems/Pneumatics.h"
|
||||
#include "Subsystems/Shooter.h"
|
||||
|
||||
class Robot : public IterativeRobot {
|
||||
public:
|
||||
static DriveTrain drivetrain;
|
||||
static Pivot pivot;
|
||||
static Collector collector;
|
||||
static Shooter shooter;
|
||||
static Pneumatics pneumatics;
|
||||
static OI oi;
|
||||
|
||||
private:
|
||||
frc::Command* m_autonomousCommand = nullptr;
|
||||
DriveAndShootAutonomous m_driveAndShootAuto;
|
||||
DriveForward m_driveForwardAuto;
|
||||
SendableChooser<frc::Command*> m_autoChooser;
|
||||
|
||||
void RobotInit() override;
|
||||
void AutonomousInit() override;
|
||||
void AutonomousPeriodic() override;
|
||||
void TeleopInit() override;
|
||||
void TeleopPeriodic() override;
|
||||
void TestPeriodic() override;
|
||||
void DisabledInit() override;
|
||||
void DisabledPeriodic() override;
|
||||
|
||||
void Log();
|
||||
};
|
||||
@@ -0,0 +1,76 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/Subsystem.h>
|
||||
#include <DigitalInput.h>
|
||||
#include <Solenoid.h>
|
||||
#include <Spark.h>
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
class Collector : public frc::Subsystem {
|
||||
public:
|
||||
// Constants for some useful speeds
|
||||
static constexpr double kForward = 1;
|
||||
static constexpr double kStop = 0;
|
||||
static constexpr double kReverse = -1;
|
||||
|
||||
Collector();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
bool HasBall();
|
||||
|
||||
/**
|
||||
* @param speed The speed to spin the rollers.
|
||||
*/
|
||||
void SetSpeed(double speed);
|
||||
|
||||
/**
|
||||
* Stop the rollers from spinning
|
||||
*/
|
||||
void Stop();
|
||||
|
||||
/**
|
||||
* @return Whether or not the claw is open.
|
||||
*/
|
||||
bool IsOpen();
|
||||
|
||||
/**
|
||||
* Open the claw up. (For shooting)
|
||||
*/
|
||||
void Open();
|
||||
|
||||
/**
|
||||
* Close the claw. (For collecting and driving)
|
||||
*/
|
||||
void Close();
|
||||
|
||||
/**
|
||||
* No default command.
|
||||
*/
|
||||
void InitDefaultCommand() override;
|
||||
|
||||
private:
|
||||
// Subsystem devices
|
||||
frc::Spark m_rollerMotor{6};
|
||||
frc::DigitalInput m_ballDetector{10};
|
||||
frc::Solenoid m_piston{1};
|
||||
frc::DigitalInput m_openDetector{6};
|
||||
};
|
||||
@@ -0,0 +1,79 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AnalogGyro.h>
|
||||
#include <Commands/Subsystem.h>
|
||||
#include <Drive/DifferentialDrive.h>
|
||||
#include <Encoder.h>
|
||||
#include <Spark.h>
|
||||
#include <SpeedControllerGroup.h>
|
||||
|
||||
namespace frc {
|
||||
class Joystick;
|
||||
} // namespace frc
|
||||
|
||||
/**
|
||||
* The DriveTrain subsystem controls the robot's chassis and reads in
|
||||
* information about it's speed and position.
|
||||
*/
|
||||
class DriveTrain : public frc::Subsystem {
|
||||
public:
|
||||
DriveTrain();
|
||||
|
||||
/**
|
||||
* When other commands aren't using the drivetrain, allow tank drive
|
||||
* with
|
||||
* the joystick.
|
||||
*/
|
||||
void InitDefaultCommand();
|
||||
|
||||
/**
|
||||
* @param leftAxis Left sides value
|
||||
* @param rightAxis Right sides value
|
||||
*/
|
||||
void TankDrive(double leftAxis, double rightAxis);
|
||||
|
||||
/**
|
||||
* Stop the drivetrain from moving.
|
||||
*/
|
||||
void Stop();
|
||||
|
||||
/**
|
||||
* @return The encoder getting the distance and speed of left side of
|
||||
* the drivetrain.
|
||||
*/
|
||||
Encoder& GetLeftEncoder();
|
||||
|
||||
/**
|
||||
* @return The encoder getting the distance and speed of right side of
|
||||
* the drivetrain.
|
||||
*/
|
||||
Encoder& GetRightEncoder();
|
||||
|
||||
/**
|
||||
* @return The current angle of the drivetrain.
|
||||
*/
|
||||
double GetAngle();
|
||||
|
||||
private:
|
||||
// Subsystem devices
|
||||
frc::Spark m_frontLeftCIM{1};
|
||||
frc::Spark m_rearLeftCIM{2};
|
||||
frc::SpeedControllerGroup m_leftCIMs{m_frontLeftCIM, m_rearLeftCIM};
|
||||
|
||||
frc::Spark m_frontRightCIM{3};
|
||||
frc::Spark m_rearRightCIM{4};
|
||||
frc::SpeedControllerGroup m_rightCIMs{m_frontRightCIM, m_rearRightCIM};
|
||||
|
||||
frc::DifferentialDrive m_robotDrive{m_leftCIMs, m_rightCIMs};
|
||||
|
||||
frc::Encoder m_rightEncoder{1, 2, true, Encoder::k4X};
|
||||
frc::Encoder m_leftEncoder{3, 4, false, Encoder::k4X};
|
||||
frc::AnalogGyro m_gyro{0};
|
||||
};
|
||||
@@ -0,0 +1,74 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AnalogPotentiometer.h>
|
||||
#include <Commands/PIDSubsystem.h>
|
||||
#include <DigitalInput.h>
|
||||
#include <Spark.h>
|
||||
|
||||
/**
|
||||
* The Pivot subsystem contains the Van-door motor and the pot for PID control
|
||||
* of angle of the pivot and claw.
|
||||
*/
|
||||
class Pivot : public frc::PIDSubsystem {
|
||||
public:
|
||||
// Constants for some useful angles
|
||||
static constexpr double kCollect = 105;
|
||||
static constexpr double kLowGoal = 90;
|
||||
static constexpr double kShoot = 45;
|
||||
static constexpr double kShootNear = 30;
|
||||
|
||||
Pivot();
|
||||
|
||||
/**
|
||||
* No default command, if PID is enabled, the current setpoint will be
|
||||
* maintained.
|
||||
*/
|
||||
void InitDefaultCommand() override {}
|
||||
|
||||
/**
|
||||
* @return The angle read in by the potentiometer
|
||||
*/
|
||||
double ReturnPIDInput() override;
|
||||
|
||||
/**
|
||||
* Set the motor speed based off of the PID output
|
||||
*/
|
||||
void UsePIDOutput(double output) override;
|
||||
|
||||
/**
|
||||
* @return If the pivot is at its upper limit.
|
||||
*/
|
||||
bool IsAtUpperLimit();
|
||||
|
||||
/**
|
||||
* @return If the pivot is at its lower limit.
|
||||
*/
|
||||
bool IsAtLowerLimit();
|
||||
|
||||
/**
|
||||
* @return The current angle of the pivot.
|
||||
*/
|
||||
double GetAngle();
|
||||
|
||||
private:
|
||||
// Subsystem devices
|
||||
|
||||
// Sensors for measuring the position of the pivot
|
||||
frc::DigitalInput m_upperLimitSwitch{13};
|
||||
frc::DigitalInput m_lowerLimitSwitch{12};
|
||||
|
||||
/* 0 degrees is vertical facing up.
|
||||
* Angle increases the more forward the pivot goes.
|
||||
*/
|
||||
frc::AnalogPotentiometer m_pot{1};
|
||||
|
||||
// Motor to move the pivot
|
||||
frc::Spark m_motor{5};
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AnalogInput.h>
|
||||
#include <Commands/Subsystem.h>
|
||||
#include <Compressor.h>
|
||||
|
||||
/**
|
||||
* The Pneumatics subsystem contains the compressor and a pressure sensor.
|
||||
*
|
||||
* NOTE: The simulator currently doesn't support the compressor or pressure
|
||||
* sensors.
|
||||
*/
|
||||
class Pneumatics : public frc::Subsystem {
|
||||
public:
|
||||
Pneumatics();
|
||||
|
||||
/**
|
||||
* No default command
|
||||
*/
|
||||
void InitDefaultCommand() override;
|
||||
|
||||
/**
|
||||
* Start the compressor going. The compressor automatically starts and
|
||||
* stops as it goes above and below maximum pressure.
|
||||
*/
|
||||
void Start();
|
||||
|
||||
/**
|
||||
* @return Whether or not the system is fully pressurized.
|
||||
*/
|
||||
bool IsPressurized();
|
||||
|
||||
/**
|
||||
* Puts the pressure on the SmartDashboard.
|
||||
*/
|
||||
void WritePressure();
|
||||
|
||||
private:
|
||||
frc::AnalogInput m_pressureSensor{3};
|
||||
|
||||
#ifndef SIMULATION
|
||||
frc::Compressor m_compressor{1}; // TODO: (1, 14, 1, 8);
|
||||
#endif
|
||||
|
||||
static constexpr double kMaxPressure = 2.55;
|
||||
};
|
||||
@@ -0,0 +1,127 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Commands/Subsystem.h>
|
||||
#include <DigitalInput.h>
|
||||
#include <DoubleSolenoid.h>
|
||||
#include <Solenoid.h>
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* NOTE: Simulation currently approximates this as as single pneumatic cylinder
|
||||
* and ignores the latch.
|
||||
*/
|
||||
class Shooter : public frc::Subsystem {
|
||||
public:
|
||||
Shooter();
|
||||
void InitDefaultCommand() override;
|
||||
|
||||
/**
|
||||
* Extend both solenoids to shoot.
|
||||
*/
|
||||
void ExtendBoth();
|
||||
|
||||
/**
|
||||
* Retract both solenoids to prepare to shoot.
|
||||
*/
|
||||
void RetractBoth();
|
||||
|
||||
/**
|
||||
* Extend solenoid 1 to shoot.
|
||||
*/
|
||||
void Extend1();
|
||||
|
||||
/**
|
||||
* Retract solenoid 1 to prepare to shoot.
|
||||
*/
|
||||
void Retract1();
|
||||
|
||||
/**
|
||||
* Extend solenoid 2 to shoot.
|
||||
*/
|
||||
void Extend2();
|
||||
|
||||
/**
|
||||
* Retract solenoid 2 to prepare to shoot.
|
||||
*/
|
||||
void Retract2();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void Off1();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void Off2();
|
||||
|
||||
/**
|
||||
* Release the latch so that we can shoot
|
||||
*/
|
||||
void Unlatch();
|
||||
|
||||
/**
|
||||
* Latch so that pressure can build up and we aren't limited by air
|
||||
* flow.
|
||||
*/
|
||||
void Latch();
|
||||
|
||||
/**
|
||||
* Toggles the latch postions
|
||||
*/
|
||||
void ToggleLatchPosition();
|
||||
|
||||
/**
|
||||
* @return Whether or not piston 1 is fully extended.
|
||||
*/
|
||||
bool Piston1IsExtended();
|
||||
|
||||
/**
|
||||
* @return Whether or not piston 1 is fully retracted.
|
||||
*/
|
||||
bool Piston1IsRetracted();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
void OffBoth();
|
||||
|
||||
/**
|
||||
* @return Whether or not the goal is hot as read by the banner sensor
|
||||
*/
|
||||
bool GoalIsHot();
|
||||
|
||||
private:
|
||||
// Devices
|
||||
frc::DoubleSolenoid m_piston1{3, 4};
|
||||
frc::DoubleSolenoid m_piston2{5, 6};
|
||||
frc::Solenoid m_latchPiston{1, 2};
|
||||
frc::DigitalInput m_piston1ReedSwitchFront{9};
|
||||
frc::DigitalInput m_piston1ReedSwitchBack{11};
|
||||
frc::DigitalInput m_hotGoalSensor{
|
||||
7}; // NOTE: Currently ignored in simulation
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Buttons/Trigger.h>
|
||||
|
||||
namespace frc {
|
||||
class Joystick;
|
||||
} // namespace frc
|
||||
|
||||
class DoubleButton : public frc::Trigger {
|
||||
public:
|
||||
DoubleButton(frc::Joystick* joy, int button1, int button2);
|
||||
|
||||
bool Get();
|
||||
|
||||
private:
|
||||
frc::Joystick& m_joy;
|
||||
int m_button1;
|
||||
int m_button2;
|
||||
};
|
||||
Reference in New Issue
Block a user