From 21c21b4f00542e55be1afffbf2f280d351515e3b Mon Sep 17 00:00:00 2001 From: SOR-FRCTeam6059 <44914299+SOR-FRCTeam6059@users.noreply.github.com> Date: Tue, 29 Jan 2019 20:20:43 -0800 Subject: [PATCH 1/2] Michael's World Code updated to be more copy-paste friendly - now with fewer errors! --- src/main/cpp/Robot.cpp | 153 ++++++++++++++++++++++++++++++++++-- src/main/deploy/example.txt | 4 + src/main/include/Robot.h | 76 ++++++++++++++++++ src/test/cpp/main.cpp | 10 +++ 4 files changed, 237 insertions(+), 6 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..412ad39 100644 --- a/src/main/cpp/Robot.cpp +++ b/src/main/cpp/Robot.cpp @@ -1,15 +1,156 @@ -/*----------------------------------------------------------------------------*/ + + /*----------------------------------------------------------------------------*/ /* 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. */ /*----------------------------------------------------------------------------*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +constexpr double kPi = 3.14159265358979; + +class Robot : public frc::TimedRobot { + private: + frc::SendableChooser m_chooser; + const std::string kAutoNameDefault = "Default"; + const std::string kAutoNameCustom = "My Auto"; + std::string m_autoSelected; + + //Declartions + frc::Joystick gamePad{0}; + frc::Timer timer; + frc::Encoder encoder1{0, 1}; + frc::LiveWindow& m_lw = *frc::LiveWindow::GetInstance(); + + //Motors + //Drivebase + frc::PWMVictorSPX m_frontLeft{0}; + frc::PWMVictorSPX m_backLeft{1}; + frc::PWMVictorSPX m_frontRight{2}; + frc::PWMVictorSPX m_backRight{3}; + //HAB Lift + frc::PWMVictorSPX m_frontLift{4}; + frc::PWMVictorSPX m_backLift{5}; + //Elevator Lift + frc::PWMVictorSPX m_firstLayer{6}; // This may be 1 or 2 motors, not yet decided, set for 2 motors + frc::PWMVictorSPX m_secondLayer{7}; + //BAG Motor Ball Thinging + frc::PWMVictorSPX m_leftWheel{8}; + frc::PWMVictorSPX m_rightWheel{9}; + //Groups + //Drivebase + frc::SpeedControllerGroup m_left{m_frontLeft, m_backLeft}; + frc::SpeedControllerGroup m_right{m_frontRight, m_backRight}; + frc::SpeedControllerGroup m_ball{m_leftWheel, m_rightWheel}; + //Setting Drive + frc::DifferentialDrive Drive{m_left, m_right}; + + //Pneumatics/Solenoids + //Hatch Panel Grabber(trying both on one solenoid) + frc::DoubleSolenoid s_panelGrabber{1, 2}; + //Hatch Panel Launcher(trying 3 on one solenoid) + frc::DoubleSolenoid s_panelLauncher{3, 4}; + //Hatch Panel Grabber F/B Setters + static constexpr int panelGrabberForward = 1; + static constexpr int panelGrabberReverse = 2; + //Hatch Panel Launcher F/B Setters + static constexpr int panelLauncherForward = 3; + static constexpr int panelLauncherReverse = 4; + + public: + Robot() { + Drive.SetExpiration(0.1); + timer.Start(); + } + + void RobotInit() override { + encoder1.SetDistancePerPulse((kPi * 6) / 360.0); + } + + void RobotPeriodic() override { + frc::SmartDashboard::PutNumber("Encoder", encoder1.GetDistance()); + } + + void AutonomousInit() override { + timer.Reset(); + timer.Start(); + } + + void AutonomousPeriodic() override { + // Drive for 2 seconds + if (timer.Get() < 2.0) { + // Drive forwards half speed + Drive.ArcadeDrive(0.5, 0.0); + } else { + // Stop robot + Drive.ArcadeDrive(0.0, 0.0); + } + } + + void TeleopInit() override { + encoder1.Reset(); + } -#include "Drive.h" + void TeleopPeriodic() override { + //Drive + Drive.ArcadeDrive(gamePad.GetRawAxis(4), gamePad.GetRawAxis(5)); + //Elevator Lift(Set to axis but need to program in the 2 hights for the holes and 1 for bottom/rest) + //No idea is this works... need to reconfigure for the right bases + if (gamePad.GetRawButton(5) == 1) { + encoder1.Reset(); + while (encoder1.GetDistance() > 5) { + m_firstLayer.Set(.5); + } + } else if (gamePad.GetRawButton(6) == 1) { + encoder1.Reset(); + while (encoder1.GetDistance() > 10) { + m_secondLayer.Set(.5); + } + } else { + while (encoder1.GetDistance() > .01) { + m_secondLayer.Set(-.5); + } + } + + //HAB lift + m_frontLift.Set(gamePad.GetRawAxis(2)); + m_backLift.Set(gamePad.GetRawAxis(3)); + //Ball Holder Thinging + m_ball.Set(gamePad.GetRawAxis(0)); + //Solenoids for Panel Grabber(I think is done but I have not tested it yet) + if (gamePad.GetRawButton(panelGrabberForward) == 1) { + s_panelGrabber.Set(frc::DoubleSolenoid::kForward); + } else if (gamePad.GetRawButton(panelGrabberReverse) == 0) { + s_panelGrabber.Set(frc::DoubleSolenoid::kReverse); + } //I do not know if I will need the else or if I shoudl change the else if to an else statement + else { + s_panelGrabber.Set(frc::DoubleSolenoid::kOff); + } + //Solenoids for Panel Launcher + if (gamePad.GetRawButton(panelLauncherForward) == 1) { + s_panelLauncher.Set(frc::DoubleSolenoid::kForward); + } else if (gamePad.GetRawButton(panelLauncherReverse) == 0) { + s_panelGrabber.Set(frc::DoubleSolenoid::kReverse); + } else { + s_panelLauncher.Set(frc::DoubleSolenoid::kOff); + } + } -#include -#include -#include +void Robot::TestPeriodic() {} -START_ROBOT_CLASS(Drive) +#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..3defbfa --- /dev/null +++ b/src/main/include/Robot.h @@ -0,0 +1,76 @@ +/*----------------------------------------------------------------------------*/ +/* 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 + +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; + + //Declartions + frc::Joystick gamePad{0}; + frc::Timer timer; + frc::Encoder encoder1{0, 1}; + frc::LiveWindow& m_lw = *frc::LiveWindow::GetInstance(); + + //Motors + //Drivebase + frc::PWMVictorSPX m_frontLeft{0}; + frc::PWMVictorSPX m_backLeft{1}; + frc::PWMVictorSPX m_frontRight{2}; + frc::PWMVictorSPX m_backRight{3}; + //HAB Lift + frc::PWMVictorSPX m_frontLift{4}; + frc::PWMVictorSPX m_backLift{5}; + //Elevator Lift + frc::PWMVictorSPX m_firstLayer{6}; // This may be 1 or 2 motors, not yet decided, set for 2 motors + frc::PWMVictorSPX m_secondLayer{7}; + //BAG Motor Ball Thinging + frc::PWMVictorSPX m_leftWheel{8}; + frc::PWMVictorSPX m_rightWheel{9}; + //Groups + //Drivebase + frc::SpeedControllerGroup m_left{m_frontLeft, m_backLeft}; + frc::SpeedControllerGroup m_right{m_frontRight, m_backRight}; + frc::SpeedControllerGroup m_ball{m_leftWheel, m_rightWheel}; + //Setting Drive + frc::DifferentialDrive Drive{m_left, m_right}; + + //Pneumatics/Solenoids + //Hatch Panel Grabber(trying both on one solenoid) + frc::DoubleSolenoid s_panelGrabber{1, 2}; + //Hatch Panel Launcher(trying 3 on one solenoid) + frc::DoubleSolenoid s_panelLauncher{3, 4}; + //Hatch Panel Grabber F/B Setters + static constexpr int panelGrabberForward = 1; + static constexpr int panelGrabberReverse = 2; + //Hatch Panel Launcher F/B Setters + static constexpr int panelLauncherForward = 3; + static constexpr int panelLauncherReverse = 4; +}; + +#ifndef RUNNING_FRC_TESTS +int main() { return frc::StartRobot(); } +#endif +}; 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 4b9e1346c69f0150b0faad80f527298a991eda4c Mon Sep 17 00:00:00 2001 From: SOR-FRCTeam6059 <44914299+SOR-FRCTeam6059@users.noreply.github.com> Date: Fri, 8 Feb 2019 18:30:43 -0800 Subject: [PATCH 2/2] compressor michael pls this has compressor stuff im too lazy to only upload compressor so have the entire thing i copied from you it's under the comment "//Compressor??" --- Robot.cpp | 212 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 Robot.cpp diff --git a/Robot.cpp b/Robot.cpp new file mode 100644 index 0000000..d6d41ab --- /dev/null +++ b/Robot.cpp @@ -0,0 +1,212 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* +bool prevState = false; +bool currState = false; +bool driveTankMode = false; + +while (IsOperatorControl()) +{ + // + // Check for button 6 press. + // + currState = secondaryController->GetRawButton(6); + if (currState != prevState) + { + if (currState) + { + // + // Button has been pressed. + // + driveTankMode = !driveTankMode; + } + else + { + // + // Button has been released. + // + } + prevState = currState; + } + + if (driveTankMode) + { + // + // Do tank drive. + // + } + else + { + // + // Do arcade drive. + // + } + + wait(0.02); +} +*/ + + + +/*----------------------------------------------------------------------------*/ +/* 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. */ +/*----------------------------------------------------------------------------*/ + + + +class Robot : public frc::TimedRobot { + public: + Robot() {} + + void RobotInit() override {} + void RobotPeriodic() override {} + void AutonomousInit() override {} + void AutonomousPeriodic() override {} + + void TeleopInit() override { + compressor.Start(); + } + + void TeleopPeriodic() override { + //Drivebase(Works) + //The * -1 is to inverse motors, and the / 2 is to slow down regular turing and the / 3 if for presicion drive + //the else if statments is mostly likely unneeded, will test with and without so see if it is needed + // 3 = A button + if (xbox.GetRawButton(3) == 1) { + Drive.ArcadeDrive(xbox.GetRawAxis(1) * -1 / 2, xbox.GetRawAxis(0) / 2); + } else if (xbox.GetRawButton(3) == 0) { + Drive.ArcadeDrive(xbox.GetRawAxis(1) * -1, xbox.GetRawAxis(0) / 2); + } else { + Drive.ArcadeDrive(xbox.GetRawAxis(1) * -1, xbox.GetRawAxis(0) / 2); + } + + //HAB lift + //Front(Untested) + //Using trigger axis for ease of use for operator but idk if the code will work like I have it + if (xbox.GetRawAxis(2) >= .5) { + s_HABfront.Set(frc::DoubleSolenoid::kForward); + } else if (xbox.GetRawAxis(2) == 0) { + s_HABfront.Set(frc::DoubleSolenoid::kReverse); + } else { + s_HABfront.Set(frc::DoubleSolenoid::kOff); + } + //Back(Untested) + if (xbox.GetRawAxis(3) >= .5) { + s_HABback.Set(frc::DoubleSolenoid::kForward); + } else if (xbox.GetRawAxis(3) == 0) { + s_HABback.Set(frc::DoubleSolenoid::kReverse); + } else { + s_HABback.Set(frc::DoubleSolenoid::kOff); + } + + //Forklift (Works) + //POV is 0=UP 90=Right 180=Down 270=Left and 45 for all the angles + // the "== 1" might have to be "== 0/180" corresponcding to the angle + if (arcadePad.GetPOV(0) == 0) { + m_forklift.Set(.5); + } else if (arcadePad.GetPOV(0) == 180) { + m_forklift.Set(-.5); + } else { + m_forklift.Set(0); + } + + //Ball Intake (Untested) + //This is the button test + // / 3 is to small need to change on next upload + // the / 3 is since one of the motors is currently missing a gearbox but we will have the gear box before comp + if (arcadePad.GetRawButton(1) == 1) { + m_leftIntake.Set(-1 / 3); + m_rightIntake.Set(-1); + } else if (arcadePad.GetRawButton(3) == 1) { + m_leftIntake.Set(1 / 3); + m_rightIntake.Set(1); + } else { + m_leftIntake.Set(0); + m_rightIntake.Set(0); + } + //(Untested) + //This is the button/axis test, this is what we want if it works but can use code abouve incase this does not work + //The button layout with the top code is better than this one so idk what we will use in the end + //R2 and L2 axis(buttons on physical board) + m_leftIntake.Set(arcadePad.GetRawAxis(3) * -1 / 3); //devide 3 only there for now since we don't have the 2nd gearbox + m_rightIntake.Set(arcadePad.GetRawAxis(2)); + + //Hatch Panel Launcher(Works) + //4 = Y on Qanda Arcade + if (arcadePad.GetRawButton(4) == 1) { + s_panelLauncher.Set(frc::DoubleSolenoid::kForward); + s_panelGetter.Set(frc::DoubleSolenoid::kForward); + } else if (arcadePad.GetRawButton(4) == 0) { + s_panelLauncher.Set(frc::DoubleSolenoid::kReverse); + s_panelGetter.Set(frc::DoubleSolenoid::kReverse); + } else { + s_panelLauncher.Set(frc::DoubleSolenoid::kOff); + s_panelGetter.Set(frc::DoubleSolenoid::kOff); + } + //Slider/Panel Getter(Untested) + /* + if (arcadePad.GetRawButton(6) == 1) { + s_panelGetter.Set(frc::DoubleSolenoid::kReverse); + } else if (arcadePad.GetRawButton(6) == 0) { + s_panelGetter.Set(frc::DoubleSolenoid::kForward); + } else { + s_panelGetter.Set(frc::DoubleSolenoid::kOff); + } + */ + + //Compressor toggle? + if (xbox.GetRawButton(7) == 1) { + if (compressor.Enabled == true) { + compressor.Enabled == false; + } + else if (compressor.Enabled == false) { + compressor.Enabled == true; + } + } + } + + private: + //Declartions + frc::Joystick xbox{1}; + frc::Joystick arcadePad{2}; + frc::Compressor compressor; + //Motors + //Drivebase + frc::PWMVictorSPX m_frontLeft{0}; + frc::PWMVictorSPX m_backLeft{1}; + frc::PWMVictorSPX m_frontRight{2}; + frc::PWMVictorSPX m_backRight{3}; + //Ball Intake + frc::PWMVictorSPX m_leftIntake{4}; //No Gearbox Currently + frc::PWMVictorSPX m_rightIntake{5}; + //Forlift + frc::PWMVictorSPX m_forklift{6}; + //Groups + //Drivebase + frc::SpeedControllerGroup m_left{m_frontLeft, m_backLeft}; + frc::SpeedControllerGroup m_right{m_frontRight, m_backRight}; + //Setting Drive + frc::DifferentialDrive Drive{m_left, m_right}; + + //Pneumatics/Solenoids + //Hatch Panel Launcher + frc::DoubleSolenoid s_panelLauncher{0, 1}; + frc::DoubleSolenoid s_panelGetter{2, 3}; + frc::DoubleSolenoid s_HABfront{4, 5}; + frc::DoubleSolenoid s_HABback{6, 7}; +}; + +#ifndef RUNNING_FRC_TESTS +int main() { return frc::StartRobot(); } +#endif \ No newline at end of file