From 84781543072db0639739f31c75df5d80f15d40fd Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Tue, 10 Jun 2014 20:29:12 -0400 Subject: [PATCH] Code now compiles. Completed refactorign of HHBase and Compressor. Continuing with refactoring. (Untested) --- src/HHBase.cpp | 4 +- src/HHBase.h | 9 +- src/Subsystems/Compressor.h | 8 +- src/ZaphodRobot.cpp | 206 +++++++++++++++++------------------- src/ZaphodRobot.h | 12 +-- 5 files changed, 109 insertions(+), 130 deletions(-) diff --git a/src/HHBase.cpp b/src/HHBase.cpp index 18bce69..6d06766 100644 --- a/src/HHBase.cpp +++ b/src/HHBase.cpp @@ -1,7 +1,7 @@ #include "HHBase.h" -ZaphodBase::HHBase(): - hHBot(new HHRobot()){ +HHBase::HHBase(): + hHBot(new ZaphodRobot()){ printf("Done\n"); } void HHBase::RobotInit(){ diff --git a/src/HHBase.h b/src/HHBase.h index 471dc64..6941f33 100644 --- a/src/HHBase.h +++ b/src/HHBase.h @@ -1,22 +1,21 @@ #ifndef __HH_BASE_H__ #define __HH_BASE_H__ #include -#include "HHRobot.h" +#include "ZaphodRobot.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 HHRobot; +class ZaphodRobot; class HHShooter; class HHCollector; class HHCompressor; class JoystickController; -class ZaphodBase : public IterativeRobot -{ +class HHBase : public IterativeRobot{ private: - HHRobot* hHBot; + ZaphodRobot* hHBot; public: HHBase(); void RobotInit(); diff --git a/src/Subsystems/Compressor.h b/src/Subsystems/Compressor.h index 48ce225..c3dadb8 100644 --- a/src/Subsystems/Compressor.h +++ b/src/Subsystems/Compressor.h @@ -15,8 +15,8 @@ class HHCompressor }e_CollectorSolenoidState; HHCompressor(); void compressorSystemPeriodic(); - void extendCollector(); - void retractCollector(); - void startCompressing(); - void stopCompressing(); + void ExtendCollector(); + void RetractCollector(); + void StartCompressing(); + void StopCompressing(); }; diff --git a/src/ZaphodRobot.cpp b/src/ZaphodRobot.cpp index 473fc81..701036b 100644 --- a/src/ZaphodRobot.cpp +++ b/src/ZaphodRobot.cpp @@ -1,121 +1,105 @@ #include "ZaphodRobot.h" -#include "ZaphodBase.h" - +#include "HHBase.h" ZaphodRobot::ZaphodRobot(): - ControlSystem(new JoystickController()), - shooter(new ZaphodShooter()), - collector(new ZaphodCollector()), - compressorSystem(new ZaphodCompressor()), - dashboard(new ZaphodDashboard()) -{ - 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); - right1 = new Jaguar(DRIVE_RIGHT_SIDECAR, DRIVE_RIGHT_MOTOR_ONE); - right2 = new Jaguar(DRIVE_RIGHT_SIDECAR, DRIVE_RIGHT_MOTOR_ONE); - right3 = new Jaguar(DRIVE_RIGHT_SIDECAR, DRIVE_RIGHT_MOTOR_ONE); - frontSonarLeftD = new DigitalOutput(SONAR_LEFT_DIO_SIDECAR, SONAR_FRONT_LEFT_DIO); - frontSonarRightD = new DigitalOutput(SONAR_RIGHT_DIO_SIDECAR, SONAR_FRONT_RIGHT_DIO); - rearSonarLeftD = new DigitalOutput(SONAR_LEFT_DIO_SIDECAR, SONAR_REAR_LEFT_DIO); - rearSonarRightD = new DigitalOutput(SONAR_RIGHT_DIO_SIDECAR, SONAR_REAR_RIGHT_DIO); - frontSonarLeftA = new AnalogChannel(SONAR_FRONT_LEFT_ANA); - frontSonarRightA = new AnalogChannel(SONAR_FRONT_RIGHT_ANA); - rearSonarLeftA = new AnalogChannel(SONAR_REAR_LEFT_ANA); - rearSonarRightA = new AnalogChannel(SONAR_REAR_RIGHT_ANA); -} - + ControlSystem(new JoystickController()), + shooter(new ZaphodShooter()), + collector(new ZaphodCollector()), + compressorSystem(new HHCompressor()), + dashboard(new ZaphodDashboard()){ + 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); + right1=new Jaguar(DRIVE_RIGHT_SIDECAR, DRIVE_RIGHT_MOTOR_ONE); + right2=new Jaguar(DRIVE_RIGHT_SIDECAR, DRIVE_RIGHT_MOTOR_ONE); + right3=new Jaguar(DRIVE_RIGHT_SIDECAR, DRIVE_RIGHT_MOTOR_ONE); + frontSonarLeftD=new DigitalOutput(SONAR_LEFT_DIO_SIDECAR, SONAR_FRONT_LEFT_DIO); + frontSonarRightD=new DigitalOutput(SONAR_RIGHT_DIO_SIDECAR, SONAR_FRONT_RIGHT_DIO); + rearSonarLeftD=new DigitalOutput(SONAR_LEFT_DIO_SIDECAR, SONAR_REAR_LEFT_DIO); + rearSonarRightD=new DigitalOutput(SONAR_RIGHT_DIO_SIDECAR, SONAR_REAR_RIGHT_DIO); + frontSonarLeftA=new AnalogChannel(SONAR_FRONT_LEFT_ANA); + frontSonarRightA=new AnalogChannel(SONAR_FRONT_RIGHT_ANA); + rearSonarLeftA=new AnalogChannel(SONAR_REAR_LEFT_ANA); + rearSonarRightA=new AnalogChannel(SONAR_REAR_RIGHT_ANA); + } //Functions to get sonar values and return as INCH values - -float ZaphodRobot::getFrontSonar() -{ - frontSonarLeftD->Set(1); - frontSonarLeftV = (frontSonarLeftA->GetAverageVoltage()/0.00488f)/2.54f; - frontSonarLeftD->Set(0); - //Probably need some sort of delay here - frontSonarRightD->Set(1); - frontSonarRightV = (frontSonarRightA->GetAverageVoltage()/0.00488f)/2.54f; - frontSonarRightD->Set(0); - //Returns the average (useful for throwing out useless readings) - return (frontSonarRightV+frontSonarLeftV)/2; +float ZaphodRobot::getFrontSonar(){ + frontSonarLeftD->Set(1); + frontSonarLeftV=(frontSonarLeftA->GetAverageVoltage()/0.00488f)/2.54f; + frontSonarLeftD->Set(0); + //Probably need some sort of delay here + frontSonarRightD->Set(1); + frontSonarRightV=(frontSonarRightA->GetAverageVoltage()/0.00488f)/2.54f; + frontSonarRightD->Set(0); + //Returns the average (useful for throwing out useless readings) + return (frontSonarRightV+frontSonarLeftV)/2; } - -float ZaphodRobot::getRearSonar() -{ - rearSonarLeftD->Set(1); - rearSonarLeftV = (rearSonarLeftA->GetAverageVoltage()/0.00488f)/2.54f; - rearSonarLeftD->Set(0); - //Probably need some sort of delay here - rearSonarRightD->Set(1); - rearSonarRightV = (rearSonarRightA->GetAverageVoltage()/0.00488f)/2.54f; - rearSonarRightD->Set(0); - //Returns the average (useful for throwing out useless readings) - return (rearSonarRightV+rearSonarLeftV)/2; +float ZaphodRobot::getRearSonar(){ + rearSonarLeftD->Set(1); + rearSonarLeftV=(rearSonarLeftA->GetAverageVoltage()/0.00488f)/2.54f; + rearSonarLeftD->Set(0); + //Probably need some sort of delay here + rearSonarRightD->Set(1); + rearSonarRightV=(rearSonarRightA->GetAverageVoltage()/0.00488f)/2.54f; + rearSonarRightD->Set(0); + //Returns the average (useful for throwing out useless readings) + return (rearSonarRightV+rearSonarLeftV)/2; } - -bool ZaphodRobot::checkJoystickValues() -{ - float x = ControlSystem->rightJoystickAxisValues[1]; - float y = ControlSystem->rightJoystickAxisValues[2]; - if((-.1 < x && x < .1) && (-.1 < y && y < .1)) { - dashboard->putBoolValue("Joysticks Valid", true); - return true; - } else { - dashboard->putBoolValue("Joysticks Valid", false); - return true; - return false; - } +bool ZaphodRobot::checkJoystickValues(){ + float x=ControlSystem->rightJoystickAxisValues[1]; + float y=ControlSystem->rightJoystickAxisValues[2]; + if((-.1 < x && x < .1) && (-.1 < y && y < .1)) { + dashboard->putBoolValue("Joysticks Valid", true); + return true; + } else { + dashboard->putBoolValue("Joysticks Valid", false); + return true; + return false; + } } - -void ZaphodRobot::driveRobot(float x, float y) -{ - if(y>1.0f) { - y=1.0f; - } else if(y!=0.0f&&y<-1.0f) { - y=-1.0f; - } - float leftPower=((y+x)/2+1)*127+1; - float rightPower=((y-x)/2+1)*127+1; - right1->SetRaw(int(rightPower)); - right2->SetRaw(int(rightPower)); - right3->SetRaw(int(rightPower)); - left1->SetRaw(int(leftPower)); - left2->SetRaw(int(leftPower)); - left3->SetRaw(int(leftPower)); +void ZaphodRobot::driveRobot(float x, float y){ + if(y>1.0f) { + y=1.0f; + } else if(y!=0.0f&&y<-1.0f) { + y=-1.0f; + } + float leftPower=((y+x)/2+1)*127+1; + float rightPower=((y-x)/2+1)*127+1; + right1->SetRaw(int(rightPower)); + right2->SetRaw(int(rightPower)); + right3->SetRaw(int(rightPower)); + left1->SetRaw(int(leftPower)); + left2->SetRaw(int(leftPower)); + left3->SetRaw(int(leftPower)); } - -void ZaphodRobot::updateDashboard() -{ - dashboard->putFloatValue("Shooting Power", ControlSystem->throttle); +void ZaphodRobot::updateDashboard(){ + dashboard->putFloatValue("Shooting Power", ControlSystem->throttle); } - //Main function used to handle periodic tasks on the robot - -void ZaphodRobot::handler() -{ - //Periodic tasks that should be run by every loop - ControlSystem->updateJoysticks(); - shooter->updateShooterPosition(); - //TODO Need to implement a timing system to not break the spike (this function doesn't run the compressor at the moment) - compressorSystem->compressorSystemPeriodic(); - collector->updateCollector(shooter->isShooting, shooter->getAngle()); - if(checkJoystickValues()) { - driveRobot(ControlSystem->rightJoystickAxisValues[3]+ControlSystem->rightJoystickAxisValues[1], -ControlSystem->rightJoystickAxisValues[2]); - } - updateDashboard(); - //Button assignments to actions - if(ControlSystem->leftJoystickValues[SHOOTER_FIRE]) { - shooter->startShootingSequence(ControlSystem->throttle); - } - if(ControlSystem->rightJoystickValues[COLLECTOR_INTAKE]) { - collector->collectBall(); - } - if(ControlSystem->rightJoystickValues[COLLECTOR_OUTTAKE]) { - collector->releaseBall(); - } - if(ControlSystem->rightJoystickValues[COLLECTOR_EXTEND]) { - compressorSystem->extendCollector(); - } - if(ControlSystem->rightJoystickValues[COLLECTOR_RETRACT]) { - compressorSystem->retractCollector(); - } +void ZaphodRobot::handler(){ + //Periodic tasks that should be run by every loop + ControlSystem->updateJoysticks(); + shooter->updateShooterPosition(); + //TODO Need to implement a timing system to not break the spike (this function doesn't run the compressor at the moment) + compressorSystem->compressorSystemPeriodic(); + collector->updateCollector(shooter->isShooting, shooter->getAngle()); + if(checkJoystickValues()) { + driveRobot(ControlSystem->rightJoystickAxisValues[3]+ControlSystem->rightJoystickAxisValues[1], -ControlSystem->rightJoystickAxisValues[2]); + } + updateDashboard(); + //Button assignments to actions + if(ControlSystem->leftJoystickValues[SHOOTER_FIRE]) { + shooter->startShootingSequence(ControlSystem->throttle); + } + if(ControlSystem->rightJoystickValues[COLLECTOR_INTAKE]) { + collector->collectBall(); + } + if(ControlSystem->rightJoystickValues[COLLECTOR_OUTTAKE]) { + collector->releaseBall(); + } + if(ControlSystem->rightJoystickValues[COLLECTOR_EXTEND]) { + compressorSystem->extendCollector(); + } + if(ControlSystem->rightJoystickValues[COLLECTOR_RETRACT]) { + compressorSystem->retractCollector(); + } } diff --git a/src/ZaphodRobot.h b/src/ZaphodRobot.h index 93f65df..8717f52 100644 --- a/src/ZaphodRobot.h +++ b/src/ZaphodRobot.h @@ -1,19 +1,15 @@ #ifndef __ZAPHOD_ROBOT_H__ #define __ZAPHOD_ROBOT_H__ - #include -#include "ZaphodBase.h" +#include "HHBase.h" #include "Definitions.h" - class JoystickController; class ZaphodShooter; class ZaphodCollector; -class ZaphodCompressor; +class HHCompressor; class ZaphodDashboard; class ZaphodRobot; - -class ZaphodRobot -{ +class ZaphodRobot{ private: Jaguar *right1, *right2, *right3, *left1, *left2, *left3; DigitalOutput *frontSonarLeftD, *frontSonarRightD, *rearSonarLeftD, *rearSonarRightD; @@ -21,7 +17,7 @@ class ZaphodRobot JoystickController *ControlSystem; ZaphodShooter *shooter; ZaphodCollector *collector; - ZaphodCompressor *compressorSystem; + HHCompressor *compressorSystem; ZaphodDashboard *dashboard; public: ZaphodRobot();