Skip to content

Commit

Permalink
Reorganize, Refactor, Document
Browse files Browse the repository at this point in the history
  • Loading branch information
StripedMonkey committed Jun 5, 2019
1 parent dc32414 commit 522acf3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 27 deletions.
45 changes: 28 additions & 17 deletions src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
/*----------------------------------------------------------------------------*/
/* 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 "Robot.h"

#include <iostream>

void Robot::AutonomousPeriodic() {
void Robot::AutonomousPeriodic()
{
PlayerControl();
}

void Robot::TeleopPeriodic() {
void Robot::TeleopPeriodic()
{
PlayerControl();
}

void Robot::PlayerControl() {

hatch.Set(Controller.GetRawButton(4));
bucket.Set(Controller.GetRawButton(1));
void Robot::PlayerControl()
{

//Pneumatic control
hatch.Set(controller.GetRawButton(4));
bucket.Set(controller.GetRawButton(1));

//Toggles the lift
if (controller.GetRawButtonPressed(2))
{
L2Lift.Set(!L2Lift.Get());
}

//Tank Drive
speedLeft += (controller.GetRawAxis(LeftJoystickY) - previousLeftSpeed) / speedScalingFactor;
speedRight += (controller.GetRawAxis(RightJoystickY) - previousRightSpeed) / speedScalingFactor;

DiffDrive.TankDrive(speedLeft * speedScale, speedRight * speedScale);

DiffDrive.TankDrive(Controller.GetRawAxis(1), Controller.GetRawAxis(4));

if(Controller.GetRawButtonPressed(3)) {
previousLeftSpeed = speedLeft;
previousRightSpeed = speedRight;

//Invert the controls when using the second camera
if (controller.GetRawButtonPressed(3))
{
cameraView = !cameraView;
speedScale = speedScale * -1;
sinkCam.SetSource(cameraView ? frontCam : backCam);
}

}

int main() { return frc::StartRobot<Robot>(); }
31 changes: 21 additions & 10 deletions src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,38 @@
#include <frc/drive/DifferentialDrive.h>
#include <cameraserver/CameraServer.h>

class Robot : public frc::TimedRobot {
public:
class Robot : public frc::TimedRobot
{
public:
void PlayerControl();
void TeleopPeriodic() override;
void AutonomousPeriodic() override;

private:
frc::Joystick Controller{0};
private: //Modify Me!
double speedScale = 1.0; //Robot Speed Multiplier
bool cameraView = false; //Either front or back Camera view; change this to change default camera view
double speedScalingFactor = 6; //Higher = Slower acceleration; Lower = faster; 1 = fastest. Multiples of 2 Ideally

frc::Solenoid L2Lift{2}; //Second Level Climb. Barely works
frc::Solenoid hatch{3}; //Push off hatches from velcro
frc::Solenoid bucket{0}; //Launch Balls up and into goals

//Left and Right GetRawAxies values
const int LeftJoystickY = 1;
const int RightJoystickY = 4;

frc::Joystick controller{0};
frc::PWMVictorSPX leftDT{0};
frc::PWMVictorSPX rightDT{1};

frc::DifferentialDrive DiffDrive{leftDT, rightDT};

//Cameras, including a sink that retrieves camera data from either the front or back
cs::VideoSink sinkCam = frc::CameraServer::GetInstance()->GetServer();
cs::UsbCamera backCam = frc::CameraServer::GetInstance()->StartAutomaticCapture(1);
cs::UsbCamera frontCam = frc::CameraServer::GetInstance()->StartAutomaticCapture(0);


double speedScale = 1;
bool cameraView = false;

frc::Solenoid bucket{0};
frc::Solenoid hatch{3};
//Don't modify these
double speedLeft = 0, previousLeftSpeed = 0;
double speedRight = 0, previousRightSpeed = 0;
};

0 comments on commit 522acf3

Please sign in to comment.