Skip to content

Commit

Permalink
Move new
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancahoon-zoox authored and rcahoon committed Nov 11, 2024
1 parent 5ac4c96 commit 5d69f7b
Show file tree
Hide file tree
Showing 102 changed files with 304 additions and 277 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

public class AdvancedUtils {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.team766.framework3;
package com.team766.framework;

import com.team766.web.AutonomousSelector;
import edu.wpi.first.wpilibj2.command.Command;
import java.util.function.Supplier;

public class AutonomousMode implements AutonomousSelector.Selectable<AutonomousMode> {
public class AutonomousMode {
private final Supplier<Command> m_constructor;
private final String m_name;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

import com.team766.library.Holder;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

import java.util.function.BooleanSupplier;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.team766.framework3;
package com.team766.framework;

import com.team766.framework.ContextStoppedException;
import com.team766.framework.StackTraceUtils;
import com.team766.hal.Clock;
import com.team766.hal.RobotProvider;
import com.team766.logging.Category;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

import java.util.Set;
import java.util.function.Consumer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

import edu.wpi.first.wpilibj2.command.Command;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

/**
* This interface can be used by the caller to manage Contexts created by startAsync.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

import com.team766.logging.Category;
import com.team766.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

import com.team766.logging.Category;
import com.team766.logging.LoggerExceptionUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

import com.google.common.collect.Sets;
import com.team766.logging.Category;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

/**
* Code (typically in a Procedure) that manipulates Mechanisms can simply make {@link Request}s of the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.team766.framework3;
package com.team766.framework;

import com.team766.framework.StackTraceUtils;
import com.team766.logging.Category;
import com.team766.logging.Logger;
import com.team766.logging.Severity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

import com.google.common.collect.Maps;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.BiMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

public enum RulePersistence {
ONCE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.team766.framework3;
package com.team766.framework;

import com.team766.framework.StackTraceUtils;
import com.team766.logging.Category;
import com.team766.logging.Logger;
import com.team766.logging.Severity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

import com.team766.logging.Category;
import com.team766.logging.LoggerExceptionUtils;
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/team766/framework/SerializableLambda.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.team766.framework;

import java.io.Serializable;
import java.lang.invoke.SerializedLambda;
import java.lang.reflect.Method;

public interface SerializableLambda extends Serializable {
public interface Runnable extends java.lang.Runnable, SerializableLambda {}

public interface Supplier<T> extends java.util.function.Supplier<T>, SerializableLambda {}

private static SerializedLambda getSerializedLambda(SerializableLambda lambda) {
SerializedLambda serializedLambda = null;
for (Class<?> cl = lambda.getClass(); cl != null; cl = cl.getSuperclass()) {
try {
Method method = cl.getDeclaredMethod("writeReplace");
method.setAccessible(true);
Object replacement = method.invoke(lambda);
if (!(replacement instanceof SerializedLambda)) {
break; // custom interface implementation
}
serializedLambda = (SerializedLambda) replacement;
break;
} catch (NoSuchMethodException e) {
// ignore
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
if (serializedLambda == null) {
throw new IllegalArgumentException("Cannot find SerializedLambda for " + lambda);
}
return serializedLambda;
}

/* package */ static Object[] getLambdaCaptures(SerializableLambda lambda) {
final SerializedLambda serializedLambda = getSerializedLambda(lambda);
final int count = serializedLambda.getCapturedArgCount();
final Object[] result = new Object[count];
for (int i = 0; i < count; ++i) {
result[i] = serializedLambda.getCapturedArg(i);
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

/**
* Marker interface for Statuses. Mechanisms and complex Procedures can publish Statuses to let
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

import com.team766.hal.RobotProvider;
import com.team766.logging.Category;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team766.framework3;
package com.team766.framework;

import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Subsystem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.team766.hal;

import com.team766.framework3.AutonomousMode;
import com.team766.framework3.RuleEngine;
import com.team766.framework3.SchedulerMonitor;
import com.team766.framework3.SchedulerUtils;
import com.team766.framework.AutonomousMode;
import com.team766.framework.RuleEngine;
import com.team766.framework.SchedulerMonitor;
import com.team766.framework.SchedulerUtils;
import com.team766.library.RateLimiter;
import com.team766.logging.Category;
import com.team766.logging.Logger;
Expand All @@ -20,13 +20,13 @@

// Team 766 - Robot Interface Base class

public final class GenericRobotMain3 implements GenericRobotMainBase {
private RobotConfigurator3 configurator;
public final class GenericRobotMain {
private RobotConfigurator configurator;
private RuleEngine m_oi;
private RuleEngine m_lights;

private WebServer m_webServer;
private AutonomousSelector<AutonomousMode> m_autonSelector;
private AutonomousSelector m_autonSelector;
private AutonomousMode m_autonMode = null;
private Command m_autonomous = null;

Expand All @@ -41,12 +41,12 @@ public final class GenericRobotMain3 implements GenericRobotMainBase {
private boolean faultInAutoInit = false;
private boolean faultInTeleopInit = false;

public GenericRobotMain3(RobotConfigurator3 configurator) {
public GenericRobotMain() {
SchedulerUtils.reset();
SchedulerMonitor.start();

this.configurator = configurator;
m_autonSelector = new AutonomousSelector<>(configurator.getAutonomousModes());
configurator = RobotSelector.createConfigurator();
m_autonSelector = new AutonomousSelector(configurator.getAutonomousModes());
m_webServer = new WebServer();
m_webServer.addHandler(new Dashboard());
m_webServer.addHandler(new DriverInterface(m_autonSelector));
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/com/team766/hal/LocalMotorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import com.ctre.phoenix.motorcontrol.FeedbackDevice;
import com.ctre.phoenix.motorcontrol.NeutralMode;
import com.team766.controllers.PIDController;
import com.team766.framework.Scheduler;
import com.team766.logging.Category;
import com.team766.logging.Logger;
import com.team766.logging.LoggerExceptionUtils;
import com.team766.logging.Severity;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.Subsystem;

public class LocalMotorController implements MotorController {
private BasicMotorController motor;
Expand All @@ -34,13 +35,18 @@ public LocalMotorController(
}
this.pidController = PIDController.loadFromConfig(configPrefix + "pid.");

// TODO(MF3): Use CommandScheduler.getInstance().registerSubsystem() when converted to MF3
Scheduler.getInstance()
.add(
new Runnable() {
// Register for a periodic callback from the scheduler.
// Register as a Subsystem (rather than a Command) so that we are called in the same phase
// as the real Subsystems. Because this LocalMotorController is almost certainly created
// inside of a Subsystem and the scheduler keeps the Subsystems in insertion order, this has
// the effect that this callback will be called immediately after the periodic function of
// the Subsystem which owns this LocalMotorController. This has the desirable effect that
// any setpoints,etc which are set by the Subsystem immediately take effect.
CommandScheduler.getInstance()
.registerSubsystem(
new Subsystem() {
@Override
public void run() {

public void periodic() {
if (leader != null) {
setPower(leader.get());
return;
Expand Down Expand Up @@ -87,7 +93,7 @@ public void run() {
}

@Override
public String toString() {
public String getName() {
return LocalMotorController.this.toString();
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.team766.hal;

import com.team766.framework3.AutonomousMode;
import com.team766.framework3.RuleEngine;
import com.team766.logging.Category;
import com.team766.logging.Logger;
import com.team766.logging.Severity;
import com.team766.framework.AutonomousMode;
import com.team766.framework.RuleEngine;

/**
* Provides Robot-specific components: initializes {@link Mechanism}s, creates the Operator Interface (OI),
* and returns the {@link AutonomousMode}s.
*
* @see RobotSelector
*/
public interface RobotConfigurator3 extends RobotConfiguratorBase {
public interface RobotConfigurator {

/**
* Initializes the {@link Mechanism}s for this robot.
Expand All @@ -35,10 +32,4 @@ public interface RobotConfigurator3 extends RobotConfiguratorBase {
* Returns an array of {@link AutonomousMode}s available for this robot.
*/
AutonomousMode[] getAutonomousModes();

@Override
default GenericRobotMainBase createRobotMain() {
Logger.get(Category.FRAMEWORK).logRaw(Severity.INFO, "Instantiating GenericRobotMain3");
return new GenericRobotMain3(this);
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/team766/hal/RobotSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private RobotSelector() {} // utility class
* Creates a configurator specified by the 'robotConfigurator' key in the config file.
* If unable to create this configurator, backs off to the example one.
*/
public static RobotConfiguratorBase createConfigurator() {
public static RobotConfigurator createConfigurator() {
ValueProvider<String> configuratorProvider =
ConfigFileReader.instance.getString(ROBOT_CONFIGURATOR_KEY);
String robotConfigurator =
Expand All @@ -37,8 +37,8 @@ public static RobotConfiguratorBase createConfigurator() {

try {
@SuppressWarnings("unchecked")
Class<RobotConfiguratorBase> clazz =
(Class<RobotConfiguratorBase>) Class.forName(robotConfigurator);
Class<RobotConfigurator> clazz =
(Class<RobotConfigurator>) Class.forName(robotConfigurator);
return clazz.getDeclaredConstructor().newInstance();
} catch (Exception e) {
Logger.get(Category.CONFIGURATION)
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/team766/hal/simulator/RobotMain.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.team766.hal.simulator;

import com.team766.config.ConfigFileReader;
import com.team766.hal.GenericRobotMainBase;
import com.team766.hal.GenericRobotMain;
import com.team766.hal.RobotProvider;
import com.team766.hal.RobotSelector;
import com.team766.logging.LoggerExceptionUtils;
import com.team766.simulator.Program;
import com.team766.simulator.ProgramInterface;
Expand All @@ -16,7 +15,7 @@ enum Mode {
VrConnector,
}

private GenericRobotMainBase robot;
private GenericRobotMain robot;
private Runnable simulator;

public RobotMain(final Mode mode) {
Expand All @@ -25,7 +24,7 @@ public RobotMain(final Mode mode) {
ConfigFileReader.instance = new ConfigFileReader("simConfig.txt");
RobotProvider.instance = new SimulationRobotProvider();

robot = RobotSelector.createConfigurator().createRobotMain();
robot = new GenericRobotMain();

robot.robotInit();

Expand Down
Loading

0 comments on commit 5d69f7b

Please sign in to comment.