From 56bb724966abc50fc3f3a406f3c5124ccab976e8 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sat, 26 Jul 2014 13:50:07 -0400 Subject: [PATCH] Templated everything. "Zaphod" has been removed from every file and replaced with HH --- src/HHBase.cpp | 2 +- src/HHBase.h | 6 +++--- src/{ZaphodRobot.cpp => HHRobot.cpp} | 22 +++++++++++----------- src/{ZaphodRobot.h => HHRobot.h} | 18 +++++++++--------- src/Subsystems/Collector.cpp | 8 ++++---- src/Subsystems/Collector.h | 5 ++--- src/Subsystems/Dashboard.cpp | 10 +++++----- src/Subsystems/Dashboard.h | 4 ++-- src/Subsystems/Shooter.cpp | 18 +++++++++--------- src/Subsystems/Shooter.h | 4 ++-- 10 files changed, 48 insertions(+), 49 deletions(-) rename src/{ZaphodRobot.cpp => HHRobot.cpp} (91%) rename src/{ZaphodRobot.h => HHRobot.h} (77%) diff --git a/src/HHBase.cpp b/src/HHBase.cpp index 6d06766..01e9dd8 100644 --- a/src/HHBase.cpp +++ b/src/HHBase.cpp @@ -1,7 +1,7 @@ #include "HHBase.h" HHBase::HHBase(): - hHBot(new ZaphodRobot()){ + hHBot(new HHRobot()){ printf("Done\n"); } void HHBase::RobotInit(){ diff --git a/src/HHBase.h b/src/HHBase.h index 6941f33..9525d49 100644 --- a/src/HHBase.h +++ b/src/HHBase.h @@ -1,21 +1,21 @@ #ifndef __HH_BASE_H__ #define __HH_BASE_H__ #include -#include "ZaphodRobot.h" +#include "HHRobot.h" #include "Subsystems/Controller.h" #include "Subsystems/Shooter.h" #include "Subsystems/Collector.h" #include "Subsystems/Compressor.h" #include "Subsystems/Dashboard.h" //Because this is the first header to be included, classes need to be declared here -class ZaphodRobot; +class HHRobot; class HHShooter; class HHCollector; class HHCompressor; class JoystickController; class HHBase : public IterativeRobot{ private: - ZaphodRobot* hHBot; + HHRobot* hHBot; public: HHBase(); void RobotInit(); diff --git a/src/ZaphodRobot.cpp b/src/HHRobot.cpp similarity index 91% rename from src/ZaphodRobot.cpp rename to src/HHRobot.cpp index 701036b..d1adac6 100644 --- a/src/ZaphodRobot.cpp +++ b/src/HHRobot.cpp @@ -1,11 +1,11 @@ -#include "ZaphodRobot.h" +#include "HHRobot.h" #include "HHBase.h" -ZaphodRobot::ZaphodRobot(): +HHRobot::HHRobot(): ControlSystem(new JoystickController()), - shooter(new ZaphodShooter()), - collector(new ZaphodCollector()), + shooter(new HHShooter()), + collector(new HHCollector()), compressorSystem(new HHCompressor()), - dashboard(new ZaphodDashboard()){ + dashboard(new HHDashboard()){ left1=new Jaguar(DRIVE_LEFT_SIDECAR, DRIVE_LEFT_MOTOR_ONE); left2=new Jaguar(DRIVE_LEFT_SIDECAR, DRIVE_LEFT_MOTOR_TWO); left3=new Jaguar(DRIVE_LEFT_SIDECAR, DRIVE_LEFT_MOTOR_THREE); @@ -22,7 +22,7 @@ ZaphodRobot::ZaphodRobot(): rearSonarRightA=new AnalogChannel(SONAR_REAR_RIGHT_ANA); } //Functions to get sonar values and return as INCH values -float ZaphodRobot::getFrontSonar(){ +float HHRobot::getFrontSonar(){ frontSonarLeftD->Set(1); frontSonarLeftV=(frontSonarLeftA->GetAverageVoltage()/0.00488f)/2.54f; frontSonarLeftD->Set(0); @@ -33,7 +33,7 @@ float ZaphodRobot::getFrontSonar(){ //Returns the average (useful for throwing out useless readings) return (frontSonarRightV+frontSonarLeftV)/2; } -float ZaphodRobot::getRearSonar(){ +float HHRobot::getRearSonar(){ rearSonarLeftD->Set(1); rearSonarLeftV=(rearSonarLeftA->GetAverageVoltage()/0.00488f)/2.54f; rearSonarLeftD->Set(0); @@ -44,7 +44,7 @@ float ZaphodRobot::getRearSonar(){ //Returns the average (useful for throwing out useless readings) return (rearSonarRightV+rearSonarLeftV)/2; } -bool ZaphodRobot::checkJoystickValues(){ +bool HHRobot::checkJoystickValues(){ float x=ControlSystem->rightJoystickAxisValues[1]; float y=ControlSystem->rightJoystickAxisValues[2]; if((-.1 < x && x < .1) && (-.1 < y && y < .1)) { @@ -56,7 +56,7 @@ bool ZaphodRobot::checkJoystickValues(){ return false; } } -void ZaphodRobot::driveRobot(float x, float y){ +void HHRobot::driveRobot(float x, float y){ if(y>1.0f) { y=1.0f; } else if(y!=0.0f&&y<-1.0f) { @@ -71,11 +71,11 @@ void ZaphodRobot::driveRobot(float x, float y){ left2->SetRaw(int(leftPower)); left3->SetRaw(int(leftPower)); } -void ZaphodRobot::updateDashboard(){ +void HHRobot::updateDashboard(){ dashboard->putFloatValue("Shooting Power", ControlSystem->throttle); } //Main function used to handle periodic tasks on the robot -void ZaphodRobot::handler(){ +void HHRobot::handler(){ //Periodic tasks that should be run by every loop ControlSystem->updateJoysticks(); shooter->updateShooterPosition(); diff --git a/src/ZaphodRobot.h b/src/HHRobot.h similarity index 77% rename from src/ZaphodRobot.h rename to src/HHRobot.h index 8717f52..dfbec5d 100644 --- a/src/ZaphodRobot.h +++ b/src/HHRobot.h @@ -4,23 +4,23 @@ #include "HHBase.h" #include "Definitions.h" class JoystickController; -class ZaphodShooter; -class ZaphodCollector; +class HHShooter; +class HHCollector; class HHCompressor; -class ZaphodDashboard; -class ZaphodRobot; -class ZaphodRobot{ +class HHDashboard; +class HHRobot; +class HHRobot{ private: Jaguar *right1, *right2, *right3, *left1, *left2, *left3; DigitalOutput *frontSonarLeftD, *frontSonarRightD, *rearSonarLeftD, *rearSonarRightD; AnalogChannel *frontSonarLeftA, *frontSonarRightA, *rearSonarLeftA, *rearSonarRightA; JoystickController *ControlSystem; - ZaphodShooter *shooter; - ZaphodCollector *collector; + HHShooter *shooter; + HHCollector *collector; HHCompressor *compressorSystem; - ZaphodDashboard *dashboard; + HHDashboard *dashboard; public: - ZaphodRobot(); + HHRobot(); float frontSonarLeftV, frontSonarRightV, rearSonarLeftV, rearSonarRightV; float getFrontSonar(); float getRearSonar(); diff --git a/src/Subsystems/Collector.cpp b/src/Subsystems/Collector.cpp index 8f52330..d889e62 100644 --- a/src/Subsystems/Collector.cpp +++ b/src/Subsystems/Collector.cpp @@ -1,8 +1,8 @@ #include "Collector.h" -ZaphodCollector::ZaphodCollector(){ +HHCollector::HHCollector(){ collectorMotor = new Jaguar(COLLECTOR_SIDECAR, COLLECTOR_MOTOR); } -void ZaphodCollector::updateCollector(bool shooting, float angle){ +void HHCollector::updateCollector(bool shooting, float angle){ //Needed for the auto running of collector when shooting if(shooting){ if(angle <= 40){ @@ -19,9 +19,9 @@ void ZaphodCollector::updateCollector(bool shooting, float angle){ collectorMotor->Set(0); } } -void ZaphodCollector::collectBall(){ +void HHCollector::collectBall(){ collectorMotor->Set(1); } -void ZaphodCollector::releaseBall(){ +void HHCollector::releaseBall(){ collectorMotor->Set(255); } diff --git a/src/Subsystems/Collector.h b/src/Subsystems/Collector.h index 11f8e78..64c6f80 100644 --- a/src/Subsystems/Collector.h +++ b/src/Subsystems/Collector.h @@ -1,7 +1,6 @@ #include #include "../Definitions.h" -class ZaphodCollector -{ +class HHCollector{ private: Jaguar *collectorMotor; public: @@ -10,7 +9,7 @@ class ZaphodCollector RELEASE, STOP }e_CollectorState; - ZaphodCollector(); + HHCollector(); void updateCollector(bool, float); void collectBall(); void releaseBall(); diff --git a/src/Subsystems/Dashboard.cpp b/src/Subsystems/Dashboard.cpp index 3c1a3a8..a805de0 100644 --- a/src/Subsystems/Dashboard.cpp +++ b/src/Subsystems/Dashboard.cpp @@ -1,22 +1,22 @@ #include "Dashboard.h" -ZaphodDashboard::ZaphodDashboard(){ +HHDashboard::HHDashboard(){ //Add Dashboard Initalizations here (for now) SmartDashboard::PutNumber("Shooting Power", 0.0f); SmartDashboard::PutBoolean("Joysticks Valid", false); } -float ZaphodDashboard::getFloatValue(const char* key){ +float HHDashboard::getFloatValue(const char* key){ float value=SmartDashboard::GetNumber(key); return value; } -bool ZaphodDashboard::putFloatValue(const char* key, float value){ +bool HHDashboard::putFloatValue(const char* key, float value){ SmartDashboard::PutNumber(key,value); return true; } -bool ZaphodDashboard::getBoolValue(const char* key){ +bool HHDashboard::getBoolValue(const char* key){ bool value=SmartDashboard::GetBoolean(key); return value; } -bool ZaphodDashboard::putBoolValue(const char* key, bool value){ +bool HHDashboard::putBoolValue(const char* key, bool value){ SmartDashboard::PutBoolean(key,value); return true; } diff --git a/src/Subsystems/Dashboard.h b/src/Subsystems/Dashboard.h index f8bf1d5..c6973eb 100644 --- a/src/Subsystems/Dashboard.h +++ b/src/Subsystems/Dashboard.h @@ -1,9 +1,9 @@ #include "SmartDashboard/SmartDashboard.h" #include #include "../Definitions.h" -class ZaphodDashboard{ +class HHDashboard{ public: - ZaphodDashboard(); + HHDashboard(); //Array used to track the values in the dashboard bool DashboardValues[]; float getFloatValue(const char* key); diff --git a/src/Subsystems/Shooter.cpp b/src/Subsystems/Shooter.cpp index 0595b24..bf64cff 100644 --- a/src/Subsystems/Shooter.cpp +++ b/src/Subsystems/Shooter.cpp @@ -1,5 +1,5 @@ #include "Shooter.h" -ZaphodShooter::ZaphodShooter(){ +HHShooter::HHShooter(){ shooterLeft1=new Jaguar(SHOOTER_LEFT_SIDECAR, SHOOTER_LEFT_MOTOR_ONE); shooterLeft2=new Jaguar(SHOOTER_LEFT_SIDECAR, SHOOTER_LEFT_MOTOR_TWO); shooterRight1=new Jaguar(SHOOTER_RIGHT_SIDECAR, SHOOTER_RIGHT_MOTOR_ONE); @@ -7,13 +7,13 @@ ZaphodShooter::ZaphodShooter(){ shooterAngle=new AnalogChannel(SHOOTER_ANGLE_POT); e_ShooterState=IDLE_PRESHOT; } -void ZaphodShooter::startShootingSequence(float throttle){ +void HHShooter::startShootingSequence(float throttle){ //Changes the enum to tell the shooter to be firing e_ShooterState=FIRING; shootingPower=throttle; } //First step in shooting process -void ZaphodShooter::shootForAngle(float power, float desiredAngle){ +void HHShooter::shootForAngle(float power, float desiredAngle){ if(getAngle() <= desiredAngle && power >= 15){ shootRaw(power); e_ShooterState=FIRING; @@ -24,7 +24,7 @@ void ZaphodShooter::shootForAngle(float power, float desiredAngle){ } //Second step in shooting process //Probably wont need to be used without shootForAngle -void ZaphodShooter::lower(float desiredAngle){ +void HHShooter::lower(float desiredAngle){ if(getAngle() >= desiredAngle){ shootRaw(-0.1f); e_ShooterState=LOWERING; @@ -35,20 +35,20 @@ void ZaphodShooter::lower(float desiredAngle){ } } //Not needed anywhere other than after/before the shooting process -void ZaphodShooter::stopShooter(){ +void HHShooter::stopShooter(){ if(e_ShooterState == IDLE_PRESHOT){ shootRaw(0.0f); } } //Shouldn't be used in any other class but this one -void ZaphodShooter::shootRaw(float power){ +void HHShooter::shootRaw(float power){ shooterLeft1->SetRaw(int(floatToPWM(power))); shooterLeft2->SetRaw(int(floatToPWM(power))); shooterRight1->SetRaw(int(floatToPWM(-power))); shooterRight2->SetRaw(int(floatToPWM(-power))); } //Should be run in a loop -void ZaphodShooter::updateShooterPosition(){ +void HHShooter::updateShooterPosition(){ if(e_ShooterState == IDLE_PRESHOT){ isShooting=false; stopShooter(); @@ -62,11 +62,11 @@ void ZaphodShooter::updateShooterPosition(){ lower(40); } } -float ZaphodShooter::floatToPWM(float input){ +float HHShooter::floatToPWM(float input){ return input*127.0+128; } //Returns angle measure in degrees -float ZaphodShooter::getAngle(){ +float HHShooter::getAngle(){ float max=-.0003948; float min=5.0245547; float b=shooterAngle->GetAverageVoltage()-max; diff --git a/src/Subsystems/Shooter.h b/src/Subsystems/Shooter.h index 49f4fa7..a0e4172 100644 --- a/src/Subsystems/Shooter.h +++ b/src/Subsystems/Shooter.h @@ -1,11 +1,11 @@ #include #include "../Definitions.h" -class ZaphodShooter{ +class HHShooter{ private: Jaguar*shooterLeft1, *shooterLeft2, *shooterRight1, *shooterRight2; AnalogChannel*shooterAngle; public: - ZaphodShooter(); + HHShooter(); enum { IDLE_PRESHOT, FIRING,