Skip to content

Commit

Permalink
Merge pull request #43 from varun7654/move-robot-side-to-main-reop
Browse files Browse the repository at this point in the history
Move robot side to main reop
  • Loading branch information
varun7654 authored Oct 27, 2023
2 parents b82261e + 392b396 commit 4c948f1
Show file tree
Hide file tree
Showing 198 changed files with 4,595 additions and 12,191 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ Thumbs.db

/desktop/out/*

sonarlint
sonarlint
/autobuilder-robot/build/
2 changes: 2 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/modules/AutoBuilder.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/modules/core/AutoBuilder.core.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/modules/core/AutoBuilder.core.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/modules/core/AutoBuilder.core.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/modules/desktop/AutoBuilder.desktop.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/modules/desktop/AutoBuilder.desktop.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/modules/desktop/AutoBuilder.desktop.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions autobuilder-robot/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
plugins {
// Apply the java-library plugin for API and implementation separation.
id 'java-library'
id 'maven-publish'
id "java"
id 'signing'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

group = 'com.dacubeking'
version = '2.2.8'
var wpilibVersion = "2023.4.3"

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()

repositories {
maven {
url "https://frcmaven.wpi.edu/artifactory/release/"
}
}
}

dependencies {
implementation 'org.jetbrains:annotations:23.0.0'

// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
implementation 'com.google.guava:guava:31.1-jre'
implementation 'org.reflections:reflections:0.10.2'


implementation "edu.wpi.first.wpilibj:wpilibj-java:${wpilibVersion}"
implementation "edu.wpi.first.wpimath:wpimath-java:${wpilibVersion}"
implementation "edu.wpi.first.ntcore:ntcore-java:${wpilibVersion}"
implementation "edu.wpi.first.hal:hal-java:${wpilibVersion}"
implementation "edu.wpi.first.wpinet:wpinet-java:${wpilibVersion}"
implementation "edu.wpi.first.wpiutil:wpiutil-java:${wpilibVersion}"
// implementation "edu.wpi.first.cscore:cscore-java:${wpilibVersion}"
// implementation "edu.wpi.first.cameraserver:cameraserver-java:${wpilibVersion}"


implementation "edu.wpi.first.wpilibNewCommands:wpilibNewCommands-java:${wpilibVersion}"


implementation 'org.msgpack:jackson-dataformat-msgpack:0.9.3'
}

tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}

java {
withSourcesJar()
withJavadocJar()
}

publishing {
publications {
myLibrary(MavenPublication) {
from components.java
}
}

publishing {
repositories {
maven {
name = "releases"
credentials(PasswordCredentials)
url = uri("https://maven.dacubeking.com/releases/")
}

maven {
name = "snapshots"
credentials(PasswordCredentials)
url = uri("https://maven.dacubeking.com/snapshots/")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package com.dacubeking.AutoBuilder.robot;

import com.dacubeking.AutoBuilder.robot.robotinterface.AutonomousContainer;
import com.dacubeking.AutoBuilder.robot.serialization.AbstractAutonomousStep;
import com.dacubeking.AutoBuilder.robot.serialization.Autonomous;
import com.dacubeking.AutoBuilder.robot.serialization.Serializer;
import com.dacubeking.AutoBuilder.robot.serialization.TrajectoryAutonomousStep;
import com.dacubeking.AutoBuilder.robot.serialization.command.CommandExecutionFailedException;
import com.dacubeking.AutoBuilder.robot.serialization.command.SendableScript;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.trajectory.Trajectory;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Timer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

import static com.dacubeking.AutoBuilder.robot.robotinterface.AutonomousContainer.getCommandTranslator;

public class GuiAuto implements Runnable {

private static final Autonomous DO_NOTHING_AUTONOMOUS = new Autonomous(new ArrayList<>());
private @NotNull Autonomous autonomous = DO_NOTHING_AUTONOMOUS; // default to do nothing in case of some error
private @Nullable Pose2d initialPose;

/**
* Ensure you are creating the objects for your auto on robot init. The roborio will take multiple seconds to initialize the
* auto.
*
* @param autonomousFile File location of the auto
*/
public GuiAuto(File autonomousFile) throws IOException {
autonomous = (Autonomous) Serializer.deserializeFromFile(autonomousFile, Autonomous.class,
autonomousFile.getName().endsWith(".json"));
init();
}

