diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/EducationalRobot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/EducationalRobot.java new file mode 100644 index 0000000000..8fed60df7e --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/EducationalRobot.java @@ -0,0 +1,77 @@ +// 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 edu.wpi.first.wpilibj.templates.romieducational; + +import edu.wpi.first.hal.HAL; +import edu.wpi.first.wpilibj.DriverStation; +import edu.wpi.first.wpilibj.RobotBase; + +/** Educational robot base class. */ +public class EducationalRobot extends RobotBase { + public void robotInit() {} + + public void disabled() {} + + public void run() {} + + public void autonomous() { + run(); + } + + public void teleop() { + run(); + } + + public void test() { + run(); + } + + private volatile boolean m_exit; + + @Override + public void startCompetition() { + robotInit(); + + // Tell the DS that the robot is ready to be enabled + HAL.observeUserProgramStarting(); + + while (!Thread.currentThread().isInterrupted() && !m_exit) { + if (isDisabled()) { + DriverStation.inDisabled(true); + disabled(); + DriverStation.inDisabled(false); + while (isDisabled()) { + DriverStation.waitForData(); + } + } else if (isAutonomous()) { + DriverStation.inAutonomous(true); + autonomous(); + DriverStation.inAutonomous(false); + while (isAutonomousEnabled()) { + DriverStation.waitForData(); + } + } else if (isTest()) { + DriverStation.inTest(true); + test(); + DriverStation.inTest(false); + while (isTest() && isEnabled()) { + DriverStation.waitForData(); + } + } else { + DriverStation.inTeleop(true); + teleop(); + DriverStation.inTeleop(false); + while (isTeleopEnabled()) { + DriverStation.waitForData(); + } + } + } + } + + @Override + public void endCompetition() { + m_exit = true; + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/Main.java new file mode 100644 index 0000000000..091543ec0f --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/Main.java @@ -0,0 +1,25 @@ +// 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 edu.wpi.first.wpilibj.templates.romieducational; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. Unless you know what + * you are doing, do not modify this file except to change the parameter class to the startRobot + * call. + */ +public final class Main { + private Main() {} + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/Robot.java new file mode 100644 index 0000000000..be58b7270b --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/Robot.java @@ -0,0 +1,23 @@ +// 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 edu.wpi.first.wpilibj.templates.romieducational; + +/** + * The VM is configured to automatically run this class, and to call the run() function when the + * robot is enabled. If you change the name of this class or the package after creating this + * project, you must also update the build.gradle file in the project. + */ +public class Robot extends EducationalRobot { + /** + * This function is run when the robot is first started up and should be used for any + * initialization code. + */ + @Override + public void robotInit() {} + + /** This function is run when the robot is enabled. */ + @Override + public void run() {} +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/RomiDrivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/RomiDrivetrain.java new file mode 100644 index 0000000000..bbba080e9a --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/RomiDrivetrain.java @@ -0,0 +1,52 @@ +// 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 edu.wpi.first.wpilibj.templates.romieducational; + +import edu.wpi.first.wpilibj.Encoder; +import edu.wpi.first.wpilibj.drive.DifferentialDrive; +import edu.wpi.first.wpilibj.motorcontrol.Spark; + +public class RomiDrivetrain { + private static final double kCountsPerRevolution = 1440.0; + private static final double kWheelDiameterInch = 2.75591; // 70 mm + + // The Romi has the left and right motors set to + // PWM channels 0 and 1 respectively + private final Spark m_leftMotor = new Spark(0); + private final Spark m_rightMotor = new Spark(1); + + // The Romi has onboard encoders that are hardcoded + // to use DIO pins 4/5 and 6/7 for the left and right + private final Encoder m_leftEncoder = new Encoder(4, 5); + private final Encoder m_rightEncoder = new Encoder(6, 7); + + // Set up the differential drive controller + private final DifferentialDrive m_diffDrive = new DifferentialDrive(m_leftMotor, m_rightMotor); + + /** Creates a new RomiDrivetrain. */ + public RomiDrivetrain() { + // Use inches as unit for encoder distances + m_leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + m_rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + resetEncoders(); + } + + public void arcadeDrive(double xaxisSpeed, double zaxisRotate) { + m_diffDrive.arcadeDrive(xaxisSpeed, zaxisRotate); + } + + public void resetEncoders() { + m_leftEncoder.reset(); + m_rightEncoder.reset(); + } + + public double getLeftDistanceInch() { + return m_leftEncoder.getDistance(); + } + + public double getRightDistanceInch() { + return m_rightEncoder.getDistance(); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json index 9dd408f411..4625310adc 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json @@ -14,7 +14,8 @@ "name": "Timed Skeleton (Advanced)", "description": "Skeleton (stub) code for TimedRobot", "tags": [ - "Timed", "Skeleton" + "Timed", + "Skeleton" ], "foldername": "timedskeleton", "gradlebase": "java", @@ -25,7 +26,8 @@ "name": "RobotBase Skeleton (Advanced)", "description": "Skeleton (stub) code for RobotBase", "tags": [ - "RobotBase", "Skeleton" + "RobotBase", + "Skeleton" ], "foldername": "robotbaseskeleton", "gradlebase": "java", @@ -47,7 +49,8 @@ "name": "Romi - Timed Robot", "description": "Romi - Timed style", "tags": [ - "Timed", "Romi" + "Timed", + "Romi" ], "foldername": "romitimed", "gradlebase": "javaromi", @@ -58,7 +61,8 @@ "name": "Romi - Command Robot", "description": "Romi - Command style", "tags": [ - "Command", "Romi" + "Command", + "Romi" ], "foldername": "romicommandbased", "gradlebase": "javaromi", @@ -75,5 +79,17 @@ "gradlebase": "java", "mainclass": "Main", "commandversion": 2 + }, + { + "name": "Romi - Educational Robot", + "description": "Romi - Educational Robot", + "tags": [ + "Educational", + "Romi" + ], + "foldername": "romieducational", + "gradlebase": "javaromi", + "mainclass": "Main", + "commandversion": 2 } ]