From 9be96ef26ff519fe56218c2733bc028a87ff9fb4 Mon Sep 17 00:00:00 2001 From: DinoHunter696 <55260008+DinoHunter696@users.noreply.github.com> Date: Tue, 28 Sep 2021 22:12:30 -0700 Subject: [PATCH 1/2] Moved 2021 robot code over from 2020 robot code --- NewDriveTest/.gitignore => .gitignore | 0 {NewDriveTest/.vscode => .vscode}/launch.json | 0 .../.vscode => .vscode}/settings.json | 4 +- .../wpilib_preferences.json | 0 NewDriveTest/WPILib-License.md | 24 -- .../src/main/java/frc/robot/Constants.java | 22 - .../src/main/java/frc/robot/Robot.java | 119 ------ .../main/java/frc/robot/RobotContainer.java | 44 -- .../java/frc/robot/subsystems/DriveTrain.java | 56 --- README.md | 1 + Version and Port Tracking.xlsx | Bin 0 -> 9757 bytes NewDriveTest/build.gradle => build.gradle | 46 ++- config/checkstyle/checkstyle.xml | 223 ++++++++++ .../wrapper/gradle-wrapper.jar | Bin .../wrapper/gradle-wrapper.properties | 0 NewDriveTest/gradlew => gradlew | 0 NewDriveTest/gradlew.bat => gradlew.bat | 0 .../settings.gradle => settings.gradle | 2 +- .../src => src}/main/deploy/example.txt | 0 .../java/org/team696/robot/Constants.java | 229 ++++++++++ .../main/java/org/team696}/robot/Main.java | 14 +- src/main/java/org/team696/robot/Robot.java | 202 +++++++++ .../org/team696/robot/RobotContainer.java | 229 ++++++++++ .../org/team696/robot/TrajectoryTable.java | 349 ++++++++++++++++ .../team696/robot/commands/ATCForCommand.java | 70 ++++ .../team696/robot/commands/ATCRevCommand.java | 63 +++ .../robot/commands/AutoIndexKickUp.java | 34 ++ .../team696/robot/commands/ClimberLift.java | 69 ++++ .../team696/robot/commands/ClimberReach.java | 68 +++ .../robot/commands/ContinuousShoot.java | 61 +++ .../org/team696/robot/commands/Drive.java | 59 +++ .../team696/robot/commands/DriveTimer.java | 55 +++ .../team696/robot/commands/FireCommand.java | 65 +++ .../org/team696/robot/commands/FullShoot.java | 44 ++ .../team696/robot/commands/IntakeCommand.java | 53 +++ .../robot/commands/IntakeTimerCommand.java | 55 +++ .../team696/robot/commands/OmniKickUp.java | 50 +++ .../robot/commands/OmniKickUpTimer.java | 61 +++ .../robot/commands/ShooterCommand.java | 72 ++++ .../robot/commands/ShooterHoodCommand.java | 71 ++++ .../robot/commands/ShooterPowerCommand.java | 51 +++ .../team696/robot/commands/ShooterPrep.java | 54 +++ .../robot/commands/ShooterTimerCommand.java | 60 +++ .../team696/robot/commands/SpinToPocket.java | 71 ++++ .../robot/commands/SpindexerLoading.java | 57 +++ .../team696/robot/commands/StopTurret.java | 47 +++ .../team696/robot/commands/TurretLockOn.java | 53 +++ .../team696/robot/commands/TurretManual.java | 64 +++ .../team696/robot/subsystems/BallSensors.java | 138 +++++++ .../robot/subsystems/ClimberServos.java | 54 +++ .../robot/subsystems/ClimberSubsystem.java | 224 ++++++++++ .../team696/robot/subsystems/Drivetrain.java | 325 +++++++++++++++ .../org/team696/robot/subsystems/Intake.java | 44 ++ .../team696/robot/subsystems/Limelight.java | 163 ++++++++ .../org/team696/robot/subsystems/Shooter.java | 332 +++++++++++++++ .../team696/robot/subsystems/ShooterHood.java | 70 ++++ .../team696/robot/subsystems/Spindexer.java | 391 ++++++++++++++++++ .../robot/subsystems/TurretSubsystem.java | 149 +++++++ src/main/resources/log4j2.xml | 22 + vendordeps/Phoenix.json | 214 ++++++++++ vendordeps/REV2mDistanceSensor.json | 55 +++ .../REVRobotics.json | 78 ++-- .../WPILibNewCommands.json | 0 vendordeps/navx_frc.json | 35 ++ 64 files changed, 4942 insertions(+), 323 deletions(-) rename NewDriveTest/.gitignore => .gitignore (100%) rename {NewDriveTest/.vscode => .vscode}/launch.json (100%) rename {NewDriveTest/.vscode => .vscode}/settings.json (77%) rename {NewDriveTest/.wpilib => .wpilib}/wpilib_preferences.json (100%) delete mode 100644 NewDriveTest/WPILib-License.md delete mode 100644 NewDriveTest/src/main/java/frc/robot/Constants.java delete mode 100644 NewDriveTest/src/main/java/frc/robot/Robot.java delete mode 100644 NewDriveTest/src/main/java/frc/robot/RobotContainer.java delete mode 100644 NewDriveTest/src/main/java/frc/robot/subsystems/DriveTrain.java create mode 100644 README.md create mode 100644 Version and Port Tracking.xlsx rename NewDriveTest/build.gradle => build.gradle (70%) create mode 100644 config/checkstyle/checkstyle.xml rename {NewDriveTest/gradle => gradle}/wrapper/gradle-wrapper.jar (100%) rename {NewDriveTest/gradle => gradle}/wrapper/gradle-wrapper.properties (100%) rename NewDriveTest/gradlew => gradlew (100%) rename NewDriveTest/gradlew.bat => gradlew.bat (100%) rename NewDriveTest/settings.gradle => settings.gradle (96%) rename {NewDriveTest/src => src}/main/deploy/example.txt (100%) create mode 100644 src/main/java/org/team696/robot/Constants.java rename {NewDriveTest/src/main/java/frc => src/main/java/org/team696}/robot/Main.java (50%) create mode 100644 src/main/java/org/team696/robot/Robot.java create mode 100644 src/main/java/org/team696/robot/RobotContainer.java create mode 100644 src/main/java/org/team696/robot/TrajectoryTable.java create mode 100644 src/main/java/org/team696/robot/commands/ATCForCommand.java create mode 100644 src/main/java/org/team696/robot/commands/ATCRevCommand.java create mode 100644 src/main/java/org/team696/robot/commands/AutoIndexKickUp.java create mode 100644 src/main/java/org/team696/robot/commands/ClimberLift.java create mode 100644 src/main/java/org/team696/robot/commands/ClimberReach.java create mode 100644 src/main/java/org/team696/robot/commands/ContinuousShoot.java create mode 100644 src/main/java/org/team696/robot/commands/Drive.java create mode 100644 src/main/java/org/team696/robot/commands/DriveTimer.java create mode 100644 src/main/java/org/team696/robot/commands/FireCommand.java create mode 100644 src/main/java/org/team696/robot/commands/FullShoot.java create mode 100644 src/main/java/org/team696/robot/commands/IntakeCommand.java create mode 100644 src/main/java/org/team696/robot/commands/IntakeTimerCommand.java create mode 100644 src/main/java/org/team696/robot/commands/OmniKickUp.java create mode 100644 src/main/java/org/team696/robot/commands/OmniKickUpTimer.java create mode 100644 src/main/java/org/team696/robot/commands/ShooterCommand.java create mode 100644 src/main/java/org/team696/robot/commands/ShooterHoodCommand.java create mode 100644 src/main/java/org/team696/robot/commands/ShooterPowerCommand.java create mode 100644 src/main/java/org/team696/robot/commands/ShooterPrep.java create mode 100644 src/main/java/org/team696/robot/commands/ShooterTimerCommand.java create mode 100644 src/main/java/org/team696/robot/commands/SpinToPocket.java create mode 100644 src/main/java/org/team696/robot/commands/SpindexerLoading.java create mode 100644 src/main/java/org/team696/robot/commands/StopTurret.java create mode 100644 src/main/java/org/team696/robot/commands/TurretLockOn.java create mode 100644 src/main/java/org/team696/robot/commands/TurretManual.java create mode 100644 src/main/java/org/team696/robot/subsystems/BallSensors.java create mode 100644 src/main/java/org/team696/robot/subsystems/ClimberServos.java create mode 100644 src/main/java/org/team696/robot/subsystems/ClimberSubsystem.java create mode 100644 src/main/java/org/team696/robot/subsystems/Drivetrain.java create mode 100644 src/main/java/org/team696/robot/subsystems/Intake.java create mode 100644 src/main/java/org/team696/robot/subsystems/Limelight.java create mode 100644 src/main/java/org/team696/robot/subsystems/Shooter.java create mode 100644 src/main/java/org/team696/robot/subsystems/ShooterHood.java create mode 100644 src/main/java/org/team696/robot/subsystems/Spindexer.java create mode 100644 src/main/java/org/team696/robot/subsystems/TurretSubsystem.java create mode 100644 src/main/resources/log4j2.xml create mode 100644 vendordeps/Phoenix.json create mode 100644 vendordeps/REV2mDistanceSensor.json rename {NewDriveTest/vendordeps => vendordeps}/REVRobotics.json (92%) rename {NewDriveTest/vendordeps => vendordeps}/WPILibNewCommands.json (100%) create mode 100644 vendordeps/navx_frc.json diff --git a/NewDriveTest/.gitignore b/.gitignore similarity index 100% rename from NewDriveTest/.gitignore rename to .gitignore diff --git a/NewDriveTest/.vscode/launch.json b/.vscode/launch.json similarity index 100% rename from NewDriveTest/.vscode/launch.json rename to .vscode/launch.json diff --git a/NewDriveTest/.vscode/settings.json b/.vscode/settings.json similarity index 77% rename from NewDriveTest/.vscode/settings.json rename to .vscode/settings.json index 786b2c7..5200b5c 100644 --- a/NewDriveTest/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,5 @@ { "java.configuration.updateBuildConfiguration": "automatic", - "java.server.launchMode": "Standard", "files.exclude": { "**/.git": true, "**/.svn": true, @@ -11,7 +10,6 @@ "**/.classpath": true, "**/.project": true, "**/.settings": true, - "**/.factorypath": true, - "**/*~": true + "**/.factorypath": true } } diff --git a/NewDriveTest/.wpilib/wpilib_preferences.json b/.wpilib/wpilib_preferences.json similarity index 100% rename from NewDriveTest/.wpilib/wpilib_preferences.json rename to .wpilib/wpilib_preferences.json diff --git a/NewDriveTest/WPILib-License.md b/NewDriveTest/WPILib-License.md deleted file mode 100644 index 3d5a824..0000000 --- a/NewDriveTest/WPILib-License.md +++ /dev/null @@ -1,24 +0,0 @@ -Copyright (c) 2009-2021 FIRST and other WPILib contributors -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of FIRST, WPILib, nor the names of other WPILib - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY FIRST AND OTHER WPILIB CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR -PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FIRST OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/NewDriveTest/src/main/java/frc/robot/Constants.java b/NewDriveTest/src/main/java/frc/robot/Constants.java deleted file mode 100644 index 230563b..0000000 --- a/NewDriveTest/src/main/java/frc/robot/Constants.java +++ /dev/null @@ -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 frc.robot; - -/** - * The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean - * constants. This class should not be used for any other purpose. All constants should be declared - * globally (i.e. public static). Do not put anything functional in this class. - * - *

It is advised to statically import this class (or one of its inner classes) wherever the - * constants are needed, to reduce verbosity. - */ -public final class Constants { - /** Organizes all the non-changing values we use in the code */ - public static final int leftFrontPort = 10; - public static final int leftBackPort = 11; - public static final int rightFrontPort = 12; - public static final int rightBackPort = 13; - -} diff --git a/NewDriveTest/src/main/java/frc/robot/Robot.java b/NewDriveTest/src/main/java/frc/robot/Robot.java deleted file mode 100644 index 885590d..0000000 --- a/NewDriveTest/src/main/java/frc/robot/Robot.java +++ /dev/null @@ -1,119 +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 frc.robot; - -import edu.wpi.first.wpilibj.TimedRobot; -import edu.wpi.first.wpilibj2.command.Command; -import edu.wpi.first.wpilibj2.command.CommandScheduler; -import frc.robot.subsystems.DriveTrain; - -/** - * 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 { - /** You can leave this in if you want, it only changes anything if you are using the autonomous part of the code, - * if you do remove it, just delete any errors it creates */ - private Command m_autonomousCommand; - - /**Creates an object for our DriveTrain class so we can call things from the class - * make sure to include any variables needed for the parameters - */ - public static DriveTrain m_driveTrain = new DriveTrain(Constants.leftFrontPort, Constants.leftBackPort, Constants.rightFrontPort, Constants.rightBackPort); - /** Similar to the previous line, creates a RobotContainer object so we can call things from the robotcontainer class, - * what you name this is up to you */ - private RobotContainer m_robotContainer; - - - /** The values that we will use from the joystick */ - double xAxis; - double yAxis; - /** Values that will go in the parameters that are needed for the RobotDrive method */ - double leftSpeed; - double rightSpeed; - - /** - * This function is run when the robot is first started up and should be used for any - * initialization code. - */ - @Override - public void robotInit() { - // Instantiate our RobotContainer. This will perform all our button bindings, and put our - // autonomous chooser on the dashboard. - m_robotContainer = new RobotContainer(); - } - - /** - * 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. - * - *

This runs after the mode specific periodic functions, but before LiveWindow and - * SmartDashboard integrated updating. - */ - @Override - public void robotPeriodic() { - // Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled - // commands, running already-scheduled commands, removing finished or interrupted commands, - // and running subsystem periodic() methods. This must be called from the robot's periodic - // block in order for anything in the Command-based framework to work. - CommandScheduler.getInstance().run(); - } - - /** This function is called once each time the robot enters Disabled mode. */ - @Override - public void disabledInit() {} - - @Override - public void disabledPeriodic() {} - - /** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */ - @Override - public void autonomousInit() { - - } - - /** This function is called periodically during autonomous. */ - @Override - public void autonomousPeriodic() {} - - @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() { - /** Defining the XAxis and yAxis objects as the x and y values from our joysticks on the controller */ - xAxis = -m_robotContainer.xboxController.getRawAxis(1); - yAxis = m_robotContainer.xboxController.getRawAxis(4); - /** The math required to make the robot turn left and right properly according to the joystick configuration. */ - leftSpeed = yAxis + xAxis; - rightSpeed = yAxis - xAxis; - /** Calling back the robotDrive method from the DriveTrain class so that it runs fifty times a second - * uses the parameters leftSpeed and rightSpeed that we just defined - */ - m_driveTrain.robotDrive(leftSpeed, rightSpeed); - - } - - @Override - public void testInit() { - // Cancels all running commands at the start of test mode. - CommandScheduler.getInstance().cancelAll(); - } - - /** This function is called periodically during test mode. */ - @Override - public void testPeriodic() {} -} diff --git a/NewDriveTest/src/main/java/frc/robot/RobotContainer.java b/NewDriveTest/src/main/java/frc/robot/RobotContainer.java deleted file mode 100644 index 44489ff..0000000 --- a/NewDriveTest/src/main/java/frc/robot/RobotContainer.java +++ /dev/null @@ -1,44 +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 frc.robot; - -import edu.wpi.first.wpilibj.GenericHID; -import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.XboxController; - -import edu.wpi.first.wpilibj2.command.Command; - -/** - * This class is where the bulk of the robot should be declared. Since Command-based is a - * "declarative" paradigm, very little robot logic should actually be handled in the {@link Robot} - * periodic methods (other than the scheduler calls). Instead, the structure of the robot (including - * subsystems, commands, and button mappings) should be declared here. - */ -public class RobotContainer { - // The robot's subsystems and commands are defined here... - /** Declaring and defining our joystick object */ - public static Joystick xboxController = new Joystick(1); - - /** The container for the robot. Contains subsystems, OI devices, and commands. */ - public RobotContainer() { - // Configure the button bindings - configureButtonBindings(); - } - - /** - * Use this method to define your button->command mappings. Buttons can be created by - * instantiating a {@link GenericHID} or one of its subclasses ({@link - * edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a {@link - * edu.wpi.first.wpilibj2.command.button.JoystickButton}. - */ - private void configureButtonBindings() {} - - /** - * Use this to pass the autonomous command to the main {@link Robot} class. - * - * @return the command to run in autonomous - */ - -} diff --git a/NewDriveTest/src/main/java/frc/robot/subsystems/DriveTrain.java b/NewDriveTest/src/main/java/frc/robot/subsystems/DriveTrain.java deleted file mode 100644 index ba233bf..0000000 --- a/NewDriveTest/src/main/java/frc/robot/subsystems/DriveTrain.java +++ /dev/null @@ -1,56 +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 frc.robot.subsystems; - -/** YOU DO NOT HAVE TO WORRY ABOUT THIS SECTION, USING TAB WILL ADD ANYTHING NEEDED HERE AUTOMATICALLY */ -import com.revrobotics.CANSparkMax; -import com.revrobotics.CANSparkMaxLowLevel.MotorType; - - -import edu.wpi.first.wpilibj.SpeedControllerGroup; -import edu.wpi.first.wpilibj.drive.DifferentialDrive; -import edu.wpi.first.wpilibj2.command.SubsystemBase; - -public class DriveTrain extends SubsystemBase { - /** Creates a new DriveTrain. */ - /** Creates a differential drive which allows the two speed controller groups to work together */ - DifferentialDrive diffDrive; - /**Creates a speed controller group which allows you to run multiple motors with one object */ - SpeedControllerGroup leftSide; - SpeedControllerGroup rightSide; - /**Creates the objects for each motor controller */ - CANSparkMax leftFront; - CANSparkMax leftBack; - CANSparkMax rightFront; - CANSparkMax rightBack; - - - public DriveTrain(int leftFrontPort, int leftBackPort, int rightFrontPort, int rightBackPort) { - /** Defining all the motor controllers with the CANSparkMax(port, motor type) method */ - leftFront = new CANSparkMax(leftFrontPort, MotorType.kBrushless); - leftBack = new CANSparkMax(leftBackPort, MotorType.kBrushless); - rightBack = new CANSparkMax(rightBackPort, MotorType.kBrushless); - rightFront = new CANSparkMax(rightFrontPort, MotorType.kBrushless); - /**Defining the two speed controller groups using the SpeedControllerGroup(motor, motor) method */ - leftSide = new SpeedControllerGroup(leftFront, leftBack); - rightSide = new SpeedControllerGroup(rightFront, rightBack); - - /**Defining the differential drive object using the DifferentialDrive(speedcontrollergroup, speedcontrollergroup) method */ - diffDrive = new DifferentialDrive(leftSide, rightSide); - } - - /**Method we will use to actually control the robot, which need the parameters leftSpeed and rightSpeed, which will be defined in robot */ - public void robotDrive(double leftSpeed, double rightSpeed){ - /** A method tied to the DifferentialDrive object in the Wpilib libraries, basically lets us control the motors in a tank drive fashion */ - diffDrive.tankDrive(leftSpeed, rightSpeed); - /** Creates a minimum required output for the joystick to run the motor */ - diffDrive.setDeadband(0.1); - } - - @Override - public void periodic() { - // This method will be called once per scheduler run (50 times a second) - } -} diff --git a/README.md b/README.md new file mode 100644 index 0000000..f5306f1 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# FRC Team 696's code for the 2020 season. diff --git a/Version and Port Tracking.xlsx b/Version and Port Tracking.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..8aa5ebc95d96ea53ce1ab76deae9a4a4908f260a GIT binary patch literal 9757 zcmd^F1z40@x29W41cn+K6bT)=TjJ0NN_R7K_s|F`r9*d0cPk(gN{O^E14BrM5<_0_ z-2Wbr|2gMA_kaHX#&g#^vuA(%nZ3Tf-@U%I_Ikgqu8fXBhJu5GgW{g0qmJ@}P+rx& z9k?xAO}%Wv)^2~R+~e|gbjTPn1b6WeVDH}CBz!n;t4DcLhRkS0m4^_{0;Z0CHb9v7 zIdD{o-_{S6&hfnja%T|i-f%2ycGI6}y@nLi_g3AWArs+_Q*AQ4AY{@cv{&BXc@Oxs z4!~DF+*ZW6LlO|%t*4|TCJet%@MWy-#u9yDf^Z4$kfNu~(5rR1eMy{Dzqd_U ztc&ZN=&9(4uNNwlVGVqEM^YIyCxQ%N(P3|b`ri#tsl zx2F}P&qZ+sFQ^XY`ZPNR#*O>t$a+y})w=IC%lP(1R;>F2L!=WwVtnlJxQ%h+hFu8fU?ZDt#aiHd@PjgEq%{+~hV<>YGbW@BmT?#BK7 z=T|7_Ml~4~$=~gHw+&hYM>QmA|EBO3b+ckDsNvDRZ_9W*yi+pT)XLPe8rQ*U> zEKN=R{dncqw9duA`PhnyI99Jv9-5U-3*O8_0Wq3kMPTj5#-8O@Q%@w1ZQ*+rwy!JT zI)fWQE+QSqqDTBl9S;G3@sRbC>4W_*uKd%7byS_p*+|dnGHeTM^i+cc5*7Kc+(btb zWi4&Saf{FP=Dd-sz6Pz}j?6>g${4~CD6tu__i4rZ;H=k}&1<*^COh5qs^?n>F!mxX z|FV(|Kq#wcxK?b0FJ3mfTv3F(VfC`_kXT6Mu@`dVY;!5lee7)FZqVyX4{<>ez$TsX zdu#G(3NW1idE>&Zb-V}@Ac#t|!GZRIl0Y2#7? ze3{!CF{jeipg6@>o%hY^Ns}Xq7w5oOG0ZM^mi6R*g*(~SAiwP_>(OQg$S;vzoJN~v^>mRuBn2=m(n_NgoCI8kO(yd=OWc+qzeK4(z(-CkRs`{v5mJ|av$^!4JK8DIO^#W!K4nX&gfYL$5}C!`Kb^71{%0s=F4v+J2H z8<`8X^F7itUY_f^2JlRZX;&^iWwULMH%vM*?!Ougaa7F!w;H&+TOOX)*S?xg?N3a}UHqpE_Fd zg}$-gtw~Ps4b9zZ|J3lV(MkS*;0?GmuP{?;3FJLZq}V<-a!9?>Q0Q=}H;m#C-I7_< z&XA-lAQzbzG`+9T9zQZgXZRql;lWYhV0eD}XupPPW$dC1K%?RD=?v8+&-uz@lk{KT1aTzq}J`(XJS*TI^qvR@c2 z-$VG$q=7;J;iT?G0Ex~{kp9A>^H;6+6FQYmv%}-b?{NN7$1~O?jUPuYd^c7`Pa!dy zH|6gNjnvqW7D=pmynup!b`^Qs`$~!5n@CkyM=k!SxUa%GX7NV_o=V|}#UB;1tmeFc zynafRcQ*Is6Yr(Qj#_+gD(V+hd1rfHHPIzCcFZE36~PO*Zjz7Sr2>3(uu$lZXHa<% z!Al4D=x?Ebp1`1@5W&j`Sd7K6W)@`X1mF%SILkvor0MbS?@f8ZpsxG$P%MnuU=teR zGIWTKWEBw(7Fwq?JroCnI>dyTxC{f5B3X44CjzZglOBqPp&w#$m$(cQ(kxj;frEwK zX+{qvz(@-*;UzA^f=o+RQR76Qce>I;2{C3vOhk#xupvmvDj*IPMkjC~daTy-uu~ZcYP6TFW z4Ly_`V-{j!KwO3o@sXm)ddmp zkYLbamJ}Q)4bPH>17+Y@GH{^mKced&9Kye<8;OX_+acm=knASGKc%_^^M)Jyz+pbe zPr1e5vB#5i$47L>6u@Hv;IS^S>YsL>f9jxrR>tm$)iabm1t1d%HM3UVB#6n7ss{b@ z83S`_^m_Z>J-lj=#U=qjMCRSl^Z%vQm7{pL zKmyz=0p6GZKT3cLBpyF)RlIs0&zX;JuvGmk#@{)lUIilCB)}Ar`9D}a&fq|nb0FI} zkb@k^IS%9&M>QyErzwPGC<@j^`j1X2)YO`1lOQ6avkFA%iPb%1G6f(I`Ty4_=!w-k z1fK%Xh=iJ3J8u#^&FHKK{r_tufJH`hE;iV{0Ls4~o$k+1f$^>m&dud|3Hd=Ql%#`p zM(5j_#kVe*dtaC7H_%#nsj_o95uC zw3n*#nhyxLr2AU{sx`Wx2{3$;aRn?UuS^G3UkZXk(FiGTZ3-F%hZr-Ct|HWfm;HL2 z40SCS6P%eB)rK&&7(!LU8`Iwq;UlO!&5u~`5hO7?U(B?3Cs>oq8b(*f9NfIdpuBiP zrS@uucdnR_KW9NmuKr=+WUlV&Bm}>oO<`R^*LRm+1E(snXN6A*7BHbu7#rv?$sr-#CE$;3PBj9q1g+~SV?6q0bl*a z1G^WZCQG3s^)_)4q`)@_MURIH?+aXZ7h^FgsCL<7>Q+C#@TPz)hj}-nv-nft(sp|x zl5qCc8{Xm}85$(-EA2!<=@FQWx&z0aR>WjGW%GOkYX2bizbx!SJ71BTAb=^La&0L_tpqyXxQNVYV1?YYgop zRg6VzFp-TV>(ti>r=D-vGF_p2@RtbR{ME|bZ7dxvxxbg+DW*YPeWw{7vJ1>pq8G5q z&p4WMhI+)Ue9i^(;HYj= zt__f(R# z*KGt&>Mt~elEo9vJ(6-HgkZOWRV(hOVJ&Hen3LW4jHTfU&;N|V$wQ@&+p`-pelLsU zu)>dTg>%f77E(qVvUB3Sj`KF`W4nLu@vD)yvZ{)8TGC>pN~^&XB~%l$_0G5tdeWpHUQWcfzzKK4!v@}l=Isaw5t@1Hn!@ML zqYfR_)b6h)?$0OtP9V{}63Q-7uOGE05NgkzD>}EC@UNU1*{_e9n~kZfrG=Ke>orAw z?aw^4XP?gS5T8RXLYIpUa}=}FxJnbsh?8RQJejiRI#Mm@$vg5Jn!oMXr#47uW{WP< zSg)jm0M=?0xBGBom-Uw2iCL0@OWg;@#fxD4wMR@!W#*+;(j0wj+*RL7yb~X9L|tl6 zr}GchXDv?Y+)%J$nuF|rP^Ioq58^wWYQTErNR7fKC;CgmvuX(&+n0_z~A6u@Mipc!!9?Dzoe)r!JpC+ZcK!A=Gk3@&y9Out$)Z zZ%f)0${rUX77{kHVndJ}#y=SpQl?uxJ2{+h;Ey|+Jik7E7T&g;u(d#|gzgERv)OVk zHp~O8gUoaHWmDtv_;ob_UK zNUhcSZm~rA$+|IH_<-6C2~-ks!5YxTO9JGiYX@9EJx8yc^wMvJI{zLqBv5`qX#-`6FWEyCfI2J2A82yCVgw4IZb-e7yt~IiV=-%QS z^1w^u^INRab`>-t@Ni7GkNM-)-16%u>|oWm7l(HP(XVaBRRjjzzjDofn15w6H~!sb z+mgiG=6)S2A_r}Q-T zNA|VoR7J+zi$sx{rqmr87YLhbGfS9>u1G;sD~Zb|jIdI4aHQlcBT9gLC>m3f)vR!q zY_he|<%M;}iwexFe^hbhjOJ3#tPRMwcU7^OXX+1tzRqVV@i7>uK+)Ig1#vamx0X4R zChG}3ac$S+de_bny$SNoMRVVmj%OaIAHfpJMzOV;&n>nv9m-hH_P&W*jUd@Bfu}6^ zQ6kLyz{QWP?x~L19>p$*5+BQ0&#Xxq9MupHhfgW^M29j&OS<*ODwzgPz@9WjK*%<0 zQN{*OhaEa!CZC$w`1wbTLny?bEuU8v?|MTwjS26+`CR3}T?`s43>IJK$XJ+PLZ4I} ziO1c8`>pCWgX(WU-Q&%{-ja~&Jt)%a*FHqoo6K!TM@_OoWrb?e%4d2hQ1nH% zaWjJlm_Q1QGa~U$j|8r|stR^gtpdb#+xj@%)ryH#MnZ zUOEB!;u2vK_(l*xE>_mtYA0AD9**tRIiylm4URtNq((Shz~oGl%A1@GFkwRsL{Pa} zF<7YAY0-S2fCz>TWa|eCNfs^QX~{<%4nc)ac?X2$9~%9>em7brchd zJh!8JZ<6A6Gb9!&^jBuVMEH*-O0okiJX{On|))G+@Nx8SK$ zxD}Y7fQPcb({9DZ7JprdaN*$p@b( zRFiBDX_7ZNXqS(MTnLl<+mbCqeG|h?J8GbF=T9mtJ*vgqhBjc8b^!sGmJfg7&VpqP zyjt5EKG}a>$nd~jLQICWjsvmJeeHJ4=EEajU%8#*zkK^h_3PUInsEGR0pC-O@&pyt zZXV)rwKuePcc|HxAK;9yVKI2%FQdH66x1+Nvrr59OeZ6kn#*oBntYJSw-d1MU3>0M z>laB({Vjpw@esf}u5eFhfAV~6J+oF}fOi zn<2NNvjl2NBtEB2nV!oWdaM0oc@6!9Pas~FnkQ&+&x)cj?O z1)8SZ`0~vc8D{s_3gn}n&u!g7^-fXc=$i8J!u8Ko?~qv= zx1FI~19~aj-h_Jv=ym-6^F#*!3eaEC{ElG3a}~QQ1m)F6M53m95f&Os(djC;Ehu9A zf=hTC!a3ufC-FB2$mP^U+{H5-8b0y{op$$duV-j^lJYvFk&|IFO@wQ7+h4Z%pd{mC zDnG%Pa9$>e+y-BE;U}l|Cq8-nP@#{iP;-&VjQ^(JK%6Y0$9;u;ZMzitSPLsEfS04+ zvo!(qmRnl1c0v)*U0~JzXvMWv$1_5oS7}sz-Vx+X3xSDM9UuGTGa9sHo zM@x583sZMf)HM|HOOzh+8Ou9te64)O_2$c>A(8SWw!`d}S+hg;5397k&bmF$cnD8|>MgBZnGd=Y^qr!;aPCZQkzIW{jamw3ClN zaaxilX9&#UTQqxe1f%$jizIu?{hE|E3C5Vf9ZhghSlsW3is0fZ1MJ8>?0@R|@P4FUc?o+p)_}hxTi@GWsz*;j3Hbt`srQ+JpjmwVio! zT}Z_dCPsn$!b9Pk<(;+6XBKAoydBWVganN!oCqb^idPP6h_X2+-bi93rX9ohE2SVv z{%k>-BZt_wxdZLn198(h0xZglBJw*7xjqQ?Zt2K%B&oA6XKw%$M|nXszd78dQ7A9+ zb*%CNQy~K$)%4<#S)))LHm=YCxE|M1 zm7T5?#xLzbwG%}Rmj=lVNisSm&%kSmS4#E7a z2$bJz`9lurXN5mf2iFwLZ=yl^2ZYSe z-G5Anu1)wislB?q8qd#c!_NwS+#6qKO}_~p#digNmqY!m;m0k`^&a{+(FFXe;XiiN zKX?5xLSFBIev?7!|3LF^JEEUE{}>IfgXnM4Py4;|pM=z(_5A2Yubt&@LIwO?B>B1H wkB;T{9dFZrAHd&y?#~^6H1^*wnmWTDdLeaXOswl+5nO#puY%tJVEdT%j literal 0 HcmV?d00001 diff --git a/NewDriveTest/build.gradle b/build.gradle similarity index 70% rename from NewDriveTest/build.gradle rename to build.gradle index 1e9dafc..66739c9 100644 --- a/NewDriveTest/build.gradle +++ b/build.gradle @@ -1,12 +1,20 @@ plugins { id "java" id "edu.wpi.first.GradleRIO" version "2021.3.1" + id "maven" +} + +apply plugin: 'checkstyle' + +checkstyle { + toolVersion "8.11" + configFile rootProject.file('config/checkstyle/checkstyle.xml') } sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 -def ROBOT_MAIN_CLASS = "frc.robot.Main" +def ROBOT_MAIN_CLASS = "org.team696.robot.Main" // Define my targets (RoboRIO) and artifacts (deployable files) // This is added by GradleRIO's backing project EmbeddedTools. @@ -54,20 +62,26 @@ dependencies { testImplementation 'junit:junit:4.12' + implementation 'org.team696:TCA9548ADriver:0.3' + implementation 'org.team696:TCS34725Driver:0.4' + implementation 'org.team696:ColorUtils:0.2' + + + compile 'org.apache.logging.log4j:log4j-core:2.13.0' + + compile'org.apache.logging.log4j:log4j-core:2.13.0' + compile 'org.team696:MathUtils:0.3' // Enable simulation gui support. Must check the box in vscode to enable support // upon debugging simulation wpi.deps.sim.gui(wpi.platforms.desktop, false) - simulation wpi.deps.sim.driverstation(wpi.platforms.desktop, false) - - // Websocket extensions require additional configuration. - // simulation wpi.deps.sim.ws_server(wpi.platforms.desktop, false) - // simulation wpi.deps.sim.ws_client(wpi.platforms.desktop, false) + simulation wpi.deps.sim.driverstation(wpi.platforms.desktop, false) } -// Simulation configuration (e.g. environment variables). -sim { - // Sets the websocket client remote host. - // envVar "HALSIMWS_HOST", "10.0.0.2" +repositories { + maven{ + url "http://artifactory.696private.org/team696-libs-release-local" + } + //mavenLocal() } // Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar') @@ -77,3 +91,15 @@ jar { from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } manifest edu.wpi.first.gradlerio.GradleRIOPlugin.javaManifest(ROBOT_MAIN_CLASS) } + +tasks.withType(Checkstyle) { + ignoreFailures = true + exclude '**/com/**' + exclude '**/frc/team696/autonomousCommands/**' + reports { + html.enabled = true + html.destination rootProject.file("build/reports/checkstyle.html") + xml.enabled = true + xml.destination rootProject.file("build/reports/checkstyle-result.xml") + } +} \ No newline at end of file diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000..e802218 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NewDriveTest/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from NewDriveTest/gradle/wrapper/gradle-wrapper.jar rename to gradle/wrapper/gradle-wrapper.jar diff --git a/NewDriveTest/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from NewDriveTest/gradle/wrapper/gradle-wrapper.properties rename to gradle/wrapper/gradle-wrapper.properties diff --git a/NewDriveTest/gradlew b/gradlew similarity index 100% rename from NewDriveTest/gradlew rename to gradlew diff --git a/NewDriveTest/gradlew.bat b/gradlew.bat similarity index 100% rename from NewDriveTest/gradlew.bat rename to gradlew.bat diff --git a/NewDriveTest/settings.gradle b/settings.gradle similarity index 96% rename from NewDriveTest/settings.gradle rename to settings.gradle index 0bc697a..81f96ab 100644 --- a/NewDriveTest/settings.gradle +++ b/settings.gradle @@ -4,7 +4,7 @@ pluginManagement { repositories { mavenLocal() gradlePluginPortal() - String frcYear = '2021' + String frcYear = '2020' File frcHome if (OperatingSystem.current().isWindows()) { String publicFolder = System.getenv('PUBLIC') diff --git a/NewDriveTest/src/main/deploy/example.txt b/src/main/deploy/example.txt similarity index 100% rename from NewDriveTest/src/main/deploy/example.txt rename to src/main/deploy/example.txt diff --git a/src/main/java/org/team696/robot/Constants.java b/src/main/java/org/team696/robot/Constants.java new file mode 100644 index 0000000..4016734 --- /dev/null +++ b/src/main/java/org/team696/robot/Constants.java @@ -0,0 +1,229 @@ +/*----------------------------------------------------------------------------*/ +/* 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 org.team696.robot; + +/** + * The Constants class provides a convenient place for teams to hold robot-wide + * numerical or boolean constants. This class should not be used for any other + * purpose. All constants should be declared globally (i.e. public static). Do + * not put anything functional in this class. + * + *

+ * It is advised to statically import this class (or one of its inner classes) + * wherever the constants are needed, to reduce verbosity. + */ +public final class Constants { + public static final int CANtimeout = 10; + + public static final int timeBetweenPockets = 50; + + public static final class SpindexerConstants { + public static final int nPockets = 5; + public static final int MotorCANID = 20; + public static final int EncoderPort = 0; + public static final double P = 0.08; + public static final double closedLoopRampRate = 0.5; + public static final double openLoopRampRate = 0.25; + public static final int RevTBEMinMicroseconds = 1; + public static final int RevTBEMaxMicroseconds = 1024; + // public static final double[] PocketPositions = {0.9335, 0.1398, 0.3431, + // 0.5386, 0.7351}; + // public static final double[] PocketPositions = {0.9689, 0.1689, 0.3689, + // 0.5689, 0.7689}; + public static final double[] PocketPositions = { 0.964, 0.173, 0.375, 0.580, 0.775 }; + public static final double PositionTolerance = 0.005; // Used to calcuate isOnTarget + public static final double VelocityTolerance = 0.01; // used to calculate isMoving + public static final double MotorTurnsPerSpindexerTurn = 62.5; + public static final byte ColorSensorsMuxAddress = 0x70; + public static final byte ColorSensor1MuxChannel = 0; + public static final byte ColorSensor2MuxChannel = 1; + public static final byte ColorSensor3MuxChannel = 2; + public static final byte ColorSensor4MuxChannel = 3; + public static final byte ColorSensor5MuxChannel = 7; + + public static final double HueMax = 1; + public static final double HueMin = 0; + public static final double SatMax = 1; + public static final double SatMin = 0; + public static final double ValueMax = 1; + public static final double ValueMin = 0; + + public static final int KickMotorCANID = 21; + public static final double KickMotorSpeed = 1.; + public static final double KickMotorReverseSpeed = -0.1; + + public static final double loadingDrumPower = 0.22; + public static final double continuousShootDrumPower = 0.55; + public static final double stopDrumPower = 0; + + public static final double timeBetweenIndex = 1; + + public static final double indexingJamDetectionCurrent = 15; + public static final double loadingJamDetectionCurrent = 10; + public static final double antiJamTimeout = 50; + } + + public static final class ShooterConstants { + public static final int leftShooterHoodServo = 2; + public static final int rightShooterHoodServo = 3; + + public static final int leftShooterPort = 42; + public static final boolean leftShooterInverted = false; + public static final boolean leftShooterSensorPhase = false; + public static final int rightShooterPort = 43; + public static final boolean rightShooterInverted = true; + public static final boolean rightShooterSensorPhase = false; + public static final int pidSlot = 0; + public static double shooterkP = 0.6; + public static double shooterkI = 0.0; + public static double shooterkD = 0.0; + public static double shooterkF = 0.06; + public static final int allowableShooterError = 10; + + // TODO: run simple motor characterization routine to deterine feedforward gains + public static final double shooterkSGain = 0; + public static final double shooterkVGain = 0; + public static final double shooterkAGain = 0; + + public static final double shooterHoodAngleMaxLimit = 115; + public static final double shooterHoodAngleMinLimit = 175; + + public static final int acceleratorPort = 41; + public static final double acceleratorPower = 0.3; + public static double acceleratorkP = 0; + public static double acceleratorkI = 0; + public static double acceleratorkD = 0; + public static double acceleratorkF = 0; + public static final int allowableAcceleratorError = 100; + public static final boolean acceleratorInverted = true; + public static final boolean acceleratorSensorPhase = false; + + public static final double shooterGearRatio = 2.5; + + public static final double autoLineTargetRPM = 3900; + public static final double autoLineTargetAngle = 30; + + public static final double trenchRunTargetRPM = 5742.27; + public static final double trenchRunTargetAngle = 18.6; + + } + + public static final class TurretConstants { + public static final int turretMotorPort = 40; + // public static final boolean turret + + public static final boolean turretMotorInverted = false; + public static final boolean turretMotorSensorPhase = true; + + public static final int forwardSoftLimit = -370; + public static final int reverseSoftLimit = -570; + + public static final int turretCenterPos = -540; + + public static final double positionTolerance = 0.6; + + public static final double peakOutput = 0.75; + + public static final double kP = 0.05; + public static final double kI = 0.0; + public static final double kD = 0.001; + } + + + public static final class LimelightConstants { + public static final int camTranPipeline = 1; + public static final int loadingpipeline = 1; + } + + public static final class OperatorConstants { + public static final int operatorPanelPort = 0; + public static final int driverJoystickPort = 1; + + // Driver gamepad mappings + public static final int driveModeButton = 4; + + // Operator panel mappings + public static final int ATCRevButton = 1; + public static final int intakeOnButton = 3; + public static final int intakeOffButton = 4; + public static final int intakeOutButton = 5; + public static final int fitUnderTrenchButton = 6; + public static final int intakeInButton = 6; + public static final int ATCForButton = 7; + public static final int fireButton = 8; + public static final int hoodAutoButton = 9; + public static final int shooterAutoButton = 10; + public static final int colorWheelPositionControl = 11; + public static final int climberUpButton = 12; + public static final int colorWheelDeploy = 13; + public static final int turretAutoButton = 14; + public static final int shooterManualButton = 15; + public static final int spinUpButton = 16; + public static final int climberDownButton = 17; + public static final int colorWheelRotationControl = 18; + public static final int driveAssistButton = 19; + + public static final int shooterManualAxis = 3; + public static final int turretManualAxis = 2; + public static final int hoodManualAxis = 1; + + public static final int ATCRevLED = 0; + public static final int limelightLockLED = 1; + public static final int limelightCaptureLED = 2; + public static final int ATCForLED = 3; + public static final int fireLED = 4; + public static final int realsenseCaptureLED = 5; + public static final int realsenseLockLED = 6; + public static final int carabinerLatchLED = 7; + public static final int climberUpLimLED = 8; + public static final int climberDownLimLED = 9; + public static final int colorWheelDeployLED = 10; + } + + public static final class DrivetrainConstants { + public static final int leftFrontCANID = 10; + public static final int leftRearCANID = 11; + public static final int rightFrontCANID = 12; + public static final int rightRearCANID = 13; + + public static final boolean leftFrontIsInverted = true; + public static final boolean leftRearIsInverted = true; + public static final boolean rightFrontIsInverted = false; + public static final boolean rightRearIsInverted = false; + + public static final double wheelDiameter = 6.; // In inches. Used for calculating speed. + public static final double driveGearboxReduction = (60. / 10.) * (30. / 18.); + + public static final int IMUCalTime = 8; + public static final double yawkP = 1.; + public static final double yawkI = 0.; + public static final double yawkD = 0.; + + public static final double maxSpeed = 184.6; // In in/s + public static final double maxTurnRate = 5; // In degrees/iteration + + public static final int stallCurrentLimit = 80; + public static final int freeCurrentLimit = 80; + public static final int stallThresholdRPM = 1000; + + public static final double openLoopRampRate = 0.5; + + public static final double driveControllerDeadband = 0.05; + + public static final int slowTasksSpeed = 50; + } + + public static final class IntakeConstants { + public static final int IntakeMotorPort = 50; + public static final boolean IntakeInverted = false; + + public static final double intakePower = 0.7; + public static final double outtakePower = -1; + public static final double stopIntakePower = 0; + } +} diff --git a/NewDriveTest/src/main/java/frc/robot/Main.java b/src/main/java/org/team696/robot/Main.java similarity index 50% rename from NewDriveTest/src/main/java/frc/robot/Main.java rename to src/main/java/org/team696/robot/Main.java index 8776e5d..a961ae0 100644 --- a/NewDriveTest/src/main/java/frc/robot/Main.java +++ b/src/main/java/org/team696/robot/Main.java @@ -1,8 +1,11 @@ -// 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. +/*----------------------------------------------------------------------------*/ +/* 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; +package org.team696.robot; import edu.wpi.first.wpilibj.RobotBase; @@ -12,7 +15,8 @@ * call. */ public final class Main { - private Main() {} + private Main() { + } /** * Main initialization function. Do not perform any initialization here. diff --git a/src/main/java/org/team696/robot/Robot.java b/src/main/java/org/team696/robot/Robot.java new file mode 100644 index 0000000..f869600 --- /dev/null +++ b/src/main/java/org/team696/robot/Robot.java @@ -0,0 +1,202 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-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 org.team696.robot; + +import edu.wpi.first.wpilibj.TimedRobot; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.CommandScheduler; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.team696.robot.Constants.OperatorConstants; +import org.team696.robot.subsystems.Limelight; +import org.team696.robot.subsystems.ShooterHood; + + +/** + * 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 { + private static final Logger logger = LogManager.getLogger(Robot.class); + public static RobotContainer m_robotContainer; + public static OperatorConstants m_robotConstants; + private Command m_autonomousCommand; + double last_hood_axis = -69.23; //arbitrary value for initialization later + + // public static double shootAngle; + + + /** + * This function is run when the robot is first started up and should be used for any + * initialization code. + */ + @Override + public void robotInit() { + logger.info("Starting up..."); + m_robotContainer = new RobotContainer(); + m_robotConstants = new OperatorConstants(); + } + + /** + * 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. + * + *

This runs after the mode specific periodic functions, but before + * LiveWindow and SmartDashboard integrated updating. + */ + @Override + public void robotPeriodic() { + // Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled + // commands, running already-scheduled commands, removing finished or interrupted commands, + // and running subsystem periodic() methods. This must be called from the robot's periodic + // block in order for anything in the Command-based framework to work. + CommandScheduler.getInstance().run(); + + RobotContainer.limelight.pipeline(1); + SmartDashboard.putBoolean("isOnTarget", m_robotContainer.turretSubsystem.onTarget()); + SmartDashboard.putNumber("Current RPM", m_robotContainer.shooter.getRPM()); + SmartDashboard.putNumber("Shoot Angle", m_robotContainer.shooterHood.shootAngleToServoAngle(m_robotContainer.shooterHood.servoAngle())); + SmartDashboard.putNumber("Hood Axis", Math.round(m_robotContainer.operatorPanel.getRawAxis(1)*128)); + SmartDashboard.putNumber("Shoot Angle", m_robotContainer.shooterHood.servoAngleToShootAngle(m_robotContainer.shooterHood.servoAngle())); + SmartDashboard.putBoolean("Up to Speed", m_robotContainer.shooter.isUpToSpeed()); + SmartDashboard.putNumber("Spindexer Current", m_robotContainer.spindexer.getCurrent()); + SmartDashboard.putNumber("Hood Angle", m_robotContainer.shooterHood.servoAngle()); + SmartDashboard.putNumber("Accelerator Velocity", m_robotContainer.shooter.getAcceleratorVelocity()); + + + // SmartDashboard.putNumber("spin pos", m_robotContainer.spindexer.getEncoderPosition()); + // SmartDashboard.putNumber("servo angle", m_robotContainer.shooterHood.servoAngle()); + // SmartDashboard.putNumber("Number of Balls", m_robotContainer.spindexer.getNumberOfFilledPockets()); + // SmartDashboard.putNumber("distance", Limelight.distanceFromTarget()); + // SmartDashboard.putNumber("shooter power", m_robotContainer.shooter.getShooterPower()); + // SmartDashboard.putNumber("index", Limelight.indexForDistance()); + // SmartDashboard.putNumber("AUTORPM", m_robotContainer.shooter.getAutoRPM()); + // SmartDashboard.putNumber("AUTOANGLE", m_robotContainer.shooter.getAutoAngle()); + // SmartDashboard.putNumber("SERVOAUTOANGLE", m_robotContainer.shooterHood.shootAngleToServoAngle(m_robotContainer.shooter.getAutoAngle())); + // SmartDashboard.putNumber("AngleDistance", Limelight.angleDistance()); + // SmartDashboard.putNumber("Intake Current", m_robotContainer.intake.intakeCurrent()); + // RobotContainer.limelight.setLights(3); + // SmartDashboard.putNumber("Roll", m_robotContainer.drivetrain.roll()); + + } + + + /** + * This function is called once each time the robot enters Disabled mode. + */ + @Override + public void disabledInit() { + logger.info("Transitioning to disabled."); + m_robotContainer.spindexer.setBrake(false); + // RobotContainer.limelight.setLights(3); + } + + @Override + public void disabledPeriodic() { + Limelight.setLights(1); + } + + /** + * This autonomous runs the autonomous command selected by your {@link RobotContainer} class. + */ + @Override + public void autonomousInit() { + logger.info("Transitioning to autonomous."); + m_robotContainer.spindexer.setBrake(true); + m_autonomousCommand = m_robotContainer.getAutonomousCommand(); + + // schedule the autonomous command (example) + if (m_autonomousCommand != null) { + m_autonomousCommand.schedule(); + } + + } + + /** + * This function is called periodically during autonomous. + */ + @Override + public void autonomousPeriodic() { + + + } + + @Override + public void teleopInit() { + logger.info("Transitioning to teleop."); + m_robotContainer.spindexer.setBrake(true); + // SmartDashboard.putNumber("Target RPM", 3900); + // SmartDashboard.putNumber("Target Angle", 30); + + } + + /** + * This function is called periodically during operator control. + */ + + + @Override + public void teleopPeriodic() { + if(RobotContainer.operatorPanel.getRawButton(OperatorConstants.hoodAutoButton)){ + //Previous comp: m_robotContainer.shooterHood.moveServoAngle(51); + m_robotContainer.shooterHood.moveServoAngle(51); + + + + } + else{ + double hood_axis = -Math.round(m_robotContainer.operatorPanel.getRawAxis(1)*128*1.5); + if (last_hood_axis == -69.23){ + last_hood_axis = hood_axis; + } + double delta = hood_axis - last_hood_axis; + + SmartDashboard.putNumber("Hood Axis", Math.round(m_robotContainer.operatorPanel.getRawAxis(1)*128)); + + if (delta + m_robotContainer.shooterHood.servoAngle() <= 51 && delta + m_robotContainer.shooterHood.servoAngle() >= 10){ + m_robotContainer.shooterHood.moveServoAngle(m_robotContainer.shooterHood.servoAngle()+delta); + + /* + if (m_robotContainer.shooterHood.servoAngle() >= 51 && delta < 0){ + m_robotContainer.shooterHood.moveServoAngle(m_robotContainer.shooterHood.servoAngle()+delta); + } + else if (m_robotContainer.shooterHood.servoAngle() <= 10 && delta > 0){ + m_robotContainer.shooterHood.moveServoAngle(m_robotContainer.shooterHood.servoAngle()+delta); + } + + if (m_robotContainer.shooterHood.servoAngle() < 51 && m_robotContainer.shooterHood.servoAngle() > 10){ + m_robotContainer.shooterHood.moveServoAngle(m_robotContainer.shooterHood.servoAngle()+delta); + } + */ + } + last_hood_axis = hood_axis; + + + } + // } + + + } + + @Override + public void testInit() { + // Cancels all running commands at the start of test mode. + CommandScheduler.getInstance().cancelAll(); + } + + /** + * This function is called periodically during test mode. + */ + @Override + public void testPeriodic() { + } +} diff --git a/src/main/java/org/team696/robot/RobotContainer.java b/src/main/java/org/team696/robot/RobotContainer.java new file mode 100644 index 0000000..7375cd7 --- /dev/null +++ b/src/main/java/org/team696/robot/RobotContainer.java @@ -0,0 +1,229 @@ +/*----------------------------------------------------------------------------*/ +/* 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 org.team696.robot; + +import edu.wpi.first.wpilibj.GenericHID.Hand; +import edu.wpi.first.wpilibj.Joystick; +import edu.wpi.first.wpilibj.XboxController; +import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.ParallelCommandGroup; +import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; +import edu.wpi.first.wpilibj2.command.button.JoystickButton; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import org.team696.MathUtils.MathUtils; +import org.team696.robot.Constants.IntakeConstants; +import org.team696.robot.Constants.OperatorConstants; +import org.team696.robot.Constants.SpindexerConstants; +import org.team696.robot.commands.ATCForCommand; +import org.team696.robot.commands.ATCRevCommand; +import org.team696.robot.commands.AutoIndexKickUp; +import org.team696.robot.commands.Drive; +import org.team696.robot.commands.DriveTimer; +import org.team696.robot.commands.FireCommand; +import org.team696.robot.commands.IntakeTimerCommand; +import org.team696.robot.commands.OmniKickUp; +import org.team696.robot.commands.OmniKickUpTimer; +import org.team696.robot.commands.ShooterCommand; +import org.team696.robot.commands.ShooterHoodCommand; +import org.team696.robot.commands.ShooterPowerCommand; +import org.team696.robot.commands.ShooterPrep; +import org.team696.robot.commands.SpinToPocket; +import org.team696.robot.commands.SpindexerLoading; +import org.team696.robot.commands.TurretLockOn; +import org.team696.robot.commands.TurretManual; +import org.team696.robot.subsystems.Drivetrain; +import org.team696.robot.subsystems.Intake; +import org.team696.robot.subsystems.Limelight; +import org.team696.robot.subsystems.Shooter; +import org.team696.robot.subsystems.ShooterHood; +import org.team696.robot.subsystems.Spindexer; +import org.team696.robot.subsystems.TurretSubsystem; + +/** + * This class is where the bulk of the robot should be declared. Since + * Command-based is a "declarative" paradigm, very little robot logic should + * actually be handled in the {@link Robot} periodic methods (other than the + * scheduler calls). Instead, the structure of the robot (including subsystems, + * commands, and button mappings) should be declared here. + */ +public class RobotContainer { + // Subystem declarations + private static final Logger logger = LogManager.getLogger(RobotContainer.class); + public final Drivetrain drivetrain = new Drivetrain(); + public final Spindexer spindexer = new Spindexer(); + public final Shooter shooter = new Shooter(); + public final ShooterHood shooterHood = new ShooterHood(); + public final TurretSubsystem turretSubsystem = new TurretSubsystem(); + public static final Limelight limelight = new Limelight(); + public final Intake intake = new Intake(); + + // Joysticks + public final XboxController driverController = new XboxController(OperatorConstants.driverJoystickPort); + public static final Joystick operatorPanel = new Joystick(OperatorConstants.operatorPanelPort); + + // Buttons + + // make hood/shooter auto/man to change from 2 distances + // make intake in/out be for color wheel height + private final JoystickButton driveMode = new JoystickButton(driverController, OperatorConstants.driveModeButton); + + private final JoystickButton spinUpButton = new JoystickButton(operatorPanel, OperatorConstants.spinUpButton); + private final JoystickButton shooterAutoButton = new JoystickButton(operatorPanel, OperatorConstants.shooterAutoButton); + private final JoystickButton shooterManualButton = new JoystickButton(operatorPanel, OperatorConstants.shooterManualButton); + private final JoystickButton fireButton = new JoystickButton(operatorPanel, OperatorConstants.fireButton); + private final JoystickButton ATCForButton = new JoystickButton(operatorPanel, OperatorConstants.ATCForButton); + private final JoystickButton ATCRevButton = new JoystickButton(operatorPanel, OperatorConstants.ATCRevButton); + + private final JoystickButton turretAutoButton = new JoystickButton(operatorPanel, OperatorConstants.turretAutoButton); + private final JoystickButton hoodAutoButton = new JoystickButton(operatorPanel, OperatorConstants.hoodAutoButton); + + private final JoystickButton intakeOnButton = new JoystickButton(operatorPanel, OperatorConstants.intakeOnButton); + private final JoystickButton intakeOffButton = new JoystickButton(operatorPanel, OperatorConstants.intakeOffButton); + + private final JoystickButton fitUnderTrenchButton = new JoystickButton(operatorPanel, OperatorConstants.fitUnderTrenchButton); + + private final JoystickButton continuousButton = new JoystickButton(operatorPanel, OperatorConstants.colorWheelDeploy); + private final JoystickButton omniReverse = new JoystickButton(operatorPanel, OperatorConstants.colorWheelRotationControl); + private final JoystickButton automaticShootPrep = new JoystickButton(operatorPanel, OperatorConstants.driveAssistButton); + private final JoystickButton automaticIndex = new JoystickButton(operatorPanel, OperatorConstants.colorWheelPositionControl); + + public double getDriveSpeed() { + // Math to correct for nonlinearities in the controller should happen here. + double jsVal = -driverController.getY(Hand.kLeft); + if (jsVal > 0) { + return MathUtils.deadBand(jsVal, Constants.DrivetrainConstants.driveControllerDeadband); + } else { + return -MathUtils.deadBand(-jsVal, Constants.DrivetrainConstants.driveControllerDeadband); + } + } + + public double getDriveTurn() { + // Math to correct for nonlinearities in the controller should happen here. + double jsVal = -driverController.getX(Hand.kRight); + if (jsVal > 0) { + return MathUtils.deadBand(jsVal, Constants.DrivetrainConstants.driveControllerDeadband); + } else { + return -MathUtils.deadBand(-jsVal, Constants.DrivetrainConstants.driveControllerDeadband); + } + } + + public double turretManual() { + return operatorPanel.getRawAxis(1); + } + + public RobotContainer() { + Command driveCommand = new Drive(() -> getDriveSpeed(), () -> getDriveTurn(), drivetrain); + drivetrain.setDefaultCommand(driveCommand); + configureButtonBindings(); + } + + /** + * The container for the robot. Contains subsystems, OI devices, and commands. + */ + private void configureButtonBindings() { + // rpm is 3900 + spinUpButton.whenPressed(new ShooterCommand(shooter, shooter.shootRPM, true)); + spinUpButton.whenReleased(new ShooterPowerCommand(shooter, 0, false)); + + turretAutoButton.whileHeld(new TurretLockOn(turretSubsystem, limelight)); + turretAutoButton.whenReleased(new TurretManual(turretSubsystem, limelight)); + + SpindexerLoading loadingOff = new SpindexerLoading(spindexer, intake, SpindexerConstants.stopDrumPower, IntakeConstants.stopIntakePower); + intakeOnButton.whileHeld( + new SpindexerLoading(spindexer, intake, SpindexerConstants.loadingDrumPower, IntakeConstants.intakePower)); + intakeOnButton.whenReleased(loadingOff); + intakeOffButton.whileHeld( + new SpindexerLoading(spindexer, intake, SpindexerConstants.stopDrumPower, IntakeConstants.outtakePower)); + intakeOffButton.whenReleased(loadingOff); + + // maybe have this button cancel the human player loading sequence + continuousButton.whileHeld(new SpindexerLoading(spindexer, intake, SpindexerConstants.continuousShootDrumPower, + IntakeConstants.stopIntakePower)); + continuousButton.whenReleased(loadingOff); + + automaticShootPrep.whenPressed(new ShooterPrep(shooter, turretSubsystem)); + automaticShootPrep.whenReleased(new ShooterPowerCommand(shooter, 0, false)); + automaticShootPrep.whenReleased(new TurretManual(turretSubsystem, limelight)); + + automaticIndex.whenPressed(new AutoIndexKickUp(spindexer, intake, SpindexerConstants.continuousShootDrumPower, 0)); + automaticIndex.whenReleased(loadingOff); + + fireButton.whenPressed(new FireCommand(shooter, spindexer, SpindexerConstants.KickMotorSpeed)); + fireButton.whenReleased(new FireCommand(shooter, spindexer, SpindexerConstants.stopDrumPower)); + + OmniKickUp reverseOmni = new OmniKickUp(spindexer, SpindexerConstants.KickMotorReverseSpeed); + omniReverse.whenPressed(reverseOmni); + omniReverse.whenReleased(new OmniKickUp(spindexer, SpindexerConstants.stopDrumPower)); + + ATCForCommand ATCfor = new ATCForCommand(spindexer); + ATCRevCommand ATCrev = new ATCRevCommand(spindexer); + + ATCForButton.whenPressed(ATCfor); + ATCForButton.cancelWhenPressed(ATCrev); + + ATCRevButton.whenPressed(ATCrev); + ATCRevButton.cancelWhenPressed(ATCfor); + + intakeOnButton.whenReleased(ATCfor); + + } + + /** + * Use this to pass the autonomous command to the main {@link Robot} class. + * + * @return the command to run in autonomous + */ + @SuppressWarnings("checkstyle:magicnumber") + public Command getAutonomousCommand() { + + return new SequentialCommandGroup( + + new ParallelCommandGroup( + new TurretLockOn(turretSubsystem, limelight), + new ShooterCommand(shooter, 3900, true), + + new SequentialCommandGroup( + new ShooterHoodCommand(shooterHood, 51), + // new IntakeTimerCommand(intake, 50); + new SpinToPocket(spindexer, 1), + new OmniKickUpTimer(spindexer, true, 25), + new SpinToPocket(spindexer, 2), + new OmniKickUpTimer(spindexer, true, 25), + new SpinToPocket(spindexer, 3), + new OmniKickUpTimer(spindexer, true, 25) + ) + ), + + new DriveTimer(drivetrain, -0.5, 0, 50), + new DriveTimer(drivetrain, 0, 0.7, 40), + new DriveTimer(drivetrain, 0.5, 0, 25), + new ParallelCommandGroup( + new DriveTimer(drivetrain, 0.5, 0, 35), + new IntakeTimerCommand(intake, 35) + ) + + + ); + + } + + public boolean getDriveMode() { + return driveMode.get(); + } + + public void setLimelightCaptureLED(boolean state) { + operatorPanel.setOutput(OperatorConstants.limelightCaptureLED, state); + } + + public void setLimelightLockLED(boolean state) { + operatorPanel.setOutput(OperatorConstants.limelightLockLED, state); + } +} diff --git a/src/main/java/org/team696/robot/TrajectoryTable.java b/src/main/java/org/team696/robot/TrajectoryTable.java new file mode 100644 index 0000000..213a3ca --- /dev/null +++ b/src/main/java/org/team696/robot/TrajectoryTable.java @@ -0,0 +1,349 @@ +/*----------------------------------------------------------------------------*/ +/* 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 org.team696.robot; + +/** + * Add your docs here. + */ +public class TrajectoryTable { + + /** + * First line is 120 inches away + * First column is angle that ball is shot + * Second column is velcity of the ball in RPM + */ +public static final double[][] TrajectoryTable = { + +{0.0,0.0}, +{51.2,2354.45}, +{51.0,2362.16}, +{50.8,2369.90}, +{50.6,2377.69}, +{50.3,2385.51}, +{50.1,2393.37}, +{49.9,2401.27}, +{49.7,2409.20}, +{49.4,2417.17}, +{49.2,2425.17}, +{49.0,2433.22}, +{48.8,2441.29}, +{48.6,2449.40}, +{48.3,2457.55}, +{48.1,2465.73}, +{47.9,2473.94}, +{47.7,2482.19}, +{47.5,2490.47}, +{47.3,2498.79}, +{47.1,2507.13}, +{46.9,2515.51}, +{46.7,2523.92}, +{46.5,2532.37}, +{46.3,2540.84}, +{46.1,2549.35}, +{45.9,2557.88}, +{45.7,2566.45}, +{45.5,2575.04}, +{45.3,2583.67}, +{45.1,2592.32}, +{44.9,2601.01}, +{44.7,2609.72}, +{44.5,2618.46}, +{44.3,2627.23}, +{44.2,2636.03}, +{44.0,2644.86}, +{43.8,2653.71}, +{43.6,2662.59}, +{43.4,2671.50}, +{43.2,2680.44}, +{43.1,2689.40}, +{42.9,2698.38}, +{42.7,2707.40}, +{42.5,2716.43}, +{42.4,2725.50}, +{42.2,2734.59}, +{42.0,2743.70}, +{41.8,2752.84}, +{41.7,2762.00}, +{41.5,2771.19}, +{41.3,2780.40}, +{41.2,2789.63}, +{41.0,2798.89}, +{40.8,2808.17}, +{40.7,2817.48}, +{40.5,2826.80}, +{40.3,2836.15}, +{40.2,2845.53}, +{40.0,2854.92}, +{39.9,2864.34}, +{39.7,2873.77}, +{39.6,2883.23}, +{39.4,2892.71}, +{39.2,2902.21}, +{39.1,2911.73}, +{38.9,2921.28}, +{38.8,2930.84}, +{38.6,2940.42}, +{38.5,2950.02}, +{38.3,2959.65}, +{38.2,2969.29}, +{38.1,2978.95}, +{37.9,2988.63}, +{37.8,2998.33}, +{37.6,3008.05}, +{37.5,3017.79}, +{37.3,3027.54}, +{37.2,3037.32}, +{37.1,3047.11}, +{36.9,3056.92}, +{36.8,3066.75}, +{36.6,3076.60}, +{36.5,3086.46}, +{36.4,3096.34}, +{36.2,3106.24}, +{36.1,3116.15}, +{36.0,3126.08}, +{35.8,3136.03}, +{35.7,3146.00}, +{35.6,3155.98}, +{35.4,3165.98}, +{35.3,3175.99}, +{35.2,3186.02}, +{35.1,3196.06}, +{34.9,3206.12}, +{34.8,3216.20}, +{34.7,3226.29}, +{34.6,3236.40}, +{34.4,3246.52}, +{34.3,3256.65}, +{34.2,3266.81}, +{34.1,3276.97}, +{34.0,3287.15}, +{33.8,3297.35}, +{33.7,3307.55}, +{33.6,3317.78}, +{33.5,3328.01}, +{33.4,3338.26}, +{33.3,3348.53}, +{33.1,3358.80}, +{33.0,3369.10}, +{32.9,3379.40}, +{32.8,3389.72}, +{32.7,3400.05}, +{32.6,3410.39}, +{32.5,3420.75}, +{32.4,3431.12}, +{32.2,3441.50}, +{32.1,3451.89}, +{32.0,3462.30}, +{31.9,3472.72}, +{31.8,3483.15}, +{31.7,3493.59}, +{31.6,3504.04}, +{31.5,3514.51}, +{31.4,3524.99}, +{31.3,3535.48}, +{31.2,3545.98}, +{31.1,3556.49}, +{31.0,3567.02}, +{30.9,3577.55}, +{30.8,3588.10}, +{30.7,3598.66}, +{30.6,3609.22}, +{30.5,3619.80}, +{30.4,3630.39}, +{30.3,3640.99}, +{30.2,3651.60}, +{30.1,3662.22}, +{30.0,3672.86}, +{29.9,3683.50}, +{29.8,3694.15}, +{29.7,3704.81}, +{29.6,3715.49}, +{29.5,3726.17}, +{29.4,3736.86}, +{29.3,3747.56}, +{29.2,3758.27}, +{29.2,3768.99}, +{29.1,3779.72}, +{29.0,3790.46}, +{28.9,3801.21}, +{28.8,3811.97}, +{28.7,3822.74}, +{28.6,3833.52}, +{28.5,3844.30}, +{28.4,3855.10}, +{28.4,3865.90}, +{28.3,3876.71}, +{28.2,3887.53}, +{28.1,3898.36}, +{28.0,3909.20}, +{27.9,3920.05}, +{27.8,3930.90}, +{27.8,3941.77}, +{27.7,3952.64}, +{27.6,3963.52}, +{27.5,3974.41}, +{27.4,3985.31}, +{27.4,3996.21}, +{27.3,4007.12}, +{27.2,4018.04}, +{27.1,4028.97}, +{27.0,4039.91}, +{27.0,4050.85}, +{26.9,4061.80}, +{26.8,4072.76}, +{26.7,4083.73}, +{26.6,4094.70}, +{26.6,4105.68}, +{26.5,4116.67}, +{26.4,4127.67}, +{26.3,4138.67}, +{26.3,4149.68}, +{26.2,4160.70}, +{26.1,4171.72}, +{26.0,4182.76}, +{26.0,4193.80}, +{25.9,4204.84}, +{25.8,4215.89}, +{25.7,4226.95}, +{25.7,4238.02}, +{25.6,4249.09}, +{25.5,4260.17}, +{25.5,4271.26}, +{25.4,4282.35}, +{25.3,4293.45}, +{25.2,4304.55}, +{25.2,4315.66}, +{25.1,4326.78}, +{25.0,4337.91}, +{25.0,4349.04}, +{24.9,4360.17}, +{24.8,4371.31}, +{24.8,4382.46}, +{24.7,4393.62}, +{24.6,4404.78}, +{24.6,4415.95}, +{24.5,4427.12}, +{24.4,4438.30}, +{24.4,4449.48}, +{24.3,4460.67}, +{24.2,4471.87}, +{24.2,4483.07}, +{24.1,4494.28}, +{24.0,4505.49}, +{24.0,4516.71}, +{23.9,4527.93}, +{23.9,4539.16}, +{23.8,4550.40}, +{23.7,4561.64}, +{23.7,4572.88}, +{23.6,4584.13}, +{23.6,4595.39}, +{23.5,4606.65}, +{23.4,4617.92}, +{23.4,4629.19}, +{23.3,4640.46}, +{23.2,4651.75}, +{23.2,4663.03}, +{23.1,4674.33}, +{23.1,4685.62}, +{23.0,4696.92}, +{23.0,4708.23}, +{22.9,4719.54}, +{22.8,4730.86}, +{22.8,4742.18}, +{22.7,4753.51}, +{22.7,4764.84}, +{22.6,4776.17}, +{22.6,4787.51}, +{22.5,4798.86}, +{22.4,4810.21}, +{22.4,4821.56}, +{22.3,4832.92}, +{22.3,4844.28}, +{22.2,4855.65}, +{22.2,4867.02}, +{22.1,4878.40}, +{22.1,4889.78}, +{22.0,4901.17}, +{21.9,4912.56}, +{21.9,4923.95}, +{21.8,4935.35}, +{21.8,4946.75}, +{21.7,4958.16}, +{21.7,4969.57}, +{21.6,4980.98}, +{21.6,4992.40}, +{21.5,5003.82}, +{21.5,5015.25}, +{21.4,5026.68}, +{21.4,5038.12}, +{21.3,5049.56}, +{21.3,5061.00}, +{21.2,5072.44}, +{21.2,5083.90}, +{21.1,5095.35}, +{21.1,5106.81}, +{21.0,5118.27}, +{21.0,5129.74}, +{20.9,5141.21}, +{20.9,5152.68}, +{20.8,5164.16}, +{20.8,5175.64}, +{20.7,5187.12}, +{20.7,5198.61}, +{20.6,5210.10}, +{20.6,5221.60}, +{20.5,5233.10}, +{20.5,5244.60}, +{20.4,5256.11}, +{20.4,5267.62}, +{20.4,5279.13}, +{20.3,5290.65}, +{20.3,5302.17}, +{20.2,5313.69}, +{20.2,5325.22}, +{20.1,5336.75}, +{20.1,5348.28}, +{20.0,5359.82}, +{20.0,5371.36}, +{19.9,5382.90}, +{19.9,5394.45}, +{19.9,5406.00}, +{19.8,5417.55}, +{19.8,5429.11}, +{19.7,5440.67}, +{19.7,5452.23}, +{19.6,5463.80}, +{19.6,5475.37}, +{19.6,5486.94}, +{19.5,5498.51}, +{19.5,5510.09}, +{19.4,5521.67}, +{19.4,5533.26}, +{19.3,5544.84}, +{19.3,5556.44}, +{19.3,5568.03}, +{19.2,5579.62}, +{19.2,5591.22}, +{19.1,5602.83}, +{19.1,5614.43}, +{19.0,5626.04}, +{19.0,5637.65}, +{19.0,5649.26}, +{18.9,5660.88}, +{18.9,5672.50}, +{18.8,5684.12}, +{18.8,5695.74}, +{18.8,5707.37}, +{18.7,5719.00}, +{18.7,5730.64}, +{18.6,5742.27} +}; + +} \ No newline at end of file diff --git a/src/main/java/org/team696/robot/commands/ATCForCommand.java b/src/main/java/org/team696/robot/commands/ATCForCommand.java new file mode 100644 index 0000000..d7d6ed1 --- /dev/null +++ b/src/main/java/org/team696/robot/commands/ATCForCommand.java @@ -0,0 +1,70 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import org.team696.robot.Constants; +import org.team696.robot.subsystems.Spindexer; + +public class ATCForCommand extends CommandBase { + /** + * Creates a new SpinToIndex. + */ + private static final Logger logger = LogManager.getLogger(ATCForCommand.class); + Spindexer spindexer; + + int oldSpindexerPocket = 0; + + public ATCForCommand(Spindexer spindexer) { + this.spindexer = spindexer; + addRequirements(spindexer); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + oldSpindexerPocket = spindexer.getTargetPocket(); + int targetPocket; + if (spindexer.getTargetPocket() == Constants.SpindexerConstants.nPockets) { + targetPocket = 1; + } else { + targetPocket = spindexer.getTargetPocket() + 1; + } + logger.info(String.format("Moving spindexer from %d to %d", oldSpindexerPocket, targetPocket)); + spindexer.setTargetPocket(targetPocket); + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + + + + + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + if(interrupted){ + logger.info("Spindexer command interrupted."); + } else { + logger.info("Spindexer on target."); + } + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return spindexer.isOnTarget(); + } +} diff --git a/src/main/java/org/team696/robot/commands/ATCRevCommand.java b/src/main/java/org/team696/robot/commands/ATCRevCommand.java new file mode 100644 index 0000000..beb0e54 --- /dev/null +++ b/src/main/java/org/team696/robot/commands/ATCRevCommand.java @@ -0,0 +1,63 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import org.team696.robot.Constants; +import org.team696.robot.subsystems.Spindexer; + +public class ATCRevCommand extends CommandBase { + private static final Logger logger = LogManager.getLogger(ATCRevCommand.class); + Spindexer spindexer; + int oldSpindexerPocket; + + public ATCRevCommand(Spindexer spindexer) { + this.spindexer = spindexer; + addRequirements(spindexer); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + oldSpindexerPocket = spindexer.getTargetPocket(); + int targetPocket; + if (spindexer.getTargetPocket() == 1) { + targetPocket = Constants.SpindexerConstants.nPockets; + } else { + targetPocket = spindexer.getTargetPocket() - 1; + } + logger.info(String.format("Moving spindexer from %d to %d", oldSpindexerPocket, targetPocket)); + spindexer.setTargetPocket(targetPocket); + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + if(interrupted){ + logger.info("Spindexer command interrupted."); + } else { + logger.info("Spindexer on target."); + } + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return spindexer.isOnTarget(); + } +} diff --git a/src/main/java/org/team696/robot/commands/AutoIndexKickUp.java b/src/main/java/org/team696/robot/commands/AutoIndexKickUp.java new file mode 100644 index 0000000..9a2f3b2 --- /dev/null +++ b/src/main/java/org/team696/robot/commands/AutoIndexKickUp.java @@ -0,0 +1,34 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import org.team696.robot.subsystems.Intake; +import org.team696.robot.subsystems.Spindexer; + +import edu.wpi.first.wpilibj2.command.ParallelCommandGroup; +import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; +import edu.wpi.first.wpilibj2.command.WaitCommand; + +// NOTE: Consider using this command inline, rather than writing a subclass. For more +// information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +public class AutoIndexKickUp extends SequentialCommandGroup { + /** + * Creates a new AutoIndexKickUp. + */ + public AutoIndexKickUp(Spindexer spindexer, Intake intake, double drumPower, double omniPower) { + // Add your commands in the super() call, e.g. + // super(new FooCommand(), new BarCommand()); + super( + // new ATCForCommand(spindexer), + // new OmniKickUp(spindexer, omniPower), + new ContinuousShoot(spindexer, drumPower, true) + + ); + } +} diff --git a/src/main/java/org/team696/robot/commands/ClimberLift.java b/src/main/java/org/team696/robot/commands/ClimberLift.java new file mode 100644 index 0000000..18d54c8 --- /dev/null +++ b/src/main/java/org/team696/robot/commands/ClimberLift.java @@ -0,0 +1,69 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + + +// import org.team696.robot.subsystems.ClimberSubsystem; +// import org.team696.robot.RobotContainer; +// import org.team696.robot.Constants.OperatorConstants; +// import org.team696.robot.subsystems.ClimberServos; + +// import edu.wpi.first.wpilibj2.command.CommandBase; + +// public class ClimberLift extends CommandBase { +// private ClimberSubsystem climberSubsystem; +// private ClimberServos climberServos; +// /** +// * Creates a new ClimberPullUp. +// */ +// public ClimberLift(ClimberSubsystem climberSubsystem, ClimberServos climberServos) { +// this.climberSubsystem = climberSubsystem; +// this.climberServos = climberServos; +// addRequirements(climberSubsystem); +// addRequirements(climberServos); +// } + +// // 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() { +// // servoSubsystem.closeServo(); +// // if (RobotContainer.operatorPanel.getRawButton(OperatorConstants.climberUpButton)){ + +// climberSubsystem.setClimberPower(); +// // System.out.println(climberSubsystem.climberTargetPower); + +// // } +// // else{ +// // climberSubsystem.setClimberPower(0); +// // // System.out.println(climberSubsystem.climberTargetPower); + +// // } + + +// } + + + +// // Called once the command ends or is interrupted. +// @Override +// public void end(boolean interrupted) { +// // servoSubsystem.CloseServo(); + +// } + +// // Returns true when the command should end. +// @Override +// public boolean isFinished() { +// return false; +// } +// } diff --git a/src/main/java/org/team696/robot/commands/ClimberReach.java b/src/main/java/org/team696/robot/commands/ClimberReach.java new file mode 100644 index 0000000..b32183f --- /dev/null +++ b/src/main/java/org/team696/robot/commands/ClimberReach.java @@ -0,0 +1,68 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +// import org.team696.robot.subsystems.ClimberSubsystem; +// import org.team696.robot.RobotContainer; +// import org.team696.robot.Constants.OperatorConstants; +// import org.team696.robot.subsystems.ClimberServos; + +// import edu.wpi.first.wpilibj2.command.CommandBase; + +// public class ClimberReach extends CommandBase { +// private ClimberSubsystem climberSubsystem; +// private ClimberServos servoSubsystem; +// /** +// * Creates a new ClimberPushDown. +// */ + +// boolean servoIsOpen = false; + +// public ClimberReach(ClimberSubsystem climberSubsystem, ClimberServos servoSubsystem) { +// this.climberSubsystem = climberSubsystem; +// this.servoSubsystem = servoSubsystem; +// addRequirements(climberSubsystem); +// addRequirements(servoSubsystem); +// // Use addRequirements() here to declare subsystem dependencies. +// } + +// // 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() { + +// // servoSubsystem.moveClimberServos(180); + +// if (RobotContainer.operatorPanel.getRawButton(OperatorConstants.climberDownButton)){ +// climberSubsystem.setClimberPower(); + +// } +// else{ +// climberSubsystem.setClimberPower(0); +// } + +// } + +// // Called once the command ends or is interrupted. +// @Override +// public void end(boolean interrupted) { +// //ClimberSubsystem.climberState = ClimberStates.AT_HEIGHT; +// } + +// // Returns true when the command should end. +// @Override +// public boolean isFinished() { +// //if sensor trips return tru +// // return climberSubsystem.isLatchedOn(); +// return false; +// } +// } diff --git a/src/main/java/org/team696/robot/commands/ContinuousShoot.java b/src/main/java/org/team696/robot/commands/ContinuousShoot.java new file mode 100644 index 0000000..e131fcd --- /dev/null +++ b/src/main/java/org/team696/robot/commands/ContinuousShoot.java @@ -0,0 +1,61 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import org.team696.robot.subsystems.Spindexer; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +public class ContinuousShoot extends CommandBase { + /** + * Creates a new ContinuousShoot. + */ + Spindexer spindexer; + boolean kickUpState; + double drumSpeed; + int timer; + public ContinuousShoot(Spindexer spindexer, double drumSpeed, boolean kickUpState) { + // Use addRequirements() here to declare subsystem dependencies. + this.spindexer = spindexer; + this.kickUpState = kickUpState; + this.drumSpeed = drumSpeed; + addRequirements(spindexer); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + timer = 0; + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + timer++; + if(timer>6){ + spindexer.spindexerLoadingAntiJam(drumSpeed); + + } + spindexer.setKickMotor(1); + + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + spindexer.setKickMotor(0); + timer = 0; + + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/org/team696/robot/commands/Drive.java b/src/main/java/org/team696/robot/commands/Drive.java new file mode 100644 index 0000000..8efafb3 --- /dev/null +++ b/src/main/java/org/team696/robot/commands/Drive.java @@ -0,0 +1,59 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +import java.util.function.DoubleSupplier; + +import org.team696.robot.subsystems.Drivetrain; +import org.team696.robot.subsystems.Shooter; + +public class Drive extends CommandBase { + private final Drivetrain drivetrain; + private final DoubleSupplier speedSupplier; + private final DoubleSupplier turnSupplier; + + /** + * Creates a new Drive. + */ + double currentServoPosition; + + public Drive(DoubleSupplier speed, DoubleSupplier turn, Drivetrain drivetrain) { + this.drivetrain = drivetrain; + this.speedSupplier = speed; + this.turnSupplier = turn; + + addRequirements(drivetrain); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + // currentServoPosition = shooter.servoAngle(); + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + drivetrain.arcadeDrive(speedSupplier.getAsDouble(), turnSupplier.getAsDouble()); + + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + drivetrain.arcadeDrive(0, 0); + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/org/team696/robot/commands/DriveTimer.java b/src/main/java/org/team696/robot/commands/DriveTimer.java new file mode 100644 index 0000000..705801d --- /dev/null +++ b/src/main/java/org/team696/robot/commands/DriveTimer.java @@ -0,0 +1,55 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import org.team696.robot.subsystems.Drivetrain; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +public class DriveTimer extends CommandBase { + private Drivetrain drivetrain; + /** + * Creates a new DriveTimer. + */ + int timer; + int x = 0; + double speed; + double turn; + public DriveTimer(Drivetrain drivetrain, double speed, double turn, int timer) { + this.drivetrain = drivetrain; + this.timer = timer; + this.speed = speed; + this.turn = turn; + addRequirements(drivetrain); + } + + // 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() { + drivetrain.arcadeDrive(speed, turn); + x++; + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + drivetrain.arcadeDrive(0, 0); + x = 0; + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return x>timer; + } +} diff --git a/src/main/java/org/team696/robot/commands/FireCommand.java b/src/main/java/org/team696/robot/commands/FireCommand.java new file mode 100644 index 0000000..00e140e --- /dev/null +++ b/src/main/java/org/team696/robot/commands/FireCommand.java @@ -0,0 +1,65 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +import org.team696.robot.subsystems.Shooter; +import org.team696.robot.subsystems.Spindexer; + +public class FireCommand extends CommandBase { + /** + * Creates a new FireCommand. + */ + private Shooter shooter; + private Spindexer spindexer; + private double power; + + public FireCommand(Shooter shooter, Spindexer spindexer, double kickMotorPower) { + + this.shooter = shooter; + this.spindexer = spindexer; + this.power = kickMotorPower; + addRequirements(shooter); + addRequirements(spindexer); + } + + // 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() { + if(shooter.isUpToSpeed()){ + // shooter.setAcceleratorPower(true); + spindexer.setKickMotor(power); + // spindexer.spindexerLoadingAntiJam(0.5, 20); + + + } + else{ + spindexer.setKickMotor(0); + + } + + } + + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/org/team696/robot/commands/FullShoot.java b/src/main/java/org/team696/robot/commands/FullShoot.java new file mode 100644 index 0000000..1c02161 --- /dev/null +++ b/src/main/java/org/team696/robot/commands/FullShoot.java @@ -0,0 +1,44 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import org.team696.robot.subsystems.Limelight; +import org.team696.robot.subsystems.ShooterHood; +import org.team696.robot.subsystems.Spindexer; +import org.team696.robot.subsystems.TurretSubsystem; + +import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; + +// NOTE: Consider using this command inline, rather than writing a subclass. For more +// information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +public class FullShoot extends SequentialCommandGroup { + /** + * Creates a new FullShoot. + */ + public FullShoot(ShooterHood shooterHood, Spindexer spindexer, TurretSubsystem turretSubsystem, Limelight limelight) { + // Add your commands in the super() call, e.g. + // super(new FooCommand(), new BarCommand()); + super( + new ShooterHoodCommand(shooterHood, 51), + new SpinToPocket(spindexer, 1), + new TurretLockOn(turretSubsystem, limelight), + new OmniKickUpTimer(spindexer, true, 50), + new SpinToPocket(spindexer, 2), + new OmniKickUpTimer(spindexer, true, 50), + new SpinToPocket(spindexer, 3), + new OmniKickUpTimer(spindexer, true, 50), + new SpinToPocket(spindexer, 4), + new OmniKickUpTimer(spindexer, true, 50), + new SpinToPocket(spindexer, 5), + new OmniKickUpTimer(spindexer, true, 50), + new ShooterHoodCommand(shooterHood, 10) + + ); + } +} diff --git a/src/main/java/org/team696/robot/commands/IntakeCommand.java b/src/main/java/org/team696/robot/commands/IntakeCommand.java new file mode 100644 index 0000000..c5781c2 --- /dev/null +++ b/src/main/java/org/team696/robot/commands/IntakeCommand.java @@ -0,0 +1,53 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +import org.team696.robot.subsystems.Intake; + +public class IntakeCommand extends CommandBase { + /** + * Creates a new IntakeCom + * mand. + */ + private Intake intake; + + private double intakePower; + public IntakeCommand(Intake intake, double intakePower) { + // Use addRequirements() here to declare subsystem dependencies. + + this.intake = intake; + this.intakePower = intakePower; + addRequirements(intake); + } + + // 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() { + intake.runIntake(intakePower); + // spindexer.spindexerLoadingAntiJam(power, current); + // System.out.println("loading"); + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/org/team696/robot/commands/IntakeTimerCommand.java b/src/main/java/org/team696/robot/commands/IntakeTimerCommand.java new file mode 100644 index 0000000..336c665 --- /dev/null +++ b/src/main/java/org/team696/robot/commands/IntakeTimerCommand.java @@ -0,0 +1,55 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import org.team696.robot.subsystems.Intake; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +public class IntakeTimerCommand extends CommandBase { + /** + * Creates a new IntakeTimerCommand. + */ + Intake intake; + int x = 0; + double timer; + public IntakeTimerCommand(Intake intake, double timer) { + // Use addRequirements() here to declare subsystem dependencies. + this.intake = intake; + this.timer = timer; + addRequirements(intake); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + x = 0; + + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + intake.runIntake(0.7); + x++; + // System.out.println(timer); + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + // timer = 0; + intake.runIntake(0); + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return x>timer; + } +} diff --git a/src/main/java/org/team696/robot/commands/OmniKickUp.java b/src/main/java/org/team696/robot/commands/OmniKickUp.java new file mode 100644 index 0000000..49ed7c8 --- /dev/null +++ b/src/main/java/org/team696/robot/commands/OmniKickUp.java @@ -0,0 +1,50 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +import org.team696.robot.subsystems.Spindexer; + +public class OmniKickUp extends CommandBase { + /** + * Creates a new OmniKickUp. + */ + Spindexer spindexer; + double power; + public OmniKickUp(Spindexer spindexer, double power) { + // Use addRequirements() here to declare subsystem dependencies. + this.spindexer = spindexer; + this.power = power; + addRequirements(spindexer); + + } + + // 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() { + spindexer.setKickMotor(power); + + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/org/team696/robot/commands/OmniKickUpTimer.java b/src/main/java/org/team696/robot/commands/OmniKickUpTimer.java new file mode 100644 index 0000000..4d0c7a2 --- /dev/null +++ b/src/main/java/org/team696/robot/commands/OmniKickUpTimer.java @@ -0,0 +1,61 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +import org.team696.robot.subsystems.Spindexer; + +public class OmniKickUpTimer extends CommandBase { + /** + * Creates a new OmniKickUp. + */ + Spindexer spindexer; + boolean state; + int x = 0; + double timer; + + public OmniKickUpTimer(Spindexer spindexer, boolean state, double timer) { + // Use addRequirements() here to declare subsystem dependencies. + this.spindexer = spindexer; + this.state = state; + + this.timer = timer; + addRequirements(spindexer); + + + } + + // 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() { + spindexer.setKickMotor(1); + System.out.println(x); + x++; + + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + x = 0; + System.out.println("done"); + spindexer.setKickMotor(0); + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return x>timer ; + } +} diff --git a/src/main/java/org/team696/robot/commands/ShooterCommand.java b/src/main/java/org/team696/robot/commands/ShooterCommand.java new file mode 100644 index 0000000..de47a1b --- /dev/null +++ b/src/main/java/org/team696/robot/commands/ShooterCommand.java @@ -0,0 +1,72 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.team696.robot.RobotContainer; +import org.team696.robot.Constants.OperatorConstants; +import org.team696.robot.Constants.ShooterConstants; +import org.team696.robot.subsystems.Shooter; + +public class ShooterCommand extends CommandBase { + /** + * Creates a new ShooterCommand. + */ + private static final Logger logger = LogManager.getLogger(ShooterCommand.class); + private Shooter shooter; + + double RPM; + boolean state; + public ShooterCommand(Shooter shooter, double RPM, boolean state) { + + this.shooter = shooter; + this.state = state; + this.RPM = RPM; + addRequirements(shooter); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + logger.info(String.format("Spinning up shooter to %f RPM", RPM)); + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + // if(RobotContainer.operatorPanel.getRawButton(OperatorConstants.shooterAutoButton)){ + shooter.setShooterVelocity(shooter.shooterRPMToTalonVelocity(shooter.getShootRPM())); + // } + // else if(RobotContainer.operatorPanel.getRawButton(OperatorConstants.shooterManualButton)){ + // // shooter.setShooterVelocity(shooter.shooterRPMToTalonVelocity(RPM+1000*RobotContainer.operatorPanel.getRawAxis(OperatorConstants.shooterManualAxis))); + // shooter.setShooterPower(shooter.shooterRPMToTalonVelocity(ShooterConstants.trenchRunTargetRPM)); + // } + // else{ + // shooter.setShooterPower(0); + // } + + shooter.setAcceleratorPower(state); + + //TODO: make another command to run off of feedforward gains + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + logger.info("Done with shooter command."); + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/org/team696/robot/commands/ShooterHoodCommand.java b/src/main/java/org/team696/robot/commands/ShooterHoodCommand.java new file mode 100644 index 0000000..bc2101c --- /dev/null +++ b/src/main/java/org/team696/robot/commands/ShooterHoodCommand.java @@ -0,0 +1,71 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +import org.team696.robot.RobotContainer; +import org.team696.robot.Constants.OperatorConstants; +import org.team696.robot.subsystems.Shooter; +import org.team696.robot.subsystems.ShooterHood; + +public class ShooterHoodCommand extends CommandBase { + /** + * Creates a new ShooterHoodCommand. + */ + private ShooterHood shooterHood; + private double angle; + + private double timer; + public ShooterHoodCommand(ShooterHood shooterHood, double angle) { + + this.shooterHood = shooterHood; + this.angle = angle; + addRequirements(shooterHood); + + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + timer = 0; + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + + timer++; + System.out.println("adjusting hood"); + // if(RobotContainer.operatorPanel.getRawButton(OperatorConstants.shooterAutoButton)){ + shooterHood.moveServoAngle(angle); + // } + // else if(RobotContainer.operatorPanel.getRawButton(OperatorConstants.shooterManualButton)){ + // // shooter.setShooterVelocity(shooter.shooterRPMToTalonVelocity(RPM+1000*RobotContainer.operatorPanel.getRawAxis(OperatorConstants.shooterManualAxis))); + // shooterHood.moveServoAngle(shooterHood.shootAngleToServoAngle(18)); + + // } + // else{ + // // shooter.setShooterPower(0); + // shooterHood.moveServoAngle(shooterHood.shootAngleToServoAngle(40)); + + // } + + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return timer>150; + } +} diff --git a/src/main/java/org/team696/robot/commands/ShooterPowerCommand.java b/src/main/java/org/team696/robot/commands/ShooterPowerCommand.java new file mode 100644 index 0000000..41fc4c5 --- /dev/null +++ b/src/main/java/org/team696/robot/commands/ShooterPowerCommand.java @@ -0,0 +1,51 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +import org.team696.robot.subsystems.Shooter; + +public class ShooterPowerCommand extends CommandBase { + /** + * Creates a new ShooterPowerCommand. + */ + private Shooter shooter; + private double power; + private boolean state; + public ShooterPowerCommand(Shooter shooter, double power, boolean state) { + // Use addRequirements() here to declare subsystem dependencies. + this.shooter = shooter; + this.state = state; + this.power = power; + addRequirements(shooter); + } + + // 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() { + shooter.setShooterPower(power); + shooter.setAcceleratorPower(state); + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/org/team696/robot/commands/ShooterPrep.java b/src/main/java/org/team696/robot/commands/ShooterPrep.java new file mode 100644 index 0000000..333bffd --- /dev/null +++ b/src/main/java/org/team696/robot/commands/ShooterPrep.java @@ -0,0 +1,54 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import org.team696.robot.subsystems.Limelight; +import org.team696.robot.subsystems.Shooter; +import org.team696.robot.subsystems.TurretSubsystem; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +public class ShooterPrep extends CommandBase { + + //maybe add omni to this command or make it part of the spindexer drum one + TurretSubsystem turretSubsystem; + Shooter shooter; + public ShooterPrep(Shooter shooter, TurretSubsystem turretSubsystem) { + this.turretSubsystem = turretSubsystem; + this.shooter = shooter; + addRequirements(shooter); + addRequirements(turretSubsystem); + } + + // 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() { + Limelight.setLights(3); + turretSubsystem.moveToTarget(); + shooter.setShooterVelocity(shooter.shooterRPMToTalonVelocity(shooter.getShootRPM())); + shooter.setAcceleratorPower(true); + //maybe add shooter hood + } + + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/org/team696/robot/commands/ShooterTimerCommand.java b/src/main/java/org/team696/robot/commands/ShooterTimerCommand.java new file mode 100644 index 0000000..2dea15f --- /dev/null +++ b/src/main/java/org/team696/robot/commands/ShooterTimerCommand.java @@ -0,0 +1,60 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +import org.team696.robot.subsystems.Shooter; + +public class ShooterTimerCommand extends CommandBase { + /** + * Creates a new ShooterCommand. + */ + private Shooter shooter; + + double RPM; + boolean state; + int x = 0; + public ShooterTimerCommand(Shooter shooter, double RPM, boolean state) { + + this.shooter = shooter; + this.state = state; + this.RPM = RPM; + addRequirements(shooter); + } + + // 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() { + shooter.setShooterVelocity(shooter.shooterRPMToTalonVelocity(RPM)); + shooter.setAcceleratorPower(state); + System.out.println("shooting"); + x++; + + //TODO: make another command to run off of feedforward gains + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + x = 0; + shooter.setShooterPower(0); + + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return x>150; + } +} diff --git a/src/main/java/org/team696/robot/commands/SpinToPocket.java b/src/main/java/org/team696/robot/commands/SpinToPocket.java new file mode 100644 index 0000000..5ff11af --- /dev/null +++ b/src/main/java/org/team696/robot/commands/SpinToPocket.java @@ -0,0 +1,71 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import org.team696.robot.Constants; +import org.team696.robot.subsystems.Spindexer; + +public class SpinToPocket extends CommandBase { + /** + * Creates a new SpinToIndex. + */ + private static final Logger logger = LogManager.getLogger(ATCForCommand.class); + Spindexer spindexer; + + int targetPocket; + + public SpinToPocket(Spindexer spindexer, int targetPocket) { + this.spindexer = spindexer; + this.targetPocket = targetPocket; + addRequirements(spindexer); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + // oldSpindexerPocket = spindexer.getTargetPocket(); + // int targetPocket; + // if (spindexer.getTargetPocket() == Constants.SpindexerConstants.nPockets) { + // targetPocket = 1; + // } else { + // targetPocket = spindexer.getTargetPocket() + 1; + // } + // logger.info(String.format("Moving spindexer from %d to %d", oldSpindexerPocket, targetPocket)); + // spindexer.setTargetPocket(targetPocket); + spindexer.setTargetPocket(targetPocket); + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + //System.out.println("spinning to index stuff"); + //System.out.println(spindexer.getCurrentPocket()); + + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + if(interrupted){ + logger.info("Spindexer command interrupted."); + } else { + logger.info("Spindexer on target."); + } + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return spindexer.getCurrentPocket()==targetPocket; + } +} diff --git a/src/main/java/org/team696/robot/commands/SpindexerLoading.java b/src/main/java/org/team696/robot/commands/SpindexerLoading.java new file mode 100644 index 0000000..bad50e9 --- /dev/null +++ b/src/main/java/org/team696/robot/commands/SpindexerLoading.java @@ -0,0 +1,57 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +import org.team696.robot.subsystems.Intake; +import org.team696.robot.subsystems.Spindexer; + +public class SpindexerLoading extends CommandBase { + /** + * Creates a new SpindexerLoading. + */ + Spindexer spindexer; + Intake intake; + double spindexerPower; + double intakePower; + public SpindexerLoading(Spindexer spindexer, Intake intake, double spindexerPower, double intakePower) { + // Use addRequirements() here to declare subsystem dependencies. + this.spindexerPower = spindexerPower; + this.intakePower = intakePower; + this.spindexer = spindexer; + this.intake = intake; + addRequirements(spindexer); + addRequirements(intake); + } + + // 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() { + spindexer.spindexerLoadingAntiJam(spindexerPower); + intake.runIntake(intakePower); + // System.out.println("running the loading stuff"); + } + + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/org/team696/robot/commands/StopTurret.java b/src/main/java/org/team696/robot/commands/StopTurret.java new file mode 100644 index 0000000..ef0a34a --- /dev/null +++ b/src/main/java/org/team696/robot/commands/StopTurret.java @@ -0,0 +1,47 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +import org.team696.robot.subsystems.TurretSubsystem; + +public class StopTurret extends CommandBase { + /** + * Creates a new StopTurret. + */ + private TurretSubsystem turretSubsystem; + + public StopTurret(TurretSubsystem turretSubsystem) { + // Use addRequirements() here to declare subsystem dependencies. + this.turretSubsystem = turretSubsystem; + addRequirements(turretSubsystem); + } + + // 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() { + turretSubsystem.openLoop(0); + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/org/team696/robot/commands/TurretLockOn.java b/src/main/java/org/team696/robot/commands/TurretLockOn.java new file mode 100644 index 0000000..abd8a31 --- /dev/null +++ b/src/main/java/org/team696/robot/commands/TurretLockOn.java @@ -0,0 +1,53 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +import org.team696.robot.subsystems.Limelight; +import org.team696.robot.subsystems.TurretSubsystem; + +public class TurretLockOn extends CommandBase { + /** + * Creates a new TurretLockOn. + */ + + TurretSubsystem turretSubsystem; + Limelight limelight; + public TurretLockOn(TurretSubsystem turretSubsystem, Limelight limelight) { + this.turretSubsystem = turretSubsystem; + this.limelight = limelight; + addRequirements(turretSubsystem); + addRequirements(limelight); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + limelight.setLights(3); + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + // turretSubsystem.openLoop(0.05); + turretSubsystem.moveToTarget(); + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + // return turretSubsystem.onTarget(); + return false; + } +} diff --git a/src/main/java/org/team696/robot/commands/TurretManual.java b/src/main/java/org/team696/robot/commands/TurretManual.java new file mode 100644 index 0000000..a9cbf90 --- /dev/null +++ b/src/main/java/org/team696/robot/commands/TurretManual.java @@ -0,0 +1,64 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.commands; + +import org.team696.robot.RobotContainer; +import org.team696.robot.Constants.TurretConstants; +import org.team696.robot.subsystems.Limelight; +import org.team696.robot.subsystems.TurretSubsystem; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +public class TurretManual extends CommandBase { + /** + * Creates a new TurretManual. + */ + TurretSubsystem turretSubsystem; + Limelight limelight; + double position; + public TurretManual(TurretSubsystem turretSubsystem, Limelight limelight) { + // Use addRequirements() here to declare subsystem dependencies.\ + this.turretSubsystem = turretSubsystem; + this.limelight = limelight; + this.position = position; + addRequirements(turretSubsystem); + addRequirements(limelight); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + // limelight.setLights(1); + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + // turretSubsystem.moveToPosition(TurretConstants.turretCenterPos+position*100); + // System.out.println("turret manual"); + // System.out.println(position); + if(RobotContainer.operatorPanel.getRawAxis(0)>0.05){ + limelight.setLights(1); + } + else{ + limelight.setLights(1); + } + turretSubsystem.openLoop(-RobotContainer.operatorPanel.getRawAxis(0)); + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/org/team696/robot/subsystems/BallSensors.java b/src/main/java/org/team696/robot/subsystems/BallSensors.java new file mode 100644 index 0000000..018d21c --- /dev/null +++ b/src/main/java/org/team696/robot/subsystems/BallSensors.java @@ -0,0 +1,138 @@ +package org.team696.robot.subsystems; + +import edu.wpi.first.wpilibj.I2C; +import edu.wpi.first.wpilibj.I2C.Port; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; + +import org.team696.TCA9548ADriver.TCA9548A; +import org.team696.TCA9548ADriver.TCA9548ADevice; +import org.team696.TCS34725.Gain; +import org.team696.TCS34725.IntegrationTime; +import org.team696.TCS34725.TCS34725; +import org.team696.robot.Constants.SpindexerConstants; +import org.team696.utils.ColorUtils.Color; + +public class BallSensors { + private int num_sensors; + private TCS34725[] sensors; + private static final Logger logger = LogManager.getLogger(TCA9548ADevice.class); + + /** + * Constructor that assumes a mux with the address given in Constants and sensors connected in order. + */ + public BallSensors() { + num_sensors = SpindexerConstants.nPockets; + sensors = new TCS34725[num_sensors]; + byte muxaddr = SpindexerConstants.ColorSensorsMuxAddress; + TCA9548A mux = new TCA9548A(Port.kOnboard, muxaddr); + int i; + for (i = 0; i < num_sensors; i++) { + TCA9548ADevice thisMuxChannel = new TCA9548ADevice(mux, TCS34725.I2C_constants.TCS34725_I2C_ADDR, i); + TCS34725 thisSensor = new TCS34725(thisMuxChannel); + sensors[i] = thisSensor; + } + } + + /** + * Constructor that takes premade I2C channels. + * @param channels I2C channels (should be num_sensors long) + */ + public BallSensors(I2C[] channels) { + num_sensors = SpindexerConstants.nPockets; + sensors = new TCS34725[num_sensors]; + int i; + for (i = 0; i < num_sensors; i++) { + TCS34725 thisSensor = new TCS34725(channels[i]); + sensors[i] = thisSensor; + } + } + + /** + * Constructor that takes a mux and the indices of the mux channels going to the sensors. + * @param mux A TCA9548A mux object + * @param muxChannels The mux channels to use (should be num_sensors long) + */ + public BallSensors(TCA9548A mux, byte[] muxChannels) { + num_sensors = SpindexerConstants.nPockets; + sensors = new TCS34725[num_sensors]; + int i; + for (i = 0; i < num_sensors; i++) { + TCA9548ADevice thisMuxChannel = new TCA9548ADevice(mux, TCS34725.I2C_constants.TCS34725_I2C_ADDR, muxChannels[i]); + TCS34725 thisSensor = new TCS34725(thisMuxChannel); + thisSensor.setName(String.format("Pocket %d", i)); + sensors[i] = thisSensor; + } + } + + /** + * Calls init() on all the sensors. + */ + public void initSensors() { + for (TCS34725 sensor : sensors) { + sensor.init(IntegrationTime.IT_24MS, Gain.X1); + } + } + + + public double[] getColor(int idx){ + double[] retval = new double[3]; + TCS34725 sensor = sensors[idx]; + if(sensor.readColors() == -1){ + sensor.init(IntegrationTime.IT_24MS, Gain.X1); + } + retval[0] = sensor.getRedVal(); + retval[1] = sensor.getGreenVal(); + retval[2] = sensor.getBlueVal(); + return retval; + } + /** + * Gets whether each sensor sees a ball. + * For each sensor, commands a reading, then compares the red, green, + * blue, and clear values to the limits in Constants to see if a ball + * is there. + * @return An array of num_sensors booleans, each indicating if that sensor sees a ball + */ + public boolean[] getResults() { + boolean[] results = new boolean[num_sensors]; + int i; + for (i = 0; i < num_sensors; i++) { + TCS34725 sensor = sensors[i]; + if(sensor.readColors() == -1){ + sensor.init(IntegrationTime.IT_24MS, Gain.X1); + } + //TODO: figure out how to scale colors + double red = sensor.getRedVal(); + double green = sensor.getGreenVal(); + double blue = sensor.getBlueVal(); + Color color = new Color(red, green, blue); + double[] hsv = color.getHSV(); + boolean hasBall = true; + if (hsv[0] < SpindexerConstants.HueMin || hsv[0] > SpindexerConstants.HueMax) { + hasBall = false; + } + if (hsv[1] < SpindexerConstants.SatMin || hsv[1] > SpindexerConstants.SatMax) { + hasBall = false; + } + if (hsv[2] < SpindexerConstants.ValueMin || hsv[2] > SpindexerConstants.ValueMax) { + hasBall = false; + } + results[i] = hasBall; + } + + return results; + } + + public void setLEDs(boolean state){ + int i; + for(i=0; i DrivetrainConstants.slowTasksSpeed){ + iterationCounter = 0; + + //Perform slow tasks + // logger.info(String.format("Left front drive motor temp: %f", leftFrontDrive.getMotorTemperature())); + // logger.info(String.format("Left rear drive motor temp: %f", leftRearDrive.getMotorTemperature())); + // logger.info(String.format("Right front drive motor temp: %f", rightFrontDrive.getMotorTemperature())); + // logger.info(String.format("Right rear drive motor temp: %f", rightRearDrive.getMotorTemperature())); + + } else { + iterationCounter++; + } + + } + + /** + * Drives robot using current mode. + * @param speed Robot speed (-1, 1) + * @param turn Turning-ness, (-1, 1), positive values are counterclockwise + */ + public void arcadeDrive(double speed, double turn){ + switch(mode){ + case OpenLoop: + driveOpenLoop(speed, turn); + break; + case RateCommand: + driveClosedLoop(speed, turn); + break; + default: + return; + } + } + + public double roll(){ + return navX.getPitch(); + } + + /** + * Drives robot in open loop percent-output. + * @param speed Robot speed (-1, 1) + * @param turn Turning-ness, (-1, 1), positive values are counterclockwise + */ + public void driveOpenLoop(double speed, double turn){ + double leftSpeed, rightSpeed; + if(turn > 0){ + turn = turn*turn; + } else{ + turn = -(turn*turn); + } + if(speed > 0){ + speed = speed*speed; + } else{ + speed = -(speed*speed); + } + rightSpeed = speed + turn; + leftSpeed = speed - turn; + + //Scale speeds to stay within range + if(Math.abs(rightSpeed) > 1){ + double multiplier = (1 / Math.abs(rightSpeed)); + rightSpeed *= multiplier; + leftSpeed *= multiplier; + } + if(Math.abs(leftSpeed) > 1){ + double multiplier = (1 / Math.abs(leftSpeed)); + rightSpeed *= multiplier; + leftSpeed *= multiplier; + } + + SmartDashboard.putNumber("Left Commanded Throttle", leftSpeed); + SmartDashboard.putNumber("Right Commanded Throttle", rightSpeed); + leftFrontDrive.set(leftSpeed); + rightFrontDrive.set(rightSpeed); + } + + /** + * Implements closed-loop assisted driving. + * + * @param speed Robot speed (-1, 1) + * @param turn Turning-ness, (-1, 1), positive values are counterclockwise + */ + public void driveClosedLoop(double speed, double turn){ + speed *= DrivetrainConstants.maxSpeed; + turn *= DrivetrainConstants.maxTurnRate; + + targetYaw += turn; + targetYaw = MathUtils.wrapAngle180(targetYaw); + SmartDashboard.putNumber("Target Yaw", targetYaw); + SmartDashboard.putNumber("Target Speed", speed); + + double currentYaw = getRobotYaw(); + double turnOutput = driveAssistPID.calculate(currentYaw, targetYaw); + SmartDashboard.putNumber("Turn PID Output", turnOutput); + double rightSpeed = speed + turnOutput; //In RPM + double leftSpeed = speed - turnOutput; //In RPM + + //Scale speeds to stay within range + if(Math.abs(rightSpeed) > DrivetrainConstants.maxSpeed){ + double multiplier = (DrivetrainConstants.maxSpeed / rightSpeed); + rightSpeed *= multiplier; + leftSpeed *= multiplier; + } + if(Math.abs(leftSpeed) > DrivetrainConstants.maxSpeed){ + double multiplier = (DrivetrainConstants.maxSpeed / leftSpeed); + rightSpeed *= multiplier; + leftSpeed *= multiplier; + } + + SmartDashboard.putNumber("Left Commanded Speed", leftSpeed); + SmartDashboard.putNumber("Right Commanded Speed", rightSpeed); + leftPID.setReference(leftSpeed, ControlType.kVelocity); + rightPID.setReference(rightSpeed, ControlType.kVelocity); + } + + public void setTargetYaw(double yaw){ + targetYaw = yaw; + } + + public double getRobotYaw(){ + //return MathUtils.wrapAngle180(imu.getAngle()); + return 0.0; + } + + // public void calibrateIMU(){ + // imu.configCalTime(DrivetrainConstants.IMUCalTime); + // imu.calibrate(); + // } + + /** + * Gets the speed of a side of the robot. + * @param isRight Set to false for the left side, true for the right side + * @return Speed of the side of the robot in in/s + */ + @SuppressWarnings("checkstyle:MagicNumber") + public double getSpeed(boolean isRight){ + double frontSpeed, rearSpeed; + + if(isRight){ + frontSpeed = rightFrontEncoder.getVelocity(); //in RPM + rearSpeed = rightRearEncoder.getVelocity(); //in RPM + } else{ + frontSpeed = leftFrontEncoder.getVelocity(); //in RPM + rearSpeed = leftRearEncoder.getVelocity(); //in RPM + } + + //TODO: check to make sure front/rear speeds are similar + + double motorSpeedRPM = (frontSpeed + rearSpeed)/2.; + double outputSpeedRPM = motorSpeedRPM / DrivetrainConstants.driveGearboxReduction; //Speed (RPM) of gearbox output shaft + return outputSpeedRPM * (1./60.) * Math.PI * DrivetrainConstants.wheelDiameter; //Convert shaft RPM to in/s + } + + /** + * Gets robot center speed. + * @return Robot speed in in/s + */ + public double getRobotSpeed(){ + double leftSpeed = getSpeed(false); + double rightSpeed = getSpeed(true); + return (leftSpeed + rightSpeed)/2.; + } + + private void configLFSpark(DrivetrainMode mode){ + logger.debug(String.format("Configuring left-front Spark for %s", mode.name())); + leftFrontDrive.restoreFactoryDefaults(); + leftFrontDrive.setInverted(DrivetrainConstants.leftFrontIsInverted); + leftFrontDrive.setSmartCurrentLimit(Constants.DrivetrainConstants.stallCurrentLimit, + Constants.DrivetrainConstants.freeCurrentLimit, + Constants.DrivetrainConstants.stallThresholdRPM); + leftFrontDrive.setOpenLoopRampRate(Constants.DrivetrainConstants.openLoopRampRate); + leftFrontEncoder = leftFrontDrive.getEncoder(); + leftPID = leftFrontDrive.getPIDController(); + } + + private void configLRSpark(DrivetrainMode mode){ + logger.debug(String.format("Configuring left-rear Spark for %s", mode.name())); + leftRearDrive.restoreFactoryDefaults(); + leftRearDrive.setInverted(DrivetrainConstants.leftRearIsInverted); + leftRearDrive.setSmartCurrentLimit(Constants.DrivetrainConstants.stallCurrentLimit, + Constants.DrivetrainConstants.freeCurrentLimit, + Constants.DrivetrainConstants.stallThresholdRPM); + leftRearEncoder = leftRearDrive.getEncoder(); + leftRearDrive.follow(leftFrontDrive); + } + + private void configRFSpark(DrivetrainMode mode){ + logger.debug(String.format("Configuring right-front Spark for %s", mode.name())); + rightFrontDrive.restoreFactoryDefaults(); + rightFrontDrive.setInverted(DrivetrainConstants.rightFrontIsInverted); + rightFrontDrive.setSmartCurrentLimit(Constants.DrivetrainConstants.stallCurrentLimit, + Constants.DrivetrainConstants.freeCurrentLimit, + Constants.DrivetrainConstants.stallThresholdRPM); + rightFrontDrive.setOpenLoopRampRate(Constants.DrivetrainConstants.openLoopRampRate); + rightFrontEncoder = rightFrontDrive.getEncoder(); + rightPID = rightFrontDrive.getPIDController(); + } + private void configRRSpark(DrivetrainMode mode){ + logger.debug(String.format("Configuring right-rear Spark for %s", mode.name())); + rightRearDrive.restoreFactoryDefaults(); + rightRearDrive.setInverted(DrivetrainConstants.rightRearIsInverted); + rightRearDrive.setSmartCurrentLimit(Constants.DrivetrainConstants.stallCurrentLimit, + Constants.DrivetrainConstants.freeCurrentLimit, + Constants.DrivetrainConstants.stallThresholdRPM); + rightRearEncoder = rightRearDrive.getEncoder(); + rightRearDrive.follow(rightFrontDrive); + } +} diff --git a/src/main/java/org/team696/robot/subsystems/Intake.java b/src/main/java/org/team696/robot/subsystems/Intake.java new file mode 100644 index 0000000..6f275c8 --- /dev/null +++ b/src/main/java/org/team696/robot/subsystems/Intake.java @@ -0,0 +1,44 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.subsystems; + +import com.revrobotics.CANSparkMax; +import com.revrobotics.CANSparkMaxLowLevel.MotorType; + +import org.team696.robot.Constants; + +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +public class Intake extends SubsystemBase { + /** + * Creates a new IntakeSubsystem. + */ + private CANSparkMax intakeMotor; + + public Intake() { + intakeMotor = new CANSparkMax(Constants.IntakeConstants.IntakeMotorPort, MotorType.kBrushless); + intakeMotor.restoreFactoryDefaults(); + intakeMotor.setInverted(Constants.IntakeConstants.IntakeInverted); + } + + public void runIntake(double power){ + intakeMotor.set(power); + // System.out.println("intaking"); + } + + + public double intakeCurrent(){ + return intakeMotor.getOutputCurrent(); + } + + + @Override + public void periodic() { + // This method will be called once per scheduler run + } +} diff --git a/src/main/java/org/team696/robot/subsystems/Limelight.java b/src/main/java/org/team696/robot/subsystems/Limelight.java new file mode 100644 index 0000000..8d976c4 --- /dev/null +++ b/src/main/java/org/team696/robot/subsystems/Limelight.java @@ -0,0 +1,163 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.subsystems; + +import org.team696.robot.Constants.LimelightConstants; + +import edu.wpi.first.networktables.NetworkTableEntry; +import edu.wpi.first.networktables.NetworkTableInstance; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +public class Limelight extends SubsystemBase { + /** + * Creates a new LimeLightSybsystem. + */ + + + NetworkTableEntry camTran = NetworkTableInstance.getDefault().getTable("limelight").getEntry("camtran"); + + public static double[] camTranArray = {0.0,0.0,0.0,0.0,0.0,0.0}; + + // public double[] camTranArray = new double[6]; + + // public LimelightSubsystem() { + + // } + + // public void camTran() { + // camTranArray = NetworkTableInstance.getDefault().getTable("limelight").getEntry("camtran") + // .getDoubleArray(camTranArray); + // } + + /** + * + * @param lightMode 1 is off, 3 is on + */ + public static void setLights(int lightMode){ + NetworkTableInstance.getDefault().getTable("limelight").getEntry("ledMode").setNumber(lightMode); + + } + + public void updateCamTran(){ + camTranArray = camTran.getDoubleArray(camTranArray); + } + + public boolean is3dModePipelineOn(){ + return (getPipeline()==LimelightConstants.camTranPipeline); + } + + + public static double distanceFromTarget(){ + return camTranArray[2]; + } + + + + public double tx() { + return NetworkTableInstance.getDefault().getTable("limelight").getEntry("tx").getDouble(0); + } + + public static double ty() { + return NetworkTableInstance.getDefault().getTable("limelight").getEntry("ty").getDouble(0); + } + + public double tyradian() { + return Math.toRadians(ty()); + } + + public double tvert() { + return NetworkTableInstance.getDefault().getTable("limelight").getEntry("tvert").getDouble(0); + } + + public double thor() { + return NetworkTableInstance.getDefault().getTable("limelight").getEntry("thor").getDouble(0); + } + + public double tlong() { + return NetworkTableInstance.getDefault().getTable("limelight").getEntry("tlong").getDouble(0); + } + + public double tshort() { + return NetworkTableInstance.getDefault().getTable("limelight").getEntry("tshort").getDouble(0); + } + + public double pixels() { + return thor() * tvert(); + } + + public void pipeline(int x) { + NetworkTableInstance.getDefault().getTable("limelight").getEntry("pipeline").setDouble(x); + } + + public static double getPipeline() { + + return NetworkTableInstance.getDefault().getTable("limelight").getEntry("pipeline").getDouble(0); + } + + public double thorDistance() { + + return 11.6 / (2 * Math.tan(Math.toRadians((0.17 / 2) * thor()))); + } + + public double tvertDistance() { + + return 1.85 / (2 * Math.tan(Math.toRadians((0.17 / 2) * tvert()))); + + } + + public static double angleDistance(){ + return (98.25-24.5)/Math.tan(Math.toRadians(27.5+ty())); + } + + /** + * + * @return 1 if has target, 0 if no target + */ + public static double hasTarget(){ + return NetworkTableInstance.getDefault().getTable("limelight").getEntry("tv").getDouble(0); + + } + + public boolean crosshairOnTarget(){ + if(hasTarget()==1){ + //need to adjust this threshold. maybe can change depending on distance from target + return tx()<1; + } + else{ + return false; + } + } + + /** + * + * @return Returns index of the TrajectoryTable array to look for based on the + * distance the limelight returns. If it returns 0 then it means there + * is no target and the limelight is not configured in 3d Mode. In this + * scenario it selects the first row of the array with an angle of 0 and + * a speed of 0. + * + * May need to adjust the default angle value + */ + public static int indexForDistance() { + // need to add code to prevent out of index of the array + // if statement for if there is a target and we are in 3d mode + if (Math.abs(angleDistance())>119&&Math.abs(angleDistance())<(400)) { + return (int)Math.abs(angleDistance()) - 119; + } else + return 0; + } + + @Override + public void periodic() { + + // pipeline(5); + updateCamTran(); + + } +} \ No newline at end of file diff --git a/src/main/java/org/team696/robot/subsystems/Shooter.java b/src/main/java/org/team696/robot/subsystems/Shooter.java new file mode 100644 index 0000000..4ba9ddd --- /dev/null +++ b/src/main/java/org/team696/robot/subsystems/Shooter.java @@ -0,0 +1,332 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.subsystems; + +import com.ctre.phoenix.motorcontrol.ControlMode; +import com.ctre.phoenix.motorcontrol.FeedbackDevice; +import com.ctre.phoenix.motorcontrol.NeutralMode; +import com.ctre.phoenix.motorcontrol.TalonFXControlMode; +import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX; +import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX; + +import edu.wpi.first.wpilibj.Servo; +import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +import org.team696.robot.Constants; +import org.team696.robot.Robot; +import org.team696.robot.RobotContainer; +import org.team696.robot.TrajectoryTable; +import org.team696.robot.Constants.OperatorConstants; +import org.team696.robot.Constants.ShooterConstants; + +public class Shooter extends SubsystemBase { + /** + * Creates a new ShooterSubsystem. + */ + private WPI_TalonFX leftShooterMotor; + private WPI_TalonFX rightShooterMotor; + + private SimpleMotorFeedforward shooterFeedForward; + + private WPI_TalonSRX shooterAcceleratorMotor; + + public double shootRPM; + + + // private LimelightSubsystem limelightSubsystem = new LimelightSubsystem(); + + public Shooter() { + + leftShooterMotor = new WPI_TalonFX(Constants.ShooterConstants.leftShooterPort); + rightShooterMotor = new WPI_TalonFX(Constants.ShooterConstants.rightShooterPort); + + leftShooterMotor.configFactoryDefault(); + + leftShooterMotor.configSelectedFeedbackSensor(FeedbackDevice.IntegratedSensor, Constants.ShooterConstants.pidSlot, Constants.CANtimeout); + leftShooterMotor.setSensorPhase(Constants.ShooterConstants.leftShooterSensorPhase); + leftShooterMotor.setInverted(Constants.ShooterConstants.leftShooterInverted); + leftShooterMotor.setNeutralMode(NeutralMode.Coast); + leftShooterMotor.configNominalOutputForward(0); + leftShooterMotor.configNominalOutputReverse(0); + leftShooterMotor.configPeakOutputForward(1); + leftShooterMotor.configPeakOutputReverse(-1); + + leftShooterMotor.configAllowableClosedloopError(Constants.ShooterConstants.pidSlot, + Constants.ShooterConstants.allowableShooterError); + + // leftShooterMotor.configContinuousCurrentLimit(amps) + + leftShooterMotor.config_kP(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.shooterkP); + leftShooterMotor.config_kI(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.shooterkI); + leftShooterMotor.config_kD(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.shooterkD); + leftShooterMotor.config_kF(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.shooterkF); + + rightShooterMotor.configFactoryDefault(); + rightShooterMotor.follow(leftShooterMotor); + rightShooterMotor.configSelectedFeedbackSensor(FeedbackDevice.IntegratedSensor, Constants.ShooterConstants.pidSlot, Constants.CANtimeout); + rightShooterMotor.setSensorPhase(Constants.ShooterConstants.rightShooterSensorPhase); + rightShooterMotor.setInverted(Constants.ShooterConstants.rightShooterInverted); + + shooterFeedForward = new SimpleMotorFeedforward(Constants.ShooterConstants.shooterkSGain, + Constants.ShooterConstants.shooterkVGain, Constants.ShooterConstants.shooterkAGain); + + + + shooterAcceleratorMotor = new WPI_TalonSRX(Constants.ShooterConstants.acceleratorPort); + shooterAcceleratorMotor.configFactoryDefault(); + shooterAcceleratorMotor.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Absolute, + Constants.ShooterConstants.pidSlot, Constants.CANtimeout); + shooterAcceleratorMotor.configNominalOutputForward(0); + shooterAcceleratorMotor.configNominalOutputReverse(0); + shooterAcceleratorMotor.configPeakOutputForward(1); + shooterAcceleratorMotor.configPeakOutputReverse(-1); + shooterAcceleratorMotor.setInverted(Constants.ShooterConstants.acceleratorInverted); + shooterAcceleratorMotor.setSensorPhase(Constants.ShooterConstants.acceleratorSensorPhase); + shooterAcceleratorMotor.config_kP(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.acceleratorkP); + shooterAcceleratorMotor.config_kI(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.acceleratorkI); + shooterAcceleratorMotor.config_kD(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.acceleratorkD); + shooterAcceleratorMotor.config_kF(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.acceleratorkF); + + // shooterHoodServo.dead + + } + + public void setShooterkP(double kP){ + leftShooterMotor.config_kP(0, kP); + } + public void setShooterkI(double kI){ + leftShooterMotor.config_kP(0, kI); + } + public void setShooterkD(double kD){ + leftShooterMotor.config_kP(0, kD); + } + public void setShooterkF(double kF){ + leftShooterMotor.config_kF(0, kF); + } + + + public void setAcceleratorkP(double kP){ + shooterAcceleratorMotor.config_kP(0, kP); + } + public void setAcceleratorkI(double kI){ + shooterAcceleratorMotor.config_kP(0, kI); + } + public void setAcceleratorkD(double kD){ + shooterAcceleratorMotor.config_kP(0, kD); + } + public void setAcceleratorkF(double kF){ + shooterAcceleratorMotor.config_kF(0, kF); + } + + + public void setFeederVelocity(double velocity) { + + shooterAcceleratorMotor.set(ControlMode.Velocity, velocity); + } + + public void setFeederPower(double power) { + shooterAcceleratorMotor.set(ControlMode.PercentOutput, power); + + } + + public double getShooterSetpoint(){ + return leftShooterMotor.getClosedLoopTarget(); + } + + public double getShooterPower(){ + return leftShooterMotor.getMotorOutputPercent(); + } + /** + * Commands shooter in open-loop. + * @param power Shooter power (0-1) + */ + public void setShooterPower(double power) { + + leftShooterMotor.set(ControlMode.PercentOutput, power); + // rightShooterMotor.set(ControlMode.PercentOutput, power); + } + + /** + * Commands accelerator in open-loop. + * @param power Accelerator power (0-1) + */ + public void setAcceleratorPower(double power) { + shooterAcceleratorMotor.set(ControlMode.PercentOutput, power); + // rightShooterMotor.set(ControlMode.PercentOutput, power); + } + + public void setAcceleratorPower(boolean state) { + if(state){ + shooterAcceleratorMotor.set(ControlMode.PercentOutput, 1); + } + else{ + shooterAcceleratorMotor.set(ControlMode.PercentOutput, 0); + } + } + + /** + * Commands shooter velocity in TalonFX native units. + * @param velocity Shooter motor target velocity in encoder units per 100 ms + */ + public void setShooterVelocity(double velocity) { + leftShooterMotor.set(TalonFXControlMode.Velocity, velocity); + } + + /** + * Commands accelerator velocity. + * @param velocity Velocity in Talon SRX native units + */ + public void setAcceleratorVelocity(double velocity){ + shooterAcceleratorMotor.set(ControlMode.Velocity, velocity); + } + + public void runShooterFeedForward(double targetVelocity, double targetAcceleration) { + leftShooterMotor.setVoltage(calculateFeedForwardValue(targetVelocity, targetAcceleration)); + // might use voltage depends which works better + // leftShooterMotor.set(TalonFXControlMode.PercentOutput, calculateFeedForward); + } + + + + + + + + + + + /** + * Computes Talon velocity setpoint from RPM. + * Use this value to feed directly into a shooter velocity control method + * @param RPM Flywheel speed in RPM + * @return Velocity value in TalonFX integrated sensor units per 100 ms. + */ + @SuppressWarnings("checkstyle:magicnumber") + public double shooterRPMToTalonVelocity(double RPM){ + double retval = ((RPM / 600) * (2048 / ShooterConstants.shooterGearRatio)); + return retval; + } + + /** + * Computes flywheel RPM from native units. + * @param velocity Falcon ticks / 100 ms + * @return Flywheel speed in RPM + */ + @SuppressWarnings("checkstyle:magicnumber") + public double talonVelocityToShooterRPM(double velocity){ + double retval = velocity/2048. * 600 * ShooterConstants.shooterGearRatio; + return retval; + } + + /** + * + * @param targetVelocity Tarrget Velocity in the same units of gains in + * FeedForward constructor + * @param targetAcceleration Target Velocity in the same units of gains in + * FeedForward constructor + * @return Value that feedForward calculates to pass into talon's .set() + */ + public double calculateFeedForwardValue(double targetVelocity, double targetAcceleration) { + return shooterFeedForward.calculate(targetVelocity, targetAcceleration); + } + + public double getLeftShooterCurrent() { + return leftShooterMotor.getSupplyCurrent(); + } + + public double getRightShooterCurrent() { + return rightShooterMotor.getSupplyCurrent(); + } + + public double getAcceleratorCurrent() { + return shooterAcceleratorMotor.getSupplyCurrent(); + } + + + /** + * + * @return Left TalonFX Velocity in Encoder Units per 100 ms + */ + public double getLeftShooterVelocity() { + return leftShooterMotor.getSelectedSensorVelocity(); + } + /** + * @return Right TalonFX Velocity in Encoder Units per 100 ms + */ + public double getRightShooterVelocicty() { + return rightShooterMotor.getSelectedSensorVelocity(); + } + + /** + * @return Returns Accelerator/Feeder Velocity in Encoder Units per 100 ms + */ + public double getAcceleratorVelocity() { + return shooterAcceleratorMotor.getSelectedSensorVelocity(); + } + // public double getAcceleratorRPM() { + // return shooterAcceleratorMotor. + // } + + /** + * Gets flywheel velocity + * @return Flywheel velocity in RPM + */ + public double getRPM(){ + return talonVelocityToShooterRPM(getLeftShooterVelocity()); + } + + + // public double getAutoRPM(){ + // return TrajectoryTable.TrajectoryTable[Limelight.indexForDistance()][1]; + // } + + // public double getAutoAngle(){ + + // if(TrajectoryTable.TrajectoryTable[Limelight.indexForDistance()][0]>14&&TrajectoryTable.TrajectoryTable[Limelight.indexForDistance()][0]<53){ + // return TrajectoryTable.TrajectoryTable[Limelight.indexForDistance()][0]; + // } + // else if(TrajectoryTable.TrajectoryTable[Limelight.indexForDistance()][0]<14){ + // return 14; + // } + // else{ + // return 53; + // } + // } + + // public void testShooterRPM(){ + // setShooterVelocity(shooterRPMToTalonVelocity(testtar)); + // } + + public double getShootRPM(){ + if(RobotContainer.operatorPanel.getRawButton(10)){ + return 4350; + } + else{ + return 2800; + } + } + + public boolean isUpToSpeed(){ + if(talonVelocityToShooterRPM(getLeftShooterVelocity())>0.9*getShootRPM()){ + return true; + } + else{ + return false; + } + } + + @Override + public void periodic() { + // This method will be called once per scheduler run + + + +} +} diff --git a/src/main/java/org/team696/robot/subsystems/ShooterHood.java b/src/main/java/org/team696/robot/subsystems/ShooterHood.java new file mode 100644 index 0000000..8b5054b --- /dev/null +++ b/src/main/java/org/team696/robot/subsystems/ShooterHood.java @@ -0,0 +1,70 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.subsystems; + +import edu.wpi.first.wpilibj.Servo; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +public class ShooterHood extends SubsystemBase { + /** + * Creates a new ShooterHood. + */ + + private Servo leftShooterHoodServo; + private Servo rightShooterHoodServo; + + public ShooterHood() { + leftShooterHoodServo = new Servo(2); + rightShooterHoodServo = new Servo(3); + + } + + public void moveServoAngle(double angle) { + // if (shooterHoodServo.getAngle() > Constants.ShooterConstants.shooterHoodAngleMinLimit + // || shooterHoodServo.getAngle() < Constants.ShooterConstants.shooterHoodAngleMaxLimit) { + leftShooterHoodServo.setAngle(angle); + rightShooterHoodServo.setAngle(180-angle);; + // } else { + + // } + + } + + public void moveServoPosition(double position) { + leftShooterHoodServo.setPosition(position); + rightShooterHoodServo.setPosition(1-position); + } + + + /** + * Gets last commanded hood servo angle + * @return servo angle + */ + public double servoAngle(){ + return leftShooterHoodServo.getAngle(); + } + + + public double servoAngleToShootAngle(double servoAngle){ + return -0.65828*(servoAngle)+59.3891; + //70 servo is 14 shoot + //10 servo is 53 shoot + } + + public double shootAngleToServoAngle(double shootAngle){ + return -1.5256*(shootAngle)+90.9203; + } + + @Override + public void periodic() { + // This method will be called once per scheduler run + + double testTargetAngle = SmartDashboard.getNumber("Target Angle", 30); + } +} diff --git a/src/main/java/org/team696/robot/subsystems/Spindexer.java b/src/main/java/org/team696/robot/subsystems/Spindexer.java new file mode 100644 index 0000000..a3669fb --- /dev/null +++ b/src/main/java/org/team696/robot/subsystems/Spindexer.java @@ -0,0 +1,391 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +package org.team696.robot.subsystems; + +import com.revrobotics.CANEncoder; +import com.revrobotics.CANPIDController; +import com.revrobotics.CANSparkMax; +import com.revrobotics.CANSparkMax.IdleMode; +import com.revrobotics.CANSparkMaxLowLevel.MotorType; +import com.revrobotics.ControlType; + +import edu.wpi.first.wpilibj.DigitalInput; +import edu.wpi.first.wpilibj.DutyCycle; +import edu.wpi.first.wpilibj.I2C.Port; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import org.team696.TCA9548ADriver.TCA9548A; +import org.team696.robot.Constants.SpindexerConstants; +import org.team696.robot.subsystems.BallSensors; + +/** + * Add your docs here. + */ +public class Spindexer extends SubsystemBase { + private static final Logger logger = LogManager.getLogger(Spindexer.class); + + private boolean isMoving; + private int targetPocket = 1; + private boolean isOnTarget; + private static Boolean isJammed = false; + private boolean[] ballOccupancy = new boolean[SpindexerConstants.nPockets]; + + private int forwardTimer; + private int backTimer; + + public enum SpindexerLoadingStates { + FORWARD_TIMER, FORWARD_OK, BACK_TIMER, BACK_OK + } + private SpindexerLoadingStates spindexerStates = SpindexerLoadingStates.FORWARD_TIMER; + + // Stuff related to the driving motor + private final CANSparkMax spindexerMotor = new CANSparkMax(SpindexerConstants.MotorCANID, MotorType.kBrushless); + private final CANPIDController motorPID = spindexerMotor.getPIDController(); + private final CANEncoder motorEncoder = spindexerMotor.getEncoder(); + + // Absolute encoder + private final DigitalInput encoderDI = new DigitalInput(SpindexerConstants.EncoderPort); + private final DutyCycle encoder = new DutyCycle(encoderDI); + + // Ball color sensors + TCA9548A mux = new TCA9548A(Port.kOnboard, SpindexerConstants.ColorSensorsMuxAddress); + private final BallSensors sensors = new BallSensors(mux, + new byte[] { SpindexerConstants.ColorSensor1MuxChannel, SpindexerConstants.ColorSensor2MuxChannel, + SpindexerConstants.ColorSensor3MuxChannel, SpindexerConstants.ColorSensor4MuxChannel, + SpindexerConstants.ColorSensor5MuxChannel }); + + // Kick motor + private final CANSparkMax kickMotor = new CANSparkMax(SpindexerConstants.KickMotorCANID, MotorType.kBrushless); + + public Spindexer() { + spindexerMotor.restoreFactoryDefaults(); + spindexerMotor.setIdleMode(CANSparkMax.IdleMode.kBrake); + spindexerMotor.setClosedLoopRampRate(SpindexerConstants.closedLoopRampRate); + spindexerMotor.setOpenLoopRampRate(SpindexerConstants.openLoopRampRate); + motorPID.setP(SpindexerConstants.P); + sensors.initSensors(); + kickMotor.setIdleMode(IdleMode.kBrake); + } + + public int getTargetPocket() { + return targetPocket; + } + + public boolean isMoving() { + return isMoving; + } + + public boolean isOnTarget() { + return isOnTarget; + } + + /** + * Sets brake mode of spindexer motor. + * @param isBrake True for brake, false for coast + */ + public void setBrake(boolean isBrake){ + if(isBrake){ + spindexerMotor.setIdleMode(IdleMode.kBrake); + } else{ + spindexerMotor.setIdleMode(IdleMode.kCoast); + } + } + + /** + * Safely sets target pocket. + * + * @param pocket Intended target pocket (bounds-checked) + */ + public void setTargetPocket(int pocket) { + if (1 <= pocket && pocket <= SpindexerConstants.nPockets) { + // logger.info(String.format("Setting spindexer target to pocket %d.", pocket)); + targetPocket = pocket; + } + else{ + // logger.error(String.format("Received request to set spindexer target to pocket %d. Ignoring.", pocket)); + } + } + + public double getMotorPosition() { + return motorEncoder.getPosition(); + } + + public double getCurrent() { + return spindexerMotor.getOutputCurrent(); + } + + public double getVelocity() { + return motorEncoder.getVelocity(); + } + + /**Gets ball occupancy array. + * @return Which pockets have balls + */ + public boolean[] getBallOccupancy() { + return ballOccupancy; + } + + @Override + public void periodic() { + // check if jammed + if (getCurrent() > SpindexerConstants.indexingJamDetectionCurrent) { + isJammed = true; + logger.warn("Spindexer jammed!"); + } else { + isJammed = false; + } + + // Check if moving + isMoving = (motorEncoder.getVelocity() > SpindexerConstants.VelocityTolerance); + + // Check if on target + if ((Math.abs(SpindexerConstants.PocketPositions[targetPocket - 1] + - getEncoderPosition()) < SpindexerConstants.PositionTolerance) && !isMoving) { + isOnTarget = true; + // updateBallOccupancy(); + } else { + isOnTarget = false; + + if(isJammed){ + // logger.warn(String.format("Jam while advancing to pocket %d. Reverting to previous pocket.")); + if (getVelocity() > 0) { + if (targetPocket == 1) { + setTargetPocket(5); + } else { + setTargetPocket(targetPocket - 1); + } + } else { + if (targetPocket == 5) { + setTargetPocket(1); + } else { + setTargetPocket(targetPocket + 1); + } + } + } + + motorPID.setReference(getMotorPositionForPocket(targetPocket), ControlType.kPosition); + + } + } + + /** + * Gets the currently-indexed pocket. + * + * @return Current pocket (1-5), or 0 if not on a pocket + */ + public int getCurrentPocket() { + if (isOnTarget) { + return targetPocket; + } else { + // TODO: Need a better way to represent "not at a pocket" + return 0; + } + } + + /** + * Gets the position of the spindexer, based on the absolute encoder. + * + * @return Encoder position on (0, 1) + */ + public double getEncoderPosition() { + double freq = encoder.getFrequency(); + // TODO: Check for invalid frequency (would suggest disconnected encoder) + double ratio = encoder.getOutput(); + @SuppressWarnings("checkstyle:magicnumber") + int highTime = (int) (((1. / freq) * ratio) * 1.e6); // Gets high time of signal in microseconds + // Map microseconds to rotations + return (double) (highTime - SpindexerConstants.RevTBEMinMicroseconds) + / (double) (SpindexerConstants.RevTBEMaxMicroseconds - SpindexerConstants.RevTBEMinMicroseconds); + } + + /** + * Gets the required motor position to get to the given pocket ASAP. + * + * @param pocket The index of the pocket to go to (1, ..., 5) + * @return The required motor position, taking the current motor position into + * account + */ + @SuppressWarnings("checkstyle:magicnumber") + private double getMotorPositionForPocket(int pocket) { + double currentPos = getEncoderPosition(); + double targetPos = SpindexerConstants.PocketPositions[pocket - 1]; + double toGo = computeWrappedDistance(currentPos, targetPos); + if ((0.5 - Math.abs(toGo)) < 0.1) { + toGo = Math.abs(toGo); + } + // System.out.printf("toGo: %f\n", toGo); + return getMotorPosition() + (toGo * SpindexerConstants.MotorTurnsPerSpindexerTurn); + } + + /** + * Helper function to compute shortest wrapped angular distance. + * + * @param from From point, on (0, 1) + * @param to To point, on (0, 1) + * @return Shortest distance, on (-0.5, 0.5) + */ + @SuppressWarnings("checkstyle:magicnumber") + private double computeWrappedDistance(double from, double to) { + // Adapted from https://stackoverflow.com/a/28037434 + double diff = (to - from + 0.5) % 1 - 0.5; + return diff < -0.5 ? diff + 1 : diff; + } + + /** + * Finds the pocket closest to the current position. + * @return Index of closest pocket, in the range (1, SpindexerConstants.nPockets) + */ + public int findNearestPocket(){ + double currentPos = getEncoderPosition(); + int i; + int nearest=0; + double nearestDistance = 1; + for(i=0; i SpindexerConstants.antiJamTimeout) { + forwardTimer = 0; + // logger.info("Transitioning to FORWARD_OK"); + spindexerStates = SpindexerLoadingStates.FORWARD_OK; + } + + break; + + case FORWARD_OK: + spindexerMotor.set(power); + if (getCurrent() > SpindexerConstants.loadingJamDetectionCurrent) { + // logger.info("Jam detected! Transitioning to BACK_TIMER."); + spindexerStates = SpindexerLoadingStates.BACK_TIMER; + } + break; + + case BACK_TIMER: + spindexerMotor.set(-power); + backTimer++; + if (backTimer > SpindexerConstants.antiJamTimeout) { + backTimer = 0; + // logger.info("Transitioning to BACK_OK"); + spindexerStates = SpindexerLoadingStates.BACK_OK; + } + break; + + case BACK_OK: + spindexerMotor.set(-power); + if (getCurrent() > SpindexerConstants.loadingJamDetectionCurrent) { + // logger.info("Jam detected! Transitioning to FORWARD_TIMER."); + spindexerStates = SpindexerLoadingStates.FORWARD_TIMER; + } + break; + + default: + break; + + } + + } + + public void goToNotAPocket() { + motorPID.setReference(0.867, ControlType.kPosition); + } +} diff --git a/src/main/java/org/team696/robot/subsystems/TurretSubsystem.java b/src/main/java/org/team696/robot/subsystems/TurretSubsystem.java new file mode 100644 index 0000000..b667ba0 --- /dev/null +++ b/src/main/java/org/team696/robot/subsystems/TurretSubsystem.java @@ -0,0 +1,149 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 org.team696.robot.subsystems; + +import com.ctre.phoenix.motorcontrol.ControlMode; +import com.ctre.phoenix.motorcontrol.FeedbackDevice; +import com.ctre.phoenix.motorcontrol.NeutralMode; +import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX; + +import edu.wpi.first.networktables.NetworkTableInstance; +import edu.wpi.first.wpilibj.controller.PIDController; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +import org.team696.robot.Constants.TurretConstants; +import org.team696.robot.Robot; + +public class TurretSubsystem extends SubsystemBase { + /** + * Creates a new TurretSubsystem. + */ + private WPI_TalonSRX turretMotor; + private PIDController turretController; + + private double turretSpeed; + + public TurretSubsystem() { + turretMotor = new WPI_TalonSRX(TurretConstants.turretMotorPort); + turretMotor.configFactoryDefault(); + // turretMotor.configSelectedFeedbackSensor(FeedbackDevice.Analog); + turretMotor.setSensorPhase(TurretConstants.turretMotorSensorPhase); + turretMotor.setInverted(TurretConstants.turretMotorInverted); + turretMotor.setNeutralMode(NeutralMode.Brake); + + turretMotor.configNominalOutputForward(0); + turretMotor.configNominalOutputReverse(0); + turretMotor.configPeakOutputForward(TurretConstants.peakOutput); + turretMotor.configPeakOutputReverse(-TurretConstants.peakOutput); + + turretMotor.configForwardSoftLimitThreshold(TurretConstants.forwardSoftLimit); + turretMotor.configReverseSoftLimitThreshold(TurretConstants.reverseSoftLimit); + turretMotor.configForwardSoftLimitEnable(false); + turretMotor.configReverseSoftLimitEnable(false); + + turretController = new PIDController(TurretConstants.kP, TurretConstants.kI, TurretConstants.kD); + + turretController.setTolerance(TurretConstants.positionTolerance); + } + + /** + * Gets tx value from Limelight. + * + * @return + */ + public double getTx() { + return NetworkTableInstance.getDefault().getTable("limelight").getEntry("tx").getDouble(0); + } + + /** + * Runs turret in open-loop. + * + * @param speed Output throttle + */ + public void openLoop(double speed) { + turretMotor.set(ControlMode.PercentOutput, speed); + } + + /** + * Checks if turret is on target. + * + * @return True if on target (position error within tolerance) + */ + public boolean onTarget() { + return (Math.abs(turretController.getPositionError()) < TurretConstants.positionTolerance) && Limelight.hasTarget()==1; + } + + public void moveToTarget() { + turretSpeed = turretController.calculate(getTx(), 0); + turretMotor.set(ControlMode.PercentOutput, turretSpeed); + } + + /** + * @param position moves turret to a set position in talon encoder units + */ + // todo: add some kind of degrees to encoder unit conversion + public void moveToPosition(double position) { + turretMotor.set(ControlMode.Position, position); + } + + /** + * + * @return Gets potentiometer positon based off the talon's analog input mode + */ + // public double getPotPosition() { + // return turretMotor.getSelectedSensorPosition(); + // } + + /** + * + * @return Gets supply current + */ + public double getCurrent() { + return turretMotor.getSupplyCurrent(); + } + + public double getVelocity() { + return turretMotor.getSelectedSensorVelocity(); + } + + public double getRPM() { + return 0; + } + + // public double setpoint() { + // return turretController.getSetpoint(); + // } + + // public double getError() { + // return turretController.getPositionError(); + // } + + // public void resetEncoder() { + // turretMotor.setSelectedSensorPosition(0); + // } + + // public double encoderToDegrees(double encoder) { + // return encoder / 1.1366666666666666666 - 581 + 130; + // } + + public void setPIDSlot(int slot) { + turretMotor.selectProfileSlot(slot, 0); + } + + @Override + public void periodic() { + // This method will be called once per scheduler run + // SmartDashboard.putNumber("degrees", encoderToDegrees(getPotPosition())); + // SmartDashboard.putNumber("pot position", getPotPosition()); + SmartDashboard.putNumber("tx", getTx()); + Robot.m_robotContainer.setLimelightCaptureLED((Limelight.hasTarget()==1)); + Robot.m_robotContainer.setLimelightLockLED(Math.abs(turretController.getPositionError()) < TurretConstants.positionTolerance); + + } +} diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 0000000..d3254bf --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,22 @@ + + + + + + + + + %d [%t] %p %c - %m%n + + + + + + + + + + + + + \ No newline at end of file diff --git a/vendordeps/Phoenix.json b/vendordeps/Phoenix.json new file mode 100644 index 0000000..87f03cb --- /dev/null +++ b/vendordeps/Phoenix.json @@ -0,0 +1,214 @@ +{ + "fileName": "Phoenix.json", + "name": "CTRE-Phoenix", + "version": "5.19.4", + "uuid": "ab676553-b602-441f-a38d-f1296eff6537", + "mavenUrls": [ + "https://devsite.ctr-electronics.com/maven/release/" + ], + "jsonUrl": "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/Phoenix-latest.json", + "javaDependencies": [ + { + "groupId": "com.ctre.phoenix", + "artifactId": "api-java", + "version": "5.19.4" + }, + { + "groupId": "com.ctre.phoenix", + "artifactId": "wpiapi-java", + "version": "5.19.4" + } + ], + "jniDependencies": [ + { + "groupId": "com.ctre.phoenix", + "artifactId": "cci", + "version": "5.19.4", + "isJar": false, + "skipInvalidPlatforms": true, + "validPlatforms": [ + "linuxathena" + ] + }, + { + "groupId": "com.ctre.phoenix.sim", + "artifactId": "cci-sim", + "version": "5.19.4", + "isJar": false, + "skipInvalidPlatforms": true, + "validPlatforms": [ + "windowsx86-64", + "linuxx86-64", + "osxx86-64" + ] + }, + { + "groupId": "com.ctre.phoenix.sim", + "artifactId": "simTalonSRX", + "version": "5.19.4", + "isJar": false, + "skipInvalidPlatforms": true, + "validPlatforms": [ + "windowsx86-64", + "linuxx86-64", + "osxx86-64" + ] + }, + { + "groupId": "com.ctre.phoenix.sim", + "artifactId": "simVictorSPX", + "version": "5.19.4", + "isJar": false, + "skipInvalidPlatforms": true, + "validPlatforms": [ + "windowsx86-64", + "linuxx86-64", + "osxx86-64" + ] + } + ], + "cppDependencies": [ + { + "groupId": "com.ctre.phoenix", + "artifactId": "wpiapi-cpp", + "version": "5.19.4", + "libName": "CTRE_Phoenix_WPI", + "headerClassifier": "headers", + "sharedLibrary": false, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "linuxathena", + "windowsx86-64", + "linuxx86-64", + "osxx86-64" + ] + }, + { + "groupId": "com.ctre.phoenix", + "artifactId": "api-cpp", + "version": "5.19.4", + "libName": "CTRE_Phoenix", + "headerClassifier": "headers", + "sharedLibrary": false, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "linuxathena", + "windowsx86-64", + "linuxx86-64", + "osxx86-64" + ] + }, + { + "groupId": "com.ctre.phoenix", + "artifactId": "cci", + "version": "5.19.4", + "libName": "CTRE_PhoenixCCI", + "headerClassifier": "headers", + "sharedLibrary": false, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "linuxathena" + ] + }, + { + "groupId": "com.ctre.phoenix.sim", + "artifactId": "cci-sim", + "version": "5.19.4", + "libName": "CTRE_PhoenixCCISim", + "headerClassifier": "headers", + "sharedLibrary": false, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "windowsx86-64", + "linuxx86-64", + "osxx86-64" + ] + }, + { + "groupId": "com.ctre.phoenix", + "artifactId": "diagnostics", + "version": "5.19.4", + "libName": "CTRE_PhoenixDiagnostics", + "headerClassifier": "headers", + "sharedLibrary": false, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "linuxathena", + "windowsx86-64", + "linuxx86-64", + "osxx86-64" + ] + }, + { + "groupId": "com.ctre.phoenix", + "artifactId": "canutils", + "version": "5.19.4", + "libName": "CTRE_PhoenixCanutils", + "headerClassifier": "headers", + "sharedLibrary": false, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "windowsx86-64", + "linuxx86-64", + "osxx86-64" + ] + }, + { + "groupId": "com.ctre.phoenix", + "artifactId": "platform-sim", + "version": "5.19.4", + "libName": "CTRE_PhoenixPlatform", + "headerClassifier": "headers", + "sharedLibrary": false, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "windowsx86-64", + "linuxx86-64", + "osxx86-64" + ] + }, + { + "groupId": "com.ctre.phoenix", + "artifactId": "core", + "version": "5.19.4", + "libName": "CTRE_PhoenixCore", + "headerClassifier": "headers", + "sharedLibrary": false, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "linuxathena", + "windowsx86-64", + "linuxx86-64", + "osxx86-64" + ] + }, + { + "groupId": "com.ctre.phoenix.sim", + "artifactId": "simTalonSRX", + "version": "5.19.4", + "libName": "CTRE_SimTalonSRX", + "headerClassifier": "headers", + "sharedLibrary": true, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "windowsx86-64", + "linuxx86-64", + "osxx86-64" + ] + }, + { + "groupId": "com.ctre.phoenix.sim", + "artifactId": "simVictorSPX", + "version": "5.19.4", + "libName": "CTRE_SimVictorSPX", + "headerClassifier": "headers", + "sharedLibrary": true, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "windowsx86-64", + "linuxx86-64", + "osxx86-64" + ] + } + ] +} \ No newline at end of file diff --git a/vendordeps/REV2mDistanceSensor.json b/vendordeps/REV2mDistanceSensor.json new file mode 100644 index 0000000..35a1bf0 --- /dev/null +++ b/vendordeps/REV2mDistanceSensor.json @@ -0,0 +1,55 @@ +{ + "fileName": "REV2mDistanceSensor.json", + "name": "REV2mDistanceSensor", + "version": "0.3.0", + "uuid": "9e352acd-4eec-40f7-8490-3357b5ed65ae", + "mavenUrls": [ + "http://www.revrobotics.com/content/sw/max/sdk/maven/" + ], + "jsonUrl": "http://www.revrobotics.com/content/sw/max/sdk/Rev2mDistanceSensor.json", + "javaDependencies": [ + { + "groupId": "com.revrobotics.frc", + "artifactId": "DistanceSensor-java", + "version": "0.3.0" + } + ], + "jniDependencies": [ + { + "groupId": "com.revrobotics.frc", + "artifactId": "DistanceSensor-driver", + "version": "0.3.0", + "skipInvalidPlatforms": true, + "isJar": false, + "validPlatforms": [ + "linuxathena" + ] + } + ], + "cppDependencies": [ + { + "groupId": "com.revrobotics.frc", + "artifactId": "DistanceSensor-cpp", + "version": "0.3.0", + "libName": "libDistanceSensor", + "headerClassifier": "headers", + "sharedLibrary": true, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "linuxathena" + ] + }, + { + "groupId": "com.revrobotics.frc", + "artifactId": "DistanceSensor-driver", + "version": "0.3.0", + "libName": "libDistanceSensorDriver", + "headerClassifier": "headers", + "sharedLibrary": false, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "linuxathena" + ] + } + ] +} \ No newline at end of file diff --git a/NewDriveTest/vendordeps/REVRobotics.json b/vendordeps/REVRobotics.json similarity index 92% rename from NewDriveTest/vendordeps/REVRobotics.json rename to vendordeps/REVRobotics.json index ca33a31..724da3a 100644 --- a/NewDriveTest/vendordeps/REVRobotics.json +++ b/vendordeps/REVRobotics.json @@ -1,27 +1,8 @@ { - "fileName": "REVRobotics.json", - "name": "REVRobotics", - "version": "1.5.4", - "uuid": "3f48eb8c-50fe-43a6-9cb7-44c86353c4cb", - "mavenUrls": [ - "http://www.revrobotics.com/content/sw/max/sdk/maven/" - ], - "jsonUrl": "http://www.revrobotics.com/content/sw/max/sdk/REVRobotics.json", - "javaDependencies": [ - { - "groupId": "com.revrobotics.frc", - "artifactId": "SparkMax-java", - "version": "1.5.4" - } - ], - "jniDependencies": [ + "cppDependencies": [ { - "groupId": "com.revrobotics.frc", - "artifactId": "SparkMax-driver", - "version": "1.5.4", - "skipInvalidPlatforms": true, - "isJar": false, - "validPlatforms": [ + "artifactId": "SparkMax-cpp", + "binaryPlatforms": [ "windowsx86-64", "windowsx86", "linuxaarch64bionic", @@ -29,18 +10,16 @@ "linuxathena", "linuxraspbian", "osxx86-64" - ] - } - ], - "cppDependencies": [ - { + ], "groupId": "com.revrobotics.frc", - "artifactId": "SparkMax-cpp", - "version": "1.5.4", - "libName": "SparkMax", "headerClassifier": "headers", + "libName": "SparkMax", "sharedLibrary": false, "skipInvalidPlatforms": true, + "version": "1.5.4" + }, + { + "artifactId": "SparkMax-driver", "binaryPlatforms": [ "windowsx86-64", "windowsx86", @@ -49,17 +28,30 @@ "linuxathena", "linuxraspbian", "osxx86-64" - ] - }, - { + ], "groupId": "com.revrobotics.frc", - "artifactId": "SparkMax-driver", - "version": "1.5.4", - "libName": "SparkMaxDriver", "headerClassifier": "headers", + "libName": "SparkMaxDriver", "sharedLibrary": false, "skipInvalidPlatforms": true, - "binaryPlatforms": [ + "version": "1.5.4" + } + ], + "fileName": "REVRobotics.json", + "javaDependencies": [ + { + "artifactId": "SparkMax-java", + "groupId": "com.revrobotics.frc", + "version": "1.5.4" + } + ], + "jniDependencies": [ + { + "artifactId": "SparkMax-driver", + "groupId": "com.revrobotics.frc", + "isJar": false, + "skipInvalidPlatforms": true, + "validPlatforms": [ "windowsx86-64", "windowsx86", "linuxaarch64bionic", @@ -67,7 +59,15 @@ "linuxathena", "linuxraspbian", "osxx86-64" - ] + ], + "version": "1.5.4" } - ] + ], + "jsonUrl": "http://www.revrobotics.com/content/sw/max/sdk/REVRobotics.json", + "mavenUrls": [ + "http://www.revrobotics.com/content/sw/max/sdk/maven/" + ], + "name": "REVRobotics", + "uuid": "3f48eb8c-50fe-43a6-9cb7-44c86353c4cb", + "version": "1.5.4" } \ No newline at end of file diff --git a/NewDriveTest/vendordeps/WPILibNewCommands.json b/vendordeps/WPILibNewCommands.json similarity index 100% rename from NewDriveTest/vendordeps/WPILibNewCommands.json rename to vendordeps/WPILibNewCommands.json diff --git a/vendordeps/navx_frc.json b/vendordeps/navx_frc.json new file mode 100644 index 0000000..dca1d82 --- /dev/null +++ b/vendordeps/navx_frc.json @@ -0,0 +1,35 @@ +{ + "fileName": "navx_frc.json", + "name": "KauaiLabs_navX_FRC", + "version": "3.1.413", + "uuid": "cb311d09-36e9-4143-a032-55bb2b94443b", + "mavenUrls": [ + "https://repo1.maven.org/maven2/" + ], + "jsonUrl": "https://www.kauailabs.com/dist/frc/2020/navx_frc.json", + "javaDependencies": [ + { + "groupId": "com.kauailabs.navx.frc", + "artifactId": "navx-java", + "version": "3.1.413" + } + ], + "jniDependencies": [], + "cppDependencies": [ + { + "groupId": "com.kauailabs.navx.frc", + "artifactId": "navx-cpp", + "version": "3.1.413", + "headerClassifier": "headers", + "sourcesClassifier": "sources", + "sharedLibrary": false, + "libName": "navx_frc", + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "linuxathena", + "linuxraspbian", + "windowsx86-64" + ] + } + ] +} \ No newline at end of file From 2963459e647fbce759c0a7d9de956eca68a9b719 Mon Sep 17 00:00:00 2001 From: DinoHunter696 <55260008+DinoHunter696@users.noreply.github.com> Date: Wed, 29 Sep 2021 14:45:16 -0700 Subject: [PATCH 2/2] Changed to the drive training code --- .vscode/settings.json | 4 +- README.md | 1 - Version and Port Tracking.xlsx | Bin 9757 -> 0 bytes WPILib-License.md | 24 ++ build.gradle | 46 +-- config/checkstyle/checkstyle.xml | 223 ---------- settings.gradle | 2 +- src/main/java/frc/robot/Constants.java | 22 + .../java/{org/team696 => frc}/robot/Main.java | 14 +- src/main/java/frc/robot/Robot.java | 119 ++++++ src/main/java/frc/robot/RobotContainer.java | 44 ++ .../java/frc/robot/subsystems/DriveTrain.java | 56 +++ .../java/org/team696/robot/Constants.java | 229 ---------- src/main/java/org/team696/robot/Robot.java | 202 --------- .../org/team696/robot/RobotContainer.java | 229 ---------- .../org/team696/robot/TrajectoryTable.java | 349 ---------------- .../team696/robot/commands/ATCForCommand.java | 70 ---- .../team696/robot/commands/ATCRevCommand.java | 63 --- .../robot/commands/AutoIndexKickUp.java | 34 -- .../team696/robot/commands/ClimberLift.java | 69 ---- .../team696/robot/commands/ClimberReach.java | 68 --- .../robot/commands/ContinuousShoot.java | 61 --- .../org/team696/robot/commands/Drive.java | 59 --- .../team696/robot/commands/DriveTimer.java | 55 --- .../team696/robot/commands/FireCommand.java | 65 --- .../org/team696/robot/commands/FullShoot.java | 44 -- .../team696/robot/commands/IntakeCommand.java | 53 --- .../robot/commands/IntakeTimerCommand.java | 55 --- .../team696/robot/commands/OmniKickUp.java | 50 --- .../robot/commands/OmniKickUpTimer.java | 61 --- .../robot/commands/ShooterCommand.java | 72 ---- .../robot/commands/ShooterHoodCommand.java | 71 ---- .../robot/commands/ShooterPowerCommand.java | 51 --- .../team696/robot/commands/ShooterPrep.java | 54 --- .../robot/commands/ShooterTimerCommand.java | 60 --- .../team696/robot/commands/SpinToPocket.java | 71 ---- .../robot/commands/SpindexerLoading.java | 57 --- .../team696/robot/commands/StopTurret.java | 47 --- .../team696/robot/commands/TurretLockOn.java | 53 --- .../team696/robot/commands/TurretManual.java | 64 --- .../team696/robot/subsystems/BallSensors.java | 138 ------- .../robot/subsystems/ClimberServos.java | 54 --- .../robot/subsystems/ClimberSubsystem.java | 224 ---------- .../team696/robot/subsystems/Drivetrain.java | 325 --------------- .../org/team696/robot/subsystems/Intake.java | 44 -- .../team696/robot/subsystems/Limelight.java | 163 -------- .../org/team696/robot/subsystems/Shooter.java | 332 --------------- .../team696/robot/subsystems/ShooterHood.java | 70 ---- .../team696/robot/subsystems/Spindexer.java | 391 ------------------ .../robot/subsystems/TurretSubsystem.java | 149 ------- src/main/resources/log4j2.xml | 22 - vendordeps/Phoenix.json | 214 ---------- vendordeps/REV2mDistanceSensor.json | 55 --- vendordeps/REVRobotics.json | 78 ++-- vendordeps/navx_frc.json | 35 -- 55 files changed, 323 insertions(+), 4942 deletions(-) delete mode 100644 README.md delete mode 100644 Version and Port Tracking.xlsx create mode 100644 WPILib-License.md delete mode 100644 config/checkstyle/checkstyle.xml create mode 100644 src/main/java/frc/robot/Constants.java rename src/main/java/{org/team696 => frc}/robot/Main.java (50%) create mode 100644 src/main/java/frc/robot/Robot.java create mode 100644 src/main/java/frc/robot/RobotContainer.java create mode 100644 src/main/java/frc/robot/subsystems/DriveTrain.java delete mode 100644 src/main/java/org/team696/robot/Constants.java delete mode 100644 src/main/java/org/team696/robot/Robot.java delete mode 100644 src/main/java/org/team696/robot/RobotContainer.java delete mode 100644 src/main/java/org/team696/robot/TrajectoryTable.java delete mode 100644 src/main/java/org/team696/robot/commands/ATCForCommand.java delete mode 100644 src/main/java/org/team696/robot/commands/ATCRevCommand.java delete mode 100644 src/main/java/org/team696/robot/commands/AutoIndexKickUp.java delete mode 100644 src/main/java/org/team696/robot/commands/ClimberLift.java delete mode 100644 src/main/java/org/team696/robot/commands/ClimberReach.java delete mode 100644 src/main/java/org/team696/robot/commands/ContinuousShoot.java delete mode 100644 src/main/java/org/team696/robot/commands/Drive.java delete mode 100644 src/main/java/org/team696/robot/commands/DriveTimer.java delete mode 100644 src/main/java/org/team696/robot/commands/FireCommand.java delete mode 100644 src/main/java/org/team696/robot/commands/FullShoot.java delete mode 100644 src/main/java/org/team696/robot/commands/IntakeCommand.java delete mode 100644 src/main/java/org/team696/robot/commands/IntakeTimerCommand.java delete mode 100644 src/main/java/org/team696/robot/commands/OmniKickUp.java delete mode 100644 src/main/java/org/team696/robot/commands/OmniKickUpTimer.java delete mode 100644 src/main/java/org/team696/robot/commands/ShooterCommand.java delete mode 100644 src/main/java/org/team696/robot/commands/ShooterHoodCommand.java delete mode 100644 src/main/java/org/team696/robot/commands/ShooterPowerCommand.java delete mode 100644 src/main/java/org/team696/robot/commands/ShooterPrep.java delete mode 100644 src/main/java/org/team696/robot/commands/ShooterTimerCommand.java delete mode 100644 src/main/java/org/team696/robot/commands/SpinToPocket.java delete mode 100644 src/main/java/org/team696/robot/commands/SpindexerLoading.java delete mode 100644 src/main/java/org/team696/robot/commands/StopTurret.java delete mode 100644 src/main/java/org/team696/robot/commands/TurretLockOn.java delete mode 100644 src/main/java/org/team696/robot/commands/TurretManual.java delete mode 100644 src/main/java/org/team696/robot/subsystems/BallSensors.java delete mode 100644 src/main/java/org/team696/robot/subsystems/ClimberServos.java delete mode 100644 src/main/java/org/team696/robot/subsystems/ClimberSubsystem.java delete mode 100644 src/main/java/org/team696/robot/subsystems/Drivetrain.java delete mode 100644 src/main/java/org/team696/robot/subsystems/Intake.java delete mode 100644 src/main/java/org/team696/robot/subsystems/Limelight.java delete mode 100644 src/main/java/org/team696/robot/subsystems/Shooter.java delete mode 100644 src/main/java/org/team696/robot/subsystems/ShooterHood.java delete mode 100644 src/main/java/org/team696/robot/subsystems/Spindexer.java delete mode 100644 src/main/java/org/team696/robot/subsystems/TurretSubsystem.java delete mode 100644 src/main/resources/log4j2.xml delete mode 100644 vendordeps/Phoenix.json delete mode 100644 vendordeps/REV2mDistanceSensor.json delete mode 100644 vendordeps/navx_frc.json diff --git a/.vscode/settings.json b/.vscode/settings.json index 5200b5c..786b2c7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "java.configuration.updateBuildConfiguration": "automatic", + "java.server.launchMode": "Standard", "files.exclude": { "**/.git": true, "**/.svn": true, @@ -10,6 +11,7 @@ "**/.classpath": true, "**/.project": true, "**/.settings": true, - "**/.factorypath": true + "**/.factorypath": true, + "**/*~": true } } diff --git a/README.md b/README.md deleted file mode 100644 index f5306f1..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# FRC Team 696's code for the 2020 season. diff --git a/Version and Port Tracking.xlsx b/Version and Port Tracking.xlsx deleted file mode 100644 index 8aa5ebc95d96ea53ce1ab76deae9a4a4908f260a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9757 zcmd^F1z40@x29W41cn+K6bT)=TjJ0NN_R7K_s|F`r9*d0cPk(gN{O^E14BrM5<_0_ z-2Wbr|2gMA_kaHX#&g#^vuA(%nZ3Tf-@U%I_Ikgqu8fXBhJu5GgW{g0qmJ@}P+rx& z9k?xAO}%Wv)^2~R+~e|gbjTPn1b6WeVDH}CBz!n;t4DcLhRkS0m4^_{0;Z0CHb9v7 zIdD{o-_{S6&hfnja%T|i-f%2ycGI6}y@nLi_g3AWArs+_Q*AQ4AY{@cv{&BXc@Oxs z4!~DF+*ZW6LlO|%t*4|TCJet%@MWy-#u9yDf^Z4$kfNu~(5rR1eMy{Dzqd_U ztc&ZN=&9(4uNNwlVGVqEM^YIyCxQ%N(P3|b`ri#tsl zx2F}P&qZ+sFQ^XY`ZPNR#*O>t$a+y})w=IC%lP(1R;>F2L!=WwVtnlJxQ%h+hFu8fU?ZDt#aiHd@PjgEq%{+~hV<>YGbW@BmT?#BK7 z=T|7_Ml~4~$=~gHw+&hYM>QmA|EBO3b+ckDsNvDRZ_9W*yi+pT)XLPe8rQ*U> zEKN=R{dncqw9duA`PhnyI99Jv9-5U-3*O8_0Wq3kMPTj5#-8O@Q%@w1ZQ*+rwy!JT zI)fWQE+QSqqDTBl9S;G3@sRbC>4W_*uKd%7byS_p*+|dnGHeTM^i+cc5*7Kc+(btb zWi4&Saf{FP=Dd-sz6Pz}j?6>g${4~CD6tu__i4rZ;H=k}&1<*^COh5qs^?n>F!mxX z|FV(|Kq#wcxK?b0FJ3mfTv3F(VfC`_kXT6Mu@`dVY;!5lee7)FZqVyX4{<>ez$TsX zdu#G(3NW1idE>&Zb-V}@Ac#t|!GZRIl0Y2#7? ze3{!CF{jeipg6@>o%hY^Ns}Xq7w5oOG0ZM^mi6R*g*(~SAiwP_>(OQg$S;vzoJN~v^>mRuBn2=m(n_NgoCI8kO(yd=OWc+qzeK4(z(-CkRs`{v5mJ|av$^!4JK8DIO^#W!K4nX&gfYL$5}C!`Kb^71{%0s=F4v+J2H z8<`8X^F7itUY_f^2JlRZX;&^iWwULMH%vM*?!Ougaa7F!w;H&+TOOX)*S?xg?N3a}UHqpE_Fd zg}$-gtw~Ps4b9zZ|J3lV(MkS*;0?GmuP{?;3FJLZq}V<-a!9?>Q0Q=}H;m#C-I7_< z&XA-lAQzbzG`+9T9zQZgXZRql;lWYhV0eD}XupPPW$dC1K%?RD=?v8+&-uz@lk{KT1aTzq}J`(XJS*TI^qvR@c2 z-$VG$q=7;J;iT?G0Ex~{kp9A>^H;6+6FQYmv%}-b?{NN7$1~O?jUPuYd^c7`Pa!dy zH|6gNjnvqW7D=pmynup!b`^Qs`$~!5n@CkyM=k!SxUa%GX7NV_o=V|}#UB;1tmeFc zynafRcQ*Is6Yr(Qj#_+gD(V+hd1rfHHPIzCcFZE36~PO*Zjz7Sr2>3(uu$lZXHa<% z!Al4D=x?Ebp1`1@5W&j`Sd7K6W)@`X1mF%SILkvor0MbS?@f8ZpsxG$P%MnuU=teR zGIWTKWEBw(7Fwq?JroCnI>dyTxC{f5B3X44CjzZglOBqPp&w#$m$(cQ(kxj;frEwK zX+{qvz(@-*;UzA^f=o+RQR76Qce>I;2{C3vOhk#xupvmvDj*IPMkjC~daTy-uu~ZcYP6TFW z4Ly_`V-{j!KwO3o@sXm)ddmp zkYLbamJ}Q)4bPH>17+Y@GH{^mKced&9Kye<8;OX_+acm=knASGKc%_^^M)Jyz+pbe zPr1e5vB#5i$47L>6u@Hv;IS^S>YsL>f9jxrR>tm$)iabm1t1d%HM3UVB#6n7ss{b@ z83S`_^m_Z>J-lj=#U=qjMCRSl^Z%vQm7{pL zKmyz=0p6GZKT3cLBpyF)RlIs0&zX;JuvGmk#@{)lUIilCB)}Ar`9D}a&fq|nb0FI} zkb@k^IS%9&M>QyErzwPGC<@j^`j1X2)YO`1lOQ6avkFA%iPb%1G6f(I`Ty4_=!w-k z1fK%Xh=iJ3J8u#^&FHKK{r_tufJH`hE;iV{0Ls4~o$k+1f$^>m&dud|3Hd=Ql%#`p zM(5j_#kVe*dtaC7H_%#nsj_o95uC zw3n*#nhyxLr2AU{sx`Wx2{3$;aRn?UuS^G3UkZXk(FiGTZ3-F%hZr-Ct|HWfm;HL2 z40SCS6P%eB)rK&&7(!LU8`Iwq;UlO!&5u~`5hO7?U(B?3Cs>oq8b(*f9NfIdpuBiP zrS@uucdnR_KW9NmuKr=+WUlV&Bm}>oO<`R^*LRm+1E(snXN6A*7BHbu7#rv?$sr-#CE$;3PBj9q1g+~SV?6q0bl*a z1G^WZCQG3s^)_)4q`)@_MURIH?+aXZ7h^FgsCL<7>Q+C#@TPz)hj}-nv-nft(sp|x zl5qCc8{Xm}85$(-EA2!<=@FQWx&z0aR>WjGW%GOkYX2bizbx!SJ71BTAb=^La&0L_tpqyXxQNVYV1?YYgop zRg6VzFp-TV>(ti>r=D-vGF_p2@RtbR{ME|bZ7dxvxxbg+DW*YPeWw{7vJ1>pq8G5q z&p4WMhI+)Ue9i^(;HYj= zt__f(R# z*KGt&>Mt~elEo9vJ(6-HgkZOWRV(hOVJ&Hen3LW4jHTfU&;N|V$wQ@&+p`-pelLsU zu)>dTg>%f77E(qVvUB3Sj`KF`W4nLu@vD)yvZ{)8TGC>pN~^&XB~%l$_0G5tdeWpHUQWcfzzKK4!v@}l=Isaw5t@1Hn!@ML zqYfR_)b6h)?$0OtP9V{}63Q-7uOGE05NgkzD>}EC@UNU1*{_e9n~kZfrG=Ke>orAw z?aw^4XP?gS5T8RXLYIpUa}=}FxJnbsh?8RQJejiRI#Mm@$vg5Jn!oMXr#47uW{WP< zSg)jm0M=?0xBGBom-Uw2iCL0@OWg;@#fxD4wMR@!W#*+;(j0wj+*RL7yb~X9L|tl6 zr}GchXDv?Y+)%J$nuF|rP^Ioq58^wWYQTErNR7fKC;CgmvuX(&+n0_z~A6u@Mipc!!9?Dzoe)r!JpC+ZcK!A=Gk3@&y9Out$)Z zZ%f)0${rUX77{kHVndJ}#y=SpQl?uxJ2{+h;Ey|+Jik7E7T&g;u(d#|gzgERv)OVk zHp~O8gUoaHWmDtv_;ob_UK zNUhcSZm~rA$+|IH_<-6C2~-ks!5YxTO9JGiYX@9EJx8yc^wMvJI{zLqBv5`qX#-`6FWEyCfI2J2A82yCVgw4IZb-e7yt~IiV=-%QS z^1w^u^INRab`>-t@Ni7GkNM-)-16%u>|oWm7l(HP(XVaBRRjjzzjDofn15w6H~!sb z+mgiG=6)S2A_r}Q-T zNA|VoR7J+zi$sx{rqmr87YLhbGfS9>u1G;sD~Zb|jIdI4aHQlcBT9gLC>m3f)vR!q zY_he|<%M;}iwexFe^hbhjOJ3#tPRMwcU7^OXX+1tzRqVV@i7>uK+)Ig1#vamx0X4R zChG}3ac$S+de_bny$SNoMRVVmj%OaIAHfpJMzOV;&n>nv9m-hH_P&W*jUd@Bfu}6^ zQ6kLyz{QWP?x~L19>p$*5+BQ0&#Xxq9MupHhfgW^M29j&OS<*ODwzgPz@9WjK*%<0 zQN{*OhaEa!CZC$w`1wbTLny?bEuU8v?|MTwjS26+`CR3}T?`s43>IJK$XJ+PLZ4I} ziO1c8`>pCWgX(WU-Q&%{-ja~&Jt)%a*FHqoo6K!TM@_OoWrb?e%4d2hQ1nH% zaWjJlm_Q1QGa~U$j|8r|stR^gtpdb#+xj@%)ryH#MnZ zUOEB!;u2vK_(l*xE>_mtYA0AD9**tRIiylm4URtNq((Shz~oGl%A1@GFkwRsL{Pa} zF<7YAY0-S2fCz>TWa|eCNfs^QX~{<%4nc)ac?X2$9~%9>em7brchd zJh!8JZ<6A6Gb9!&^jBuVMEH*-O0okiJX{On|))G+@Nx8SK$ zxD}Y7fQPcb({9DZ7JprdaN*$p@b( zRFiBDX_7ZNXqS(MTnLl<+mbCqeG|h?J8GbF=T9mtJ*vgqhBjc8b^!sGmJfg7&VpqP zyjt5EKG}a>$nd~jLQICWjsvmJeeHJ4=EEajU%8#*zkK^h_3PUInsEGR0pC-O@&pyt zZXV)rwKuePcc|HxAK;9yVKI2%FQdH66x1+Nvrr59OeZ6kn#*oBntYJSw-d1MU3>0M z>laB({Vjpw@esf}u5eFhfAV~6J+oF}fOi zn<2NNvjl2NBtEB2nV!oWdaM0oc@6!9Pas~FnkQ&+&x)cj?O z1)8SZ`0~vc8D{s_3gn}n&u!g7^-fXc=$i8J!u8Ko?~qv= zx1FI~19~aj-h_Jv=ym-6^F#*!3eaEC{ElG3a}~QQ1m)F6M53m95f&Os(djC;Ehu9A zf=hTC!a3ufC-FB2$mP^U+{H5-8b0y{op$$duV-j^lJYvFk&|IFO@wQ7+h4Z%pd{mC zDnG%Pa9$>e+y-BE;U}l|Cq8-nP@#{iP;-&VjQ^(JK%6Y0$9;u;ZMzitSPLsEfS04+ zvo!(qmRnl1c0v)*U0~JzXvMWv$1_5oS7}sz-Vx+X3xSDM9UuGTGa9sHo zM@x583sZMf)HM|HOOzh+8Ou9te64)O_2$c>A(8SWw!`d}S+hg;5397k&bmF$cnD8|>MgBZnGd=Y^qr!;aPCZQkzIW{jamw3ClN zaaxilX9&#UTQqxe1f%$jizIu?{hE|E3C5Vf9ZhghSlsW3is0fZ1MJ8>?0@R|@P4FUc?o+p)_}hxTi@GWsz*;j3Hbt`srQ+JpjmwVio! zT}Z_dCPsn$!b9Pk<(;+6XBKAoydBWVganN!oCqb^idPP6h_X2+-bi93rX9ohE2SVv z{%k>-BZt_wxdZLn198(h0xZglBJw*7xjqQ?Zt2K%B&oA6XKw%$M|nXszd78dQ7A9+ zb*%CNQy~K$)%4<#S)))LHm=YCxE|M1 zm7T5?#xLzbwG%}Rmj=lVNisSm&%kSmS4#E7a z2$bJz`9lurXN5mf2iFwLZ=yl^2ZYSe z-G5Anu1)wislB?q8qd#c!_NwS+#6qKO}_~p#digNmqY!m;m0k`^&a{+(FFXe;XiiN zKX?5xLSFBIev?7!|3LF^JEEUE{}>IfgXnM4Py4;|pM=z(_5A2Yubt&@LIwO?B>B1H wkB;T{9dFZrAHd&y?#~^6H1^*wnmWTDdLeaXOswl+5nO#puY%tJVEdT%j diff --git a/WPILib-License.md b/WPILib-License.md new file mode 100644 index 0000000..3d5a824 --- /dev/null +++ b/WPILib-License.md @@ -0,0 +1,24 @@ +Copyright (c) 2009-2021 FIRST and other WPILib contributors +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of FIRST, WPILib, nor the names of other WPILib + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY FIRST AND OTHER WPILIB CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FIRST OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/build.gradle b/build.gradle index 66739c9..1e9dafc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,20 +1,12 @@ plugins { id "java" id "edu.wpi.first.GradleRIO" version "2021.3.1" - id "maven" -} - -apply plugin: 'checkstyle' - -checkstyle { - toolVersion "8.11" - configFile rootProject.file('config/checkstyle/checkstyle.xml') } sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 -def ROBOT_MAIN_CLASS = "org.team696.robot.Main" +def ROBOT_MAIN_CLASS = "frc.robot.Main" // Define my targets (RoboRIO) and artifacts (deployable files) // This is added by GradleRIO's backing project EmbeddedTools. @@ -62,26 +54,20 @@ dependencies { testImplementation 'junit:junit:4.12' - implementation 'org.team696:TCA9548ADriver:0.3' - implementation 'org.team696:TCS34725Driver:0.4' - implementation 'org.team696:ColorUtils:0.2' - - - compile 'org.apache.logging.log4j:log4j-core:2.13.0' - - compile'org.apache.logging.log4j:log4j-core:2.13.0' - compile 'org.team696:MathUtils:0.3' // Enable simulation gui support. Must check the box in vscode to enable support // upon debugging simulation wpi.deps.sim.gui(wpi.platforms.desktop, false) - simulation wpi.deps.sim.driverstation(wpi.platforms.desktop, false) + simulation wpi.deps.sim.driverstation(wpi.platforms.desktop, false) + + // Websocket extensions require additional configuration. + // simulation wpi.deps.sim.ws_server(wpi.platforms.desktop, false) + // simulation wpi.deps.sim.ws_client(wpi.platforms.desktop, false) } -repositories { - maven{ - url "http://artifactory.696private.org/team696-libs-release-local" - } - //mavenLocal() +// Simulation configuration (e.g. environment variables). +sim { + // Sets the websocket client remote host. + // envVar "HALSIMWS_HOST", "10.0.0.2" } // Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar') @@ -91,15 +77,3 @@ jar { from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } manifest edu.wpi.first.gradlerio.GradleRIOPlugin.javaManifest(ROBOT_MAIN_CLASS) } - -tasks.withType(Checkstyle) { - ignoreFailures = true - exclude '**/com/**' - exclude '**/frc/team696/autonomousCommands/**' - reports { - html.enabled = true - html.destination rootProject.file("build/reports/checkstyle.html") - xml.enabled = true - xml.destination rootProject.file("build/reports/checkstyle-result.xml") - } -} \ No newline at end of file diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml deleted file mode 100644 index e802218..0000000 --- a/config/checkstyle/checkstyle.xml +++ /dev/null @@ -1,223 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/settings.gradle b/settings.gradle index 81f96ab..0bc697a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,7 +4,7 @@ pluginManagement { repositories { mavenLocal() gradlePluginPortal() - String frcYear = '2020' + String frcYear = '2021' File frcHome if (OperatingSystem.current().isWindows()) { String publicFolder = System.getenv('PUBLIC') diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java new file mode 100644 index 0000000..230563b --- /dev/null +++ b/src/main/java/frc/robot/Constants.java @@ -0,0 +1,22 @@ +// 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 frc.robot; + +/** + * The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean + * constants. This class should not be used for any other purpose. All constants should be declared + * globally (i.e. public static). Do not put anything functional in this class. + * + *

It is advised to statically import this class (or one of its inner classes) wherever the + * constants are needed, to reduce verbosity. + */ +public final class Constants { + /** Organizes all the non-changing values we use in the code */ + public static final int leftFrontPort = 10; + public static final int leftBackPort = 11; + public static final int rightFrontPort = 12; + public static final int rightBackPort = 13; + +} diff --git a/src/main/java/org/team696/robot/Main.java b/src/main/java/frc/robot/Main.java similarity index 50% rename from src/main/java/org/team696/robot/Main.java rename to src/main/java/frc/robot/Main.java index a961ae0..8776e5d 100644 --- a/src/main/java/org/team696/robot/Main.java +++ b/src/main/java/frc/robot/Main.java @@ -1,11 +1,8 @@ -/*----------------------------------------------------------------------------*/ -/* 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. */ -/*----------------------------------------------------------------------------*/ +// 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 org.team696.robot; +package frc.robot; import edu.wpi.first.wpilibj.RobotBase; @@ -15,8 +12,7 @@ * call. */ public final class Main { - private Main() { - } + private Main() {} /** * Main initialization function. Do not perform any initialization here. diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java new file mode 100644 index 0000000..885590d --- /dev/null +++ b/src/main/java/frc/robot/Robot.java @@ -0,0 +1,119 @@ +// 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 frc.robot; + +import edu.wpi.first.wpilibj.TimedRobot; +import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.CommandScheduler; +import frc.robot.subsystems.DriveTrain; + +/** + * 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 { + /** You can leave this in if you want, it only changes anything if you are using the autonomous part of the code, + * if you do remove it, just delete any errors it creates */ + private Command m_autonomousCommand; + + /**Creates an object for our DriveTrain class so we can call things from the class + * make sure to include any variables needed for the parameters + */ + public static DriveTrain m_driveTrain = new DriveTrain(Constants.leftFrontPort, Constants.leftBackPort, Constants.rightFrontPort, Constants.rightBackPort); + /** Similar to the previous line, creates a RobotContainer object so we can call things from the robotcontainer class, + * what you name this is up to you */ + private RobotContainer m_robotContainer; + + + /** The values that we will use from the joystick */ + double xAxis; + double yAxis; + /** Values that will go in the parameters that are needed for the RobotDrive method */ + double leftSpeed; + double rightSpeed; + + /** + * This function is run when the robot is first started up and should be used for any + * initialization code. + */ + @Override + public void robotInit() { + // Instantiate our RobotContainer. This will perform all our button bindings, and put our + // autonomous chooser on the dashboard. + m_robotContainer = new RobotContainer(); + } + + /** + * 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. + * + *

This runs after the mode specific periodic functions, but before LiveWindow and + * SmartDashboard integrated updating. + */ + @Override + public void robotPeriodic() { + // Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled + // commands, running already-scheduled commands, removing finished or interrupted commands, + // and running subsystem periodic() methods. This must be called from the robot's periodic + // block in order for anything in the Command-based framework to work. + CommandScheduler.getInstance().run(); + } + + /** This function is called once each time the robot enters Disabled mode. */ + @Override + public void disabledInit() {} + + @Override + public void disabledPeriodic() {} + + /** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */ + @Override + public void autonomousInit() { + + } + + /** This function is called periodically during autonomous. */ + @Override + public void autonomousPeriodic() {} + + @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() { + /** Defining the XAxis and yAxis objects as the x and y values from our joysticks on the controller */ + xAxis = -m_robotContainer.xboxController.getRawAxis(1); + yAxis = m_robotContainer.xboxController.getRawAxis(4); + /** The math required to make the robot turn left and right properly according to the joystick configuration. */ + leftSpeed = yAxis + xAxis; + rightSpeed = yAxis - xAxis; + /** Calling back the robotDrive method from the DriveTrain class so that it runs fifty times a second + * uses the parameters leftSpeed and rightSpeed that we just defined + */ + m_driveTrain.robotDrive(leftSpeed, rightSpeed); + + } + + @Override + public void testInit() { + // Cancels all running commands at the start of test mode. + CommandScheduler.getInstance().cancelAll(); + } + + /** This function is called periodically during test mode. */ + @Override + public void testPeriodic() {} +} diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java new file mode 100644 index 0000000..44489ff --- /dev/null +++ b/src/main/java/frc/robot/RobotContainer.java @@ -0,0 +1,44 @@ +// 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 frc.robot; + +import edu.wpi.first.wpilibj.GenericHID; +import edu.wpi.first.wpilibj.Joystick; +import edu.wpi.first.wpilibj.XboxController; + +import edu.wpi.first.wpilibj2.command.Command; + +/** + * This class is where the bulk of the robot should be declared. Since Command-based is a + * "declarative" paradigm, very little robot logic should actually be handled in the {@link Robot} + * periodic methods (other than the scheduler calls). Instead, the structure of the robot (including + * subsystems, commands, and button mappings) should be declared here. + */ +public class RobotContainer { + // The robot's subsystems and commands are defined here... + /** Declaring and defining our joystick object */ + public static Joystick xboxController = new Joystick(1); + + /** The container for the robot. Contains subsystems, OI devices, and commands. */ + public RobotContainer() { + // Configure the button bindings + configureButtonBindings(); + } + + /** + * Use this method to define your button->command mappings. Buttons can be created by + * instantiating a {@link GenericHID} or one of its subclasses ({@link + * edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a {@link + * edu.wpi.first.wpilibj2.command.button.JoystickButton}. + */ + private void configureButtonBindings() {} + + /** + * Use this to pass the autonomous command to the main {@link Robot} class. + * + * @return the command to run in autonomous + */ + +} diff --git a/src/main/java/frc/robot/subsystems/DriveTrain.java b/src/main/java/frc/robot/subsystems/DriveTrain.java new file mode 100644 index 0000000..ba233bf --- /dev/null +++ b/src/main/java/frc/robot/subsystems/DriveTrain.java @@ -0,0 +1,56 @@ +// 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 frc.robot.subsystems; + +/** YOU DO NOT HAVE TO WORRY ABOUT THIS SECTION, USING TAB WILL ADD ANYTHING NEEDED HERE AUTOMATICALLY */ +import com.revrobotics.CANSparkMax; +import com.revrobotics.CANSparkMaxLowLevel.MotorType; + + +import edu.wpi.first.wpilibj.SpeedControllerGroup; +import edu.wpi.first.wpilibj.drive.DifferentialDrive; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +public class DriveTrain extends SubsystemBase { + /** Creates a new DriveTrain. */ + /** Creates a differential drive which allows the two speed controller groups to work together */ + DifferentialDrive diffDrive; + /**Creates a speed controller group which allows you to run multiple motors with one object */ + SpeedControllerGroup leftSide; + SpeedControllerGroup rightSide; + /**Creates the objects for each motor controller */ + CANSparkMax leftFront; + CANSparkMax leftBack; + CANSparkMax rightFront; + CANSparkMax rightBack; + + + public DriveTrain(int leftFrontPort, int leftBackPort, int rightFrontPort, int rightBackPort) { + /** Defining all the motor controllers with the CANSparkMax(port, motor type) method */ + leftFront = new CANSparkMax(leftFrontPort, MotorType.kBrushless); + leftBack = new CANSparkMax(leftBackPort, MotorType.kBrushless); + rightBack = new CANSparkMax(rightBackPort, MotorType.kBrushless); + rightFront = new CANSparkMax(rightFrontPort, MotorType.kBrushless); + /**Defining the two speed controller groups using the SpeedControllerGroup(motor, motor) method */ + leftSide = new SpeedControllerGroup(leftFront, leftBack); + rightSide = new SpeedControllerGroup(rightFront, rightBack); + + /**Defining the differential drive object using the DifferentialDrive(speedcontrollergroup, speedcontrollergroup) method */ + diffDrive = new DifferentialDrive(leftSide, rightSide); + } + + /**Method we will use to actually control the robot, which need the parameters leftSpeed and rightSpeed, which will be defined in robot */ + public void robotDrive(double leftSpeed, double rightSpeed){ + /** A method tied to the DifferentialDrive object in the Wpilib libraries, basically lets us control the motors in a tank drive fashion */ + diffDrive.tankDrive(leftSpeed, rightSpeed); + /** Creates a minimum required output for the joystick to run the motor */ + diffDrive.setDeadband(0.1); + } + + @Override + public void periodic() { + // This method will be called once per scheduler run (50 times a second) + } +} diff --git a/src/main/java/org/team696/robot/Constants.java b/src/main/java/org/team696/robot/Constants.java deleted file mode 100644 index 4016734..0000000 --- a/src/main/java/org/team696/robot/Constants.java +++ /dev/null @@ -1,229 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* 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 org.team696.robot; - -/** - * The Constants class provides a convenient place for teams to hold robot-wide - * numerical or boolean constants. This class should not be used for any other - * purpose. All constants should be declared globally (i.e. public static). Do - * not put anything functional in this class. - * - *

- * It is advised to statically import this class (or one of its inner classes) - * wherever the constants are needed, to reduce verbosity. - */ -public final class Constants { - public static final int CANtimeout = 10; - - public static final int timeBetweenPockets = 50; - - public static final class SpindexerConstants { - public static final int nPockets = 5; - public static final int MotorCANID = 20; - public static final int EncoderPort = 0; - public static final double P = 0.08; - public static final double closedLoopRampRate = 0.5; - public static final double openLoopRampRate = 0.25; - public static final int RevTBEMinMicroseconds = 1; - public static final int RevTBEMaxMicroseconds = 1024; - // public static final double[] PocketPositions = {0.9335, 0.1398, 0.3431, - // 0.5386, 0.7351}; - // public static final double[] PocketPositions = {0.9689, 0.1689, 0.3689, - // 0.5689, 0.7689}; - public static final double[] PocketPositions = { 0.964, 0.173, 0.375, 0.580, 0.775 }; - public static final double PositionTolerance = 0.005; // Used to calcuate isOnTarget - public static final double VelocityTolerance = 0.01; // used to calculate isMoving - public static final double MotorTurnsPerSpindexerTurn = 62.5; - public static final byte ColorSensorsMuxAddress = 0x70; - public static final byte ColorSensor1MuxChannel = 0; - public static final byte ColorSensor2MuxChannel = 1; - public static final byte ColorSensor3MuxChannel = 2; - public static final byte ColorSensor4MuxChannel = 3; - public static final byte ColorSensor5MuxChannel = 7; - - public static final double HueMax = 1; - public static final double HueMin = 0; - public static final double SatMax = 1; - public static final double SatMin = 0; - public static final double ValueMax = 1; - public static final double ValueMin = 0; - - public static final int KickMotorCANID = 21; - public static final double KickMotorSpeed = 1.; - public static final double KickMotorReverseSpeed = -0.1; - - public static final double loadingDrumPower = 0.22; - public static final double continuousShootDrumPower = 0.55; - public static final double stopDrumPower = 0; - - public static final double timeBetweenIndex = 1; - - public static final double indexingJamDetectionCurrent = 15; - public static final double loadingJamDetectionCurrent = 10; - public static final double antiJamTimeout = 50; - } - - public static final class ShooterConstants { - public static final int leftShooterHoodServo = 2; - public static final int rightShooterHoodServo = 3; - - public static final int leftShooterPort = 42; - public static final boolean leftShooterInverted = false; - public static final boolean leftShooterSensorPhase = false; - public static final int rightShooterPort = 43; - public static final boolean rightShooterInverted = true; - public static final boolean rightShooterSensorPhase = false; - public static final int pidSlot = 0; - public static double shooterkP = 0.6; - public static double shooterkI = 0.0; - public static double shooterkD = 0.0; - public static double shooterkF = 0.06; - public static final int allowableShooterError = 10; - - // TODO: run simple motor characterization routine to deterine feedforward gains - public static final double shooterkSGain = 0; - public static final double shooterkVGain = 0; - public static final double shooterkAGain = 0; - - public static final double shooterHoodAngleMaxLimit = 115; - public static final double shooterHoodAngleMinLimit = 175; - - public static final int acceleratorPort = 41; - public static final double acceleratorPower = 0.3; - public static double acceleratorkP = 0; - public static double acceleratorkI = 0; - public static double acceleratorkD = 0; - public static double acceleratorkF = 0; - public static final int allowableAcceleratorError = 100; - public static final boolean acceleratorInverted = true; - public static final boolean acceleratorSensorPhase = false; - - public static final double shooterGearRatio = 2.5; - - public static final double autoLineTargetRPM = 3900; - public static final double autoLineTargetAngle = 30; - - public static final double trenchRunTargetRPM = 5742.27; - public static final double trenchRunTargetAngle = 18.6; - - } - - public static final class TurretConstants { - public static final int turretMotorPort = 40; - // public static final boolean turret - - public static final boolean turretMotorInverted = false; - public static final boolean turretMotorSensorPhase = true; - - public static final int forwardSoftLimit = -370; - public static final int reverseSoftLimit = -570; - - public static final int turretCenterPos = -540; - - public static final double positionTolerance = 0.6; - - public static final double peakOutput = 0.75; - - public static final double kP = 0.05; - public static final double kI = 0.0; - public static final double kD = 0.001; - } - - - public static final class LimelightConstants { - public static final int camTranPipeline = 1; - public static final int loadingpipeline = 1; - } - - public static final class OperatorConstants { - public static final int operatorPanelPort = 0; - public static final int driverJoystickPort = 1; - - // Driver gamepad mappings - public static final int driveModeButton = 4; - - // Operator panel mappings - public static final int ATCRevButton = 1; - public static final int intakeOnButton = 3; - public static final int intakeOffButton = 4; - public static final int intakeOutButton = 5; - public static final int fitUnderTrenchButton = 6; - public static final int intakeInButton = 6; - public static final int ATCForButton = 7; - public static final int fireButton = 8; - public static final int hoodAutoButton = 9; - public static final int shooterAutoButton = 10; - public static final int colorWheelPositionControl = 11; - public static final int climberUpButton = 12; - public static final int colorWheelDeploy = 13; - public static final int turretAutoButton = 14; - public static final int shooterManualButton = 15; - public static final int spinUpButton = 16; - public static final int climberDownButton = 17; - public static final int colorWheelRotationControl = 18; - public static final int driveAssistButton = 19; - - public static final int shooterManualAxis = 3; - public static final int turretManualAxis = 2; - public static final int hoodManualAxis = 1; - - public static final int ATCRevLED = 0; - public static final int limelightLockLED = 1; - public static final int limelightCaptureLED = 2; - public static final int ATCForLED = 3; - public static final int fireLED = 4; - public static final int realsenseCaptureLED = 5; - public static final int realsenseLockLED = 6; - public static final int carabinerLatchLED = 7; - public static final int climberUpLimLED = 8; - public static final int climberDownLimLED = 9; - public static final int colorWheelDeployLED = 10; - } - - public static final class DrivetrainConstants { - public static final int leftFrontCANID = 10; - public static final int leftRearCANID = 11; - public static final int rightFrontCANID = 12; - public static final int rightRearCANID = 13; - - public static final boolean leftFrontIsInverted = true; - public static final boolean leftRearIsInverted = true; - public static final boolean rightFrontIsInverted = false; - public static final boolean rightRearIsInverted = false; - - public static final double wheelDiameter = 6.; // In inches. Used for calculating speed. - public static final double driveGearboxReduction = (60. / 10.) * (30. / 18.); - - public static final int IMUCalTime = 8; - public static final double yawkP = 1.; - public static final double yawkI = 0.; - public static final double yawkD = 0.; - - public static final double maxSpeed = 184.6; // In in/s - public static final double maxTurnRate = 5; // In degrees/iteration - - public static final int stallCurrentLimit = 80; - public static final int freeCurrentLimit = 80; - public static final int stallThresholdRPM = 1000; - - public static final double openLoopRampRate = 0.5; - - public static final double driveControllerDeadband = 0.05; - - public static final int slowTasksSpeed = 50; - } - - public static final class IntakeConstants { - public static final int IntakeMotorPort = 50; - public static final boolean IntakeInverted = false; - - public static final double intakePower = 0.7; - public static final double outtakePower = -1; - public static final double stopIntakePower = 0; - } -} diff --git a/src/main/java/org/team696/robot/Robot.java b/src/main/java/org/team696/robot/Robot.java deleted file mode 100644 index f869600..0000000 --- a/src/main/java/org/team696/robot/Robot.java +++ /dev/null @@ -1,202 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-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 org.team696.robot; - -import edu.wpi.first.wpilibj.TimedRobot; -import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; -import edu.wpi.first.wpilibj2.command.Command; -import edu.wpi.first.wpilibj2.command.CommandScheduler; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.team696.robot.Constants.OperatorConstants; -import org.team696.robot.subsystems.Limelight; -import org.team696.robot.subsystems.ShooterHood; - - -/** - * 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 { - private static final Logger logger = LogManager.getLogger(Robot.class); - public static RobotContainer m_robotContainer; - public static OperatorConstants m_robotConstants; - private Command m_autonomousCommand; - double last_hood_axis = -69.23; //arbitrary value for initialization later - - // public static double shootAngle; - - - /** - * This function is run when the robot is first started up and should be used for any - * initialization code. - */ - @Override - public void robotInit() { - logger.info("Starting up..."); - m_robotContainer = new RobotContainer(); - m_robotConstants = new OperatorConstants(); - } - - /** - * 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. - * - *

This runs after the mode specific periodic functions, but before - * LiveWindow and SmartDashboard integrated updating. - */ - @Override - public void robotPeriodic() { - // Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled - // commands, running already-scheduled commands, removing finished or interrupted commands, - // and running subsystem periodic() methods. This must be called from the robot's periodic - // block in order for anything in the Command-based framework to work. - CommandScheduler.getInstance().run(); - - RobotContainer.limelight.pipeline(1); - SmartDashboard.putBoolean("isOnTarget", m_robotContainer.turretSubsystem.onTarget()); - SmartDashboard.putNumber("Current RPM", m_robotContainer.shooter.getRPM()); - SmartDashboard.putNumber("Shoot Angle", m_robotContainer.shooterHood.shootAngleToServoAngle(m_robotContainer.shooterHood.servoAngle())); - SmartDashboard.putNumber("Hood Axis", Math.round(m_robotContainer.operatorPanel.getRawAxis(1)*128)); - SmartDashboard.putNumber("Shoot Angle", m_robotContainer.shooterHood.servoAngleToShootAngle(m_robotContainer.shooterHood.servoAngle())); - SmartDashboard.putBoolean("Up to Speed", m_robotContainer.shooter.isUpToSpeed()); - SmartDashboard.putNumber("Spindexer Current", m_robotContainer.spindexer.getCurrent()); - SmartDashboard.putNumber("Hood Angle", m_robotContainer.shooterHood.servoAngle()); - SmartDashboard.putNumber("Accelerator Velocity", m_robotContainer.shooter.getAcceleratorVelocity()); - - - // SmartDashboard.putNumber("spin pos", m_robotContainer.spindexer.getEncoderPosition()); - // SmartDashboard.putNumber("servo angle", m_robotContainer.shooterHood.servoAngle()); - // SmartDashboard.putNumber("Number of Balls", m_robotContainer.spindexer.getNumberOfFilledPockets()); - // SmartDashboard.putNumber("distance", Limelight.distanceFromTarget()); - // SmartDashboard.putNumber("shooter power", m_robotContainer.shooter.getShooterPower()); - // SmartDashboard.putNumber("index", Limelight.indexForDistance()); - // SmartDashboard.putNumber("AUTORPM", m_robotContainer.shooter.getAutoRPM()); - // SmartDashboard.putNumber("AUTOANGLE", m_robotContainer.shooter.getAutoAngle()); - // SmartDashboard.putNumber("SERVOAUTOANGLE", m_robotContainer.shooterHood.shootAngleToServoAngle(m_robotContainer.shooter.getAutoAngle())); - // SmartDashboard.putNumber("AngleDistance", Limelight.angleDistance()); - // SmartDashboard.putNumber("Intake Current", m_robotContainer.intake.intakeCurrent()); - // RobotContainer.limelight.setLights(3); - // SmartDashboard.putNumber("Roll", m_robotContainer.drivetrain.roll()); - - } - - - /** - * This function is called once each time the robot enters Disabled mode. - */ - @Override - public void disabledInit() { - logger.info("Transitioning to disabled."); - m_robotContainer.spindexer.setBrake(false); - // RobotContainer.limelight.setLights(3); - } - - @Override - public void disabledPeriodic() { - Limelight.setLights(1); - } - - /** - * This autonomous runs the autonomous command selected by your {@link RobotContainer} class. - */ - @Override - public void autonomousInit() { - logger.info("Transitioning to autonomous."); - m_robotContainer.spindexer.setBrake(true); - m_autonomousCommand = m_robotContainer.getAutonomousCommand(); - - // schedule the autonomous command (example) - if (m_autonomousCommand != null) { - m_autonomousCommand.schedule(); - } - - } - - /** - * This function is called periodically during autonomous. - */ - @Override - public void autonomousPeriodic() { - - - } - - @Override - public void teleopInit() { - logger.info("Transitioning to teleop."); - m_robotContainer.spindexer.setBrake(true); - // SmartDashboard.putNumber("Target RPM", 3900); - // SmartDashboard.putNumber("Target Angle", 30); - - } - - /** - * This function is called periodically during operator control. - */ - - - @Override - public void teleopPeriodic() { - if(RobotContainer.operatorPanel.getRawButton(OperatorConstants.hoodAutoButton)){ - //Previous comp: m_robotContainer.shooterHood.moveServoAngle(51); - m_robotContainer.shooterHood.moveServoAngle(51); - - - - } - else{ - double hood_axis = -Math.round(m_robotContainer.operatorPanel.getRawAxis(1)*128*1.5); - if (last_hood_axis == -69.23){ - last_hood_axis = hood_axis; - } - double delta = hood_axis - last_hood_axis; - - SmartDashboard.putNumber("Hood Axis", Math.round(m_robotContainer.operatorPanel.getRawAxis(1)*128)); - - if (delta + m_robotContainer.shooterHood.servoAngle() <= 51 && delta + m_robotContainer.shooterHood.servoAngle() >= 10){ - m_robotContainer.shooterHood.moveServoAngle(m_robotContainer.shooterHood.servoAngle()+delta); - - /* - if (m_robotContainer.shooterHood.servoAngle() >= 51 && delta < 0){ - m_robotContainer.shooterHood.moveServoAngle(m_robotContainer.shooterHood.servoAngle()+delta); - } - else if (m_robotContainer.shooterHood.servoAngle() <= 10 && delta > 0){ - m_robotContainer.shooterHood.moveServoAngle(m_robotContainer.shooterHood.servoAngle()+delta); - } - - if (m_robotContainer.shooterHood.servoAngle() < 51 && m_robotContainer.shooterHood.servoAngle() > 10){ - m_robotContainer.shooterHood.moveServoAngle(m_robotContainer.shooterHood.servoAngle()+delta); - } - */ - } - last_hood_axis = hood_axis; - - - } - // } - - - } - - @Override - public void testInit() { - // Cancels all running commands at the start of test mode. - CommandScheduler.getInstance().cancelAll(); - } - - /** - * This function is called periodically during test mode. - */ - @Override - public void testPeriodic() { - } -} diff --git a/src/main/java/org/team696/robot/RobotContainer.java b/src/main/java/org/team696/robot/RobotContainer.java deleted file mode 100644 index 7375cd7..0000000 --- a/src/main/java/org/team696/robot/RobotContainer.java +++ /dev/null @@ -1,229 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* 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 org.team696.robot; - -import edu.wpi.first.wpilibj.GenericHID.Hand; -import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.XboxController; -import edu.wpi.first.wpilibj2.command.Command; -import edu.wpi.first.wpilibj2.command.ParallelCommandGroup; -import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; -import edu.wpi.first.wpilibj2.command.button.JoystickButton; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import org.team696.MathUtils.MathUtils; -import org.team696.robot.Constants.IntakeConstants; -import org.team696.robot.Constants.OperatorConstants; -import org.team696.robot.Constants.SpindexerConstants; -import org.team696.robot.commands.ATCForCommand; -import org.team696.robot.commands.ATCRevCommand; -import org.team696.robot.commands.AutoIndexKickUp; -import org.team696.robot.commands.Drive; -import org.team696.robot.commands.DriveTimer; -import org.team696.robot.commands.FireCommand; -import org.team696.robot.commands.IntakeTimerCommand; -import org.team696.robot.commands.OmniKickUp; -import org.team696.robot.commands.OmniKickUpTimer; -import org.team696.robot.commands.ShooterCommand; -import org.team696.robot.commands.ShooterHoodCommand; -import org.team696.robot.commands.ShooterPowerCommand; -import org.team696.robot.commands.ShooterPrep; -import org.team696.robot.commands.SpinToPocket; -import org.team696.robot.commands.SpindexerLoading; -import org.team696.robot.commands.TurretLockOn; -import org.team696.robot.commands.TurretManual; -import org.team696.robot.subsystems.Drivetrain; -import org.team696.robot.subsystems.Intake; -import org.team696.robot.subsystems.Limelight; -import org.team696.robot.subsystems.Shooter; -import org.team696.robot.subsystems.ShooterHood; -import org.team696.robot.subsystems.Spindexer; -import org.team696.robot.subsystems.TurretSubsystem; - -/** - * This class is where the bulk of the robot should be declared. Since - * Command-based is a "declarative" paradigm, very little robot logic should - * actually be handled in the {@link Robot} periodic methods (other than the - * scheduler calls). Instead, the structure of the robot (including subsystems, - * commands, and button mappings) should be declared here. - */ -public class RobotContainer { - // Subystem declarations - private static final Logger logger = LogManager.getLogger(RobotContainer.class); - public final Drivetrain drivetrain = new Drivetrain(); - public final Spindexer spindexer = new Spindexer(); - public final Shooter shooter = new Shooter(); - public final ShooterHood shooterHood = new ShooterHood(); - public final TurretSubsystem turretSubsystem = new TurretSubsystem(); - public static final Limelight limelight = new Limelight(); - public final Intake intake = new Intake(); - - // Joysticks - public final XboxController driverController = new XboxController(OperatorConstants.driverJoystickPort); - public static final Joystick operatorPanel = new Joystick(OperatorConstants.operatorPanelPort); - - // Buttons - - // make hood/shooter auto/man to change from 2 distances - // make intake in/out be for color wheel height - private final JoystickButton driveMode = new JoystickButton(driverController, OperatorConstants.driveModeButton); - - private final JoystickButton spinUpButton = new JoystickButton(operatorPanel, OperatorConstants.spinUpButton); - private final JoystickButton shooterAutoButton = new JoystickButton(operatorPanel, OperatorConstants.shooterAutoButton); - private final JoystickButton shooterManualButton = new JoystickButton(operatorPanel, OperatorConstants.shooterManualButton); - private final JoystickButton fireButton = new JoystickButton(operatorPanel, OperatorConstants.fireButton); - private final JoystickButton ATCForButton = new JoystickButton(operatorPanel, OperatorConstants.ATCForButton); - private final JoystickButton ATCRevButton = new JoystickButton(operatorPanel, OperatorConstants.ATCRevButton); - - private final JoystickButton turretAutoButton = new JoystickButton(operatorPanel, OperatorConstants.turretAutoButton); - private final JoystickButton hoodAutoButton = new JoystickButton(operatorPanel, OperatorConstants.hoodAutoButton); - - private final JoystickButton intakeOnButton = new JoystickButton(operatorPanel, OperatorConstants.intakeOnButton); - private final JoystickButton intakeOffButton = new JoystickButton(operatorPanel, OperatorConstants.intakeOffButton); - - private final JoystickButton fitUnderTrenchButton = new JoystickButton(operatorPanel, OperatorConstants.fitUnderTrenchButton); - - private final JoystickButton continuousButton = new JoystickButton(operatorPanel, OperatorConstants.colorWheelDeploy); - private final JoystickButton omniReverse = new JoystickButton(operatorPanel, OperatorConstants.colorWheelRotationControl); - private final JoystickButton automaticShootPrep = new JoystickButton(operatorPanel, OperatorConstants.driveAssistButton); - private final JoystickButton automaticIndex = new JoystickButton(operatorPanel, OperatorConstants.colorWheelPositionControl); - - public double getDriveSpeed() { - // Math to correct for nonlinearities in the controller should happen here. - double jsVal = -driverController.getY(Hand.kLeft); - if (jsVal > 0) { - return MathUtils.deadBand(jsVal, Constants.DrivetrainConstants.driveControllerDeadband); - } else { - return -MathUtils.deadBand(-jsVal, Constants.DrivetrainConstants.driveControllerDeadband); - } - } - - public double getDriveTurn() { - // Math to correct for nonlinearities in the controller should happen here. - double jsVal = -driverController.getX(Hand.kRight); - if (jsVal > 0) { - return MathUtils.deadBand(jsVal, Constants.DrivetrainConstants.driveControllerDeadband); - } else { - return -MathUtils.deadBand(-jsVal, Constants.DrivetrainConstants.driveControllerDeadband); - } - } - - public double turretManual() { - return operatorPanel.getRawAxis(1); - } - - public RobotContainer() { - Command driveCommand = new Drive(() -> getDriveSpeed(), () -> getDriveTurn(), drivetrain); - drivetrain.setDefaultCommand(driveCommand); - configureButtonBindings(); - } - - /** - * The container for the robot. Contains subsystems, OI devices, and commands. - */ - private void configureButtonBindings() { - // rpm is 3900 - spinUpButton.whenPressed(new ShooterCommand(shooter, shooter.shootRPM, true)); - spinUpButton.whenReleased(new ShooterPowerCommand(shooter, 0, false)); - - turretAutoButton.whileHeld(new TurretLockOn(turretSubsystem, limelight)); - turretAutoButton.whenReleased(new TurretManual(turretSubsystem, limelight)); - - SpindexerLoading loadingOff = new SpindexerLoading(spindexer, intake, SpindexerConstants.stopDrumPower, IntakeConstants.stopIntakePower); - intakeOnButton.whileHeld( - new SpindexerLoading(spindexer, intake, SpindexerConstants.loadingDrumPower, IntakeConstants.intakePower)); - intakeOnButton.whenReleased(loadingOff); - intakeOffButton.whileHeld( - new SpindexerLoading(spindexer, intake, SpindexerConstants.stopDrumPower, IntakeConstants.outtakePower)); - intakeOffButton.whenReleased(loadingOff); - - // maybe have this button cancel the human player loading sequence - continuousButton.whileHeld(new SpindexerLoading(spindexer, intake, SpindexerConstants.continuousShootDrumPower, - IntakeConstants.stopIntakePower)); - continuousButton.whenReleased(loadingOff); - - automaticShootPrep.whenPressed(new ShooterPrep(shooter, turretSubsystem)); - automaticShootPrep.whenReleased(new ShooterPowerCommand(shooter, 0, false)); - automaticShootPrep.whenReleased(new TurretManual(turretSubsystem, limelight)); - - automaticIndex.whenPressed(new AutoIndexKickUp(spindexer, intake, SpindexerConstants.continuousShootDrumPower, 0)); - automaticIndex.whenReleased(loadingOff); - - fireButton.whenPressed(new FireCommand(shooter, spindexer, SpindexerConstants.KickMotorSpeed)); - fireButton.whenReleased(new FireCommand(shooter, spindexer, SpindexerConstants.stopDrumPower)); - - OmniKickUp reverseOmni = new OmniKickUp(spindexer, SpindexerConstants.KickMotorReverseSpeed); - omniReverse.whenPressed(reverseOmni); - omniReverse.whenReleased(new OmniKickUp(spindexer, SpindexerConstants.stopDrumPower)); - - ATCForCommand ATCfor = new ATCForCommand(spindexer); - ATCRevCommand ATCrev = new ATCRevCommand(spindexer); - - ATCForButton.whenPressed(ATCfor); - ATCForButton.cancelWhenPressed(ATCrev); - - ATCRevButton.whenPressed(ATCrev); - ATCRevButton.cancelWhenPressed(ATCfor); - - intakeOnButton.whenReleased(ATCfor); - - } - - /** - * Use this to pass the autonomous command to the main {@link Robot} class. - * - * @return the command to run in autonomous - */ - @SuppressWarnings("checkstyle:magicnumber") - public Command getAutonomousCommand() { - - return new SequentialCommandGroup( - - new ParallelCommandGroup( - new TurretLockOn(turretSubsystem, limelight), - new ShooterCommand(shooter, 3900, true), - - new SequentialCommandGroup( - new ShooterHoodCommand(shooterHood, 51), - // new IntakeTimerCommand(intake, 50); - new SpinToPocket(spindexer, 1), - new OmniKickUpTimer(spindexer, true, 25), - new SpinToPocket(spindexer, 2), - new OmniKickUpTimer(spindexer, true, 25), - new SpinToPocket(spindexer, 3), - new OmniKickUpTimer(spindexer, true, 25) - ) - ), - - new DriveTimer(drivetrain, -0.5, 0, 50), - new DriveTimer(drivetrain, 0, 0.7, 40), - new DriveTimer(drivetrain, 0.5, 0, 25), - new ParallelCommandGroup( - new DriveTimer(drivetrain, 0.5, 0, 35), - new IntakeTimerCommand(intake, 35) - ) - - - ); - - } - - public boolean getDriveMode() { - return driveMode.get(); - } - - public void setLimelightCaptureLED(boolean state) { - operatorPanel.setOutput(OperatorConstants.limelightCaptureLED, state); - } - - public void setLimelightLockLED(boolean state) { - operatorPanel.setOutput(OperatorConstants.limelightLockLED, state); - } -} diff --git a/src/main/java/org/team696/robot/TrajectoryTable.java b/src/main/java/org/team696/robot/TrajectoryTable.java deleted file mode 100644 index 213a3ca..0000000 --- a/src/main/java/org/team696/robot/TrajectoryTable.java +++ /dev/null @@ -1,349 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* 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 org.team696.robot; - -/** - * Add your docs here. - */ -public class TrajectoryTable { - - /** - * First line is 120 inches away - * First column is angle that ball is shot - * Second column is velcity of the ball in RPM - */ -public static final double[][] TrajectoryTable = { - -{0.0,0.0}, -{51.2,2354.45}, -{51.0,2362.16}, -{50.8,2369.90}, -{50.6,2377.69}, -{50.3,2385.51}, -{50.1,2393.37}, -{49.9,2401.27}, -{49.7,2409.20}, -{49.4,2417.17}, -{49.2,2425.17}, -{49.0,2433.22}, -{48.8,2441.29}, -{48.6,2449.40}, -{48.3,2457.55}, -{48.1,2465.73}, -{47.9,2473.94}, -{47.7,2482.19}, -{47.5,2490.47}, -{47.3,2498.79}, -{47.1,2507.13}, -{46.9,2515.51}, -{46.7,2523.92}, -{46.5,2532.37}, -{46.3,2540.84}, -{46.1,2549.35}, -{45.9,2557.88}, -{45.7,2566.45}, -{45.5,2575.04}, -{45.3,2583.67}, -{45.1,2592.32}, -{44.9,2601.01}, -{44.7,2609.72}, -{44.5,2618.46}, -{44.3,2627.23}, -{44.2,2636.03}, -{44.0,2644.86}, -{43.8,2653.71}, -{43.6,2662.59}, -{43.4,2671.50}, -{43.2,2680.44}, -{43.1,2689.40}, -{42.9,2698.38}, -{42.7,2707.40}, -{42.5,2716.43}, -{42.4,2725.50}, -{42.2,2734.59}, -{42.0,2743.70}, -{41.8,2752.84}, -{41.7,2762.00}, -{41.5,2771.19}, -{41.3,2780.40}, -{41.2,2789.63}, -{41.0,2798.89}, -{40.8,2808.17}, -{40.7,2817.48}, -{40.5,2826.80}, -{40.3,2836.15}, -{40.2,2845.53}, -{40.0,2854.92}, -{39.9,2864.34}, -{39.7,2873.77}, -{39.6,2883.23}, -{39.4,2892.71}, -{39.2,2902.21}, -{39.1,2911.73}, -{38.9,2921.28}, -{38.8,2930.84}, -{38.6,2940.42}, -{38.5,2950.02}, -{38.3,2959.65}, -{38.2,2969.29}, -{38.1,2978.95}, -{37.9,2988.63}, -{37.8,2998.33}, -{37.6,3008.05}, -{37.5,3017.79}, -{37.3,3027.54}, -{37.2,3037.32}, -{37.1,3047.11}, -{36.9,3056.92}, -{36.8,3066.75}, -{36.6,3076.60}, -{36.5,3086.46}, -{36.4,3096.34}, -{36.2,3106.24}, -{36.1,3116.15}, -{36.0,3126.08}, -{35.8,3136.03}, -{35.7,3146.00}, -{35.6,3155.98}, -{35.4,3165.98}, -{35.3,3175.99}, -{35.2,3186.02}, -{35.1,3196.06}, -{34.9,3206.12}, -{34.8,3216.20}, -{34.7,3226.29}, -{34.6,3236.40}, -{34.4,3246.52}, -{34.3,3256.65}, -{34.2,3266.81}, -{34.1,3276.97}, -{34.0,3287.15}, -{33.8,3297.35}, -{33.7,3307.55}, -{33.6,3317.78}, -{33.5,3328.01}, -{33.4,3338.26}, -{33.3,3348.53}, -{33.1,3358.80}, -{33.0,3369.10}, -{32.9,3379.40}, -{32.8,3389.72}, -{32.7,3400.05}, -{32.6,3410.39}, -{32.5,3420.75}, -{32.4,3431.12}, -{32.2,3441.50}, -{32.1,3451.89}, -{32.0,3462.30}, -{31.9,3472.72}, -{31.8,3483.15}, -{31.7,3493.59}, -{31.6,3504.04}, -{31.5,3514.51}, -{31.4,3524.99}, -{31.3,3535.48}, -{31.2,3545.98}, -{31.1,3556.49}, -{31.0,3567.02}, -{30.9,3577.55}, -{30.8,3588.10}, -{30.7,3598.66}, -{30.6,3609.22}, -{30.5,3619.80}, -{30.4,3630.39}, -{30.3,3640.99}, -{30.2,3651.60}, -{30.1,3662.22}, -{30.0,3672.86}, -{29.9,3683.50}, -{29.8,3694.15}, -{29.7,3704.81}, -{29.6,3715.49}, -{29.5,3726.17}, -{29.4,3736.86}, -{29.3,3747.56}, -{29.2,3758.27}, -{29.2,3768.99}, -{29.1,3779.72}, -{29.0,3790.46}, -{28.9,3801.21}, -{28.8,3811.97}, -{28.7,3822.74}, -{28.6,3833.52}, -{28.5,3844.30}, -{28.4,3855.10}, -{28.4,3865.90}, -{28.3,3876.71}, -{28.2,3887.53}, -{28.1,3898.36}, -{28.0,3909.20}, -{27.9,3920.05}, -{27.8,3930.90}, -{27.8,3941.77}, -{27.7,3952.64}, -{27.6,3963.52}, -{27.5,3974.41}, -{27.4,3985.31}, -{27.4,3996.21}, -{27.3,4007.12}, -{27.2,4018.04}, -{27.1,4028.97}, -{27.0,4039.91}, -{27.0,4050.85}, -{26.9,4061.80}, -{26.8,4072.76}, -{26.7,4083.73}, -{26.6,4094.70}, -{26.6,4105.68}, -{26.5,4116.67}, -{26.4,4127.67}, -{26.3,4138.67}, -{26.3,4149.68}, -{26.2,4160.70}, -{26.1,4171.72}, -{26.0,4182.76}, -{26.0,4193.80}, -{25.9,4204.84}, -{25.8,4215.89}, -{25.7,4226.95}, -{25.7,4238.02}, -{25.6,4249.09}, -{25.5,4260.17}, -{25.5,4271.26}, -{25.4,4282.35}, -{25.3,4293.45}, -{25.2,4304.55}, -{25.2,4315.66}, -{25.1,4326.78}, -{25.0,4337.91}, -{25.0,4349.04}, -{24.9,4360.17}, -{24.8,4371.31}, -{24.8,4382.46}, -{24.7,4393.62}, -{24.6,4404.78}, -{24.6,4415.95}, -{24.5,4427.12}, -{24.4,4438.30}, -{24.4,4449.48}, -{24.3,4460.67}, -{24.2,4471.87}, -{24.2,4483.07}, -{24.1,4494.28}, -{24.0,4505.49}, -{24.0,4516.71}, -{23.9,4527.93}, -{23.9,4539.16}, -{23.8,4550.40}, -{23.7,4561.64}, -{23.7,4572.88}, -{23.6,4584.13}, -{23.6,4595.39}, -{23.5,4606.65}, -{23.4,4617.92}, -{23.4,4629.19}, -{23.3,4640.46}, -{23.2,4651.75}, -{23.2,4663.03}, -{23.1,4674.33}, -{23.1,4685.62}, -{23.0,4696.92}, -{23.0,4708.23}, -{22.9,4719.54}, -{22.8,4730.86}, -{22.8,4742.18}, -{22.7,4753.51}, -{22.7,4764.84}, -{22.6,4776.17}, -{22.6,4787.51}, -{22.5,4798.86}, -{22.4,4810.21}, -{22.4,4821.56}, -{22.3,4832.92}, -{22.3,4844.28}, -{22.2,4855.65}, -{22.2,4867.02}, -{22.1,4878.40}, -{22.1,4889.78}, -{22.0,4901.17}, -{21.9,4912.56}, -{21.9,4923.95}, -{21.8,4935.35}, -{21.8,4946.75}, -{21.7,4958.16}, -{21.7,4969.57}, -{21.6,4980.98}, -{21.6,4992.40}, -{21.5,5003.82}, -{21.5,5015.25}, -{21.4,5026.68}, -{21.4,5038.12}, -{21.3,5049.56}, -{21.3,5061.00}, -{21.2,5072.44}, -{21.2,5083.90}, -{21.1,5095.35}, -{21.1,5106.81}, -{21.0,5118.27}, -{21.0,5129.74}, -{20.9,5141.21}, -{20.9,5152.68}, -{20.8,5164.16}, -{20.8,5175.64}, -{20.7,5187.12}, -{20.7,5198.61}, -{20.6,5210.10}, -{20.6,5221.60}, -{20.5,5233.10}, -{20.5,5244.60}, -{20.4,5256.11}, -{20.4,5267.62}, -{20.4,5279.13}, -{20.3,5290.65}, -{20.3,5302.17}, -{20.2,5313.69}, -{20.2,5325.22}, -{20.1,5336.75}, -{20.1,5348.28}, -{20.0,5359.82}, -{20.0,5371.36}, -{19.9,5382.90}, -{19.9,5394.45}, -{19.9,5406.00}, -{19.8,5417.55}, -{19.8,5429.11}, -{19.7,5440.67}, -{19.7,5452.23}, -{19.6,5463.80}, -{19.6,5475.37}, -{19.6,5486.94}, -{19.5,5498.51}, -{19.5,5510.09}, -{19.4,5521.67}, -{19.4,5533.26}, -{19.3,5544.84}, -{19.3,5556.44}, -{19.3,5568.03}, -{19.2,5579.62}, -{19.2,5591.22}, -{19.1,5602.83}, -{19.1,5614.43}, -{19.0,5626.04}, -{19.0,5637.65}, -{19.0,5649.26}, -{18.9,5660.88}, -{18.9,5672.50}, -{18.8,5684.12}, -{18.8,5695.74}, -{18.8,5707.37}, -{18.7,5719.00}, -{18.7,5730.64}, -{18.6,5742.27} -}; - -} \ No newline at end of file diff --git a/src/main/java/org/team696/robot/commands/ATCForCommand.java b/src/main/java/org/team696/robot/commands/ATCForCommand.java deleted file mode 100644 index d7d6ed1..0000000 --- a/src/main/java/org/team696/robot/commands/ATCForCommand.java +++ /dev/null @@ -1,70 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import org.team696.robot.Constants; -import org.team696.robot.subsystems.Spindexer; - -public class ATCForCommand extends CommandBase { - /** - * Creates a new SpinToIndex. - */ - private static final Logger logger = LogManager.getLogger(ATCForCommand.class); - Spindexer spindexer; - - int oldSpindexerPocket = 0; - - public ATCForCommand(Spindexer spindexer) { - this.spindexer = spindexer; - addRequirements(spindexer); - } - - // Called when the command is initially scheduled. - @Override - public void initialize() { - oldSpindexerPocket = spindexer.getTargetPocket(); - int targetPocket; - if (spindexer.getTargetPocket() == Constants.SpindexerConstants.nPockets) { - targetPocket = 1; - } else { - targetPocket = spindexer.getTargetPocket() + 1; - } - logger.info(String.format("Moving spindexer from %d to %d", oldSpindexerPocket, targetPocket)); - spindexer.setTargetPocket(targetPocket); - } - - // Called every time the scheduler runs while the command is scheduled. - @Override - public void execute() { - - - - - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - if(interrupted){ - logger.info("Spindexer command interrupted."); - } else { - logger.info("Spindexer on target."); - } - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return spindexer.isOnTarget(); - } -} diff --git a/src/main/java/org/team696/robot/commands/ATCRevCommand.java b/src/main/java/org/team696/robot/commands/ATCRevCommand.java deleted file mode 100644 index beb0e54..0000000 --- a/src/main/java/org/team696/robot/commands/ATCRevCommand.java +++ /dev/null @@ -1,63 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import org.team696.robot.Constants; -import org.team696.robot.subsystems.Spindexer; - -public class ATCRevCommand extends CommandBase { - private static final Logger logger = LogManager.getLogger(ATCRevCommand.class); - Spindexer spindexer; - int oldSpindexerPocket; - - public ATCRevCommand(Spindexer spindexer) { - this.spindexer = spindexer; - addRequirements(spindexer); - } - - // Called when the command is initially scheduled. - @Override - public void initialize() { - oldSpindexerPocket = spindexer.getTargetPocket(); - int targetPocket; - if (spindexer.getTargetPocket() == 1) { - targetPocket = Constants.SpindexerConstants.nPockets; - } else { - targetPocket = spindexer.getTargetPocket() - 1; - } - logger.info(String.format("Moving spindexer from %d to %d", oldSpindexerPocket, targetPocket)); - spindexer.setTargetPocket(targetPocket); - } - - // Called every time the scheduler runs while the command is scheduled. - @Override - public void execute() { - - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - if(interrupted){ - logger.info("Spindexer command interrupted."); - } else { - logger.info("Spindexer on target."); - } - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return spindexer.isOnTarget(); - } -} diff --git a/src/main/java/org/team696/robot/commands/AutoIndexKickUp.java b/src/main/java/org/team696/robot/commands/AutoIndexKickUp.java deleted file mode 100644 index 9a2f3b2..0000000 --- a/src/main/java/org/team696/robot/commands/AutoIndexKickUp.java +++ /dev/null @@ -1,34 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import org.team696.robot.subsystems.Intake; -import org.team696.robot.subsystems.Spindexer; - -import edu.wpi.first.wpilibj2.command.ParallelCommandGroup; -import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; -import edu.wpi.first.wpilibj2.command.WaitCommand; - -// NOTE: Consider using this command inline, rather than writing a subclass. For more -// information, see: -// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html -public class AutoIndexKickUp extends SequentialCommandGroup { - /** - * Creates a new AutoIndexKickUp. - */ - public AutoIndexKickUp(Spindexer spindexer, Intake intake, double drumPower, double omniPower) { - // Add your commands in the super() call, e.g. - // super(new FooCommand(), new BarCommand()); - super( - // new ATCForCommand(spindexer), - // new OmniKickUp(spindexer, omniPower), - new ContinuousShoot(spindexer, drumPower, true) - - ); - } -} diff --git a/src/main/java/org/team696/robot/commands/ClimberLift.java b/src/main/java/org/team696/robot/commands/ClimberLift.java deleted file mode 100644 index 18d54c8..0000000 --- a/src/main/java/org/team696/robot/commands/ClimberLift.java +++ /dev/null @@ -1,69 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - - -// import org.team696.robot.subsystems.ClimberSubsystem; -// import org.team696.robot.RobotContainer; -// import org.team696.robot.Constants.OperatorConstants; -// import org.team696.robot.subsystems.ClimberServos; - -// import edu.wpi.first.wpilibj2.command.CommandBase; - -// public class ClimberLift extends CommandBase { -// private ClimberSubsystem climberSubsystem; -// private ClimberServos climberServos; -// /** -// * Creates a new ClimberPullUp. -// */ -// public ClimberLift(ClimberSubsystem climberSubsystem, ClimberServos climberServos) { -// this.climberSubsystem = climberSubsystem; -// this.climberServos = climberServos; -// addRequirements(climberSubsystem); -// addRequirements(climberServos); -// } - -// // 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() { -// // servoSubsystem.closeServo(); -// // if (RobotContainer.operatorPanel.getRawButton(OperatorConstants.climberUpButton)){ - -// climberSubsystem.setClimberPower(); -// // System.out.println(climberSubsystem.climberTargetPower); - -// // } -// // else{ -// // climberSubsystem.setClimberPower(0); -// // // System.out.println(climberSubsystem.climberTargetPower); - -// // } - - -// } - - - -// // Called once the command ends or is interrupted. -// @Override -// public void end(boolean interrupted) { -// // servoSubsystem.CloseServo(); - -// } - -// // Returns true when the command should end. -// @Override -// public boolean isFinished() { -// return false; -// } -// } diff --git a/src/main/java/org/team696/robot/commands/ClimberReach.java b/src/main/java/org/team696/robot/commands/ClimberReach.java deleted file mode 100644 index b32183f..0000000 --- a/src/main/java/org/team696/robot/commands/ClimberReach.java +++ /dev/null @@ -1,68 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -// import org.team696.robot.subsystems.ClimberSubsystem; -// import org.team696.robot.RobotContainer; -// import org.team696.robot.Constants.OperatorConstants; -// import org.team696.robot.subsystems.ClimberServos; - -// import edu.wpi.first.wpilibj2.command.CommandBase; - -// public class ClimberReach extends CommandBase { -// private ClimberSubsystem climberSubsystem; -// private ClimberServos servoSubsystem; -// /** -// * Creates a new ClimberPushDown. -// */ - -// boolean servoIsOpen = false; - -// public ClimberReach(ClimberSubsystem climberSubsystem, ClimberServos servoSubsystem) { -// this.climberSubsystem = climberSubsystem; -// this.servoSubsystem = servoSubsystem; -// addRequirements(climberSubsystem); -// addRequirements(servoSubsystem); -// // Use addRequirements() here to declare subsystem dependencies. -// } - -// // 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() { - -// // servoSubsystem.moveClimberServos(180); - -// if (RobotContainer.operatorPanel.getRawButton(OperatorConstants.climberDownButton)){ -// climberSubsystem.setClimberPower(); - -// } -// else{ -// climberSubsystem.setClimberPower(0); -// } - -// } - -// // Called once the command ends or is interrupted. -// @Override -// public void end(boolean interrupted) { -// //ClimberSubsystem.climberState = ClimberStates.AT_HEIGHT; -// } - -// // Returns true when the command should end. -// @Override -// public boolean isFinished() { -// //if sensor trips return tru -// // return climberSubsystem.isLatchedOn(); -// return false; -// } -// } diff --git a/src/main/java/org/team696/robot/commands/ContinuousShoot.java b/src/main/java/org/team696/robot/commands/ContinuousShoot.java deleted file mode 100644 index e131fcd..0000000 --- a/src/main/java/org/team696/robot/commands/ContinuousShoot.java +++ /dev/null @@ -1,61 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import org.team696.robot.subsystems.Spindexer; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -public class ContinuousShoot extends CommandBase { - /** - * Creates a new ContinuousShoot. - */ - Spindexer spindexer; - boolean kickUpState; - double drumSpeed; - int timer; - public ContinuousShoot(Spindexer spindexer, double drumSpeed, boolean kickUpState) { - // Use addRequirements() here to declare subsystem dependencies. - this.spindexer = spindexer; - this.kickUpState = kickUpState; - this.drumSpeed = drumSpeed; - addRequirements(spindexer); - } - - // Called when the command is initially scheduled. - @Override - public void initialize() { - timer = 0; - } - - // Called every time the scheduler runs while the command is scheduled. - @Override - public void execute() { - timer++; - if(timer>6){ - spindexer.spindexerLoadingAntiJam(drumSpeed); - - } - spindexer.setKickMotor(1); - - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - spindexer.setKickMotor(0); - timer = 0; - - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return false; - } -} diff --git a/src/main/java/org/team696/robot/commands/Drive.java b/src/main/java/org/team696/robot/commands/Drive.java deleted file mode 100644 index 8efafb3..0000000 --- a/src/main/java/org/team696/robot/commands/Drive.java +++ /dev/null @@ -1,59 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import java.util.function.DoubleSupplier; - -import org.team696.robot.subsystems.Drivetrain; -import org.team696.robot.subsystems.Shooter; - -public class Drive extends CommandBase { - private final Drivetrain drivetrain; - private final DoubleSupplier speedSupplier; - private final DoubleSupplier turnSupplier; - - /** - * Creates a new Drive. - */ - double currentServoPosition; - - public Drive(DoubleSupplier speed, DoubleSupplier turn, Drivetrain drivetrain) { - this.drivetrain = drivetrain; - this.speedSupplier = speed; - this.turnSupplier = turn; - - addRequirements(drivetrain); - } - - // Called when the command is initially scheduled. - @Override - public void initialize() { - // currentServoPosition = shooter.servoAngle(); - } - - // Called every time the scheduler runs while the command is scheduled. - @Override - public void execute() { - drivetrain.arcadeDrive(speedSupplier.getAsDouble(), turnSupplier.getAsDouble()); - - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - drivetrain.arcadeDrive(0, 0); - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return false; - } -} diff --git a/src/main/java/org/team696/robot/commands/DriveTimer.java b/src/main/java/org/team696/robot/commands/DriveTimer.java deleted file mode 100644 index 705801d..0000000 --- a/src/main/java/org/team696/robot/commands/DriveTimer.java +++ /dev/null @@ -1,55 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import org.team696.robot.subsystems.Drivetrain; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -public class DriveTimer extends CommandBase { - private Drivetrain drivetrain; - /** - * Creates a new DriveTimer. - */ - int timer; - int x = 0; - double speed; - double turn; - public DriveTimer(Drivetrain drivetrain, double speed, double turn, int timer) { - this.drivetrain = drivetrain; - this.timer = timer; - this.speed = speed; - this.turn = turn; - addRequirements(drivetrain); - } - - // 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() { - drivetrain.arcadeDrive(speed, turn); - x++; - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - drivetrain.arcadeDrive(0, 0); - x = 0; - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return x>timer; - } -} diff --git a/src/main/java/org/team696/robot/commands/FireCommand.java b/src/main/java/org/team696/robot/commands/FireCommand.java deleted file mode 100644 index 00e140e..0000000 --- a/src/main/java/org/team696/robot/commands/FireCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import org.team696.robot.subsystems.Shooter; -import org.team696.robot.subsystems.Spindexer; - -public class FireCommand extends CommandBase { - /** - * Creates a new FireCommand. - */ - private Shooter shooter; - private Spindexer spindexer; - private double power; - - public FireCommand(Shooter shooter, Spindexer spindexer, double kickMotorPower) { - - this.shooter = shooter; - this.spindexer = spindexer; - this.power = kickMotorPower; - addRequirements(shooter); - addRequirements(spindexer); - } - - // 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() { - if(shooter.isUpToSpeed()){ - // shooter.setAcceleratorPower(true); - spindexer.setKickMotor(power); - // spindexer.spindexerLoadingAntiJam(0.5, 20); - - - } - else{ - spindexer.setKickMotor(0); - - } - - } - - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return false; - } -} diff --git a/src/main/java/org/team696/robot/commands/FullShoot.java b/src/main/java/org/team696/robot/commands/FullShoot.java deleted file mode 100644 index 1c02161..0000000 --- a/src/main/java/org/team696/robot/commands/FullShoot.java +++ /dev/null @@ -1,44 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import org.team696.robot.subsystems.Limelight; -import org.team696.robot.subsystems.ShooterHood; -import org.team696.robot.subsystems.Spindexer; -import org.team696.robot.subsystems.TurretSubsystem; - -import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; - -// NOTE: Consider using this command inline, rather than writing a subclass. For more -// information, see: -// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html -public class FullShoot extends SequentialCommandGroup { - /** - * Creates a new FullShoot. - */ - public FullShoot(ShooterHood shooterHood, Spindexer spindexer, TurretSubsystem turretSubsystem, Limelight limelight) { - // Add your commands in the super() call, e.g. - // super(new FooCommand(), new BarCommand()); - super( - new ShooterHoodCommand(shooterHood, 51), - new SpinToPocket(spindexer, 1), - new TurretLockOn(turretSubsystem, limelight), - new OmniKickUpTimer(spindexer, true, 50), - new SpinToPocket(spindexer, 2), - new OmniKickUpTimer(spindexer, true, 50), - new SpinToPocket(spindexer, 3), - new OmniKickUpTimer(spindexer, true, 50), - new SpinToPocket(spindexer, 4), - new OmniKickUpTimer(spindexer, true, 50), - new SpinToPocket(spindexer, 5), - new OmniKickUpTimer(spindexer, true, 50), - new ShooterHoodCommand(shooterHood, 10) - - ); - } -} diff --git a/src/main/java/org/team696/robot/commands/IntakeCommand.java b/src/main/java/org/team696/robot/commands/IntakeCommand.java deleted file mode 100644 index c5781c2..0000000 --- a/src/main/java/org/team696/robot/commands/IntakeCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import org.team696.robot.subsystems.Intake; - -public class IntakeCommand extends CommandBase { - /** - * Creates a new IntakeCom - * mand. - */ - private Intake intake; - - private double intakePower; - public IntakeCommand(Intake intake, double intakePower) { - // Use addRequirements() here to declare subsystem dependencies. - - this.intake = intake; - this.intakePower = intakePower; - addRequirements(intake); - } - - // 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() { - intake.runIntake(intakePower); - // spindexer.spindexerLoadingAntiJam(power, current); - // System.out.println("loading"); - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return false; - } -} diff --git a/src/main/java/org/team696/robot/commands/IntakeTimerCommand.java b/src/main/java/org/team696/robot/commands/IntakeTimerCommand.java deleted file mode 100644 index 336c665..0000000 --- a/src/main/java/org/team696/robot/commands/IntakeTimerCommand.java +++ /dev/null @@ -1,55 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import org.team696.robot.subsystems.Intake; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -public class IntakeTimerCommand extends CommandBase { - /** - * Creates a new IntakeTimerCommand. - */ - Intake intake; - int x = 0; - double timer; - public IntakeTimerCommand(Intake intake, double timer) { - // Use addRequirements() here to declare subsystem dependencies. - this.intake = intake; - this.timer = timer; - addRequirements(intake); - } - - // Called when the command is initially scheduled. - @Override - public void initialize() { - x = 0; - - } - - // Called every time the scheduler runs while the command is scheduled. - @Override - public void execute() { - intake.runIntake(0.7); - x++; - // System.out.println(timer); - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - // timer = 0; - intake.runIntake(0); - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return x>timer; - } -} diff --git a/src/main/java/org/team696/robot/commands/OmniKickUp.java b/src/main/java/org/team696/robot/commands/OmniKickUp.java deleted file mode 100644 index 49ed7c8..0000000 --- a/src/main/java/org/team696/robot/commands/OmniKickUp.java +++ /dev/null @@ -1,50 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import org.team696.robot.subsystems.Spindexer; - -public class OmniKickUp extends CommandBase { - /** - * Creates a new OmniKickUp. - */ - Spindexer spindexer; - double power; - public OmniKickUp(Spindexer spindexer, double power) { - // Use addRequirements() here to declare subsystem dependencies. - this.spindexer = spindexer; - this.power = power; - addRequirements(spindexer); - - } - - // 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() { - spindexer.setKickMotor(power); - - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return false; - } -} diff --git a/src/main/java/org/team696/robot/commands/OmniKickUpTimer.java b/src/main/java/org/team696/robot/commands/OmniKickUpTimer.java deleted file mode 100644 index 4d0c7a2..0000000 --- a/src/main/java/org/team696/robot/commands/OmniKickUpTimer.java +++ /dev/null @@ -1,61 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import org.team696.robot.subsystems.Spindexer; - -public class OmniKickUpTimer extends CommandBase { - /** - * Creates a new OmniKickUp. - */ - Spindexer spindexer; - boolean state; - int x = 0; - double timer; - - public OmniKickUpTimer(Spindexer spindexer, boolean state, double timer) { - // Use addRequirements() here to declare subsystem dependencies. - this.spindexer = spindexer; - this.state = state; - - this.timer = timer; - addRequirements(spindexer); - - - } - - // 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() { - spindexer.setKickMotor(1); - System.out.println(x); - x++; - - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - x = 0; - System.out.println("done"); - spindexer.setKickMotor(0); - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return x>timer ; - } -} diff --git a/src/main/java/org/team696/robot/commands/ShooterCommand.java b/src/main/java/org/team696/robot/commands/ShooterCommand.java deleted file mode 100644 index de47a1b..0000000 --- a/src/main/java/org/team696/robot/commands/ShooterCommand.java +++ /dev/null @@ -1,72 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.team696.robot.RobotContainer; -import org.team696.robot.Constants.OperatorConstants; -import org.team696.robot.Constants.ShooterConstants; -import org.team696.robot.subsystems.Shooter; - -public class ShooterCommand extends CommandBase { - /** - * Creates a new ShooterCommand. - */ - private static final Logger logger = LogManager.getLogger(ShooterCommand.class); - private Shooter shooter; - - double RPM; - boolean state; - public ShooterCommand(Shooter shooter, double RPM, boolean state) { - - this.shooter = shooter; - this.state = state; - this.RPM = RPM; - addRequirements(shooter); - } - - // Called when the command is initially scheduled. - @Override - public void initialize() { - logger.info(String.format("Spinning up shooter to %f RPM", RPM)); - } - - // Called every time the scheduler runs while the command is scheduled. - @Override - public void execute() { - // if(RobotContainer.operatorPanel.getRawButton(OperatorConstants.shooterAutoButton)){ - shooter.setShooterVelocity(shooter.shooterRPMToTalonVelocity(shooter.getShootRPM())); - // } - // else if(RobotContainer.operatorPanel.getRawButton(OperatorConstants.shooterManualButton)){ - // // shooter.setShooterVelocity(shooter.shooterRPMToTalonVelocity(RPM+1000*RobotContainer.operatorPanel.getRawAxis(OperatorConstants.shooterManualAxis))); - // shooter.setShooterPower(shooter.shooterRPMToTalonVelocity(ShooterConstants.trenchRunTargetRPM)); - // } - // else{ - // shooter.setShooterPower(0); - // } - - shooter.setAcceleratorPower(state); - - //TODO: make another command to run off of feedforward gains - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - logger.info("Done with shooter command."); - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return false; - } -} diff --git a/src/main/java/org/team696/robot/commands/ShooterHoodCommand.java b/src/main/java/org/team696/robot/commands/ShooterHoodCommand.java deleted file mode 100644 index bc2101c..0000000 --- a/src/main/java/org/team696/robot/commands/ShooterHoodCommand.java +++ /dev/null @@ -1,71 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import org.team696.robot.RobotContainer; -import org.team696.robot.Constants.OperatorConstants; -import org.team696.robot.subsystems.Shooter; -import org.team696.robot.subsystems.ShooterHood; - -public class ShooterHoodCommand extends CommandBase { - /** - * Creates a new ShooterHoodCommand. - */ - private ShooterHood shooterHood; - private double angle; - - private double timer; - public ShooterHoodCommand(ShooterHood shooterHood, double angle) { - - this.shooterHood = shooterHood; - this.angle = angle; - addRequirements(shooterHood); - - } - - // Called when the command is initially scheduled. - @Override - public void initialize() { - timer = 0; - } - - // Called every time the scheduler runs while the command is scheduled. - @Override - public void execute() { - - timer++; - System.out.println("adjusting hood"); - // if(RobotContainer.operatorPanel.getRawButton(OperatorConstants.shooterAutoButton)){ - shooterHood.moveServoAngle(angle); - // } - // else if(RobotContainer.operatorPanel.getRawButton(OperatorConstants.shooterManualButton)){ - // // shooter.setShooterVelocity(shooter.shooterRPMToTalonVelocity(RPM+1000*RobotContainer.operatorPanel.getRawAxis(OperatorConstants.shooterManualAxis))); - // shooterHood.moveServoAngle(shooterHood.shootAngleToServoAngle(18)); - - // } - // else{ - // // shooter.setShooterPower(0); - // shooterHood.moveServoAngle(shooterHood.shootAngleToServoAngle(40)); - - // } - - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return timer>150; - } -} diff --git a/src/main/java/org/team696/robot/commands/ShooterPowerCommand.java b/src/main/java/org/team696/robot/commands/ShooterPowerCommand.java deleted file mode 100644 index 41fc4c5..0000000 --- a/src/main/java/org/team696/robot/commands/ShooterPowerCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import org.team696.robot.subsystems.Shooter; - -public class ShooterPowerCommand extends CommandBase { - /** - * Creates a new ShooterPowerCommand. - */ - private Shooter shooter; - private double power; - private boolean state; - public ShooterPowerCommand(Shooter shooter, double power, boolean state) { - // Use addRequirements() here to declare subsystem dependencies. - this.shooter = shooter; - this.state = state; - this.power = power; - addRequirements(shooter); - } - - // 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() { - shooter.setShooterPower(power); - shooter.setAcceleratorPower(state); - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return false; - } -} diff --git a/src/main/java/org/team696/robot/commands/ShooterPrep.java b/src/main/java/org/team696/robot/commands/ShooterPrep.java deleted file mode 100644 index 333bffd..0000000 --- a/src/main/java/org/team696/robot/commands/ShooterPrep.java +++ /dev/null @@ -1,54 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import org.team696.robot.subsystems.Limelight; -import org.team696.robot.subsystems.Shooter; -import org.team696.robot.subsystems.TurretSubsystem; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -public class ShooterPrep extends CommandBase { - - //maybe add omni to this command or make it part of the spindexer drum one - TurretSubsystem turretSubsystem; - Shooter shooter; - public ShooterPrep(Shooter shooter, TurretSubsystem turretSubsystem) { - this.turretSubsystem = turretSubsystem; - this.shooter = shooter; - addRequirements(shooter); - addRequirements(turretSubsystem); - } - - // 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() { - Limelight.setLights(3); - turretSubsystem.moveToTarget(); - shooter.setShooterVelocity(shooter.shooterRPMToTalonVelocity(shooter.getShootRPM())); - shooter.setAcceleratorPower(true); - //maybe add shooter hood - } - - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return false; - } -} diff --git a/src/main/java/org/team696/robot/commands/ShooterTimerCommand.java b/src/main/java/org/team696/robot/commands/ShooterTimerCommand.java deleted file mode 100644 index 2dea15f..0000000 --- a/src/main/java/org/team696/robot/commands/ShooterTimerCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import org.team696.robot.subsystems.Shooter; - -public class ShooterTimerCommand extends CommandBase { - /** - * Creates a new ShooterCommand. - */ - private Shooter shooter; - - double RPM; - boolean state; - int x = 0; - public ShooterTimerCommand(Shooter shooter, double RPM, boolean state) { - - this.shooter = shooter; - this.state = state; - this.RPM = RPM; - addRequirements(shooter); - } - - // 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() { - shooter.setShooterVelocity(shooter.shooterRPMToTalonVelocity(RPM)); - shooter.setAcceleratorPower(state); - System.out.println("shooting"); - x++; - - //TODO: make another command to run off of feedforward gains - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - x = 0; - shooter.setShooterPower(0); - - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return x>150; - } -} diff --git a/src/main/java/org/team696/robot/commands/SpinToPocket.java b/src/main/java/org/team696/robot/commands/SpinToPocket.java deleted file mode 100644 index 5ff11af..0000000 --- a/src/main/java/org/team696/robot/commands/SpinToPocket.java +++ /dev/null @@ -1,71 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import org.team696.robot.Constants; -import org.team696.robot.subsystems.Spindexer; - -public class SpinToPocket extends CommandBase { - /** - * Creates a new SpinToIndex. - */ - private static final Logger logger = LogManager.getLogger(ATCForCommand.class); - Spindexer spindexer; - - int targetPocket; - - public SpinToPocket(Spindexer spindexer, int targetPocket) { - this.spindexer = spindexer; - this.targetPocket = targetPocket; - addRequirements(spindexer); - } - - // Called when the command is initially scheduled. - @Override - public void initialize() { - // oldSpindexerPocket = spindexer.getTargetPocket(); - // int targetPocket; - // if (spindexer.getTargetPocket() == Constants.SpindexerConstants.nPockets) { - // targetPocket = 1; - // } else { - // targetPocket = spindexer.getTargetPocket() + 1; - // } - // logger.info(String.format("Moving spindexer from %d to %d", oldSpindexerPocket, targetPocket)); - // spindexer.setTargetPocket(targetPocket); - spindexer.setTargetPocket(targetPocket); - } - - // Called every time the scheduler runs while the command is scheduled. - @Override - public void execute() { - //System.out.println("spinning to index stuff"); - //System.out.println(spindexer.getCurrentPocket()); - - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - if(interrupted){ - logger.info("Spindexer command interrupted."); - } else { - logger.info("Spindexer on target."); - } - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return spindexer.getCurrentPocket()==targetPocket; - } -} diff --git a/src/main/java/org/team696/robot/commands/SpindexerLoading.java b/src/main/java/org/team696/robot/commands/SpindexerLoading.java deleted file mode 100644 index bad50e9..0000000 --- a/src/main/java/org/team696/robot/commands/SpindexerLoading.java +++ /dev/null @@ -1,57 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import org.team696.robot.subsystems.Intake; -import org.team696.robot.subsystems.Spindexer; - -public class SpindexerLoading extends CommandBase { - /** - * Creates a new SpindexerLoading. - */ - Spindexer spindexer; - Intake intake; - double spindexerPower; - double intakePower; - public SpindexerLoading(Spindexer spindexer, Intake intake, double spindexerPower, double intakePower) { - // Use addRequirements() here to declare subsystem dependencies. - this.spindexerPower = spindexerPower; - this.intakePower = intakePower; - this.spindexer = spindexer; - this.intake = intake; - addRequirements(spindexer); - addRequirements(intake); - } - - // 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() { - spindexer.spindexerLoadingAntiJam(spindexerPower); - intake.runIntake(intakePower); - // System.out.println("running the loading stuff"); - } - - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return false; - } -} diff --git a/src/main/java/org/team696/robot/commands/StopTurret.java b/src/main/java/org/team696/robot/commands/StopTurret.java deleted file mode 100644 index ef0a34a..0000000 --- a/src/main/java/org/team696/robot/commands/StopTurret.java +++ /dev/null @@ -1,47 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import org.team696.robot.subsystems.TurretSubsystem; - -public class StopTurret extends CommandBase { - /** - * Creates a new StopTurret. - */ - private TurretSubsystem turretSubsystem; - - public StopTurret(TurretSubsystem turretSubsystem) { - // Use addRequirements() here to declare subsystem dependencies. - this.turretSubsystem = turretSubsystem; - addRequirements(turretSubsystem); - } - - // 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() { - turretSubsystem.openLoop(0); - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return false; - } -} diff --git a/src/main/java/org/team696/robot/commands/TurretLockOn.java b/src/main/java/org/team696/robot/commands/TurretLockOn.java deleted file mode 100644 index abd8a31..0000000 --- a/src/main/java/org/team696/robot/commands/TurretLockOn.java +++ /dev/null @@ -1,53 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import org.team696.robot.subsystems.Limelight; -import org.team696.robot.subsystems.TurretSubsystem; - -public class TurretLockOn extends CommandBase { - /** - * Creates a new TurretLockOn. - */ - - TurretSubsystem turretSubsystem; - Limelight limelight; - public TurretLockOn(TurretSubsystem turretSubsystem, Limelight limelight) { - this.turretSubsystem = turretSubsystem; - this.limelight = limelight; - addRequirements(turretSubsystem); - addRequirements(limelight); - } - - // Called when the command is initially scheduled. - @Override - public void initialize() { - limelight.setLights(3); - } - - // Called every time the scheduler runs while the command is scheduled. - @Override - public void execute() { - // turretSubsystem.openLoop(0.05); - turretSubsystem.moveToTarget(); - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - // return turretSubsystem.onTarget(); - return false; - } -} diff --git a/src/main/java/org/team696/robot/commands/TurretManual.java b/src/main/java/org/team696/robot/commands/TurretManual.java deleted file mode 100644 index a9cbf90..0000000 --- a/src/main/java/org/team696/robot/commands/TurretManual.java +++ /dev/null @@ -1,64 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.commands; - -import org.team696.robot.RobotContainer; -import org.team696.robot.Constants.TurretConstants; -import org.team696.robot.subsystems.Limelight; -import org.team696.robot.subsystems.TurretSubsystem; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -public class TurretManual extends CommandBase { - /** - * Creates a new TurretManual. - */ - TurretSubsystem turretSubsystem; - Limelight limelight; - double position; - public TurretManual(TurretSubsystem turretSubsystem, Limelight limelight) { - // Use addRequirements() here to declare subsystem dependencies.\ - this.turretSubsystem = turretSubsystem; - this.limelight = limelight; - this.position = position; - addRequirements(turretSubsystem); - addRequirements(limelight); - } - - // Called when the command is initially scheduled. - @Override - public void initialize() { - // limelight.setLights(1); - } - - // Called every time the scheduler runs while the command is scheduled. - @Override - public void execute() { - // turretSubsystem.moveToPosition(TurretConstants.turretCenterPos+position*100); - // System.out.println("turret manual"); - // System.out.println(position); - if(RobotContainer.operatorPanel.getRawAxis(0)>0.05){ - limelight.setLights(1); - } - else{ - limelight.setLights(1); - } - turretSubsystem.openLoop(-RobotContainer.operatorPanel.getRawAxis(0)); - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return false; - } -} diff --git a/src/main/java/org/team696/robot/subsystems/BallSensors.java b/src/main/java/org/team696/robot/subsystems/BallSensors.java deleted file mode 100644 index 018d21c..0000000 --- a/src/main/java/org/team696/robot/subsystems/BallSensors.java +++ /dev/null @@ -1,138 +0,0 @@ -package org.team696.robot.subsystems; - -import edu.wpi.first.wpilibj.I2C; -import edu.wpi.first.wpilibj.I2C.Port; - -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; - -import org.team696.TCA9548ADriver.TCA9548A; -import org.team696.TCA9548ADriver.TCA9548ADevice; -import org.team696.TCS34725.Gain; -import org.team696.TCS34725.IntegrationTime; -import org.team696.TCS34725.TCS34725; -import org.team696.robot.Constants.SpindexerConstants; -import org.team696.utils.ColorUtils.Color; - -public class BallSensors { - private int num_sensors; - private TCS34725[] sensors; - private static final Logger logger = LogManager.getLogger(TCA9548ADevice.class); - - /** - * Constructor that assumes a mux with the address given in Constants and sensors connected in order. - */ - public BallSensors() { - num_sensors = SpindexerConstants.nPockets; - sensors = new TCS34725[num_sensors]; - byte muxaddr = SpindexerConstants.ColorSensorsMuxAddress; - TCA9548A mux = new TCA9548A(Port.kOnboard, muxaddr); - int i; - for (i = 0; i < num_sensors; i++) { - TCA9548ADevice thisMuxChannel = new TCA9548ADevice(mux, TCS34725.I2C_constants.TCS34725_I2C_ADDR, i); - TCS34725 thisSensor = new TCS34725(thisMuxChannel); - sensors[i] = thisSensor; - } - } - - /** - * Constructor that takes premade I2C channels. - * @param channels I2C channels (should be num_sensors long) - */ - public BallSensors(I2C[] channels) { - num_sensors = SpindexerConstants.nPockets; - sensors = new TCS34725[num_sensors]; - int i; - for (i = 0; i < num_sensors; i++) { - TCS34725 thisSensor = new TCS34725(channels[i]); - sensors[i] = thisSensor; - } - } - - /** - * Constructor that takes a mux and the indices of the mux channels going to the sensors. - * @param mux A TCA9548A mux object - * @param muxChannels The mux channels to use (should be num_sensors long) - */ - public BallSensors(TCA9548A mux, byte[] muxChannels) { - num_sensors = SpindexerConstants.nPockets; - sensors = new TCS34725[num_sensors]; - int i; - for (i = 0; i < num_sensors; i++) { - TCA9548ADevice thisMuxChannel = new TCA9548ADevice(mux, TCS34725.I2C_constants.TCS34725_I2C_ADDR, muxChannels[i]); - TCS34725 thisSensor = new TCS34725(thisMuxChannel); - thisSensor.setName(String.format("Pocket %d", i)); - sensors[i] = thisSensor; - } - } - - /** - * Calls init() on all the sensors. - */ - public void initSensors() { - for (TCS34725 sensor : sensors) { - sensor.init(IntegrationTime.IT_24MS, Gain.X1); - } - } - - - public double[] getColor(int idx){ - double[] retval = new double[3]; - TCS34725 sensor = sensors[idx]; - if(sensor.readColors() == -1){ - sensor.init(IntegrationTime.IT_24MS, Gain.X1); - } - retval[0] = sensor.getRedVal(); - retval[1] = sensor.getGreenVal(); - retval[2] = sensor.getBlueVal(); - return retval; - } - /** - * Gets whether each sensor sees a ball. - * For each sensor, commands a reading, then compares the red, green, - * blue, and clear values to the limits in Constants to see if a ball - * is there. - * @return An array of num_sensors booleans, each indicating if that sensor sees a ball - */ - public boolean[] getResults() { - boolean[] results = new boolean[num_sensors]; - int i; - for (i = 0; i < num_sensors; i++) { - TCS34725 sensor = sensors[i]; - if(sensor.readColors() == -1){ - sensor.init(IntegrationTime.IT_24MS, Gain.X1); - } - //TODO: figure out how to scale colors - double red = sensor.getRedVal(); - double green = sensor.getGreenVal(); - double blue = sensor.getBlueVal(); - Color color = new Color(red, green, blue); - double[] hsv = color.getHSV(); - boolean hasBall = true; - if (hsv[0] < SpindexerConstants.HueMin || hsv[0] > SpindexerConstants.HueMax) { - hasBall = false; - } - if (hsv[1] < SpindexerConstants.SatMin || hsv[1] > SpindexerConstants.SatMax) { - hasBall = false; - } - if (hsv[2] < SpindexerConstants.ValueMin || hsv[2] > SpindexerConstants.ValueMax) { - hasBall = false; - } - results[i] = hasBall; - } - - return results; - } - - public void setLEDs(boolean state){ - int i; - for(i=0; i DrivetrainConstants.slowTasksSpeed){ - iterationCounter = 0; - - //Perform slow tasks - // logger.info(String.format("Left front drive motor temp: %f", leftFrontDrive.getMotorTemperature())); - // logger.info(String.format("Left rear drive motor temp: %f", leftRearDrive.getMotorTemperature())); - // logger.info(String.format("Right front drive motor temp: %f", rightFrontDrive.getMotorTemperature())); - // logger.info(String.format("Right rear drive motor temp: %f", rightRearDrive.getMotorTemperature())); - - } else { - iterationCounter++; - } - - } - - /** - * Drives robot using current mode. - * @param speed Robot speed (-1, 1) - * @param turn Turning-ness, (-1, 1), positive values are counterclockwise - */ - public void arcadeDrive(double speed, double turn){ - switch(mode){ - case OpenLoop: - driveOpenLoop(speed, turn); - break; - case RateCommand: - driveClosedLoop(speed, turn); - break; - default: - return; - } - } - - public double roll(){ - return navX.getPitch(); - } - - /** - * Drives robot in open loop percent-output. - * @param speed Robot speed (-1, 1) - * @param turn Turning-ness, (-1, 1), positive values are counterclockwise - */ - public void driveOpenLoop(double speed, double turn){ - double leftSpeed, rightSpeed; - if(turn > 0){ - turn = turn*turn; - } else{ - turn = -(turn*turn); - } - if(speed > 0){ - speed = speed*speed; - } else{ - speed = -(speed*speed); - } - rightSpeed = speed + turn; - leftSpeed = speed - turn; - - //Scale speeds to stay within range - if(Math.abs(rightSpeed) > 1){ - double multiplier = (1 / Math.abs(rightSpeed)); - rightSpeed *= multiplier; - leftSpeed *= multiplier; - } - if(Math.abs(leftSpeed) > 1){ - double multiplier = (1 / Math.abs(leftSpeed)); - rightSpeed *= multiplier; - leftSpeed *= multiplier; - } - - SmartDashboard.putNumber("Left Commanded Throttle", leftSpeed); - SmartDashboard.putNumber("Right Commanded Throttle", rightSpeed); - leftFrontDrive.set(leftSpeed); - rightFrontDrive.set(rightSpeed); - } - - /** - * Implements closed-loop assisted driving. - * - * @param speed Robot speed (-1, 1) - * @param turn Turning-ness, (-1, 1), positive values are counterclockwise - */ - public void driveClosedLoop(double speed, double turn){ - speed *= DrivetrainConstants.maxSpeed; - turn *= DrivetrainConstants.maxTurnRate; - - targetYaw += turn; - targetYaw = MathUtils.wrapAngle180(targetYaw); - SmartDashboard.putNumber("Target Yaw", targetYaw); - SmartDashboard.putNumber("Target Speed", speed); - - double currentYaw = getRobotYaw(); - double turnOutput = driveAssistPID.calculate(currentYaw, targetYaw); - SmartDashboard.putNumber("Turn PID Output", turnOutput); - double rightSpeed = speed + turnOutput; //In RPM - double leftSpeed = speed - turnOutput; //In RPM - - //Scale speeds to stay within range - if(Math.abs(rightSpeed) > DrivetrainConstants.maxSpeed){ - double multiplier = (DrivetrainConstants.maxSpeed / rightSpeed); - rightSpeed *= multiplier; - leftSpeed *= multiplier; - } - if(Math.abs(leftSpeed) > DrivetrainConstants.maxSpeed){ - double multiplier = (DrivetrainConstants.maxSpeed / leftSpeed); - rightSpeed *= multiplier; - leftSpeed *= multiplier; - } - - SmartDashboard.putNumber("Left Commanded Speed", leftSpeed); - SmartDashboard.putNumber("Right Commanded Speed", rightSpeed); - leftPID.setReference(leftSpeed, ControlType.kVelocity); - rightPID.setReference(rightSpeed, ControlType.kVelocity); - } - - public void setTargetYaw(double yaw){ - targetYaw = yaw; - } - - public double getRobotYaw(){ - //return MathUtils.wrapAngle180(imu.getAngle()); - return 0.0; - } - - // public void calibrateIMU(){ - // imu.configCalTime(DrivetrainConstants.IMUCalTime); - // imu.calibrate(); - // } - - /** - * Gets the speed of a side of the robot. - * @param isRight Set to false for the left side, true for the right side - * @return Speed of the side of the robot in in/s - */ - @SuppressWarnings("checkstyle:MagicNumber") - public double getSpeed(boolean isRight){ - double frontSpeed, rearSpeed; - - if(isRight){ - frontSpeed = rightFrontEncoder.getVelocity(); //in RPM - rearSpeed = rightRearEncoder.getVelocity(); //in RPM - } else{ - frontSpeed = leftFrontEncoder.getVelocity(); //in RPM - rearSpeed = leftRearEncoder.getVelocity(); //in RPM - } - - //TODO: check to make sure front/rear speeds are similar - - double motorSpeedRPM = (frontSpeed + rearSpeed)/2.; - double outputSpeedRPM = motorSpeedRPM / DrivetrainConstants.driveGearboxReduction; //Speed (RPM) of gearbox output shaft - return outputSpeedRPM * (1./60.) * Math.PI * DrivetrainConstants.wheelDiameter; //Convert shaft RPM to in/s - } - - /** - * Gets robot center speed. - * @return Robot speed in in/s - */ - public double getRobotSpeed(){ - double leftSpeed = getSpeed(false); - double rightSpeed = getSpeed(true); - return (leftSpeed + rightSpeed)/2.; - } - - private void configLFSpark(DrivetrainMode mode){ - logger.debug(String.format("Configuring left-front Spark for %s", mode.name())); - leftFrontDrive.restoreFactoryDefaults(); - leftFrontDrive.setInverted(DrivetrainConstants.leftFrontIsInverted); - leftFrontDrive.setSmartCurrentLimit(Constants.DrivetrainConstants.stallCurrentLimit, - Constants.DrivetrainConstants.freeCurrentLimit, - Constants.DrivetrainConstants.stallThresholdRPM); - leftFrontDrive.setOpenLoopRampRate(Constants.DrivetrainConstants.openLoopRampRate); - leftFrontEncoder = leftFrontDrive.getEncoder(); - leftPID = leftFrontDrive.getPIDController(); - } - - private void configLRSpark(DrivetrainMode mode){ - logger.debug(String.format("Configuring left-rear Spark for %s", mode.name())); - leftRearDrive.restoreFactoryDefaults(); - leftRearDrive.setInverted(DrivetrainConstants.leftRearIsInverted); - leftRearDrive.setSmartCurrentLimit(Constants.DrivetrainConstants.stallCurrentLimit, - Constants.DrivetrainConstants.freeCurrentLimit, - Constants.DrivetrainConstants.stallThresholdRPM); - leftRearEncoder = leftRearDrive.getEncoder(); - leftRearDrive.follow(leftFrontDrive); - } - - private void configRFSpark(DrivetrainMode mode){ - logger.debug(String.format("Configuring right-front Spark for %s", mode.name())); - rightFrontDrive.restoreFactoryDefaults(); - rightFrontDrive.setInverted(DrivetrainConstants.rightFrontIsInverted); - rightFrontDrive.setSmartCurrentLimit(Constants.DrivetrainConstants.stallCurrentLimit, - Constants.DrivetrainConstants.freeCurrentLimit, - Constants.DrivetrainConstants.stallThresholdRPM); - rightFrontDrive.setOpenLoopRampRate(Constants.DrivetrainConstants.openLoopRampRate); - rightFrontEncoder = rightFrontDrive.getEncoder(); - rightPID = rightFrontDrive.getPIDController(); - } - private void configRRSpark(DrivetrainMode mode){ - logger.debug(String.format("Configuring right-rear Spark for %s", mode.name())); - rightRearDrive.restoreFactoryDefaults(); - rightRearDrive.setInverted(DrivetrainConstants.rightRearIsInverted); - rightRearDrive.setSmartCurrentLimit(Constants.DrivetrainConstants.stallCurrentLimit, - Constants.DrivetrainConstants.freeCurrentLimit, - Constants.DrivetrainConstants.stallThresholdRPM); - rightRearEncoder = rightRearDrive.getEncoder(); - rightRearDrive.follow(rightFrontDrive); - } -} diff --git a/src/main/java/org/team696/robot/subsystems/Intake.java b/src/main/java/org/team696/robot/subsystems/Intake.java deleted file mode 100644 index 6f275c8..0000000 --- a/src/main/java/org/team696/robot/subsystems/Intake.java +++ /dev/null @@ -1,44 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.subsystems; - -import com.revrobotics.CANSparkMax; -import com.revrobotics.CANSparkMaxLowLevel.MotorType; - -import org.team696.robot.Constants; - -import edu.wpi.first.wpilibj2.command.SubsystemBase; - -public class Intake extends SubsystemBase { - /** - * Creates a new IntakeSubsystem. - */ - private CANSparkMax intakeMotor; - - public Intake() { - intakeMotor = new CANSparkMax(Constants.IntakeConstants.IntakeMotorPort, MotorType.kBrushless); - intakeMotor.restoreFactoryDefaults(); - intakeMotor.setInverted(Constants.IntakeConstants.IntakeInverted); - } - - public void runIntake(double power){ - intakeMotor.set(power); - // System.out.println("intaking"); - } - - - public double intakeCurrent(){ - return intakeMotor.getOutputCurrent(); - } - - - @Override - public void periodic() { - // This method will be called once per scheduler run - } -} diff --git a/src/main/java/org/team696/robot/subsystems/Limelight.java b/src/main/java/org/team696/robot/subsystems/Limelight.java deleted file mode 100644 index 8d976c4..0000000 --- a/src/main/java/org/team696/robot/subsystems/Limelight.java +++ /dev/null @@ -1,163 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.subsystems; - -import org.team696.robot.Constants.LimelightConstants; - -import edu.wpi.first.networktables.NetworkTableEntry; -import edu.wpi.first.networktables.NetworkTableInstance; -import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; -import edu.wpi.first.wpilibj2.command.SubsystemBase; - -public class Limelight extends SubsystemBase { - /** - * Creates a new LimeLightSybsystem. - */ - - - NetworkTableEntry camTran = NetworkTableInstance.getDefault().getTable("limelight").getEntry("camtran"); - - public static double[] camTranArray = {0.0,0.0,0.0,0.0,0.0,0.0}; - - // public double[] camTranArray = new double[6]; - - // public LimelightSubsystem() { - - // } - - // public void camTran() { - // camTranArray = NetworkTableInstance.getDefault().getTable("limelight").getEntry("camtran") - // .getDoubleArray(camTranArray); - // } - - /** - * - * @param lightMode 1 is off, 3 is on - */ - public static void setLights(int lightMode){ - NetworkTableInstance.getDefault().getTable("limelight").getEntry("ledMode").setNumber(lightMode); - - } - - public void updateCamTran(){ - camTranArray = camTran.getDoubleArray(camTranArray); - } - - public boolean is3dModePipelineOn(){ - return (getPipeline()==LimelightConstants.camTranPipeline); - } - - - public static double distanceFromTarget(){ - return camTranArray[2]; - } - - - - public double tx() { - return NetworkTableInstance.getDefault().getTable("limelight").getEntry("tx").getDouble(0); - } - - public static double ty() { - return NetworkTableInstance.getDefault().getTable("limelight").getEntry("ty").getDouble(0); - } - - public double tyradian() { - return Math.toRadians(ty()); - } - - public double tvert() { - return NetworkTableInstance.getDefault().getTable("limelight").getEntry("tvert").getDouble(0); - } - - public double thor() { - return NetworkTableInstance.getDefault().getTable("limelight").getEntry("thor").getDouble(0); - } - - public double tlong() { - return NetworkTableInstance.getDefault().getTable("limelight").getEntry("tlong").getDouble(0); - } - - public double tshort() { - return NetworkTableInstance.getDefault().getTable("limelight").getEntry("tshort").getDouble(0); - } - - public double pixels() { - return thor() * tvert(); - } - - public void pipeline(int x) { - NetworkTableInstance.getDefault().getTable("limelight").getEntry("pipeline").setDouble(x); - } - - public static double getPipeline() { - - return NetworkTableInstance.getDefault().getTable("limelight").getEntry("pipeline").getDouble(0); - } - - public double thorDistance() { - - return 11.6 / (2 * Math.tan(Math.toRadians((0.17 / 2) * thor()))); - } - - public double tvertDistance() { - - return 1.85 / (2 * Math.tan(Math.toRadians((0.17 / 2) * tvert()))); - - } - - public static double angleDistance(){ - return (98.25-24.5)/Math.tan(Math.toRadians(27.5+ty())); - } - - /** - * - * @return 1 if has target, 0 if no target - */ - public static double hasTarget(){ - return NetworkTableInstance.getDefault().getTable("limelight").getEntry("tv").getDouble(0); - - } - - public boolean crosshairOnTarget(){ - if(hasTarget()==1){ - //need to adjust this threshold. maybe can change depending on distance from target - return tx()<1; - } - else{ - return false; - } - } - - /** - * - * @return Returns index of the TrajectoryTable array to look for based on the - * distance the limelight returns. If it returns 0 then it means there - * is no target and the limelight is not configured in 3d Mode. In this - * scenario it selects the first row of the array with an angle of 0 and - * a speed of 0. - * - * May need to adjust the default angle value - */ - public static int indexForDistance() { - // need to add code to prevent out of index of the array - // if statement for if there is a target and we are in 3d mode - if (Math.abs(angleDistance())>119&&Math.abs(angleDistance())<(400)) { - return (int)Math.abs(angleDistance()) - 119; - } else - return 0; - } - - @Override - public void periodic() { - - // pipeline(5); - updateCamTran(); - - } -} \ No newline at end of file diff --git a/src/main/java/org/team696/robot/subsystems/Shooter.java b/src/main/java/org/team696/robot/subsystems/Shooter.java deleted file mode 100644 index 4ba9ddd..0000000 --- a/src/main/java/org/team696/robot/subsystems/Shooter.java +++ /dev/null @@ -1,332 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.subsystems; - -import com.ctre.phoenix.motorcontrol.ControlMode; -import com.ctre.phoenix.motorcontrol.FeedbackDevice; -import com.ctre.phoenix.motorcontrol.NeutralMode; -import com.ctre.phoenix.motorcontrol.TalonFXControlMode; -import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX; -import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX; - -import edu.wpi.first.wpilibj.Servo; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; -import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; -import edu.wpi.first.wpilibj2.command.SubsystemBase; - -import org.team696.robot.Constants; -import org.team696.robot.Robot; -import org.team696.robot.RobotContainer; -import org.team696.robot.TrajectoryTable; -import org.team696.robot.Constants.OperatorConstants; -import org.team696.robot.Constants.ShooterConstants; - -public class Shooter extends SubsystemBase { - /** - * Creates a new ShooterSubsystem. - */ - private WPI_TalonFX leftShooterMotor; - private WPI_TalonFX rightShooterMotor; - - private SimpleMotorFeedforward shooterFeedForward; - - private WPI_TalonSRX shooterAcceleratorMotor; - - public double shootRPM; - - - // private LimelightSubsystem limelightSubsystem = new LimelightSubsystem(); - - public Shooter() { - - leftShooterMotor = new WPI_TalonFX(Constants.ShooterConstants.leftShooterPort); - rightShooterMotor = new WPI_TalonFX(Constants.ShooterConstants.rightShooterPort); - - leftShooterMotor.configFactoryDefault(); - - leftShooterMotor.configSelectedFeedbackSensor(FeedbackDevice.IntegratedSensor, Constants.ShooterConstants.pidSlot, Constants.CANtimeout); - leftShooterMotor.setSensorPhase(Constants.ShooterConstants.leftShooterSensorPhase); - leftShooterMotor.setInverted(Constants.ShooterConstants.leftShooterInverted); - leftShooterMotor.setNeutralMode(NeutralMode.Coast); - leftShooterMotor.configNominalOutputForward(0); - leftShooterMotor.configNominalOutputReverse(0); - leftShooterMotor.configPeakOutputForward(1); - leftShooterMotor.configPeakOutputReverse(-1); - - leftShooterMotor.configAllowableClosedloopError(Constants.ShooterConstants.pidSlot, - Constants.ShooterConstants.allowableShooterError); - - // leftShooterMotor.configContinuousCurrentLimit(amps) - - leftShooterMotor.config_kP(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.shooterkP); - leftShooterMotor.config_kI(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.shooterkI); - leftShooterMotor.config_kD(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.shooterkD); - leftShooterMotor.config_kF(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.shooterkF); - - rightShooterMotor.configFactoryDefault(); - rightShooterMotor.follow(leftShooterMotor); - rightShooterMotor.configSelectedFeedbackSensor(FeedbackDevice.IntegratedSensor, Constants.ShooterConstants.pidSlot, Constants.CANtimeout); - rightShooterMotor.setSensorPhase(Constants.ShooterConstants.rightShooterSensorPhase); - rightShooterMotor.setInverted(Constants.ShooterConstants.rightShooterInverted); - - shooterFeedForward = new SimpleMotorFeedforward(Constants.ShooterConstants.shooterkSGain, - Constants.ShooterConstants.shooterkVGain, Constants.ShooterConstants.shooterkAGain); - - - - shooterAcceleratorMotor = new WPI_TalonSRX(Constants.ShooterConstants.acceleratorPort); - shooterAcceleratorMotor.configFactoryDefault(); - shooterAcceleratorMotor.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Absolute, - Constants.ShooterConstants.pidSlot, Constants.CANtimeout); - shooterAcceleratorMotor.configNominalOutputForward(0); - shooterAcceleratorMotor.configNominalOutputReverse(0); - shooterAcceleratorMotor.configPeakOutputForward(1); - shooterAcceleratorMotor.configPeakOutputReverse(-1); - shooterAcceleratorMotor.setInverted(Constants.ShooterConstants.acceleratorInverted); - shooterAcceleratorMotor.setSensorPhase(Constants.ShooterConstants.acceleratorSensorPhase); - shooterAcceleratorMotor.config_kP(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.acceleratorkP); - shooterAcceleratorMotor.config_kI(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.acceleratorkI); - shooterAcceleratorMotor.config_kD(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.acceleratorkD); - shooterAcceleratorMotor.config_kF(Constants.ShooterConstants.pidSlot, Constants.ShooterConstants.acceleratorkF); - - // shooterHoodServo.dead - - } - - public void setShooterkP(double kP){ - leftShooterMotor.config_kP(0, kP); - } - public void setShooterkI(double kI){ - leftShooterMotor.config_kP(0, kI); - } - public void setShooterkD(double kD){ - leftShooterMotor.config_kP(0, kD); - } - public void setShooterkF(double kF){ - leftShooterMotor.config_kF(0, kF); - } - - - public void setAcceleratorkP(double kP){ - shooterAcceleratorMotor.config_kP(0, kP); - } - public void setAcceleratorkI(double kI){ - shooterAcceleratorMotor.config_kP(0, kI); - } - public void setAcceleratorkD(double kD){ - shooterAcceleratorMotor.config_kP(0, kD); - } - public void setAcceleratorkF(double kF){ - shooterAcceleratorMotor.config_kF(0, kF); - } - - - public void setFeederVelocity(double velocity) { - - shooterAcceleratorMotor.set(ControlMode.Velocity, velocity); - } - - public void setFeederPower(double power) { - shooterAcceleratorMotor.set(ControlMode.PercentOutput, power); - - } - - public double getShooterSetpoint(){ - return leftShooterMotor.getClosedLoopTarget(); - } - - public double getShooterPower(){ - return leftShooterMotor.getMotorOutputPercent(); - } - /** - * Commands shooter in open-loop. - * @param power Shooter power (0-1) - */ - public void setShooterPower(double power) { - - leftShooterMotor.set(ControlMode.PercentOutput, power); - // rightShooterMotor.set(ControlMode.PercentOutput, power); - } - - /** - * Commands accelerator in open-loop. - * @param power Accelerator power (0-1) - */ - public void setAcceleratorPower(double power) { - shooterAcceleratorMotor.set(ControlMode.PercentOutput, power); - // rightShooterMotor.set(ControlMode.PercentOutput, power); - } - - public void setAcceleratorPower(boolean state) { - if(state){ - shooterAcceleratorMotor.set(ControlMode.PercentOutput, 1); - } - else{ - shooterAcceleratorMotor.set(ControlMode.PercentOutput, 0); - } - } - - /** - * Commands shooter velocity in TalonFX native units. - * @param velocity Shooter motor target velocity in encoder units per 100 ms - */ - public void setShooterVelocity(double velocity) { - leftShooterMotor.set(TalonFXControlMode.Velocity, velocity); - } - - /** - * Commands accelerator velocity. - * @param velocity Velocity in Talon SRX native units - */ - public void setAcceleratorVelocity(double velocity){ - shooterAcceleratorMotor.set(ControlMode.Velocity, velocity); - } - - public void runShooterFeedForward(double targetVelocity, double targetAcceleration) { - leftShooterMotor.setVoltage(calculateFeedForwardValue(targetVelocity, targetAcceleration)); - // might use voltage depends which works better - // leftShooterMotor.set(TalonFXControlMode.PercentOutput, calculateFeedForward); - } - - - - - - - - - - - /** - * Computes Talon velocity setpoint from RPM. - * Use this value to feed directly into a shooter velocity control method - * @param RPM Flywheel speed in RPM - * @return Velocity value in TalonFX integrated sensor units per 100 ms. - */ - @SuppressWarnings("checkstyle:magicnumber") - public double shooterRPMToTalonVelocity(double RPM){ - double retval = ((RPM / 600) * (2048 / ShooterConstants.shooterGearRatio)); - return retval; - } - - /** - * Computes flywheel RPM from native units. - * @param velocity Falcon ticks / 100 ms - * @return Flywheel speed in RPM - */ - @SuppressWarnings("checkstyle:magicnumber") - public double talonVelocityToShooterRPM(double velocity){ - double retval = velocity/2048. * 600 * ShooterConstants.shooterGearRatio; - return retval; - } - - /** - * - * @param targetVelocity Tarrget Velocity in the same units of gains in - * FeedForward constructor - * @param targetAcceleration Target Velocity in the same units of gains in - * FeedForward constructor - * @return Value that feedForward calculates to pass into talon's .set() - */ - public double calculateFeedForwardValue(double targetVelocity, double targetAcceleration) { - return shooterFeedForward.calculate(targetVelocity, targetAcceleration); - } - - public double getLeftShooterCurrent() { - return leftShooterMotor.getSupplyCurrent(); - } - - public double getRightShooterCurrent() { - return rightShooterMotor.getSupplyCurrent(); - } - - public double getAcceleratorCurrent() { - return shooterAcceleratorMotor.getSupplyCurrent(); - } - - - /** - * - * @return Left TalonFX Velocity in Encoder Units per 100 ms - */ - public double getLeftShooterVelocity() { - return leftShooterMotor.getSelectedSensorVelocity(); - } - /** - * @return Right TalonFX Velocity in Encoder Units per 100 ms - */ - public double getRightShooterVelocicty() { - return rightShooterMotor.getSelectedSensorVelocity(); - } - - /** - * @return Returns Accelerator/Feeder Velocity in Encoder Units per 100 ms - */ - public double getAcceleratorVelocity() { - return shooterAcceleratorMotor.getSelectedSensorVelocity(); - } - // public double getAcceleratorRPM() { - // return shooterAcceleratorMotor. - // } - - /** - * Gets flywheel velocity - * @return Flywheel velocity in RPM - */ - public double getRPM(){ - return talonVelocityToShooterRPM(getLeftShooterVelocity()); - } - - - // public double getAutoRPM(){ - // return TrajectoryTable.TrajectoryTable[Limelight.indexForDistance()][1]; - // } - - // public double getAutoAngle(){ - - // if(TrajectoryTable.TrajectoryTable[Limelight.indexForDistance()][0]>14&&TrajectoryTable.TrajectoryTable[Limelight.indexForDistance()][0]<53){ - // return TrajectoryTable.TrajectoryTable[Limelight.indexForDistance()][0]; - // } - // else if(TrajectoryTable.TrajectoryTable[Limelight.indexForDistance()][0]<14){ - // return 14; - // } - // else{ - // return 53; - // } - // } - - // public void testShooterRPM(){ - // setShooterVelocity(shooterRPMToTalonVelocity(testtar)); - // } - - public double getShootRPM(){ - if(RobotContainer.operatorPanel.getRawButton(10)){ - return 4350; - } - else{ - return 2800; - } - } - - public boolean isUpToSpeed(){ - if(talonVelocityToShooterRPM(getLeftShooterVelocity())>0.9*getShootRPM()){ - return true; - } - else{ - return false; - } - } - - @Override - public void periodic() { - // This method will be called once per scheduler run - - - -} -} diff --git a/src/main/java/org/team696/robot/subsystems/ShooterHood.java b/src/main/java/org/team696/robot/subsystems/ShooterHood.java deleted file mode 100644 index 8b5054b..0000000 --- a/src/main/java/org/team696/robot/subsystems/ShooterHood.java +++ /dev/null @@ -1,70 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.subsystems; - -import edu.wpi.first.wpilibj.Servo; -import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; -import edu.wpi.first.wpilibj2.command.SubsystemBase; - -public class ShooterHood extends SubsystemBase { - /** - * Creates a new ShooterHood. - */ - - private Servo leftShooterHoodServo; - private Servo rightShooterHoodServo; - - public ShooterHood() { - leftShooterHoodServo = new Servo(2); - rightShooterHoodServo = new Servo(3); - - } - - public void moveServoAngle(double angle) { - // if (shooterHoodServo.getAngle() > Constants.ShooterConstants.shooterHoodAngleMinLimit - // || shooterHoodServo.getAngle() < Constants.ShooterConstants.shooterHoodAngleMaxLimit) { - leftShooterHoodServo.setAngle(angle); - rightShooterHoodServo.setAngle(180-angle);; - // } else { - - // } - - } - - public void moveServoPosition(double position) { - leftShooterHoodServo.setPosition(position); - rightShooterHoodServo.setPosition(1-position); - } - - - /** - * Gets last commanded hood servo angle - * @return servo angle - */ - public double servoAngle(){ - return leftShooterHoodServo.getAngle(); - } - - - public double servoAngleToShootAngle(double servoAngle){ - return -0.65828*(servoAngle)+59.3891; - //70 servo is 14 shoot - //10 servo is 53 shoot - } - - public double shootAngleToServoAngle(double shootAngle){ - return -1.5256*(shootAngle)+90.9203; - } - - @Override - public void periodic() { - // This method will be called once per scheduler run - - double testTargetAngle = SmartDashboard.getNumber("Target Angle", 30); - } -} diff --git a/src/main/java/org/team696/robot/subsystems/Spindexer.java b/src/main/java/org/team696/robot/subsystems/Spindexer.java deleted file mode 100644 index a3669fb..0000000 --- a/src/main/java/org/team696/robot/subsystems/Spindexer.java +++ /dev/null @@ -1,391 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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. */ -/*----------------------------------------------------------------------------*/ - -package org.team696.robot.subsystems; - -import com.revrobotics.CANEncoder; -import com.revrobotics.CANPIDController; -import com.revrobotics.CANSparkMax; -import com.revrobotics.CANSparkMax.IdleMode; -import com.revrobotics.CANSparkMaxLowLevel.MotorType; -import com.revrobotics.ControlType; - -import edu.wpi.first.wpilibj.DigitalInput; -import edu.wpi.first.wpilibj.DutyCycle; -import edu.wpi.first.wpilibj.I2C.Port; -import edu.wpi.first.wpilibj2.command.SubsystemBase; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import org.team696.TCA9548ADriver.TCA9548A; -import org.team696.robot.Constants.SpindexerConstants; -import org.team696.robot.subsystems.BallSensors; - -/** - * Add your docs here. - */ -public class Spindexer extends SubsystemBase { - private static final Logger logger = LogManager.getLogger(Spindexer.class); - - private boolean isMoving; - private int targetPocket = 1; - private boolean isOnTarget; - private static Boolean isJammed = false; - private boolean[] ballOccupancy = new boolean[SpindexerConstants.nPockets]; - - private int forwardTimer; - private int backTimer; - - public enum SpindexerLoadingStates { - FORWARD_TIMER, FORWARD_OK, BACK_TIMER, BACK_OK - } - private SpindexerLoadingStates spindexerStates = SpindexerLoadingStates.FORWARD_TIMER; - - // Stuff related to the driving motor - private final CANSparkMax spindexerMotor = new CANSparkMax(SpindexerConstants.MotorCANID, MotorType.kBrushless); - private final CANPIDController motorPID = spindexerMotor.getPIDController(); - private final CANEncoder motorEncoder = spindexerMotor.getEncoder(); - - // Absolute encoder - private final DigitalInput encoderDI = new DigitalInput(SpindexerConstants.EncoderPort); - private final DutyCycle encoder = new DutyCycle(encoderDI); - - // Ball color sensors - TCA9548A mux = new TCA9548A(Port.kOnboard, SpindexerConstants.ColorSensorsMuxAddress); - private final BallSensors sensors = new BallSensors(mux, - new byte[] { SpindexerConstants.ColorSensor1MuxChannel, SpindexerConstants.ColorSensor2MuxChannel, - SpindexerConstants.ColorSensor3MuxChannel, SpindexerConstants.ColorSensor4MuxChannel, - SpindexerConstants.ColorSensor5MuxChannel }); - - // Kick motor - private final CANSparkMax kickMotor = new CANSparkMax(SpindexerConstants.KickMotorCANID, MotorType.kBrushless); - - public Spindexer() { - spindexerMotor.restoreFactoryDefaults(); - spindexerMotor.setIdleMode(CANSparkMax.IdleMode.kBrake); - spindexerMotor.setClosedLoopRampRate(SpindexerConstants.closedLoopRampRate); - spindexerMotor.setOpenLoopRampRate(SpindexerConstants.openLoopRampRate); - motorPID.setP(SpindexerConstants.P); - sensors.initSensors(); - kickMotor.setIdleMode(IdleMode.kBrake); - } - - public int getTargetPocket() { - return targetPocket; - } - - public boolean isMoving() { - return isMoving; - } - - public boolean isOnTarget() { - return isOnTarget; - } - - /** - * Sets brake mode of spindexer motor. - * @param isBrake True for brake, false for coast - */ - public void setBrake(boolean isBrake){ - if(isBrake){ - spindexerMotor.setIdleMode(IdleMode.kBrake); - } else{ - spindexerMotor.setIdleMode(IdleMode.kCoast); - } - } - - /** - * Safely sets target pocket. - * - * @param pocket Intended target pocket (bounds-checked) - */ - public void setTargetPocket(int pocket) { - if (1 <= pocket && pocket <= SpindexerConstants.nPockets) { - // logger.info(String.format("Setting spindexer target to pocket %d.", pocket)); - targetPocket = pocket; - } - else{ - // logger.error(String.format("Received request to set spindexer target to pocket %d. Ignoring.", pocket)); - } - } - - public double getMotorPosition() { - return motorEncoder.getPosition(); - } - - public double getCurrent() { - return spindexerMotor.getOutputCurrent(); - } - - public double getVelocity() { - return motorEncoder.getVelocity(); - } - - /**Gets ball occupancy array. - * @return Which pockets have balls - */ - public boolean[] getBallOccupancy() { - return ballOccupancy; - } - - @Override - public void periodic() { - // check if jammed - if (getCurrent() > SpindexerConstants.indexingJamDetectionCurrent) { - isJammed = true; - logger.warn("Spindexer jammed!"); - } else { - isJammed = false; - } - - // Check if moving - isMoving = (motorEncoder.getVelocity() > SpindexerConstants.VelocityTolerance); - - // Check if on target - if ((Math.abs(SpindexerConstants.PocketPositions[targetPocket - 1] - - getEncoderPosition()) < SpindexerConstants.PositionTolerance) && !isMoving) { - isOnTarget = true; - // updateBallOccupancy(); - } else { - isOnTarget = false; - - if(isJammed){ - // logger.warn(String.format("Jam while advancing to pocket %d. Reverting to previous pocket.")); - if (getVelocity() > 0) { - if (targetPocket == 1) { - setTargetPocket(5); - } else { - setTargetPocket(targetPocket - 1); - } - } else { - if (targetPocket == 5) { - setTargetPocket(1); - } else { - setTargetPocket(targetPocket + 1); - } - } - } - - motorPID.setReference(getMotorPositionForPocket(targetPocket), ControlType.kPosition); - - } - } - - /** - * Gets the currently-indexed pocket. - * - * @return Current pocket (1-5), or 0 if not on a pocket - */ - public int getCurrentPocket() { - if (isOnTarget) { - return targetPocket; - } else { - // TODO: Need a better way to represent "not at a pocket" - return 0; - } - } - - /** - * Gets the position of the spindexer, based on the absolute encoder. - * - * @return Encoder position on (0, 1) - */ - public double getEncoderPosition() { - double freq = encoder.getFrequency(); - // TODO: Check for invalid frequency (would suggest disconnected encoder) - double ratio = encoder.getOutput(); - @SuppressWarnings("checkstyle:magicnumber") - int highTime = (int) (((1. / freq) * ratio) * 1.e6); // Gets high time of signal in microseconds - // Map microseconds to rotations - return (double) (highTime - SpindexerConstants.RevTBEMinMicroseconds) - / (double) (SpindexerConstants.RevTBEMaxMicroseconds - SpindexerConstants.RevTBEMinMicroseconds); - } - - /** - * Gets the required motor position to get to the given pocket ASAP. - * - * @param pocket The index of the pocket to go to (1, ..., 5) - * @return The required motor position, taking the current motor position into - * account - */ - @SuppressWarnings("checkstyle:magicnumber") - private double getMotorPositionForPocket(int pocket) { - double currentPos = getEncoderPosition(); - double targetPos = SpindexerConstants.PocketPositions[pocket - 1]; - double toGo = computeWrappedDistance(currentPos, targetPos); - if ((0.5 - Math.abs(toGo)) < 0.1) { - toGo = Math.abs(toGo); - } - // System.out.printf("toGo: %f\n", toGo); - return getMotorPosition() + (toGo * SpindexerConstants.MotorTurnsPerSpindexerTurn); - } - - /** - * Helper function to compute shortest wrapped angular distance. - * - * @param from From point, on (0, 1) - * @param to To point, on (0, 1) - * @return Shortest distance, on (-0.5, 0.5) - */ - @SuppressWarnings("checkstyle:magicnumber") - private double computeWrappedDistance(double from, double to) { - // Adapted from https://stackoverflow.com/a/28037434 - double diff = (to - from + 0.5) % 1 - 0.5; - return diff < -0.5 ? diff + 1 : diff; - } - - /** - * Finds the pocket closest to the current position. - * @return Index of closest pocket, in the range (1, SpindexerConstants.nPockets) - */ - public int findNearestPocket(){ - double currentPos = getEncoderPosition(); - int i; - int nearest=0; - double nearestDistance = 1; - for(i=0; i SpindexerConstants.antiJamTimeout) { - forwardTimer = 0; - // logger.info("Transitioning to FORWARD_OK"); - spindexerStates = SpindexerLoadingStates.FORWARD_OK; - } - - break; - - case FORWARD_OK: - spindexerMotor.set(power); - if (getCurrent() > SpindexerConstants.loadingJamDetectionCurrent) { - // logger.info("Jam detected! Transitioning to BACK_TIMER."); - spindexerStates = SpindexerLoadingStates.BACK_TIMER; - } - break; - - case BACK_TIMER: - spindexerMotor.set(-power); - backTimer++; - if (backTimer > SpindexerConstants.antiJamTimeout) { - backTimer = 0; - // logger.info("Transitioning to BACK_OK"); - spindexerStates = SpindexerLoadingStates.BACK_OK; - } - break; - - case BACK_OK: - spindexerMotor.set(-power); - if (getCurrent() > SpindexerConstants.loadingJamDetectionCurrent) { - // logger.info("Jam detected! Transitioning to FORWARD_TIMER."); - spindexerStates = SpindexerLoadingStates.FORWARD_TIMER; - } - break; - - default: - break; - - } - - } - - public void goToNotAPocket() { - motorPID.setReference(0.867, ControlType.kPosition); - } -} diff --git a/src/main/java/org/team696/robot/subsystems/TurretSubsystem.java b/src/main/java/org/team696/robot/subsystems/TurretSubsystem.java deleted file mode 100644 index b667ba0..0000000 --- a/src/main/java/org/team696/robot/subsystems/TurretSubsystem.java +++ /dev/null @@ -1,149 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 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 org.team696.robot.subsystems; - -import com.ctre.phoenix.motorcontrol.ControlMode; -import com.ctre.phoenix.motorcontrol.FeedbackDevice; -import com.ctre.phoenix.motorcontrol.NeutralMode; -import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX; - -import edu.wpi.first.networktables.NetworkTableInstance; -import edu.wpi.first.wpilibj.controller.PIDController; -import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; -import edu.wpi.first.wpilibj2.command.SubsystemBase; - -import org.team696.robot.Constants.TurretConstants; -import org.team696.robot.Robot; - -public class TurretSubsystem extends SubsystemBase { - /** - * Creates a new TurretSubsystem. - */ - private WPI_TalonSRX turretMotor; - private PIDController turretController; - - private double turretSpeed; - - public TurretSubsystem() { - turretMotor = new WPI_TalonSRX(TurretConstants.turretMotorPort); - turretMotor.configFactoryDefault(); - // turretMotor.configSelectedFeedbackSensor(FeedbackDevice.Analog); - turretMotor.setSensorPhase(TurretConstants.turretMotorSensorPhase); - turretMotor.setInverted(TurretConstants.turretMotorInverted); - turretMotor.setNeutralMode(NeutralMode.Brake); - - turretMotor.configNominalOutputForward(0); - turretMotor.configNominalOutputReverse(0); - turretMotor.configPeakOutputForward(TurretConstants.peakOutput); - turretMotor.configPeakOutputReverse(-TurretConstants.peakOutput); - - turretMotor.configForwardSoftLimitThreshold(TurretConstants.forwardSoftLimit); - turretMotor.configReverseSoftLimitThreshold(TurretConstants.reverseSoftLimit); - turretMotor.configForwardSoftLimitEnable(false); - turretMotor.configReverseSoftLimitEnable(false); - - turretController = new PIDController(TurretConstants.kP, TurretConstants.kI, TurretConstants.kD); - - turretController.setTolerance(TurretConstants.positionTolerance); - } - - /** - * Gets tx value from Limelight. - * - * @return - */ - public double getTx() { - return NetworkTableInstance.getDefault().getTable("limelight").getEntry("tx").getDouble(0); - } - - /** - * Runs turret in open-loop. - * - * @param speed Output throttle - */ - public void openLoop(double speed) { - turretMotor.set(ControlMode.PercentOutput, speed); - } - - /** - * Checks if turret is on target. - * - * @return True if on target (position error within tolerance) - */ - public boolean onTarget() { - return (Math.abs(turretController.getPositionError()) < TurretConstants.positionTolerance) && Limelight.hasTarget()==1; - } - - public void moveToTarget() { - turretSpeed = turretController.calculate(getTx(), 0); - turretMotor.set(ControlMode.PercentOutput, turretSpeed); - } - - /** - * @param position moves turret to a set position in talon encoder units - */ - // todo: add some kind of degrees to encoder unit conversion - public void moveToPosition(double position) { - turretMotor.set(ControlMode.Position, position); - } - - /** - * - * @return Gets potentiometer positon based off the talon's analog input mode - */ - // public double getPotPosition() { - // return turretMotor.getSelectedSensorPosition(); - // } - - /** - * - * @return Gets supply current - */ - public double getCurrent() { - return turretMotor.getSupplyCurrent(); - } - - public double getVelocity() { - return turretMotor.getSelectedSensorVelocity(); - } - - public double getRPM() { - return 0; - } - - // public double setpoint() { - // return turretController.getSetpoint(); - // } - - // public double getError() { - // return turretController.getPositionError(); - // } - - // public void resetEncoder() { - // turretMotor.setSelectedSensorPosition(0); - // } - - // public double encoderToDegrees(double encoder) { - // return encoder / 1.1366666666666666666 - 581 + 130; - // } - - public void setPIDSlot(int slot) { - turretMotor.selectProfileSlot(slot, 0); - } - - @Override - public void periodic() { - // This method will be called once per scheduler run - // SmartDashboard.putNumber("degrees", encoderToDegrees(getPotPosition())); - // SmartDashboard.putNumber("pot position", getPotPosition()); - SmartDashboard.putNumber("tx", getTx()); - Robot.m_robotContainer.setLimelightCaptureLED((Limelight.hasTarget()==1)); - Robot.m_robotContainer.setLimelightLockLED(Math.abs(turretController.getPositionError()) < TurretConstants.positionTolerance); - - } -} diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml deleted file mode 100644 index d3254bf..0000000 --- a/src/main/resources/log4j2.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - %d [%t] %p %c - %m%n - - - - - - - - - - - - - \ No newline at end of file diff --git a/vendordeps/Phoenix.json b/vendordeps/Phoenix.json deleted file mode 100644 index 87f03cb..0000000 --- a/vendordeps/Phoenix.json +++ /dev/null @@ -1,214 +0,0 @@ -{ - "fileName": "Phoenix.json", - "name": "CTRE-Phoenix", - "version": "5.19.4", - "uuid": "ab676553-b602-441f-a38d-f1296eff6537", - "mavenUrls": [ - "https://devsite.ctr-electronics.com/maven/release/" - ], - "jsonUrl": "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/Phoenix-latest.json", - "javaDependencies": [ - { - "groupId": "com.ctre.phoenix", - "artifactId": "api-java", - "version": "5.19.4" - }, - { - "groupId": "com.ctre.phoenix", - "artifactId": "wpiapi-java", - "version": "5.19.4" - } - ], - "jniDependencies": [ - { - "groupId": "com.ctre.phoenix", - "artifactId": "cci", - "version": "5.19.4", - "isJar": false, - "skipInvalidPlatforms": true, - "validPlatforms": [ - "linuxathena" - ] - }, - { - "groupId": "com.ctre.phoenix.sim", - "artifactId": "cci-sim", - "version": "5.19.4", - "isJar": false, - "skipInvalidPlatforms": true, - "validPlatforms": [ - "windowsx86-64", - "linuxx86-64", - "osxx86-64" - ] - }, - { - "groupId": "com.ctre.phoenix.sim", - "artifactId": "simTalonSRX", - "version": "5.19.4", - "isJar": false, - "skipInvalidPlatforms": true, - "validPlatforms": [ - "windowsx86-64", - "linuxx86-64", - "osxx86-64" - ] - }, - { - "groupId": "com.ctre.phoenix.sim", - "artifactId": "simVictorSPX", - "version": "5.19.4", - "isJar": false, - "skipInvalidPlatforms": true, - "validPlatforms": [ - "windowsx86-64", - "linuxx86-64", - "osxx86-64" - ] - } - ], - "cppDependencies": [ - { - "groupId": "com.ctre.phoenix", - "artifactId": "wpiapi-cpp", - "version": "5.19.4", - "libName": "CTRE_Phoenix_WPI", - "headerClassifier": "headers", - "sharedLibrary": false, - "skipInvalidPlatforms": true, - "binaryPlatforms": [ - "linuxathena", - "windowsx86-64", - "linuxx86-64", - "osxx86-64" - ] - }, - { - "groupId": "com.ctre.phoenix", - "artifactId": "api-cpp", - "version": "5.19.4", - "libName": "CTRE_Phoenix", - "headerClassifier": "headers", - "sharedLibrary": false, - "skipInvalidPlatforms": true, - "binaryPlatforms": [ - "linuxathena", - "windowsx86-64", - "linuxx86-64", - "osxx86-64" - ] - }, - { - "groupId": "com.ctre.phoenix", - "artifactId": "cci", - "version": "5.19.4", - "libName": "CTRE_PhoenixCCI", - "headerClassifier": "headers", - "sharedLibrary": false, - "skipInvalidPlatforms": true, - "binaryPlatforms": [ - "linuxathena" - ] - }, - { - "groupId": "com.ctre.phoenix.sim", - "artifactId": "cci-sim", - "version": "5.19.4", - "libName": "CTRE_PhoenixCCISim", - "headerClassifier": "headers", - "sharedLibrary": false, - "skipInvalidPlatforms": true, - "binaryPlatforms": [ - "windowsx86-64", - "linuxx86-64", - "osxx86-64" - ] - }, - { - "groupId": "com.ctre.phoenix", - "artifactId": "diagnostics", - "version": "5.19.4", - "libName": "CTRE_PhoenixDiagnostics", - "headerClassifier": "headers", - "sharedLibrary": false, - "skipInvalidPlatforms": true, - "binaryPlatforms": [ - "linuxathena", - "windowsx86-64", - "linuxx86-64", - "osxx86-64" - ] - }, - { - "groupId": "com.ctre.phoenix", - "artifactId": "canutils", - "version": "5.19.4", - "libName": "CTRE_PhoenixCanutils", - "headerClassifier": "headers", - "sharedLibrary": false, - "skipInvalidPlatforms": true, - "binaryPlatforms": [ - "windowsx86-64", - "linuxx86-64", - "osxx86-64" - ] - }, - { - "groupId": "com.ctre.phoenix", - "artifactId": "platform-sim", - "version": "5.19.4", - "libName": "CTRE_PhoenixPlatform", - "headerClassifier": "headers", - "sharedLibrary": false, - "skipInvalidPlatforms": true, - "binaryPlatforms": [ - "windowsx86-64", - "linuxx86-64", - "osxx86-64" - ] - }, - { - "groupId": "com.ctre.phoenix", - "artifactId": "core", - "version": "5.19.4", - "libName": "CTRE_PhoenixCore", - "headerClassifier": "headers", - "sharedLibrary": false, - "skipInvalidPlatforms": true, - "binaryPlatforms": [ - "linuxathena", - "windowsx86-64", - "linuxx86-64", - "osxx86-64" - ] - }, - { - "groupId": "com.ctre.phoenix.sim", - "artifactId": "simTalonSRX", - "version": "5.19.4", - "libName": "CTRE_SimTalonSRX", - "headerClassifier": "headers", - "sharedLibrary": true, - "skipInvalidPlatforms": true, - "binaryPlatforms": [ - "windowsx86-64", - "linuxx86-64", - "osxx86-64" - ] - }, - { - "groupId": "com.ctre.phoenix.sim", - "artifactId": "simVictorSPX", - "version": "5.19.4", - "libName": "CTRE_SimVictorSPX", - "headerClassifier": "headers", - "sharedLibrary": true, - "skipInvalidPlatforms": true, - "binaryPlatforms": [ - "windowsx86-64", - "linuxx86-64", - "osxx86-64" - ] - } - ] -} \ No newline at end of file diff --git a/vendordeps/REV2mDistanceSensor.json b/vendordeps/REV2mDistanceSensor.json deleted file mode 100644 index 35a1bf0..0000000 --- a/vendordeps/REV2mDistanceSensor.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "fileName": "REV2mDistanceSensor.json", - "name": "REV2mDistanceSensor", - "version": "0.3.0", - "uuid": "9e352acd-4eec-40f7-8490-3357b5ed65ae", - "mavenUrls": [ - "http://www.revrobotics.com/content/sw/max/sdk/maven/" - ], - "jsonUrl": "http://www.revrobotics.com/content/sw/max/sdk/Rev2mDistanceSensor.json", - "javaDependencies": [ - { - "groupId": "com.revrobotics.frc", - "artifactId": "DistanceSensor-java", - "version": "0.3.0" - } - ], - "jniDependencies": [ - { - "groupId": "com.revrobotics.frc", - "artifactId": "DistanceSensor-driver", - "version": "0.3.0", - "skipInvalidPlatforms": true, - "isJar": false, - "validPlatforms": [ - "linuxathena" - ] - } - ], - "cppDependencies": [ - { - "groupId": "com.revrobotics.frc", - "artifactId": "DistanceSensor-cpp", - "version": "0.3.0", - "libName": "libDistanceSensor", - "headerClassifier": "headers", - "sharedLibrary": true, - "skipInvalidPlatforms": true, - "binaryPlatforms": [ - "linuxathena" - ] - }, - { - "groupId": "com.revrobotics.frc", - "artifactId": "DistanceSensor-driver", - "version": "0.3.0", - "libName": "libDistanceSensorDriver", - "headerClassifier": "headers", - "sharedLibrary": false, - "skipInvalidPlatforms": true, - "binaryPlatforms": [ - "linuxathena" - ] - } - ] -} \ No newline at end of file diff --git a/vendordeps/REVRobotics.json b/vendordeps/REVRobotics.json index 724da3a..ca33a31 100644 --- a/vendordeps/REVRobotics.json +++ b/vendordeps/REVRobotics.json @@ -1,8 +1,27 @@ { - "cppDependencies": [ + "fileName": "REVRobotics.json", + "name": "REVRobotics", + "version": "1.5.4", + "uuid": "3f48eb8c-50fe-43a6-9cb7-44c86353c4cb", + "mavenUrls": [ + "http://www.revrobotics.com/content/sw/max/sdk/maven/" + ], + "jsonUrl": "http://www.revrobotics.com/content/sw/max/sdk/REVRobotics.json", + "javaDependencies": [ { - "artifactId": "SparkMax-cpp", - "binaryPlatforms": [ + "groupId": "com.revrobotics.frc", + "artifactId": "SparkMax-java", + "version": "1.5.4" + } + ], + "jniDependencies": [ + { + "groupId": "com.revrobotics.frc", + "artifactId": "SparkMax-driver", + "version": "1.5.4", + "skipInvalidPlatforms": true, + "isJar": false, + "validPlatforms": [ "windowsx86-64", "windowsx86", "linuxaarch64bionic", @@ -10,16 +29,18 @@ "linuxathena", "linuxraspbian", "osxx86-64" - ], + ] + } + ], + "cppDependencies": [ + { "groupId": "com.revrobotics.frc", - "headerClassifier": "headers", + "artifactId": "SparkMax-cpp", + "version": "1.5.4", "libName": "SparkMax", + "headerClassifier": "headers", "sharedLibrary": false, "skipInvalidPlatforms": true, - "version": "1.5.4" - }, - { - "artifactId": "SparkMax-driver", "binaryPlatforms": [ "windowsx86-64", "windowsx86", @@ -28,30 +49,17 @@ "linuxathena", "linuxraspbian", "osxx86-64" - ], - "groupId": "com.revrobotics.frc", - "headerClassifier": "headers", - "libName": "SparkMaxDriver", - "sharedLibrary": false, - "skipInvalidPlatforms": true, - "version": "1.5.4" - } - ], - "fileName": "REVRobotics.json", - "javaDependencies": [ + ] + }, { - "artifactId": "SparkMax-java", "groupId": "com.revrobotics.frc", - "version": "1.5.4" - } - ], - "jniDependencies": [ - { "artifactId": "SparkMax-driver", - "groupId": "com.revrobotics.frc", - "isJar": false, + "version": "1.5.4", + "libName": "SparkMaxDriver", + "headerClassifier": "headers", + "sharedLibrary": false, "skipInvalidPlatforms": true, - "validPlatforms": [ + "binaryPlatforms": [ "windowsx86-64", "windowsx86", "linuxaarch64bionic", @@ -59,15 +67,7 @@ "linuxathena", "linuxraspbian", "osxx86-64" - ], - "version": "1.5.4" + ] } - ], - "jsonUrl": "http://www.revrobotics.com/content/sw/max/sdk/REVRobotics.json", - "mavenUrls": [ - "http://www.revrobotics.com/content/sw/max/sdk/maven/" - ], - "name": "REVRobotics", - "uuid": "3f48eb8c-50fe-43a6-9cb7-44c86353c4cb", - "version": "1.5.4" + ] } \ No newline at end of file diff --git a/vendordeps/navx_frc.json b/vendordeps/navx_frc.json deleted file mode 100644 index dca1d82..0000000 --- a/vendordeps/navx_frc.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "fileName": "navx_frc.json", - "name": "KauaiLabs_navX_FRC", - "version": "3.1.413", - "uuid": "cb311d09-36e9-4143-a032-55bb2b94443b", - "mavenUrls": [ - "https://repo1.maven.org/maven2/" - ], - "jsonUrl": "https://www.kauailabs.com/dist/frc/2020/navx_frc.json", - "javaDependencies": [ - { - "groupId": "com.kauailabs.navx.frc", - "artifactId": "navx-java", - "version": "3.1.413" - } - ], - "jniDependencies": [], - "cppDependencies": [ - { - "groupId": "com.kauailabs.navx.frc", - "artifactId": "navx-cpp", - "version": "3.1.413", - "headerClassifier": "headers", - "sourcesClassifier": "sources", - "sharedLibrary": false, - "libName": "navx_frc", - "skipInvalidPlatforms": true, - "binaryPlatforms": [ - "linuxathena", - "linuxraspbian", - "windowsx86-64" - ] - } - ] -} \ No newline at end of file