/**
* Ensure you are creating the objects for your auto before you run them. The roborio will take multiple seconds to initialize
* the auto.
*
* @param autonomousJson String of the autonomous
*/
public GuiAuto(String autonomousJson) {
try {
autonomous = (Autonomous) Serializer.deserialize(autonomousJson, Autonomous.class, true);
} catch (IOException e) {
DriverStation.reportError("Failed to deserialize auto. " + e.getMessage(), e.getStackTrace());
// The do nothing auto will be used
}
init();
}

/**
* Finds and saves the initial pose of the robot.
*/
private void init() {
for (AbstractAutonomousStep autonomousStep : autonomous.getAutonomousSteps()) {
if (autonomousStep instanceof TrajectoryAutonomousStep) {
TrajectoryAutonomousStep trajectoryAutonomousStep = (TrajectoryAutonomousStep) autonomousStep;
Trajectory.State initialState = trajectoryAutonomousStep.getTrajectory().getStates().get(0);
initialPose = new Pose2d(initialState.poseMeters.getTranslation(),
trajectoryAutonomousStep.getRotations().get(0).getRotation());
break;
}
}
}

/**
* Runs the autonomous.
*/
@Override
public void run() {
AutonomousContainer.getInstance().isInitialized();

Thread.currentThread().setUncaughtExceptionHandler((t, e) -> {
DriverStation.reportError("Uncaught exception in auto thread: " + e.getMessage(), e.getStackTrace());
getCommandTranslator().stopRobot();
});

if (autonomous == DO_NOTHING_AUTONOMOUS) {
DriverStation.reportError("No auto was loaded. Doing nothing.", false);
return;
}

AutonomousContainer.getInstance().printDebug("Started Running: " + Timer.getFPGATimestamp());


//Set our initial pose in our robot tracker
if (initialPose != null) {
getCommandTranslator().setRobotPose(initialPose);
AutonomousContainer.getInstance().printDebug("Set initial pose: " + initialPose);
} else {
AutonomousContainer.getInstance().printDebug("No initial pose set");
}

//Loop though all the steps and execute them
List<SendableScript> scriptsToExecuteByTime = new ArrayList<>();
List<SendableScript> scriptsToExecuteByPercent = new ArrayList<>();

for (AbstractAutonomousStep autonomousStep : autonomous.getAutonomousSteps()) {
AutonomousContainer.getInstance().printDebug("Doing a step: " + Timer.getFPGATimestamp());

if (Thread.interrupted()) {
getCommandTranslator().stopRobot();
AutonomousContainer.getInstance().printDebug("Auto was interrupted " + Timer.getFPGATimestamp());
return;
}

try {
autonomousStep.execute(scriptsToExecuteByTime, scriptsToExecuteByPercent);
} catch (InterruptedException e) {
getCommandTranslator().stopRobot();
AutonomousContainer.getInstance().printDebug("Auto prematurely stopped at " + Timer.getFPGATimestamp() +
". This is not an error if you disabled your robot.");
if (AutonomousContainer.getInstance().areDebugPrintsEnabled()) {
e.printStackTrace();
}
return;
} catch (CommandExecutionFailedException | ExecutionException e) {
getCommandTranslator().stopRobot();
e.printStackTrace(); // We should always print this out since it is a fatal error
return;
}
}

System.out.println("Finished Autonomous at " + Timer.getFPGATimestamp());
getCommandTranslator().stopRobot();
}

/**
* Gets the initial pose of the robot.
*
* @return The initial pose of the robot.
*/
public @Nullable Pose2d getInitialPose() {
return initialPose;
}

@Override
public String toString() {
return "GuiAuto{" +
"initialPose=" + initialPose +
",autonomous=" + autonomous +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.dacubeking.AutoBuilder.robot;

import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
import org.jetbrains.annotations.NotNull;

public class NetworkAuto extends GuiAuto {

static final @NotNull NetworkTableInstance instance = NetworkTableInstance.getDefault();
static final @NotNull NetworkTable table = instance.getTable("autodata");
static final @NotNull NetworkTableEntry autoPath = table.getEntry("autoPath");

/**
* Deserializes an auto form a NT entry.
*/
public NetworkAuto() {
super(autoPath.getString(null));
}
}
Loading

0 comments on commit 4c948f1

Please sign in to comment.