Added TimedRobot template (#673)

This commit is contained in:
Tyler Veness
2017-10-27 21:33:04 -07:00
committed by Peter Johnson
parent de95f08a10
commit c33fca34e9
2 changed files with 159 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include <iostream>
#include <string>
#include <LiveWindow/LiveWindow.h>
#include <SmartDashboard/SendableChooser.h>
#include <SmartDashboard/SmartDashboard.h>
#include <TimedRobot.h>
class Robot : public frc::TimedRobot {
public:
void RobotInit() {
m_chooser.AddDefault(kAutoNameDefault, kAutoNameDefault);
m_chooser.AddObject(kAutoNameCustom, kAutoNameCustom);
frc::SmartDashboard::PutData("Auto Modes", &m_chooser);
}
/*
* 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.
*
* You can add additional auto modes by adding additional comparisons to
* the if-else structure below with additional strings. If using the
* SendableChooser make sure to add them to the chooser code above as
* well.
*/
void AutonomousInit() override {
m_autoSelected = m_chooser.GetSelected();
// m_autoSelected = SmartDashboard::GetString("Auto Selector",
// kAutoNameDefault);
std::cout << "Auto selected: " << m_autoSelected << std::endl;
if (m_autoSelected == kAutoNameCustom) {
// Custom Auto goes here
} else {
// Default Auto goes here
}
}
void AutonomousPeriodic() {
if (m_autoSelected == kAutoNameCustom) {
// Custom Auto goes here
} else {
// Default Auto goes here
}
}
void TeleopInit() {}
void TeleopPeriodic() {}
void TestPeriodic() { m_lw.Run(); }
private:
frc::LiveWindow& m_lw = *LiveWindow::GetInstance();
frc::SendableChooser<std::string> m_chooser;
const std::string kAutoNameDefault = "Default";
const std::string kAutoNameCustom = "My Auto";
std::string m_autoSelected;
};
START_ROBOT_CLASS(Robot)