Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Se/code organization #16

Merged
merged 17 commits into from
Jan 29, 2024
22 changes: 18 additions & 4 deletions src/main/java/com/stuypulse/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

package com.stuypulse.robot;

import edu.wpi.first.wpilibj.DataLogManager;
import edu.wpi.first.wpilibj.DriverStation;
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;

Expand All @@ -15,13 +17,17 @@ public class Robot extends TimedRobot {
private RobotContainer robot;
private Command auto;

/*************************/
/*** ROBOT SCHEDULEING ***/
/*************************/
/************************/
/*** ROBOT SCHEDULING ***/
/************************/

@Override
public void robotInit() {
DataLogManager.start();

robot = new RobotContainer();

SmartDashboard.putString("Robot State", "DISABLED");
}

@Override
Expand All @@ -34,7 +40,9 @@ public void robotPeriodic() {
/*********************/

@Override
public void disabledInit() {}
public void disabledInit() {
SmartDashboard.putString("Robot State", "DISABLED");
}

@Override
public void disabledPeriodic() {
Expand Down Expand Up @@ -62,6 +70,8 @@ public void autonomousInit() {
if (auto != null) {
auto.schedule();
}

SmartDashboard.putString("Robot State", "AUTON");
}

@Override
Expand All @@ -79,6 +89,8 @@ public void teleopInit() {
if (auto != null) {
auto.cancel();
}

SmartDashboard.putString("Robot State", "TELEOP");
}

@Override
Expand All @@ -94,6 +106,8 @@ public void teleopExit() {}
@Override
public void testInit() {
CommandScheduler.getInstance().cancelAll();

SmartDashboard.putString("Robot State", "TEST");
}

@Override
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/com/stuypulse/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@

package com.stuypulse.robot;

import com.stuypulse.robot.commands.auton.DoNothingAuton;
import com.stuypulse.robot.commands.climber.ClimberDrive;
import com.stuypulse.robot.commands.swerve.SwerveDriveDrive;
import com.stuypulse.robot.commands.*;
import com.stuypulse.robot.commands.amper.*;
import com.stuypulse.robot.commands.auton.*;
import com.stuypulse.robot.commands.climber.*;
import com.stuypulse.robot.commands.swerve.*;
import com.stuypulse.robot.commands.intake.*;
import com.stuypulse.robot.commands.shooter.*;
import com.stuypulse.robot.commands.conveyor.*;
import com.stuypulse.robot.constants.Ports;
import com.stuypulse.robot.constants.Settings;
import com.stuypulse.robot.subsystems.amper.Amper;
Expand Down Expand Up @@ -35,15 +40,16 @@ public class RobotContainer {
public final Gamepad operator = new AutoGamepad(Ports.Gamepad.OPERATOR);

// Subsystem
public final Climber climber = Climber.getInstance();
public final Amper amper = Amper.getInstance();
public final SwerveDrive swerve = SwerveDrive.getInstance();
public final Odometry odometry = Odometry.getInstance();
public final AprilTagVision vision = AprilTagVision.getInstance();
public final NoteVision noteVision = NoteVision.getInstance();
public final Odometry odometry = Odometry.getInstance();

public final Amper amper = Amper.getInstance();
public final Conveyor conveyor = Conveyor.getInstance();
public final Climber climber = Climber.getInstance();
public final Intake intake = Intake.getInstance();
public final Shooter shooter = Shooter.getInstance();
public final Conveyor conveyor = Conveyor.getInstance();
public final SwerveDrive swerve = SwerveDrive.getInstance();

// Autons
private static SendableChooser<Command> autonChooser = new SendableChooser<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public void initialize() {
amper.intake();
}

@Override
public boolean isFinished() {
return amper.hasNote();
}

@Override
public void end(boolean interrupted) {
amper.stopRoller();
Expand Down
30 changes: 0 additions & 30 deletions src/main/java/com/stuypulse/robot/commands/amper/AmperOuttake.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import edu.wpi.first.wpilibj2.command.InstantCommand;

public class AmperScoreForever extends InstantCommand {
public class AmperScore extends InstantCommand {

private final Amper amper;

public AmperScoreForever() {
public AmperScore() {
amper = Amper.getInstance();
addRequirements(amper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public AmperScoreAmp() {
addCommands(
new AmperToHeight(Score.AMP_SCORE_HEIGHT.get()),
new AmperWaitToHeight(Score.AMP_SCORE_HEIGHT.get()),
new AmperOuttake()
new AmperScore()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public AmperScoreTrap() {
addCommands(
new AmperToHeight(Score.TRAP_SCORE_HEIGHT.get()),
new AmperWaitToHeight(Score.TRAP_SCORE_HEIGHT.get()),
new AmperOuttake()
new AmperScore()
);
}

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/stuypulse/robot/commands/amper/AmperStop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.stuypulse.robot.commands.amper;

import com.stuypulse.robot.subsystems.amper.Amper;

import edu.wpi.first.wpilibj2.command.InstantCommand;

public class AmperStop extends InstantCommand {

private final Amper amper;

public AmperStop() {
amper = Amper.getInstance();
addRequirements(amper);
}

@Override
public void initialize() {
amper.stopRoller();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public AmperWaitToHeight(double height) {
addRequirements(amper);
}

@Override
public void initialize() {
amper.setTargetHeight(height);
}

@Override
public boolean isFinished() {
return Math.abs(amper.getLiftHeight() - height) < Lift.MAX_HEIGHT_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ClimberDrive(Gamepad gamepad) {
public void execute() {
climber.setVoltageOverride(voltage.get());

SmartDashboard.putNumber("Climber/Gamepad Velocity", voltage.get());
SmartDashboard.putNumber("Climber/Gamepad Voltage", voltage.get());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.stuypulse.robot.commands.climber;

import com.stuypulse.robot.constants.Settings;
import com.stuypulse.robot.subsystems.climber.Climber;

import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.InstantCommand;

public class ClimberToHeight extends InstantCommand {

public class ClimberToHeight extends Command {
private final Climber climber;
private final double height;

Expand All @@ -20,9 +20,4 @@ public ClimberToHeight(double height) {
public void initialize() {
climber.setTargetHeight(height);
}

@Override
public boolean isFinished() {
return Math.abs(climber.getTargetHeight() - climber.getHeight()) < Settings.Climber.BangBang.THRESHOLD;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.stuypulse.robot.commands.climber;

import com.stuypulse.robot.constants.Settings;
import com.stuypulse.robot.subsystems.climber.Climber;

import edu.wpi.first.wpilibj2.command.InstantCommand;

public class ClimberToHeightInstant extends InstantCommand {
import edu.wpi.first.wpilibj2.command.Command;

public class ClimberWaitForHeight extends Command {
private final Climber climber;
private final double height;

public ClimberToHeightInstant(double height) {
public ClimberWaitForHeight(double height) {
climber = Climber.getInstance();
this.height = height;

Expand All @@ -20,4 +20,9 @@ public ClimberToHeightInstant(double height) {
public void initialize() {
climber.setTargetHeight(height);
}

@Override
public boolean isFinished() {
return Math.abs(climber.getTargetHeight() - climber.getHeight()) < Settings.Climber.BangBang.THRESHOLD;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.stuypulse.robot.subsystems.conveyor.Conveyor;

import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.InstantCommand;

public class ConveyorShoot extends Command{
public class ConveyorShoot extends InstantCommand {

private final Conveyor conveyor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.stuypulse.robot.subsystems.conveyor.Conveyor;

import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.InstantCommand;

public class ConveyorStop extends Command{
public class ConveyorStop extends InstantCommand {

private Conveyor conveyor;
private final Conveyor conveyor;

public ConveyorStop() {
conveyor = Conveyor.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import com.stuypulse.robot.subsystems.intake.Intake;

import com.stuypulse.robot.subsystems.amper.Amper;

import edu.wpi.first.wpilibj2.command.Command;

public class ConveyorToAmp extends Command{
import com.stuypulse.robot.subsystems.amper.Amper;

public class ConveyorToAmp extends Command {

private final Conveyor conveyor;
private final Intake intake;
Expand All @@ -26,6 +26,7 @@ public ConveyorToAmp() {
public void execute() {
conveyor.toAmp();
intake.acquire();
amper.score();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this call amper.intake() instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just reread what amper.intake() does. It doesn't need to exist? We're never going to use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we leave it, maybe delete amperintake command

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import edu.wpi.first.wpilibj2.command.Command;

public class ConveyorToShooter extends Command{
public class ConveyorToShooter extends Command {

private final Conveyor conveyor;
private final Intake intake;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/stuypulse/robot/constants/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.ArrayList;

import com.stuypulse.robot.util.Fiducial;
import com.stuypulse.robot.util.vision.Fiducial;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Pose3d;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/stuypulse/robot/constants/Motors.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface Motors {
/** Classes to store all of the values a motor needs */

public interface Amper {
CANSparkMaxConfig LIFT_MOTOR = new CANSparkMaxConfig(false, IdleMode.kCoast);
CANSparkMaxConfig LIFT_MOTOR = new CANSparkMaxConfig(false, IdleMode.kBrake);
CANSparkMaxConfig SCORE_MOTOR = new CANSparkMaxConfig(false, IdleMode.kBrake);
}

Expand All @@ -45,12 +45,12 @@ public interface Shooter {

public interface Conveyor {
CANSparkMaxConfig GANDALF_MOTOR = new CANSparkMaxConfig(false, IdleMode.kBrake);
CANSparkMaxConfig SHOOTER_FEEDER_MOTOR = new CANSparkMaxConfig(false, IdleMode.kCoast);
CANSparkMaxConfig SHOOTER_FEEDER_MOTOR = new CANSparkMaxConfig(false, IdleMode.kBrake);
}

public interface Climber {
CANSparkMaxConfig LEFT_MOTOR = new CANSparkMaxConfig(false, IdleMode.kBrake, 80);
CANSparkMaxConfig RIGHT_MOTOR = new CANSparkMaxConfig(false, IdleMode.kBrake, 80);
CANSparkMaxConfig LEFT_MOTOR = new CANSparkMaxConfig(false, IdleMode.kBrake);
CANSparkMaxConfig RIGHT_MOTOR = new CANSparkMaxConfig(false, IdleMode.kBrake);
}

public static class TalonSRXConfig {
Expand Down
Loading
Loading