diff --git a/build.gradle b/build.gradle index 8d3b4ea..aad9d37 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ plugins { id "java" - id "edu.wpi.first.GradleRIO" version "2024.1.1" + id "edu.wpi.first.GradleRIO" version "2024.3.2" + id "com.peterabeles.gversion" version "1.10" } java { @@ -47,6 +48,17 @@ wpi.java.debugJni = false // Set this to true to enable desktop support. def includeDesktopSupport = true +allprojects { + repositories { + maven { url 'https://jitpack.io' }//for lib199 + } +} + +// Don't cache changing modules +configurations.all { + resolutionStrategy.cacheChangingModulesFor 0, 'seconds' +} + // Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries. // Also defines JUnit 5. dependencies { @@ -68,11 +80,7 @@ dependencies { simulationRelease wpi.sim.enableRelease() testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1' - implementation('org.carlmontrobotics:lib199') { - version { - branch = '2024' - } - } + implementation "com.github.deepbluerobotics:lib199:400693b52180c82a1f26c08025bc12f144b930f9" } test { @@ -103,3 +111,13 @@ wpi.java.configureTestTasks(test) tasks.withType(JavaCompile) { options.compilerArgs.add '-XDstringConcat=inline' } + +project.compileJava.dependsOn(createVersionFile) +gversion { + language = "Properties" + srcDir = "src/main/deploy/" + className = "BuildInfo.properties" + dateFormat = "yyyy-MM-dd HH:mm:ss z" + timeZone = "America/Los_Angeles" + indent = " " +} \ No newline at end of file diff --git a/src/main/deploy/BuildInfo.properties b/src/main/deploy/BuildInfo.properties new file mode 100644 index 0000000..ac700ab --- /dev/null +++ b/src/main/deploy/BuildInfo.properties @@ -0,0 +1,12 @@ +#Created by build system. Do not modify +#"2024-09-28 18:42:00 PDT" +version="unspecified" +revision=9 +name="EmptyProject2024" +timestamp=1727574120858 +group="" +sha="e0a5b83b19826fcc5a1cef794b05680ea0cf1d02" +git_date="2024-09-27 22:31:58 PDT" +git_branch="Matthew-Backup-M-A-Drivetrain" +build_date="2024-09-28 18:42:00 PDT" +dirty=1 diff --git a/src/main/java/org/carlmontrobotics/Constants.java b/src/main/java/org/carlmontrobotics/Constants.java index 6d6986d..c87d0ce 100644 --- a/src/main/java/org/carlmontrobotics/Constants.java +++ b/src/main/java/org/carlmontrobotics/Constants.java @@ -1,15 +1,17 @@ package org.carlmontrobotics; public final class Constants { - // public static final class Drivetrain { - // public static final double MAX_SPEED_MPS = 2; - // } - public static final class OI { - public static final class Driver { - public static final int port = 0; - } - public static final class Manipulator { - public static final int port = 1; - } + + public final class Drivetrainc{ + public static final double halfDriveSpeedMultiplier = 0.5; + public static final double GOAL_FEET = 6.5; + public static final int WHEEL_RADIUS = 2; + public static final int RIGHTDT_PORT = 0; + public static final int LEFTDT_PORT = 1; + } + + public final class IO{ + public static final int MANIPULATOR_CONTROLLER_PORT = 3; + public static final int DRIVER_CONTROLLER_PORT = 2; } } diff --git a/src/main/java/org/carlmontrobotics/RobotContainer.java b/src/main/java/org/carlmontrobotics/RobotContainer.java index 836869c..87c3861 100644 --- a/src/main/java/org/carlmontrobotics/RobotContainer.java +++ b/src/main/java/org/carlmontrobotics/RobotContainer.java @@ -7,10 +7,14 @@ //199 files // import org.carlmontrobotics.subsystems.*; // import org.carlmontrobotics.commands.*; -import static org.carlmontrobotics.Constants.OI; + +import org.carlmontrobotics.Constants.*; +import org.carlmontrobotics.commands.Autonomous; //controllers import edu.wpi.first.wpilibj.GenericHID; +import edu.wpi.first.wpilibj.Joystick; +import edu.wpi.first.wpilibj.XboxController; import edu.wpi.first.wpilibj.XboxController.Axis; //commands @@ -24,69 +28,45 @@ import edu.wpi.first.wpilibj2.command.button.JoystickButton; import edu.wpi.first.wpilibj2.command.button.POVButton; import edu.wpi.first.wpilibj2.command.button.Trigger; +import org.carlmontrobotics.subsystems.Drivetrain; + public class RobotContainer { //1. using GenericHID allows us to use different kinds of controllers //2. Use absolute paths from constants to reduce confusion - public final GenericHID driverController = new GenericHID(OI.Driver.port); - public final GenericHID manipulatorController = new GenericHID(OI.Manipulator.port); + private final XboxController driverController = new XboxController(Constants.IO.DRIVER_CONTROLLER_PORT); + private final XboxController manipulatorController = new XboxController(Constants.IO.MANIPULATOR_CONTROLLER_PORT); + private final Drivetrain drivetrain = new Drivetrain(driverController); public RobotContainer() { - setDefaultCommands(); setBindingsDriver(); setBindingsManipulator(); } private void setDefaultCommands() { - // drivetrain.setDefaultCommand(new TeleopDrive( - // drivetrain, - // () -> ProcessedAxisValue(driverController, Axis.kLeftY)), - // () -> ProcessedAxisValue(driverController, Axis.kLeftX)), - // () -> ProcessedAxisValue(driverController, Axis.kRightX)), - // () -> driverController.getRawButton(OI.Driver.slowDriveButton) - // )); + } - private void setBindingsDriver() {} - private void setBindingsManipulator() {} + private void setBindingsDriver() { - public Command getAutonomousCommand() { - return Commands.print("No autonomous command configured"); + } + private void setBindingsManipulator() { + } - /** - * Flips an axis' Y coordinates upside down, but only if the select axis is a joystick axis - * - * @param hid The controller/plane joystick the axis is on - * @param axis The processed axis - * @return The processed value. - */ - private double getStickValue(GenericHID hid, Axis axis) { - return hid.getRawAxis(axis.value) * (axis == Axis.kLeftY || axis == Axis.kRightY ? -1 : 1); + + + public double rightJoystickValue() { + return driverController.getRightY(); } - /** - * Processes an input from the joystick into a value between -1 and 1, sinusoidally instead of linearly - * - * @param value The value to be processed. - * @return The processed value. - */ - private double inputProcessing(double value) { - double processedInput; - // processedInput = - // (((1-Math.cos(value*Math.PI))/2)*((1-Math.cos(value*Math.PI))/2))*(value/Math.abs(value)); - processedInput = Math.copySign(((1 - Math.cos(value * Math.PI)) / 2) * ((1 - Math.cos(value * Math.PI)) / 2), - value); - return processedInput; + public double leftJoystickValue() { + return driverController.getLeftY(); } - /** - * Combines both getStickValue and inputProcessing into a single function for processing joystick outputs - * - * @param hid The controller/plane joystick the axis is on - * @param axis The processed axis - * @return The processed value. - */ - private double ProcessedAxisValue(GenericHID hid, Axis axis){ - return inputProcessing(getStickValue(hid, axis)); + + + + public Command getAutonomousCommand() { + return new Autonomous(drivetrain); } } diff --git a/src/main/java/org/carlmontrobotics/commands/Autonomous.java b/src/main/java/org/carlmontrobotics/commands/Autonomous.java new file mode 100644 index 0000000..f1e5344 --- /dev/null +++ b/src/main/java/org/carlmontrobotics/commands/Autonomous.java @@ -0,0 +1,44 @@ +// 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 org.carlmontrobotics.commands; + +import edu.wpi.first.wpilibj2.command.Command; + +import org.carlmontrobotics.Constants; +import org.carlmontrobotics.subsystems.Drivetrain; + +public class Autonomous extends Command { + /** Creates a new Autonomous. */ + private final Drivetrain dt; + + public Autonomous(Drivetrain drivetrain) { + addRequirements(dt = drivetrain); + // Use addRequirements() here to declare subsystem dependencies. + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + dt.setAuto(true); + dt.autoDrive(); + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() {} + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + dt.setAuto(false); + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return dt.rightPosition() * (Constants.Drivetrainc.WHEEL_RADIUS*2) >= (Constants.Drivetrainc.GOAL_FEET)/12; + //TODO: for MA, change wheel radius and goal pos if needed + } +} diff --git a/src/main/java/org/carlmontrobotics/subsystems/Drivetrain.java b/src/main/java/org/carlmontrobotics/subsystems/Drivetrain.java new file mode 100644 index 0000000..48817ff --- /dev/null +++ b/src/main/java/org/carlmontrobotics/subsystems/Drivetrain.java @@ -0,0 +1,69 @@ +// 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 org.carlmontrobotics.subsystems; + +import org.carlmontrobotics.lib199.MotorConfig; +import org.carlmontrobotics.lib199.MotorControllerFactory; + +import org.carlmontrobotics.Constants.*; + +import com.revrobotics.CANSparkMax; +import com.revrobotics.RelativeEncoder; + +import org.carlmontrobotics.subsystems.*; +import static org.carlmontrobotics.Constants.Drivetrainc.*; +import static org.carlmontrobotics.RobotContainer.*; + +import org.carlmontrobotics.Constants; + +import edu.wpi.first.wpilibj.GenericHID; +import edu.wpi.first.wpilibj.Joystick; +import edu.wpi.first.wpilibj.XboxController; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj2.command.SubsystemBase; +import org.carlmontrobotics.RobotContainer.*; + +public class Drivetrain extends SubsystemBase { + /** Creates a new Drivetrain. */ + //private final CANSparkMax left = MotorControllerFactory.createSparkMax(Constants.Driver.leftDriveSparkMax, TemperatureLimit.NEO); + //private final CANSparkMax right = MotorControllerFactory.createSparkMax(Constants.MotorPorts.rightDriveSparkMax, TemperatureLimit.NEO); + private boolean isAuto = false; + + private final CANSparkMax right = MotorControllerFactory.createSparkMax(LEFTDT_PORT, MotorConfig.NEO); + private final CANSparkMax left = MotorControllerFactory.createSparkMax(RIGHTDT_PORT, MotorConfig.NEO); + private RelativeEncoder rightEncoder = right.getEncoder(); + private final XboxController controller; + + public Drivetrain(XboxController driverController) { + this.controller = driverController; + } + public void drive(double rightJoystickValue, double leftJoystickValue) { + //TODO: If needed, set inversions for motors + left.set(leftJoystickValue); + right.set(rightJoystickValue); + } + public void slowmode() { + double rightSlow = controller.getRightY() * Constants.Drivetrainc.halfDriveSpeedMultiplier; + double leftSlow = controller.getLeftY() * Constants.Drivetrainc.halfDriveSpeedMultiplier; + left.set(leftSlow); + right.set(rightSlow); + } + + + public double rightPosition() { + return rightEncoder.getPosition(); + } + public void setAuto(boolean isAutonomous) { + isAuto = isAutonomous; + } + public void autoDrive() { + left.set(0.3); + right.set(0.3); + } + + + @Override + public void periodic() {} +}