[examples] Add TimesliceRobot templates (#3683)

This commit is contained in:
Tyler Veness
2023-09-15 20:42:21 -07:00
committed by GitHub
parent 9047682202
commit 19a8850fb1
11 changed files with 486 additions and 0 deletions

View File

@@ -45,6 +45,29 @@
"mainclass": "Main",
"commandversion": 2
},
{
"name": "Timesice Robot",
"description": "Timeslice style",
"tags": [
"Timeslice"
],
"foldername": "timeslice",
"gradlebase": "java",
"mainclass": "Main",
"commandversion": 2
},
{
"name": "Timeslice Skeleton (Advanced)",
"description": "Skeleton (stub) code for TimesliceRobot",
"tags": [
"Timeslice",
"Skeleton"
],
"foldername": "timesliceskeleton",
"gradlebase": "java",
"mainclass": "Main",
"commandversion": 2
},
{
"name": "RobotBase Skeleton (Advanced)",
"description": "Skeleton (stub) code for RobotBase - Not recommended for competition use",

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.timeslice;
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,118 @@
// 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.timeslice;
import edu.wpi.first.wpilibj.TimesliceRobot;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
* each mode, as described in the TimesliceRobot documentation. 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 TimesliceRobot {
private static final String kDefaultAuto = "Default";
private static final String kCustomAuto = "My Auto";
private String m_autoSelected;
private final SendableChooser<String> m_chooser = new SendableChooser<>();
/** Robot constructor. */
public Robot() {
// Run robot periodic() functions for 5 ms, and run controllers every 10 ms
super(0.005, 0.01);
// LiveWindow causes drastic overruns in robot periodic functions that will
// interfere with controllers
LiveWindow.disableAllTelemetry();
// Runs for 2 ms after robot periodic functions
schedule(() -> {}, 0.002);
// Runs for 2 ms after first controller function
schedule(() -> {}, 0.002);
// Total usage: 5 ms (robot) + 2 ms (controller 1) + 2 ms (controller 2)
// = 9 ms -> 90% allocated
}
/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
m_chooser.setDefaultOption("Default Auto", kDefaultAuto);
m_chooser.addOption("My Auto", kCustomAuto);
SmartDashboard.putData("Auto choices", m_chooser);
}
/**
* This function is called every robot packet, no matter the mode. Use this for items like
* diagnostics that you want ran during disabled, autonomous, teleoperated and test.
*
* <p>This runs after the mode specific periodic functions, but before LiveWindow and
* SmartDashboard integrated updating.
*/
@Override
public void robotPeriodic() {}
/**
* This autonomous (along with the chooser code above) shows how to select between different
* autonomous modes using the dashboard. The sendable chooser code works with the Java
* SmartDashboard. If you prefer the LabVIEW Dashboard, remove all of the chooser code and
* uncomment the getString line to get the auto name from the text box below the Gyro
*
* <p>You can add additional auto modes by adding additional comparisons to the switch structure
* below with additional strings. If using the SendableChooser make sure to add them to the
* chooser code above as well.
*/
@Override
public void autonomousInit() {
m_autoSelected = m_chooser.getSelected();
// m_autoSelected = SmartDashboard.getString("Auto Selector", kDefaultAuto);
System.out.println("Auto selected: " + m_autoSelected);
}
/** This function is called periodically during autonomous. */
@Override
public void autonomousPeriodic() {
switch (m_autoSelected) {
case kCustomAuto:
// Put custom auto code here
break;
case kDefaultAuto:
default:
// Put default auto code here
break;
}
}
/** This function is called once when teleop is enabled. */
@Override
public void teleopInit() {}
/** This function is called periodically during operator control. */
@Override
public void teleopPeriodic() {}
/** This function is called once when the robot is disabled. */
@Override
public void disabledInit() {}
/** This function is called periodically when disabled. */
@Override
public void disabledPeriodic() {}
/** This function is called once when test mode is enabled. */
@Override
public void testInit() {}
/** This function is called periodically during test mode. */
@Override
public void testPeriodic() {}
}

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.timesliceskeleton;
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,70 @@
// 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.timesliceskeleton;
import edu.wpi.first.wpilibj.TimesliceRobot;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
* each mode, as described in the TimesliceRobot documentation. 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 TimesliceRobot {
/** Robot constructor. */
public Robot() {
// Run robot periodic() functions for 5 ms, and run controllers every 10 ms
super(0.005, 0.01);
// LiveWindow causes drastic overruns in robot periodic functions that will
// interfere with controllers
LiveWindow.disableAllTelemetry();
// Runs for 2 ms after robot periodic functions
schedule(() -> {}, 0.002);
// Runs for 2 ms after first controller function
schedule(() -> {}, 0.002);
// Total usage:
// 5 ms (robot) + 2 ms (controller 1) + 2 ms (controller 2) = 9 ms
// 9 ms / 10 ms -> 90% allocated
}
/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {}
@Override
public void robotPeriodic() {}
@Override
public void autonomousInit() {}
@Override
public void autonomousPeriodic() {}
@Override
public void teleopInit() {}
@Override
public void teleopPeriodic() {}
@Override
public void disabledInit() {}
@Override
public void disabledPeriodic() {}
@Override
public void testInit() {}
@Override
public void testPeriodic() {}
}