From 597e209c0949de53b4fa785f6d68cde4946ae683 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 14 Aug 2014 07:46:49 -0400 Subject: [PATCH] Add back SampleRobot Template Add GettingStarted example based on IterativeRobot Change-Id: Ic8caec4f62b7bdbaae7fafedfec5859b2f936809 --- .../core/wizards/NewProjectMainPage.java | 9 ++- .../plugins/core/wizards/ProjectType.java | 2 +- .../examples/GettingStarted/src/Robot.cpp | 59 ++++++++++++++++ .../resources/templates/examples/examples.xml | 20 ++++++ .../wizards/newproject/CPPProjectType.java | 8 +++ .../org/usfirst/frc/team190/robot/Robot.java | 69 +++++++++++++++++++ .../resources/templates/examples/examples.xml | 19 +++++ .../resources/templates/sample/Robot.java | 3 + .../wizards/newproject/JavaProjectType.java | 6 +- 9 files changed, 190 insertions(+), 5 deletions(-) create mode 100644 eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GettingStarted/src/Robot.cpp create mode 100644 eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/GettingStarted/src/org/usfirst/frc/team190/robot/Robot.java diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.core/src/main/java/edu/wpi/first/wpilib/plugins/core/wizards/NewProjectMainPage.java b/eclipse-plugins/edu.wpi.first.wpilib.plugins.core/src/main/java/edu/wpi/first/wpilib/plugins/core/wizards/NewProjectMainPage.java index d253820a49..db27d8f8d5 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.core/src/main/java/edu/wpi/first/wpilib/plugins/core/wizards/NewProjectMainPage.java +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.core/src/main/java/edu/wpi/first/wpilib/plugins/core/wizards/NewProjectMainPage.java @@ -35,7 +35,7 @@ public class NewProjectMainPage extends WizardPage { private Text worldText; private Button worldButton; - Button iterativeRobot, commandRobot; + Button iterativeRobot, commandRobot, sampleRobot; private boolean showPackage; private boolean showProjectTypes; private TeamNumberPage teamNumberPage; @@ -109,6 +109,12 @@ public class NewProjectMainPage extends WizardPage { gd = new GridData(GridData.FILL_HORIZONTAL); gd.widthHint = 300; commandRobot.setLayoutData(gd); + + sampleRobot = new Button(projectTypeGroup, SWT.RADIO | SWT.WRAP); + sampleRobot.setText("Sample Robot: A robot project used for small sample programs or for highly advanced programs with more complete control over program flow"); + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.widthHint = 300; + sampleRobot.setLayoutData(gd); } label = new Label(container, SWT.NULL); @@ -214,6 +220,7 @@ public class NewProjectMainPage extends WizardPage { public ProjectType getProjectType() { if (!showProjectTypes) return null; else if (iterativeRobot.getSelection()) return types.get(ProjectType.ITERATIVE); + else if (sampleRobot.getSelection()) return types.get(ProjectType.SAMPLE); else return types.get(ProjectType.COMMAND_BASED); } diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.core/src/main/java/edu/wpi/first/wpilib/plugins/core/wizards/ProjectType.java b/eclipse-plugins/edu.wpi.first.wpilib.plugins.core/src/main/java/edu/wpi/first/wpilib/plugins/core/wizards/ProjectType.java index 17433743be..794095be03 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.core/src/main/java/edu/wpi/first/wpilib/plugins/core/wizards/ProjectType.java +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.core/src/main/java/edu/wpi/first/wpilib/plugins/core/wizards/ProjectType.java @@ -4,7 +4,7 @@ import java.net.URL; import java.util.Map; public interface ProjectType { - String SIMPLE = "SIMPLE"; + String SAMPLE = "SAMPLE"; String ITERATIVE = "ITERATIVE"; String COMMAND_BASED = "COMMAND_BASED"; diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GettingStarted/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GettingStarted/src/Robot.cpp new file mode 100644 index 0000000000..dcbadc89c6 --- /dev/null +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GettingStarted/src/Robot.cpp @@ -0,0 +1,59 @@ +#include "WPILib.h" + +class Robot: public IterativeRobot +{ + + RobotDrive myRobot; // robot drive system + Joystick stick; // only joystick + LiveWindow *lw; + int autoLoopCounter; + +public: + Robot() : + myRobot(0, 1), // these must be initialized in the same order + stick(1), // as they are declared above. + lw(NULL), + autoLoopCounter(0) + { + myRobot.SetExpiration(0.1); + } + +private: + void RobotInit() + { + lw = LiveWindow::GetInstance(); + } + + void AutonomousInit() + { + autoLoopCounter = 0; + } + + void AutonomousPeriodic() + { + if(autoLoopCounter < 100) //Check if we've completed 100 loops (approximately 2 seconds) + { + myRobot.Drive(-0.5, 0.0); // drive forwards half speed + autoLoopCounter++; + } else { + myRobot.Drive(0.0, 0.0); // stop robot + } + } + + void TeleopInit() + { + + } + + void TeleopPeriodic() + { + myRobot.ArcadeDrive(stick); // drive with arcade style (use right stick) + } + + void TestPeriodic() + { + lw->Run(); + } +}; + +START_ROBOT_CLASS(Robot); diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/examples.xml b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/examples.xml index e373c1f9e4..cfcbc038d5 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/examples.xml +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/examples.xml @@ -15,6 +15,26 @@ Simulation Examples that can be run in simulation. --> + + Getting Started with C++ + Examples for getting started with FRC C++ + + + Getting Started + An example program which demonstrates the simplest autonomous and + teleoperated routines. + + Getting Started with C++ + + + src + + + + + + CommandBased Robot Examples for CommandBased robot programs. diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/src/main/java/edu/wpi/first/wpilib/plugins/cpp/wizards/newproject/CPPProjectType.java b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/src/main/java/edu/wpi/first/wpilib/plugins/cpp/wizards/newproject/CPPProjectType.java index 61c59fa166..3c316d7dea 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/src/main/java/edu/wpi/first/wpilib/plugins/cpp/wizards/newproject/CPPProjectType.java +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/src/main/java/edu/wpi/first/wpilib/plugins/cpp/wizards/newproject/CPPProjectType.java @@ -38,10 +38,18 @@ public class CPPProjectType implements ProjectType { return files; } }; + static ProjectType SAMPLE = new CPPProjectType() { + @Override public Map getFiles(String packageName) { + Map files = super.getFiles(packageName); + files.put("src/Robot.cpp", "sample/Robot.cpp"); + return files; + } + }; @SuppressWarnings("serial") static Map TYPES = new HashMap() {{ put(ProjectType.ITERATIVE, ITERATIVE); put(ProjectType.COMMAND_BASED, COMMAND_BASED); + put(ProjectType.SAMPLE, SAMPLE); }}; @Override diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/GettingStarted/src/org/usfirst/frc/team190/robot/Robot.java b/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/GettingStarted/src/org/usfirst/frc/team190/robot/Robot.java new file mode 100644 index 0000000000..6d5a5d6d8e --- /dev/null +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/GettingStarted/src/org/usfirst/frc/team190/robot/Robot.java @@ -0,0 +1,69 @@ +package $package; + +import edu.wpi.first.wpilibj.IterativeRobot; +import edu.wpi.first.wpilibj.Joystick; +import edu.wpi.first.wpilibj.RobotDrive; +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 IterativeRobot + * documentation. If you change the name of this class or the package after + * creating this project, you must also update the manifest file in the resource + * directory. + */ +public class Robot extends IterativeRobot { + RobotDrive myRobot; + Joystick stick; + int autoLoopCounter; + + /** + * This function is run when the robot is first started up and should be + * used for any initialization code. + */ + public void robotInit() { + myRobot = new RobotDrive(0,1); + stick = new Joystick(1); + } + + /** + * This function is run once each time the robot enters autonomous mode + */ + public void autonomousInit() { + autoLoopCounter = 0; + } + + /** + * This function is called periodically during autonomous + */ + public void autonomousPeriodic() { + if(autoLoopCounter < 100) //Check if we've completed 100 loops (approximately 2 seconds) + { + myRobot.drive(-0.5, 0.0); // drive forwards half speed + autoLoopCounter++; + } else { + myRobot.drive(0.0, 0.0); // stop robot + } + } + + /** + * This function is called once each time the robot enters tele-operated mode + */ + public void teleopInit(){ + } + + /** + * This function is called periodically during operator control + */ + public void teleopPeriodic() { + myRobot.arcadeDrive(stick); + } + + /** + * This function is called periodically during test mode + */ + public void testPeriodic() { + LiveWindow.run(); + } + +} diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/examples.xml b/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/examples.xml index 9e432d1b08..c8ebc7a77b 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/examples.xml +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/examples.xml @@ -15,6 +15,25 @@ Simulation Examples that can be run in simulation. --> + + Getting Started with Java + Examples for getting started with FRC Java + + + Getting Started + An example program which demonstrates the simplest autonomous and + teleoperated routines. + + Getting Started with Java + + + src/$package-dir + + + + + CommandBased Robot Examples for CommandBased robot programs. diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/sample/Robot.java b/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/sample/Robot.java index d67a17ec45..63e37ac15c 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/sample/Robot.java +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/sample/Robot.java @@ -3,6 +3,9 @@ package $package; import edu.wpi.first.wpilibj.SampleRobot; +import edu.wpi.first.wpilibj.RobotDrive; +import edu.wpi.first.wpilibj.Joystick; +import edu.wpi.first.wpilibj.Timer; /** * This is a demo program showing the use of the RobotDrive class. diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/src/main/java/edu/wpi/first/wpilib/plugins/java/wizards/newproject/JavaProjectType.java b/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/src/main/java/edu/wpi/first/wpilib/plugins/java/wizards/newproject/JavaProjectType.java index 3765c69302..bc8740eab6 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/src/main/java/edu/wpi/first/wpilib/plugins/java/wizards/newproject/JavaProjectType.java +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/src/main/java/edu/wpi/first/wpilib/plugins/java/wizards/newproject/JavaProjectType.java @@ -8,10 +8,10 @@ import edu.wpi.first.wpilib.plugins.core.wizards.ProjectType; import edu.wpi.first.wpilib.plugins.java.WPILibJavaPlugin; public class JavaProjectType implements ProjectType { - static ProjectType SIMPLE = new JavaProjectType() { + static ProjectType SAMPLE = new JavaProjectType() { @Override public Map getFiles(String packageName) { Map files = super.getFiles(packageName); - files.put("src/"+packageName.replace(".", "/")+"/Robot.java", "simple/Robot.java"); + files.put("src/"+packageName.replace(".", "/")+"/Robot.java", "sample/Robot.java"); return files; } }; @@ -40,7 +40,7 @@ public class JavaProjectType implements ProjectType { }; @SuppressWarnings("serial") static Map TYPES = new HashMap() {{ - put(ProjectType.SIMPLE, SIMPLE); + put(ProjectType.SAMPLE, SAMPLE); put(ProjectType.ITERATIVE, ITERATIVE); put(ProjectType.COMMAND_BASED, COMMAND_BASED); }};