Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 212 additions & 0 deletions Robot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
#include <frc/Joystick.h>
#include <frc/TimedRobot.h>
#include <frc/Timer.h>
#include <frc/PWMVictorSPX.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/SpeedControllerGroup.h>
#include <frc/DoubleSolenoid.h>
#include <frc/Solenoid.h>
#include <frc/Compressor.h>

/*
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<Robot>(); }
#endif
153 changes: 147 additions & 6 deletions src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
@@ -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 <frc/Joystick.h>
#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
#include <frc/Timer.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/livewindow/LiveWindow.h>
#include <frc/SpeedControllerGroup.h>
#include <frc/DoubleSolenoid.h>
#include <frc/Solenoid.h>
#include <frc/Encoder.h>
#include <frc/smartdashboard/SmartDashboard.h>
#include <frc/smartdashboard/SendableChooser.h>

constexpr double kPi = 3.14159265358979;

class Robot : public frc::TimedRobot {
private:
frc::SendableChooser<std::string> 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 <iostream>
#include <SmartDashboard/SmartDashboard.h>
#include <Timer.h>
void Robot::TestPeriodic() {}

START_ROBOT_CLASS(Drive)
#ifndef RUNNING_FRC_TESTS
int main() { return frc::StartRobot<Robot>(); }
#endif

};
4 changes: 4 additions & 0 deletions src/main/deploy/example.txt
Original file line number Diff line number Diff line change
@@ -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.
Loading