Skip to content

Commit

Permalink
The Great Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
wusteven815 committed Apr 15, 2022
1 parent 56f6aec commit 27dc7b3
Show file tree
Hide file tree
Showing 39 changed files with 274 additions and 411 deletions.
26 changes: 24 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp",
"*.inc": "cpp"
}
"*.inc": "cpp",
"hash_map": "cpp",
"hash_set": "cpp",
"chrono": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"list": "cpp",
"unordered_set": "cpp",
"filesystem": "cpp",
"map": "cpp",
"optional": "cpp",
"ratio": "cpp",
"set": "cpp",
"fstream": "cpp",
"future": "cpp",
"iomanip": "cpp",
"mutex": "cpp",
"sstream": "cpp",
"thread": "cpp",
"cinttypes": "cpp"
}
}
52 changes: 14 additions & 38 deletions src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
@@ -1,51 +1,32 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#include "Robot.h"
#include <iostream>

#include <cameraserver/CameraServer.h>
#include <frc/RobotController.h>
#include <frc/smartdashboard/SmartDashboard.h>
#include <frc2/command/CommandScheduler.h>
#include <frc/RobotController.h>

#include <cameraserver/CameraServer.h>

void Robot::RobotInit() {
//frc::CameraServer::GetInstance()->StartAutomaticCapture(0);
//frc::CameraServer::GetInstance()->StartAutomaticCapture(1);
// frc::CameraServer::GetInstance()->StartAutomaticCapture(0);
// frc::CameraServer::GetInstance()->StartAutomaticCapture(1);
frc::RobotController::SetBrownoutVoltage(6_V);
}

/**
* This function is called every robot packet, no matter the mode. Use
* this for items like diagnostics that you want to run during disabled,
* autonomous, teleoperated and test.
*
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/

void Robot::RobotPeriodic() {
frc2::CommandScheduler::GetInstance().Run();
}

/**
* This function is called once each time the robot enters Disabled mode. You
* can use it to reset any subsystem information you want to clear when the
* robot is disabled.
*/

void Robot::DisabledInit() {}


void Robot::DisabledPeriodic() {}

/**
* This autonomous runs the autonomous command selected by your {@link
* RobotContainer} class.
*/

