Skip to content

Commit

Permalink
Merge branch 'vision' not work
Browse files Browse the repository at this point in the history
  • Loading branch information
taj-maharj08 committed Jan 25, 2025
2 parents f89e2d7 + dcfc1b9 commit d863fe5
Show file tree
Hide file tree
Showing 19 changed files with 1,921 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
"editor.defaultFormatter": "richardwillis.vscode-spotless-gradle"
},
"[java]": {
"editor.defaultFormatter": "richardwillis.vscode-spotless-gradle"

This comment has been minimized.

Copy link
@mpatankar6

mpatankar6 Jan 26, 2025

Member

@taj-maharj08 Nooo please keep using spotless. It allows us to use formatting rules defined in build.gradle which is better than defining rules in vscode. You just have to download the spotless vscode extension.

"editor.defaultFormatter": "redhat.java"
}
}
10 changes: 9 additions & 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 "2025.1.1"
id "edu.wpi.first.GradleRIO" version "2025.2.1"
}

java {
Expand Down Expand Up @@ -49,6 +49,11 @@ wpi.java.debugJni = false
// Set this to true to enable desktop support.
def includeDesktopSupport = true

task(replayWatch, type: JavaExec) {
mainClass = "org.littletonrobotics.junction.ReplayWatch"
classpath = sourceSets.main.runtimeClasspath
}

// Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries.
// Also defines JUnit 5.
dependencies {
Expand All @@ -72,6 +77,9 @@ dependencies {

testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

def akitJson = new groovy.json.JsonSlurper().parseText(new File(projectDir.getAbsolutePath() + "/vendordeps/AdvantageKit.json").text)
annotationProcessor "org.littletonrobotics.akit:akit-autolog:$akitJson.version"
}

test {
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2021-2025 FRC 6328
// http://github.com/Mechanical-Advantage
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// version 3 as published by the Free Software Foundation or
// available in the root directory of this project.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

package frc.robot;

import edu.wpi.first.wpilibj.RobotBase;

/**
* This class defines the runtime mode used by AdvantageKit. The mode is always "real" when running
* on a roboRIO. Change the value of "simMode" to switch between "sim" (physics sim) and "replay"
* (log replay from a file).
*/
public final class Constants {
public static final Mode simMode = Mode.SIM;
public static final Mode currentMode = RobotBase.isReal() ? Mode.REAL : simMode;

public static enum Mode {
/** Running on a real robot. */
REAL,

/** Running a physics simulator. */
SIM,

/** Replaying from a log file. */
REPLAY
}
}
215 changes: 215 additions & 0 deletions src/main/java/frc/robot/FieldConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
// Copyright (c) 2025 FRC 6328
// http://github.com/Mechanical-Advantage
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file at
// the root directory of this project.

package frc.robot;

import edu.wpi.first.math.geometry.*;
import edu.wpi.first.math.util.Units;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.littletonrobotics.junction.Logger;

/**
* Contains various field dimensions and useful reference points. All units are in meters and poses
* have a blue alliance origin.
*/
public class FieldConstants {
public static final double fieldLength = Units.inchesToMeters(690.876);
public static final double fieldWidth = Units.inchesToMeters(317);
public static final double startingLineX =
Units.inchesToMeters(299.438); // Measured from the inside of starting line

public static class Processor {
public static final Pose2d centerFace =
new Pose2d(Units.inchesToMeters(235.726), 0, Rotation2d.fromDegrees(90));
}

public static class Barge {
public static final Translation2d farCage =
new Translation2d(Units.inchesToMeters(345.428), Units.inchesToMeters(286.779));
public static final Translation2d middleCage =
new Translation2d(Units.inchesToMeters(345.428), Units.inchesToMeters(242.855));
public static final Translation2d closeCage =
new Translation2d(Units.inchesToMeters(345.428), Units.inchesToMeters(199.947));

// Measured from floor to bottom of cage
public static final double deepHeight = Units.inchesToMeters(3.125);
public static final double shallowHeight = Units.inchesToMeters(30.125);
}

public static class CoralStation {
public static final Pose2d leftCenterFace =
new Pose2d(
Units.inchesToMeters(33.526),
Units.inchesToMeters(291.176),
Rotation2d.fromDegrees(90 - 144.011));
public static final Pose2d rightCenterFace =
new Pose2d(
Units.inchesToMeters(33.526),
Units.inchesToMeters(25.824),
Rotation2d.fromDegrees(144.011 - 90));
}

public static class Reef {
public static final Translation2d center =
new Translation2d(Units.inchesToMeters(176.746), Units.inchesToMeters(158.501));
public static final double faceToZoneLine =
Units.inchesToMeters(12); // Side of the reef to the inside of the reef zone line

public static final Pose2d[] centerFaces =
new Pose2d[6]; // Starting facing the driver station in clockwise order
public static final List<Map<ReefHeight, Pose3d>> branchPositions =
new ArrayList<>(); // Starting at the right branch facing the driver station in clockwise

public static List<Pose2d> AlignPositions = new ArrayList<>();

static {
// Initialize faces
centerFaces[0] =
new Pose2d(
Units.inchesToMeters(144.003),
Units.inchesToMeters(158.500),
Rotation2d.fromDegrees(180));
centerFaces[1] =
new Pose2d(
Units.inchesToMeters(160.373),
Units.inchesToMeters(186.857),
Rotation2d.fromDegrees(120));
centerFaces[2] =
new Pose2d(
Units.inchesToMeters(193.116),
Units.inchesToMeters(186.858),
Rotation2d.fromDegrees(60));
centerFaces[3] =
new Pose2d(
Units.inchesToMeters(209.489),
Units.inchesToMeters(158.502),
Rotation2d.fromDegrees(0));
centerFaces[4] =
new Pose2d(
Units.inchesToMeters(193.118),
Units.inchesToMeters(130.145),
Rotation2d.fromDegrees(-60));
centerFaces[5] =
new Pose2d(
Units.inchesToMeters(160.375),
Units.inchesToMeters(130.144),
Rotation2d.fromDegrees(-120));

// Initialize branch positions
for (int face = 0; face < 6; face++) {
Map<ReefHeight, Pose3d> fillRight = new HashMap<>();
Map<ReefHeight, Pose3d> fillLeft = new HashMap<>();
for (var level : ReefHeight.values()) {
Pose2d poseDirection = new Pose2d(center, Rotation2d.fromDegrees(180 - (60 * face)));
double adjustX = Units.inchesToMeters(30.738);
double adjustY = Units.inchesToMeters(6.469);

Pose3d rightBanch = new Pose3d(
new Translation3d(
poseDirection
.transformBy(new Transform2d(adjustX, adjustY, new Rotation2d()))
.getX(),
poseDirection
.transformBy(new Transform2d(adjustX, adjustY, new Rotation2d()))
.getY(),
level.height),
new Rotation3d(
0,
Units.degreesToRadians(level.pitch),
poseDirection.getRotation().getRadians()));

Pose3d leftBranch = new Pose3d(
new Translation3d(
poseDirection
.transformBy(new Transform2d(adjustX, -adjustY, new Rotation2d()))
.getX(),
poseDirection
.transformBy(new Transform2d(adjustX, -adjustY, new Rotation2d()))
.getY(),
level.height),
new Rotation3d(
0,
Units.degreesToRadians(level.pitch),
poseDirection.getRotation().getRadians()));


fillRight.put(
level,
rightBanch
);
fillLeft.put(
level,
leftBranch
);
}
branchPositions.add((face * 2) + 1, fillRight);
branchPositions.add((face * 2) + 2, fillLeft);
}


for (int face = 0; face < 6; face++) {
Pose2d poseDirection = new Pose2d(center, Rotation2d.fromDegrees(180 - (60 * face)));
double adjustX = Units.inchesToMeters(30.738);
double adjustY = Units.inchesToMeters(6.469);

Pose2d rightBanch = new Pose2d(
new Translation2d(
poseDirection
.transformBy(new Transform2d(adjustX, adjustY, new Rotation2d()))
.getX(),
poseDirection
.transformBy(new Transform2d(adjustX, adjustY, new Rotation2d()))
.getY()),
new Rotation2d(
poseDirection.getRotation().getRadians()));

Pose2d leftBranch = new Pose2d(
new Translation2d(
poseDirection
.transformBy(new Transform2d(adjustX, -adjustY, new Rotation2d()))
.getX(),
poseDirection
.transformBy(new Transform2d(adjustX, -adjustY, new Rotation2d()))
.getY()),
new Rotation2d(
poseDirection.getRotation().getRadians()));

AlignPositions.add(leftBranch);
AlignPositions.add(rightBanch);
}
}
}

public static class StagingPositions {
// Measured from the center of the ice cream
public static final Pose2d leftIceCream =
new Pose2d(Units.inchesToMeters(48), Units.inchesToMeters(230.5), new Rotation2d());
public static final Pose2d middleIceCream =
new Pose2d(Units.inchesToMeters(48), Units.inchesToMeters(158.5), new Rotation2d());
public static final Pose2d rightIceCream =
new Pose2d(Units.inchesToMeters(48), Units.inchesToMeters(86.5), new Rotation2d());
}

public enum ReefHeight {
L4(Units.inchesToMeters(72), -90),
L3(Units.inchesToMeters(47.625), -35),
L2(Units.inchesToMeters(31.875), -35),
L1(Units.inchesToMeters(18), 0);

ReefHeight(double height, double pitch) {
this.height = height;
this.pitch = pitch; // in degrees
}

public final double height;
public final double pitch;
}
}
56 changes: 53 additions & 3 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,67 @@

package frc.robot;

import edu.wpi.first.wpilibj.TimedRobot;
import org.littletonrobotics.junction.LogFileUtil;
import org.littletonrobotics.junction.LoggedRobot;
import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.networktables.NT4Publisher;
import org.littletonrobotics.junction.wpilog.WPILOGReader;
import org.littletonrobotics.junction.wpilog.WPILOGWriter;

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

public class Robot extends TimedRobot {
public class Robot extends LoggedRobot {
private Command m_autonomousCommand;

private final RobotContainer m_robotContainer;

public Robot() {
m_robotContainer = new RobotContainer();
// Record metadata
// Logger.recordMetadata("ProjectName", BuildConstants.MAVEN_NAME);
// Logger.recordMetadata("BuildDate", BuildConstants.BUILD_DATE);
// Logger.recordMetadata("GitSHA", BuildConstants.GIT_SHA);
// Logger.recordMetadata("GitDate", BuildConstants.GIT_DATE);
// Logger.recordMetadata("GitBranch", BuildConstants.GIT_BRANCH);
// switch (BuildConstants.DIRTY) {
// case 0:
// Logger.recordMetadata("GitDirty", "All changes committed");
// break;
// case 1:
// Logger.recordMetadata("GitDirty", "Uncomitted changes");
// break;
// default:
// Logger.recordMetadata("GitDirty", "Unknown");
// break;
// }

// Set up data receivers & replay source
switch (Constants.currentMode) {
case REAL:
// Running on a real robot, log to a USB stick ("/U/logs")
// Logger.addDataReceiver(new WPILOGWriter());
Logger.addDataReceiver(new NT4Publisher());
break;

case SIM:
// Running a physics simulator, log to NT
Logger.addDataReceiver(new NT4Publisher());
break;

case REPLAY:
// Replaying a log, set up replay source
// setUseTiming(false); // Run as fast as possible
// String logPath = LogFileUtil.findReplayLog();
// Logger.setReplaySource(new WPILOGReader(logPath));
// Logger.addDataReceiver(new WPILOGWriter(LogFileUtil.addPathSuffix(logPath, "_sim")));
// break;
}

// Start AdvantageKit logger
Logger.start();
m_robotContainer = new RobotContainer();


}

@Override
Expand Down
Loading

0 comments on commit d863fe5

Please sign in to comment.