Initial Commit

This commit is contained in:
2026-03-09 12:54:51 -04:00
commit 38491e41d7
25 changed files with 1243 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
Files placed in this directory will be deployed to the RoboRIO into the
'deploy' directory in the home folder. Use the 'Filesystem.getDeployDirectory' wpilib function
to get a proper path relative to the deploy directory.

View File

@@ -0,0 +1,15 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package com.team2648;
import edu.wpi.first.wpilibj.RobotBase;
public final class Main {
private Main() {}
public static void main(String... args) {
RobotBase.startRobot(Robot::new);
}
}

View File

@@ -0,0 +1,72 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package com.team2648;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
public class Robot extends TimedRobot {
private Command m_autonomousCommand;
private final RobotContainer m_robotContainer;
public Robot() {
m_robotContainer = new RobotContainer();
}
@Override
public void robotPeriodic() {
CommandScheduler.getInstance().run();
}
@Override
public void disabledInit() {}
@Override
public void disabledPeriodic() {}
@Override
public void disabledExit() {}
@Override
public void autonomousInit() {
m_autonomousCommand = m_robotContainer.getAutonomousCommand();
if (m_autonomousCommand != null) {
CommandScheduler.getInstance().schedule(m_autonomousCommand);
}
}
@Override
public void autonomousPeriodic() {}
@Override
public void autonomousExit() {}
@Override
public void teleopInit() {
if (m_autonomousCommand != null) {
m_autonomousCommand.cancel();
}
}
@Override
public void teleopPeriodic() {}
@Override
public void teleopExit() {}
@Override
public void testInit() {
CommandScheduler.getInstance().cancelAll();
}
@Override
public void testPeriodic() {}
@Override
public void testExit() {}
}

View File

@@ -0,0 +1,20 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package com.team2648;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
public class RobotContainer {
public RobotContainer() {
configureBindings();
}
private void configureBindings() {}
public Command getAutonomousCommand() {
return Commands.print("No autonomous command configured");
}
}

View File

@@ -0,0 +1,9 @@
package com.team2648.iocore.abstracts;
public abstract class BooleanSensorIO extends IOBase {
public BooleanSensorIO(String sensorTypeName) {
super("Sensors/Booleans/" + sensorTypeName);
}
public abstract boolean get();
}

View File

@@ -0,0 +1,21 @@
package com.team2648.iocore.abstracts;
import edu.wpi.first.units.Unit;
public abstract class DoubleSensorIO<T extends Unit> extends IOBase {
private T unitReference;
public DoubleSensorIO(String sensorTypeName, T unitReference) {
super("Sensors/Doubles/" + sensorTypeName);
this.unitReference = unitReference;
}
public abstract double get();
@SuppressWarnings("unchecked")
public T getMeasure() {
return (T) unitReference.of(get());
}
}

View File

@@ -0,0 +1,25 @@
package com.team2648.iocore.abstracts;
import com.team2648.iocore.registries.IORegistry;
public abstract class IOBase {
private String ioBaseName;
public IOBase(String ioBaseName) {
this.ioBaseName = ioBaseName;
IORegistry.getInstance().addIO(this);
}
public void periodic() {
}
public void log() {
}
public String getLoggableName() {
return "IO/" + ioBaseName;
}
}

View File

@@ -0,0 +1,40 @@
package com.team2648.iocore.abstracts;
import java.util.List;
import java.util.function.DoubleSupplier;
import com.team2648.iocore.config.CommonMotorConfig;
public abstract class MotorIO extends IOBase {
public enum ControlTypes {
kDutyCycle,
kPIDPosition,
kPIDVelocity;
}
private List<ControlTypes> supportedControlTypes;
public MotorIO(String motorTypeName, ControlTypes... supportedControlTypes) {
this(motorTypeName, List.of(supportedControlTypes));
}
public MotorIO(String motorTypeName, List<ControlTypes> supportedControlTypes) {
super("Motor/" + motorTypeName);
this.supportedControlTypes = supportedControlTypes;
}
public abstract double getOutputVoltage();
public boolean isControlTypeSupported(ControlTypes type) {
return supportedControlTypes.stream().anyMatch((t) -> t.equals(type));
}
public abstract void applyConfig(CommonMotorConfig config);
public void run(ControlTypes type, DoubleSupplier controlValueSource) {
run(type, controlValueSource.getAsDouble());
}
public abstract void run(ControlTypes type, double controlValue);
}

View File

@@ -0,0 +1,19 @@
package com.team2648.iocore.config;
public class CommonMotorConfig {
private boolean isInverted;
public CommonMotorConfig() {
}
public boolean isInverted() {
return isInverted;
}
public CommonMotorConfig setInverted(boolean inverted) {
this.isInverted = inverted;
return this;
}
}

View File

@@ -0,0 +1,9 @@
package com.team2648.iocore.interfaces;
import edu.wpi.first.wpilibj.motorcontrol.PWMMotorController;
public interface PWMFollowableMotor {
public void addFollower(PWMMotorController otherMotor);
public PWMMotorController getControllerObject();
}

View File

@@ -0,0 +1,51 @@
package com.team2648.iocore.realio;
import com.team2648.iocore.abstracts.MotorIO;
import com.team2648.iocore.config.CommonMotorConfig;
import com.team2648.iocore.interfaces.PWMFollowableMotor;
import edu.wpi.first.wpilibj.RobotController;
import edu.wpi.first.wpilibj.motorcontrol.PWMMotorController;
import edu.wpi.first.wpilibj.motorcontrol.VictorSP;
public class VictorSPIO extends MotorIO implements PWMFollowableMotor{
private VictorSP motor;
public VictorSPIO(String motorName, int pwmPort) {
super("/" + motorName, ControlTypes.kDutyCycle);
motor = new VictorSP(pwmPort);
}
@Override
public double getOutputVoltage() {
return motor.get() * RobotController.getBatteryVoltage();
}
@Override
public void applyConfig(CommonMotorConfig config) {
motor.setInverted(config.isInverted());
}
@Override
public void run(ControlTypes type, double controlValue) {
switch(type) {
case kDutyCycle:
motor.set(controlValue);
break;
default:
throw new UnsupportedOperationException("VictorSPIO does not supported ControlType " + type.name());
}
}
@Override
public void addFollower(PWMMotorController otherMotor) {
this.motor.addFollower(motor);
}
@Override
public PWMMotorController getControllerObject() {
return motor;
}
}

View File

@@ -0,0 +1,39 @@
package com.team2648.iocore.registries;
import java.util.HashSet;
import java.util.Set;
import com.team2648.iocore.abstracts.IOBase;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
public class IORegistry extends SubsystemBase {
private static IORegistry registry;
private Set<IOBase> allIO;
public static IORegistry getInstance() {
if (registry == null) {
registry = new IORegistry();
}
return registry;
}
private IORegistry() {
super();
allIO = new HashSet<IOBase>();
}
@Override
public void periodic() {
for(IOBase io: allIO) {
io.periodic();
io.log();
}
}
public void addIO(IOBase io) {
allIO.add(io);
}
}