void Robot::AutonomousInit() {
//m_container.m_drivetrain.SetIdleMode(rev::CANSparkMax::IdleMode::kBrake);

// m_container.m_drivetrain.SetIdleMode(rev::CANSparkMax::IdleMode::kBrake);

m_autonomousCommand = m_container.GetAutonomousCommand();

Expand All @@ -58,28 +39,23 @@ void Robot::AutonomousInit() {
void Robot::AutonomousPeriodic() {}

void Robot::TeleopInit() {
//m_container.m_drivetrain.SetIdleMode(rev::CANSparkMax::IdleMode::kCoast);

// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
// m_container.m_drivetrain.SetIdleMode(rev::CANSparkMax::IdleMode::kCoast);

if (m_autonomousCommand != nullptr) {
m_autonomousCommand->Cancel();
m_autonomousCommand = nullptr;
}

}

/**
* This function is called periodically during operator control.
*/

void Robot::TeleopPeriodic() {}

/**
* This function is called periodically during test mode.
*/

void Robot::TestPeriodic() {}


#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
Expand Down
24 changes: 7 additions & 17 deletions src/main/cpp/RobotContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@

RobotContainer::RobotContainer() {

m_chooser.SetDefaultOption("Only Taxi", &m_only_taxi);
m_chooser.SetDefaultOption("1 Ball", &m_ball1);
m_chooser.AddOption("2 Ball", &m_ball2);
m_chooser.AddOption("2 Ball b", &m_ball2b);
m_chooser.AddOption("3 Ball", &m_ball3);
// m_chooser.AddOption("2 Ball v2", &m_ball2b);
// m_chooser.AddOption("3 Ball", &m_ball3);

frc::SmartDashboard::PutData(&m_chooser);

// Initialize all of your commands and subsystems here
// ((-m_stick2.GetThrottle() + 2) / 3)
m_drivetrain.SetDefaultCommand(
TankDrive(
m_drivetrain,
[this] {
return ( -
(
Expand Down Expand Up @@ -90,34 +91,24 @@ RobotContainer::RobotContainer() {
// arcade
) * ((-m_stick2.GetThrottle() + 2) / 3)
);
},
m_drivetrain
}
)
);

/* no u
*/

m_arm.SetDefaultCommand(
ArmDrive(
m_arm,
[this] {
return (
m_stick3.GetY() / 5
);
},
m_arm
}
)
);

// Configure the button bindings
ConfigureButtonBindings();

// if (m_stick2.GetRawButton(3)){
// speed += 0.01;
// }
// if (m_stick2.GetRawButton(5)){
// speed -= 0.01;
// }
}

void RobotContainer::ConfigureButtonBindings() {
Expand All @@ -131,6 +122,5 @@ void RobotContainer::ConfigureButtonBindings() {
}

frc2::Command* RobotContainer::GetAutonomousCommand() {
// An example command will be run in autonomous
return m_chooser.GetSelected();
}
14 changes: 8 additions & 6 deletions src/main/cpp/commands/ArmDrive.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#include "commands/ArmDrive.h"

#include <utility>

#include "Robot.h"


ArmDrive::ArmDrive(
std::function<double()> speed,
Arm& arm):
m_speed(std::move(speed)),
m_arm(&arm){
Arm& arm,
std::function<double()> speed):
m_arm(&arm),
m_speed(std::move(speed)){

SetName("ArmDrive");
AddRequirements({m_arm});

}


void ArmDrive::Execute() {
m_arm->Rotate(m_speed());
}


void ArmDrive::End(bool) {
m_arm->Rotate(0);
}
9 changes: 5 additions & 4 deletions src/main/cpp/commands/ArmMove.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "commands/ArmMove.h"


ArmMove::ArmMove(
Arm& arm,
double speed,
Expand All @@ -15,8 +16,8 @@ ArmMove::ArmMove(

void ArmMove::Initialize(){

periods = 0;
period_target = m_duration * 50;
m_periods = 0;
m_periodTarget = m_duration * 50;

m_arm->Stop();

Expand All @@ -25,13 +26,13 @@ void ArmMove::Initialize(){
void ArmMove::Execute(){

m_arm->Rotate(m_speed);
periods++;
m_periods++;

}

bool ArmMove::IsFinished(){

return (periods >= period_target);
return (m_periods >= m_periodTarget);

}

Expand Down
3 changes: 3 additions & 0 deletions src/main/cpp/commands/IntakeDrive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ IntakeDrive::IntakeDrive(

}


void IntakeDrive::Initialize(){
m_intake->Stop();
}


void IntakeDrive::Execute() {
m_intake->Rotate(m_speed);
}


void IntakeDrive::End(bool){
m_intake->Stop();
}
9 changes: 5 additions & 4 deletions src/main/cpp/commands/IntakeMove.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "commands/IntakeMove.h"


IntakeMove::IntakeMove(
Intake& intake,
double speed,
Expand All @@ -15,8 +16,8 @@ IntakeMove::IntakeMove(

void IntakeMove::Initialize(){

periods = 0;
period_target = m_duration * 50;
m_periods = 0;
m_periodTarget = m_duration * 50;

m_intake->Stop();

Expand All @@ -25,13 +26,13 @@ void IntakeMove::Initialize(){
void IntakeMove::Execute(){

m_intake->Rotate(m_speed);
periods++;
m_periods++;

}

bool IntakeMove::IsFinished(){

return (periods >= period_target);
return (m_periods >= m_periodTarget);

}

Expand Down
22 changes: 8 additions & 14 deletions src/main/cpp/commands/TankDrive.cpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#include "commands/TankDrive.h"

#include <utility>

#include "Robot.h"

// Initialises the command with its name and requirements

TankDrive::TankDrive(
Drivetrain& drivetrain,
std::function<double()> left,
std::function<double()> right,
Drivetrain& drivetrain):
std::function<double()> right):
m_drivetrain(&drivetrain),
m_left(std::move(left)),
m_right(std::move(right)),
m_drivetrain(&drivetrain){
m_right(std::move(right)){

SetName("TankDrive");
AddRequirements({m_drivetrain});

}

// Called repeatedly when this Command is scheduled to run

void TankDrive::Execute() {
m_drivetrain->Drive(m_left(), m_right());
}

// Make this return true when this Command no longer needs to run execute()

bool TankDrive::IsFinished() {
return false;
}

// Called once after isFinished returns true

void TankDrive::End(bool) {
m_drivetrain->Drive(0, 0);
}
Loading

0 comments on commit 27dc7b3

Please sign in to comment.