Skip to content

Commit

Permalink
Make it more similar to GOS version
Browse files Browse the repository at this point in the history
  • Loading branch information
pjreiniger committed Nov 5, 2023
1 parent 98dcb6c commit adcc073
Show file tree
Hide file tree
Showing 25 changed files with 213 additions and 158 deletions.
28 changes: 3 additions & 25 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* the package after creating this project, you must also update the build.gradle file in the
* project.
*/
@SuppressWarnings("PMD.TooManyMethods")
public class Robot extends TimedRobot {
private Command m_autonomousCommand;

Expand All @@ -26,7 +25,7 @@ public class Robot extends TimedRobot {
*/
@Override
public void robotInit() {
// Instantiate our RobotContainer. This will perform all our button bindings, and put our
// Instantiate our RobotContainer. This will perform all our button bindings, and put our
// autonomous chooser on the dashboard.
m_robotContainer = new RobotContainer();
}
Expand All @@ -40,9 +39,9 @@ public void robotInit() {
*/
@Override
public void robotPeriodic() {
// Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled
// 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
// 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();
}
Expand Down Expand Up @@ -101,25 +100,4 @@ 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() {
}

/**
* This function is called once when the robot is first started up.
*/
@Override
public void simulationInit() {
}

/**
* This function is called periodically whilst in simulation.
*/
@Override
public void simulationPeriodic() {
}
}
23 changes: 19 additions & 4 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,30 @@

package frc.robot;

import frc.robot.commands.ClimberCommand;
import frc.robot.commands.DriveCommand;
import frc.robot.commands.HopperCommand;
import frc.robot.commands.KickIfShootSetRPMCommand;
import frc.robot.commands.RunIntakeCommand;
import frc.robot.commands.SetShooterSpeedCommand;
import frc.robot.commands.StopIntakeCommand;
import frc.robot.commands.ShootFromDistanceCommand;
import frc.robot.commands.TowerDownCommand;
import frc.robot.commands.TowerUpCommand;
import frc.robot.subsystems.ClimberSubsystem;
import frc.robot.subsystems.DrivetrainSubsystem;
import frc.robot.subsystems.HopperSubsystem;
import frc.robot.subsystems.IntakeSubsystem;
import frc.robot.subsystems.LimelightSubsystem;
import frc.robot.subsystems.ShooterSubsytem;
import frc.robot.subsystems.TowerSubsystem;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import frc.robot.autos.AutonomousFactory;
import edu.wpi.first.cameraserver.CameraServer;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
import frc.robot.autos.AutonomousFactory;
import frc.robot.commands.*;
import frc.robot.subsystems.*;

/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
Expand Down
38 changes: 18 additions & 20 deletions src/main/java/frc/robot/commands/AutoAimCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

import com.gos.lib.properties.PidProperty;
import com.gos.lib.properties.WpiProfiledPidPropertyBuilder;

import frc.robot.Constants;
import frc.robot.subsystems.DrivetrainSubsystem;
import frc.robot.subsystems.LimelightSubsystem;
import edu.wpi.first.math.controller.ProfiledPIDController;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.trajectory.TrapezoidProfile;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.Constants;
import frc.robot.subsystems.DrivetrainSubsystem;
import frc.robot.subsystems.LimelightSubsystem;

/**
* An example command that uses an example subsystem.
Expand All @@ -22,31 +21,29 @@ public class AutoAimCommand extends CommandBase {
private final DrivetrainSubsystem m_driveTrainSubsystem;
private final LimelightSubsystem m_limelightSubsystem;
private final ProfiledPIDController m_controller;
private final PidProperty m_pidProperty;
private final PidProperty m_pidProperties;

/**
* Creates a new AutoAimCommand.
*
* @param subsystem The subsystem used by this command.
*/
public AutoAimCommand(
DrivetrainSubsystem driveTrainSubsystem, LimelightSubsystem limelightSubsystem) {
DrivetrainSubsystem driveTrainSubsystem, LimelightSubsystem limelightSubsystem) {
m_driveTrainSubsystem = driveTrainSubsystem;
m_limelightSubsystem = limelightSubsystem;
m_controller =
new ProfiledPIDController(
0,
0,
0,
new TrapezoidProfile.Constraints(
Constants.MAX_TURN_VELOCITY, Constants.MAX_TURN_ACCELERATION));
m_pidProperty = new WpiProfiledPidPropertyBuilder("AutoAim", false, m_controller)
.addP(0)
.addI(0)
.addD(0)
.addMaxVelocity(Constants.MAX_TURN_VELOCITY)
.addMaxAcceleration(Constants.MAX_TURN_ACCELERATION)
.build();
new ProfiledPIDController(
0,
0,
0,
new TrapezoidProfile.Constraints(
Constants.MAX_TURN_VELOCITY, Constants.MAX_TURN_ACCELERATION));
m_pidProperties = new WpiProfiledPidPropertyBuilder("AutoAim", false, m_controller)
.addP(0)
.addI(0)
.addD(0)
.build();
m_controller.setTolerance(5);
// Use addRequirements() here to declare subsystem dependencies.
addRequirements(driveTrainSubsystem);
Expand All @@ -61,7 +58,8 @@ public void initialize() {
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
m_pidProperty.updateIfChanged();
m_pidProperties.updateIfChanged();

double turnSpeed = m_controller.calculate(m_limelightSubsystem.limelightAngle());
ChassisSpeeds chassisSpeed = new ChassisSpeeds(0, 0, turnSpeed);
m_driveTrainSubsystem.applyChassisSpeed(chassisSpeed);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/commands/ClimbAutoCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package frc.robot.commands;

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

/**
* An example command that uses an example subsystem.
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/frc/robot/commands/ClimbPIDComand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package frc.robot.commands;

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

public class ClimbPIDComand extends CommandBase {
private final ClimberSubsystem m_climberSubsystem;
Expand All @@ -24,13 +24,13 @@ public void execute() {

@Override
public boolean isFinished() {
return Math.abs(m_climberSubsystem.getPIDPosition()) < 100
|| (m_climberSubsystem.leftLimitSwitchPress()
|| m_climberSubsystem.rightLimitSwitchPress());
return Math.abs(m_climberSubsystem.getPIDPosition()) < 100 || (m_climberSubsystem.leftLimitSwitchPress() || m_climberSubsystem.rightLimitSwitchPress());
}

@Override
public void end(boolean interrupted) {
m_climberSubsystem.set(0);
}


}
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/commands/ClimberCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

package frc.robot.commands;

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

/**
* An example command that uses an example subsystem.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/commands/DriveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

package frc.robot.commands;

import frc.robot.subsystems.DrivetrainSubsystem;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.DrivetrainSubsystem;

/**
* An example command that uses an example subsystem.
Expand Down Expand Up @@ -37,7 +37,7 @@ public void initialize() {
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
m_subsystem.control(-0.5 * m_joystick.getLeftY(), 0.5 * m_joystick.getRightX());
m_subsystem.control(-m_joystick.getLeftY(), m_joystick.getRightX());
}

// Called once the command ends or is interrupted.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/commands/HopperCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

package frc.robot.commands;

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

/**
* An example command that uses an example subsystem.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.ShooterSubsytem;
import frc.robot.subsystems.TowerSubsystem;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase;

/**
* An example command that uses an example subsystem.
Expand Down Expand Up @@ -43,8 +43,7 @@ public void execute() {
m_towerSubsystem.setKickerSpeed(1);
m_towerSubsystem.setTowerSpeed(0.75);
}
SmartDashboard.putBoolean(
"kickIfShootRPM atSpeed", m_shooterSubsystem.checkAtSpeed(m_rpm));
SmartDashboard.putBoolean("kickIfShootRPM atSpeed", m_shooterSubsystem.checkAtSpeed(m_rpm));
}

// Called once the command ends or is interrupted.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.ShooterLookupTable;
import frc.robot.subsystems.LimelightSubsystem;
import frc.robot.subsystems.ShooterSubsytem;
import frc.robot.subsystems.TowerSubsystem;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase;

/**
* An example command that uses an example subsystem.
Expand All @@ -24,10 +24,10 @@ public class KickIfShooterDistanceGoBrrCommand extends CommandBase {
* @param subsystem The subsystem used by this command.
*/
public KickIfShooterDistanceGoBrrCommand(
ShooterSubsytem subsystem,
TowerSubsystem towerSubsystem,
LimelightSubsystem limelightSubsystem,
ShooterLookupTable shooterLookupTable) {
ShooterSubsytem subsystem,
TowerSubsystem towerSubsystem,
LimelightSubsystem limelightSubsystem,
ShooterLookupTable shooterLookupTable) {
m_shooterSubsystem = subsystem;
m_towerSubsystem = towerSubsystem;
m_limelightSubsystem = limelightSubsystem;
Expand All @@ -52,9 +52,8 @@ public void execute() {
m_towerSubsystem.setKickerSpeed(1);
m_towerSubsystem.setTowerSpeed(0.75);
}
SmartDashboard.putBoolean(
"kickIfShootDist atSpeed",
m_shooterSubsystem.checkAtSpeed(m_shooterLookupTable.getRpmTable(distance)));
SmartDashboard.putBoolean("kickIfShootDist atSpeed", m_shooterSubsystem.checkAtSpeed(m_shooterLookupTable.getRpmTable(distance)));

}

// Called once the command ends or is interrupted.
Expand All @@ -68,6 +67,6 @@ public void end(boolean interrupted) {
@Override
public boolean isFinished() {
return m_shooterSubsystem.checkAtSpeed(
m_shooterLookupTable.getRpmTable(m_limelightSubsystem.limelightDistance()));
m_shooterLookupTable.getRpmTable(m_limelightSubsystem.limelightDistance()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

package frc.robot.commands;

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

/**
* An example command that uses an example subsystem.
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/frc/robot/commands/RunIntakeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.HopperSubsystem;
import frc.robot.subsystems.IntakeSubsystem;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.TowerSubsystem;

/**
Expand All @@ -27,12 +27,7 @@ public class RunIntakeCommand extends CommandBase {
*
* @param subsystem The subsystem used by this command.
*/
public RunIntakeCommand(
IntakeSubsystem intakeSubsystem,
double intakeSpeed,
HopperSubsystem hopperSubsystem,
TowerSubsystem towerSubsystem,
double towerSpeed) {
public RunIntakeCommand(IntakeSubsystem intakeSubsystem, double intakeSpeed, HopperSubsystem hopperSubsystem, TowerSubsystem towerSubsystem, double towerSpeed) {
m_intakeSubsystem = intakeSubsystem;
m_hopperSubsystem = hopperSubsystem;
m_towerSubsystem = towerSubsystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

package frc.robot.commands;

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

/**
* An example command that uses an example subsystem.
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/frc/robot/commands/ShootFromDistanceCommand.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.ShooterLookupTable;
import frc.robot.subsystems.LimelightSubsystem;
import frc.robot.subsystems.ShooterSubsytem;
import edu.wpi.first.wpilibj2.command.CommandBase;

/**
* An example command that uses an example subsystem.
Expand All @@ -21,9 +21,9 @@ public class ShootFromDistanceCommand extends CommandBase {
* @param subsystem The subsystem used by this command.
*/
public ShootFromDistanceCommand(
ShooterSubsytem subsystem,
LimelightSubsystem limelightsubsystem,
ShooterLookupTable shooterLookupTable) {
ShooterSubsytem subsystem,
LimelightSubsystem limelightsubsystem,
ShooterLookupTable shooterLookupTable) {
m_shooterSubsystem = subsystem;
m_limelightSubsystem = limelightsubsystem;
m_shooterLookupTable = shooterLookupTable;
Expand Down Expand Up @@ -52,6 +52,6 @@ public void end(boolean interrupted) {
@Override
public boolean isFinished() {
return m_shooterSubsystem.checkAtSpeed(
m_shooterLookupTable.getRpmTable(m_limelightSubsystem.limelightDistance()));
m_shooterLookupTable.getRpmTable(m_limelightSubsystem.limelightDistance()));
}
}
Loading

0 comments on commit adcc073

Please sign in to comment.