From 27e3181caa9a049e8ef7b2c3b11a6b37165b9dfe Mon Sep 17 00:00:00 2001 From: SOR-FRCTeam6059 <44914299+SOR-FRCTeam6059@users.noreply.github.com> Date: Wed, 30 Jan 2019 19:35:33 -0800 Subject: [PATCH 1/2] Pneumatics - Gabby Style Pneumatic "code" Gabby wrote. Hopefully works, definitely exists. --- src/main/cpp/Robot.cpp | 73 +++++++++++++++++++++++++++++++++++-- src/main/deploy/example.txt | 4 ++ src/main/include/Robot.h | 37 +++++++++++++++++++ src/test/cpp/main.cpp | 10 +++++ 4 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 src/main/deploy/example.txt create mode 100644 src/main/include/Robot.h create mode 100644 src/test/cpp/main.cpp diff --git a/src/main/cpp/Robot.cpp b/src/main/cpp/Robot.cpp index 5771ac7..12f4054 100644 --- a/src/main/cpp/Robot.cpp +++ b/src/main/cpp/Robot.cpp @@ -5,11 +5,76 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#include "Drive.h" +#include "Robot.h" #include -#include -#include -START_ROBOT_CLASS(Drive) +#include +void Robot::RobotInit() { + m_chooser.SetDefaultOption(kAutoNameDefault, kAutoNameDefault); + m_chooser.AddOption(kAutoNameCustom, kAutoNameCustom); + frc::SmartDashboard::PutData("Auto Modes", &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. + * + *

This runs after the mode specific periodic functions, but before + * LiveWindow and SmartDashboard integrated updating. + */ +void Robot::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. + * + * 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 Robot::AutonomousInit() { + 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 Robot::AutonomousPeriodic() { + if (m_autoSelected == kAutoNameCustom) { + // Custom Auto goes here + } else { + // Default Auto goes here + } +} + +void Robot::TeleopInit() {} + +void Robot::TeleopPeriodic() { + + if (m_stick.GetRawButton(kDoubleSolenoidForward)) { + m_doubleSolenoid.Set(frc::DoubleSolenoid::kForward); + } else if (m_stick.GetRawButton(kDoubleSolenoidReverse)) { + m_doubleSolenoid.Set(frc::DoubleSolenoid::kReverse); + } else { + m_doubleSolenoid.Set(frc::DoubleSolenoid::kOff); + } + +} + +void Robot::TestPeriodic() {} + +#ifndef RUNNING_FRC_TESTS +int main() { return frc::StartRobot(); } +#endif diff --git a/src/main/deploy/example.txt b/src/main/deploy/example.txt new file mode 100644 index 0000000..6dadf47 --- /dev/null +++ b/src/main/deploy/example.txt @@ -0,0 +1,4 @@ +Files placed in this directory will be deployed to the RoboRIO into the +'deploy' directory in the home folder. Use the 'frc::filesystem::GetDeployDirectory' +function from the 'frc/Filesystem.h' header to get a proper path relative to the deploy +directory. \ No newline at end of file diff --git a/src/main/include/Robot.h b/src/main/include/Robot.h new file mode 100644 index 0000000..da462ce --- /dev/null +++ b/src/main/include/Robot.h @@ -0,0 +1,37 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include +#include +#include +#include +#include +#include + +class Robot : public frc::TimedRobot { + public: + void RobotInit() override; + void RobotPeriodic() override; + void AutonomousInit() override; + void AutonomousPeriodic() override; + void TeleopInit() override; + void TeleopPeriodic() override; + void TestPeriodic() override; + + private: + frc::SendableChooser m_chooser; + const std::string kAutoNameDefault = "Default"; + const std::string kAutoNameCustom = "My Auto"; + std::string m_autoSelected; + + frc::Joystick m_stick{0}; + frc::DoubleSolenoid m_doubleSolenoid{1, 2}; + static constexpr int kDoubleSolenoidForward = 1; + static constexpr int kDoubleSolenoidReverse = 2; +}; diff --git a/src/test/cpp/main.cpp b/src/test/cpp/main.cpp new file mode 100644 index 0000000..cab8aa4 --- /dev/null +++ b/src/test/cpp/main.cpp @@ -0,0 +1,10 @@ +#include + +#include "gtest/gtest.h" + +int main(int argc, char** argv) { + HAL_Initialize(500, 0); + ::testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +} From aba51de5a3b531a77ece0bfb400ac4526c313e7e Mon Sep 17 00:00:00 2001 From: Michael Crandall <44914172+MichaelCrandall@users.noreply.github.com> Date: Fri, 1 Feb 2019 18:20:36 -0800 Subject: [PATCH 2/2] Update Robot.cpp --- src/main/cpp/Robot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/cpp/Robot.cpp b/src/main/cpp/Robot.cpp index 12f4054..111bd80 100644 --- a/src/main/cpp/Robot.cpp +++ b/src/main/cpp/Robot.cpp @@ -8,7 +8,7 @@ #include "Robot.h" #include - +#include #include void Robot::RobotInit() {