Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
416c1ca
fix yagsl.json
Ocean-Moist Feb 17, 2024
23c7dc3
add github action for building
Ocean-Moist Feb 17, 2024
8b6e3cb
Replaced 2mdistancesensor with new TimeOfFlight sensors
kenhuang1964 Feb 18, 2024
f076dad
code clean up + no more errorprone errors
Ocean-Moist Feb 18, 2024
587b7e7
fix github actions
Ocean-Moist Feb 18, 2024
fe539c7
formatting and switch to functional command builder syntax in subsyst…
Ocean-Moist Feb 18, 2024
2975f1e
fixed module positions to the actual ones (backleft is actually front…
kenhuang1964 Feb 20, 2024
422707d
Updated absolute encoder offset
kenhuang1964 Feb 21, 2024
803c2b2
Revert "fixed module positions to the actual ones (backleft is actual…
Non-Binary-Programmer Feb 21, 2024
8a05035
actually fixed module positions correctly this time
Non-Binary-Programmer Feb 21, 2024
29d509c
fixed the modules again again, made temprary changes to robot contain…
Non-Binary-Programmer Feb 21, 2024
5b02cde
DO NOT TRUST, REVIEW: first 20 minute attempt at changing architectur…
Non-Binary-Programmer Feb 23, 2024
b7290a5
.
kenhuang1964 Feb 23, 2024
a4e5a42
Changed motor ids to be accurate. Swerve is now field oriented
kenhuang1964 Feb 23, 2024
f8900fe
More thorough refactoring + bindings. Code should be ready to use for…
Non-Binary-Programmer Feb 24, 2024
c1c5815
added loggers for TOF sensors
Non-Binary-Programmer Feb 24, 2024
c6ed61f
dont crash when outsied of range of shooter, add can ids, add linear …
Feb 24, 2024
66bb29a
fix hood constants, fix intake constants, try and get monologue worki…
Feb 25, 2024
08a778b
changed logic: manage state in Superstructure more clearly, abstract …
Feb 25, 2024
fd391ef
switch kens weird oop thing to functional style commands
Feb 25, 2024
149a2a4
actually implement smart current limits in hood intake and shooter
Feb 25, 2024
af50983
use functional style error handling (Optional) for shooter data table…
Feb 25, 2024
07c693b
add comments and fix logic of NO_NOTE state in Superstructure
Feb 25, 2024
569f17b
try and get monologue working
Feb 26, 2024
0a989c6
updated motor id
Non-Binary-Programmer Feb 27, 2024
3c6638e
I did the vision part for one camera. The part for 2 cameras is parti…
Billybobbe Feb 27, 2024
b042341
Filled out the triangulate function completely to use if needed.
Billybobbe Feb 27, 2024
947c333
Updated hood gear ratio
Non-Binary-Programmer Feb 27, 2024
d0b52d1
Merge remote-tracking branch 'origin/practice' into practice
Non-Binary-Programmer Feb 27, 2024
543096b
updated recalc sysid for new hood gear ratio
Non-Binary-Programmer Feb 28, 2024
f5b55ef
Improved superstructure logic for shooting case relating to swerve.
Non-Binary-Programmer Feb 28, 2024
fd248ea
upgrade gradle rio version, formatting, add logging to hood,
Mar 1, 2024
7aba373
Added vision subsystem to robotcontainer.
Billybobbe Mar 1, 2024
9477951
Merge remote-tracking branch 'origin/practice' into practice
Billybobbe Mar 1, 2024
db6586b
Attempted to fix logging for vision subsystem. Still needs a lil more…
kenhuang1964 Mar 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "java"
id "edu.wpi.first.GradleRIO" version "2024.2.1"
id "edu.wpi.first.GradleRIO" version "2024.3.1"
id "net.ltgt.errorprone" version "3.1.0"
id "com.diffplug.spotless" version "6.23.3"
id "io.freefair.lombok" version "8.4"
Expand Down
10 changes: 5 additions & 5 deletions src/main/deploy/swerve/modules/backleft.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"front": -12,
"left": 12
},
"absoluteEncoderOffset": 112.060546875,
"absoluteEncoderOffset": 317.63,
"drive": {
"type": "sparkmax",
"id": 5,
"id": 15,
"canbus": null
},
"angle": {
"type": "sparkmax",
"id": 6,
"id": 2,
"canbus": null
},
"conversionFactor": {
Expand All @@ -20,8 +20,8 @@
},
"encoder": {
"type": "cancoder",
"id": 3,
"canbus": "can"
"id": 2,
"canbus": "can"
},
"inverted": {
"drive": false,
Expand Down
8 changes: 4 additions & 4 deletions src/main/deploy/swerve/modules/backright.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"front": -12,
"left": -12
},
"absoluteEncoderOffset": 179.6484375,
"absoluteEncoderOffset": 13.27,
"drive": {
"type": "sparkmax",
"id": 3,
"id": 7,
"canbus": null
},
"angle": {
"type": "sparkmax",
"id": 4,
"id": 8,
"canbus": null
},
"conversionFactor": {
Expand All @@ -20,7 +20,7 @@
},
"encoder": {
"type": "cancoder",
"id": 1,
"id": 0,
"canbus": "can"
},
"inverted": {
Expand Down
8 changes: 4 additions & 4 deletions src/main/deploy/swerve/modules/frontleft.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"front": 12,
"left": 12
},
"absoluteEncoderOffset": 193.1,
"absoluteEncoderOffset": 359.56,
"drive": {
"type": "sparkmax",
"id": 7,
"id": 3,
"canbus": null
},
"angle": {
"type": "sparkmax",
"id": 8,
"id": 4,
"canbus": null
},
"conversionFactor": {
Expand All @@ -20,7 +20,7 @@
},
"encoder": {
"type": "cancoder",
"id": 0,
"id": 1,
"canbus": "can"
},
"inverted": {
Expand Down
8 changes: 4 additions & 4 deletions src/main/deploy/swerve/modules/frontright.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"front": 12,
"left": -12
},
"absoluteEncoderOffset": 146.25,
"absoluteEncoderOffset": 291.00,
"drive": {
"type": "sparkmax",
"id": 1,
"id": 5,
"canbus": null
},
"angle": {
"type": "sparkmax",
"id": 2,
"id": 6,
"canbus": null
},
"conversionFactor": {
Expand All @@ -20,7 +20,7 @@
},
"encoder": {
"type": "cancoder",
"id": 2,
"id": 3,
"canbus": "can"
},
"inverted": {
Expand Down
2 changes: 1 addition & 1 deletion src/main/deploy/swerve/swervedrive.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": 13,
"canbus": "can"
},
"invertedIMU": true,
"invertedIMU": false,
"modules": [
"frontleft.json",
"frontright.json",
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@

package frc.robot;

import edu.wpi.first.wpilibj.DataLogManager;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import monologue.Logged;
import monologue.Monologue;

public class Robot extends TimedRobot {
public class Robot extends TimedRobot implements Logged {
private Command m_autonomousCommand;

private RobotContainer m_robotContainer;

@Override
public void robotInit() {
m_robotContainer = new RobotContainer();
DataLogManager.start();
DriverStation.startDataLog(DataLogManager.getLog());
Monologue.setupMonologue(this, "root", false, false);
}

@Override
public void robotPeriodic() {
Monologue.updateAll();
CommandScheduler.getInstance().run();
}

Expand Down
103 changes: 60 additions & 43 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package frc.robot;

import com.pathplanner.lib.auto.AutoBuilder;
import static monologue.Annotations.*;

import com.playingwithfusion.TimeOfFlight;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.units.Distance;
import edu.wpi.first.units.Measure;
Expand All @@ -12,49 +14,39 @@
import frc.robot.inputs.NoteDetector;
import frc.robot.inputs.PoseEstimator;
import frc.robot.lib.controllers.Thrustmaster;
import frc.robot.subsystems.Indexer;
import frc.robot.subsystems.Intake;
import frc.robot.subsystems.Shooter;
import frc.robot.subsystems.Swerve;
import io.github.jdiemke.triangulation.NotEnoughPointsException;
import frc.robot.subsystems.*;
import java.io.File;
import java.io.IOException;
import monologue.Logged;
import org.photonvision.PhotonCamera;
import swervelib.SwerveDrive;
import swervelib.math.SwerveMath;
import swervelib.parser.SwerveParser;
import swervelib.telemetry.SwerveDriveTelemetry;

public class RobotContainer {
private final Measure<Velocity<Distance>> maximumSpeed = Units.FeetPerSecond.of(20);

private final Swerve drivebase;
private final PoseEstimator poseEstimator;
private final Intake intake;
private final Shooter shooter;
private final Indexer indexer;
private final NoteDetector noteDetector;
private final ShooterDataTable shooterDataTable; // TODO: Ensure to get the actual points

public class RobotContainer implements Logged {
private static final Thrustmaster leftThrustmaster = new Thrustmaster(0);
private static final Thrustmaster rightThrustmaster = new Thrustmaster(1);
private final SwerveDrive swerveDrive;
private final Superstructure superstructure;
private final SendableChooser<Command> autoChooser = new SendableChooser<>();
private final PhotonCamera photonCamera = new PhotonCamera("photonvision"); // TODO: Remember to replace with the actual camera name

static {
SwerveDriveTelemetry.verbosity = SwerveDriveTelemetry.TelemetryVerbosity.HIGH;
}

private final Vision vision = new Vision();
private final Swerve drivebase;
private final Superstructure superstructure;
private final SendableChooser<Command> autoChooser = new SendableChooser<>();

public RobotContainer() {
// Angle conversion factor = 360 / (GEAR RATIO * ENCODER RESOLUTION)
double angleConversionFactor = SwerveMath.calculateDegreesPerSteeringRotation(12.8, 4096);
// with real values
// Motor conversion factor is (PI * WHEEL DIAMETER IN METERS) / (GEAR RATIO *
// ENCODER RESOLUTION).
double driveConversionFactor = SwerveMath.calculateMetersPerRotation(0, 6.75, 1);
SwerveDrive swerveDrive;
try {
Measure<Velocity<Distance>> maximumSpeed = Units.FeetPerSecond.of(20);
swerveDrive =
new SwerveParser(new File(Filesystem.getDeployDirectory(), "swerve"))
.createSwerveDrive(
Expand All @@ -65,12 +57,35 @@ public RobotContainer() {
throw new RuntimeException(e);
}

try {
shooterDataTable = new ShooterDataTable(null, null);
} catch (NotEnoughPointsException e) {
throw new RuntimeException(e);
}
// TODO: Ensure to get the actual points
ShooterDataTable shooterDataTable;
Translation2d[] dummyPoints =
new Translation2d[] {new Translation2d(), new Translation2d(), new Translation2d()};
ShooterSpec[] dummySpecs =
new ShooterSpec[] {
new ShooterSpec(
Units.Degrees.of(0),
Units.DegreesPerSecond.of(0),
Units.DegreesPerSecond.of(0),
Units.Degrees.of(0)),
new ShooterSpec(
Units.Degrees.of(0),
Units.DegreesPerSecond.of(0),
Units.DegreesPerSecond.of(0),
Units.Degrees.of(0)),
new ShooterSpec(
Units.Degrees.of(0),
Units.DegreesPerSecond.of(0),
Units.DegreesPerSecond.of(0),
Units.Degrees.of(0))
};
shooterDataTable = new ShooterDataTable(dummyPoints, dummySpecs, false);

PoseEstimator poseEstimator;
Intake intake;
Shooter shooter;
Hood hood;
NoteDetector noteDetector;
try {
poseEstimator =
new PoseEstimator(
Expand All @@ -79,26 +94,26 @@ public RobotContainer() {
swerveDrive.swerveDrivePoseEstimator::getEstimatedPosition,
swerveDrive::getModulePositions,
swerveDrive.swerveDrivePoseEstimator::update);
// TODO: Remember to replace with the actual camera name
PhotonCamera photonCamera = new PhotonCamera("photonvision");
noteDetector = new NoteDetector(photonCamera, poseEstimator);
intake = new Intake();
shooter = new Shooter(shooterDataTable, poseEstimator);
indexer = new Indexer(shooterDataTable, poseEstimator);
TimeOfFlight sensor = new TimeOfFlight(15);
sensor.setRangingMode(TimeOfFlight.RangingMode.Short, 0.02);

PowerBudget power = new PowerBudget();
shooter = new Shooter(shooterDataTable, poseEstimator, sensor, power);
hood = new Hood(shooterDataTable, poseEstimator, sensor, power);

} catch (IOException e) {
throw new RuntimeException(e);
}

try {
drivebase =
new Swerve(
swerveDrive,
new ShooterDataTable(new Translation2d[] {}, new ShooterSpec[] {}),
poseEstimator);
} catch (NotEnoughPointsException e) {
throw new RuntimeException(e); // GG go next
}

superstructure = new Superstructure(intake, indexer, shooter, drivebase, noteDetector, poseEstimator);
drivebase = new Swerve(swerveDrive, shooterDataTable, poseEstimator);

superstructure =
new Superstructure(
intake, hood, shooter, drivebase, noteDetector, poseEstimator, shooterDataTable);

Command driveFieldOrientedDirectAngle =
drivebase.driveCommand(
Expand All @@ -108,14 +123,16 @@ public RobotContainer() {
drivebase.setDefaultCommand(driveFieldOrientedDirectAngle);
configureBindings();

autoChooser.addOption("Top with amp", superstructure.fromTopWithAmp());
autoChooser.addOption("Top with no amp", superstructure.fromTopWithoutAmp());
autoChooser.addOption("Bottom with no amp", superstructure.fromBottomWithoutAmp());
autoChooser.addOption("Middle with no amp", superstructure.fromStartingMiddleWithoutAmp());
// autoChooser.addOption("Top with amp", superstructure.fromTopWithAmp());
// autoChooser.addOption("Top with no amp", superstructure.fromTopWithoutAmp());
// autoChooser.addOption("Bottom with no amp", superstructure.fromBottomWithoutAmp());
// autoChooser.addOption("Middle with no amp",
// superstructure.fromStartingMiddleWithoutAmp());
}

private void configureBindings() {
rightThrustmaster.getButton(Thrustmaster.Button.TRIGGER).onTrue(drivebase.resetHeading());
leftThrustmaster.getButton(Thrustmaster.Button.TRIGGER).onTrue(superstructure.shoot());
}

public Command getAutonomousCommand() {
Expand Down
Loading