Add cpp examples (#659)

* Added C++ robot project examples and set up sub .clang-format for them

* Ran formatter
This commit is contained in:
Tyler Veness
2017-10-17 21:37:58 -07:00
committed by Peter Johnson
parent 66002d6cac
commit 0291a95f68
110 changed files with 4943 additions and 70 deletions

View File

@@ -0,0 +1,74 @@
/*----------------------------------------------------------------------------*/
/* 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 <memory>
#include <string>
#include <IterativeRobot.h>
#include <LiveWindow/LiveWindow.h>
#include <SmartDashboard/SendableChooser.h>
#include <SmartDashboard/SmartDashboard.h>
class Robot : public frc::IterativeRobot {
public:
void RobotInit() {
chooser.AddDefault(autoNameDefault, autoNameDefault);
chooser.AddObject(autoNameCustom, autoNameCustom);
frc::SmartDashboard::PutData("Auto Modes", &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 {
autoSelected = chooser.GetSelected();
// std::string autoSelected = SmartDashboard::GetString("Auto
// Selector", autoNameDefault);
std::cout << "Auto selected: " << autoSelected << std::endl;
if (autoSelected == autoNameCustom) {
// Custom Auto goes here
} else {
// Default Auto goes here
}
}
void AutonomousPeriodic() {
if (autoSelected == autoNameCustom) {
// Custom Auto goes here
} else {
// Default Auto goes here
}
}
void TeleopInit() {}
void TeleopPeriodic() {}
void TestPeriodic() { lw->Run(); }
private:
frc::LiveWindow* lw = LiveWindow::GetInstance();
frc::SendableChooser<std::string> chooser;
const std::string autoNameDefault = "Default";
const std::string autoNameCustom = "My Auto";
std::string autoSelected;
};
START_ROBOT_CLASS(Robot)