[templates] Add Java template for educational robot (#3309)

Educational robot is a very minimal template designed for educational use
(rather than competition).
This commit is contained in:
Peter Johnson
2021-04-24 20:22:39 -07:00
committed by GitHub
parent 6e31230adc
commit 936d3b9f83
4 changed files with 136 additions and 0 deletions

View File

@@ -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.educational;
import edu.wpi.first.hal.HAL;
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;
@SuppressWarnings("PMD.CyclomaticComplexity")
@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()) {
m_ds.InDisabled(true);
disabled();
m_ds.InDisabled(false);
while (isDisabled()) {
m_ds.waitForData();
}
} else if (isAutonomous()) {
m_ds.InAutonomous(true);
autonomous();
m_ds.InAutonomous(false);
while (isAutonomousEnabled()) {
m_ds.waitForData();
}
} else if (isTest()) {
m_ds.InTest(true);
test();
m_ds.InTest(false);
while (isTest() && isEnabled()) {
m_ds.waitForData();
}
} else {
m_ds.InOperatorControl(true);
teleop();
m_ds.InOperatorControl(false);
while (isOperatorControlEnabled()) {
m_ds.waitForData();
}
}
}
}
@Override
public void endCompetition() {
m_exit = true;
}
}

View File

@@ -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.educational;
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.
*
* <p>If you change your main robot class, change the parameter type.
*/
public static void main(String... args) {
RobotBase.startRobot(Robot::new);
}
}

View File

@@ -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.educational;
/**
* 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() {}
}

View File

@@ -75,5 +75,16 @@
"gradlebase": "javaromi",
"mainclass": "Main",
"commandversion": 2
},
{
"name": "Educational Robot",
"description": "Educational Robot - Not for competition use",
"tags": [
"Educational"
],
"foldername": "educational",
"gradlebase": "java",
"mainclass": "Main",
"commandversion": 2
}
]