Skip to content

Commit 6a7fc69

Browse files
committed
Adds 2016 template changes
1 parent 1d20716 commit 6a7fc69

File tree

3 files changed

+126
-34
lines changed

3 files changed

+126
-34
lines changed

Templates/CSharp/Project-Templates/CommandRobot/Robot.cs

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,74 @@
44
$endif$
55
using WPILib;
66
using WPILib.Commands;
7-
using WPILib.livewindow;
7+
using WPILib.LiveWindow;
88
using $safeprojectname$.Subsystems
99
using $safeprojectname$.Commands
1010

1111
namespace $safeprojectname$
1212
{
13-
/**
14-
* The VM is configured to automatically run this class, and to call the
15-
* functions corresponding to each mode, as described in the IterativeRobot
16-
* documentation.
17-
*/
13+
/// <summary>
14+
/// The VM is configured to automatically run this class, and to call the
15+
/// functions corresponding to each mode, as described in the IterativeRobot
16+
/// documentation.
17+
/// </summary>
1818
public class $safeprojectname$ : IterativeRobot
1919
{
2020
public static readonly ExampleSubsystem exampleSubsystem = new ExampleSubsystem();
2121
public static OI oi;
2222

2323
Command autonomousCommand;
24+
SendableChooser chooser;
2425

25-
/**
26-
* This function is run when the robot is first started up and should be
27-
* used for any initialization code.
28-
*/
29-
public override void RobotInit() {
26+
// This function is run when the robot is first started up and should be
27+
// used for any initialization code.
28+
//
29+
public override void RobotInit()
30+
{
3031
oi = new OI();
3132
// instantiate the command used for the autonomous period
3233
autonomousCommand = new ExampleCommand();
34+
chooser = new SendableChooser();
35+
chooser.AddDefault("Default Auto", new ExampleCommand());
36+
//chooser.AddObject("My Auto", new MyAutoCommand);
3337
}
3438

35-
public override void DisabledPeriodic() {
39+
public override void DisabledPeriodic()
40+
{
3641
Scheduler.GetInstance().Run();
3742
}
3843

39-
public override void AutonomousInit() {
44+
// This autonomous (along with the sendable chooser above) shows how to select between
45+
// different autonomous modes using the dashboard. The senable chooser code works with
46+
// the Java SmartDashboard. If you prefer the LabVIEW Dashboard, remove all the chooser
47+
// code an uncomment the GetString code to get the uto name from the text box below
48+
// the gyro.
49+
// You can add additional auto modes by adding additional commands to the chooser code
50+
// above (like the commented example) or additional comparisons to the switch structure
51+
// below with additional strings and commands.
52+
public override void AutonomousInit()
53+
{
54+
autonomousCommand = (Command) chooser.GetSelected();
55+
56+
/*
57+
string autoSelected = SmartDashboard.GetString("Auto Selector", "Default");
58+
switch(autoSelected)
59+
{
60+
case "My Auto":
61+
autonomousCommand = new MyAutoCommand();
62+
break;
63+
case "Default Auto"
64+
default:
65+
autonomousCommand = new ExampleCommand();
66+
break;
67+
}
68+
*/
4069
// schedule the autonomous command (example)
4170
if (autonomousCommand != null) autonomousCommand.Start();
4271
}
4372

44-
/**
45-
* This function is called periodically during autonomous
46-
*/
73+
74+
// This function is called periodically during autonomous
4775
public override void AutonomousPeriodic() {
4876
Scheduler.GetInstance().Run();
4977
}
@@ -56,24 +84,24 @@ public override void TeleopInit() {
5684
if (autonomousCommand != null) autonomousCommand.Cancel();
5785
}
5886

59-
/**
60-
* This function is called when the disabled button is hit.
61-
* You can use it to reset subsystems before shutting down.
62-
*/
87+
//
88+
// This function is called when the disabled button is hit.
89+
// You can use it to reset subsystems before shutting down.
90+
//
6391
public override void DisabledInit(){
6492

6593
}
6694

67-
/**
68-
* This function is called periodically during operator control
69-
*/
95+
//
96+
// This function is called periodically during operator control
97+
//
7098
public override void TeleopPeriodic() {
7199
Scheduler.GetInstance().Run();
72100
}
73101

74-
/**
75-
* This function is called periodically during test mode
76-
*/
102+
//
103+
// This function is called periodically during test mode
104+
//
77105
public override void TestPeriodic() {
78106
LiveWindow.Run();
79107
}

Templates/CSharp/Project-Templates/IterativeRobot/Robot.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,52 @@ namespace $safeprojectname$
1313
/// </summary>
1414
public class $safeprojectname$ : IterativeRobot
1515
{
16+
readonly string defaultAuto = "Default";
17+
readonly string customAuto = "My Auto";
18+
string autoSelected;
19+
SendableChooser chooser;
1620

1721
/// <summary>
1822
/// This function is run when the robot is first started up and should be
1923
/// used for any initialization code.
2024
/// </summary>
2125
public override void RobotInit()
2226
{
27+
chooser = new SendableChooser();
28+
chooser.AddDefault("Default Auto", defaultAuto);
29+
chooser.AddObject("My Auto", customAuto);
30+
}
2331

32+
// This autonomous (along with the sendable chooser above) shows how to select between
33+
// different autonomous modes using the dashboard. The senable chooser code works with
34+
// the Java SmartDashboard. If you prefer the LabVIEW Dashboard, remove all the chooser
35+
// code an uncomment the GetString code to get the uto name from the text box below
36+
// the gyro.
37+
//You can add additional auto modes by adding additional comparisons to the switch
38+
// structure below with additional strings. If using the SendableChooser
39+
// be sure to add them to the chooser code above as well.
40+
public override void AutonomousInit()
41+
{
42+
autoSelected = (string) chooser.GetSelected();
43+
//autoSelected = SmartDashboard.GetString("Auto Selector", defaultAuto);
44+
Console.WriteLine("Auto selected: " + autoSelected);
2445
}
2546

2647
/// <summary>
2748
/// This function is called periodically during autonomous
2849
/// </summary>
2950
public override void AutonomousPeriodic()
3051
{
31-
52+
switch (autoSelected)
53+
{
54+
case customAuto:
55+
//Put custom auto code here
56+
break;
57+
case defaultAuto:
58+
default:
59+
//Put default auto code here
60+
break;
61+
}
3262
}
3363

3464
/// <summary>

Templates/CSharp/Project-Templates/SampleRobot/Robot.cs

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,55 @@ public class $safeprojectname$ : SampleRobot
2323
{
2424
RobotDrive myRobot;
2525
Joystick stick;
26+
readonly string defaultAuto = "Default";
27+
readonly string customAuto = "My Auto";
28+
SendableChooser chooser;
29+
30+
2631
public $safeprojectname$()
2732
{
2833
myRobot = new RobotDrive(0, 1);
2934
myRobot.Expiration = 0.1;
3035
stick = new Joystick(0);
3136
}
32-
/**
33-
* Drive left & right motors for 2 seconds then stop
34-
*/
37+
38+
public override void RobotInit()
39+
{
40+
chooser = new SendableChooser();
41+
chooser.AddDefault("Default Auto", defaultAuto);
42+
chooser.AddObject("My Auto", customAuto);
43+
}
44+
45+
// This autonomous (along with the sendable chooser above) shows how to select between
46+
// different autonomous modes using the dashboard. The senable chooser code works with
47+
// the Java SmartDashboard. If you prefer the LabVIEW Dashboard, remove all the chooser
48+
// code an uncomment the GetString code to get the uto name from the text box below
49+
// the gyro.
50+
// You can add additional auto modes by adding additional comparisons to the if-else
51+
// structure below with additional strings. If using the SendableChooser
52+
// be sure to add them to the chooser code above as well.
3553
public override void Autonomous()
3654
{
37-
myRobot.SafetyEnabled = false;
38-
myRobot.Drive(-0.5, 0.0); // drive forwards half speed
39-
Timer.Delay(2.0); // for 2 seconds
40-
myRobot.Drive(0.0, 0.0); // stop robot
55+
autoSelected = (string) chooser.GetSelected();
56+
//autoSelected = SmartDashboard.GetString("Auto Selector", defaultAuto);
57+
Console.WriteLine("Auto selected: " + autoSelected);
58+
59+
switch (autoSelected)
60+
{
61+
case customAuto:
62+
myRobot.SafetyEnabled = false;
63+
myRobot.Drive(-0.5, 1.0); //Spin at half speed
64+
Timer.Delay(2.0); //for 2 seconds
65+
myRobot.Drive(0.0, 0.0); //Stop robot
66+
break;
67+
case defaultAuto:
68+
default:
69+
myRobot.SafetyEnabled = false;
70+
myRobot.Drive(-0.5, 0.0); //Drive forward half speed
71+
Timer.Delay(2.0); //For 2 seconds
72+
myRobot.Drive(0.0, 0.0); //Stop Robot
73+
break;
74+
}
4175
}
4276

4377
/**

0 commit comments

Comments
 (0)