From 7b24f4914eb1a5d5683a9c5a775b6652063ff6f3 Mon Sep 17 00:00:00 2001 From: Adam Long Date: Sun, 28 Dec 2014 20:40:47 +0000 Subject: [PATCH] Moved the compressor code the lib/pnumatics and updated the old code to work with it --- src/HHBase.h | 3 - src/HHRobot.cpp | 17 ++---- src/HHRobot.h | 4 +- src/Subsystems/Compressor.cpp | 60 ------------------- src/lib/pneumatics/Compressor.cpp | 47 +++++++++++++++ .../pneumatics}/Compressor.h | 14 ++--- 6 files changed, 61 insertions(+), 84 deletions(-) delete mode 100644 src/Subsystems/Compressor.cpp create mode 100644 src/lib/pneumatics/Compressor.cpp rename src/{Subsystems => lib/pneumatics}/Compressor.h (54%) diff --git a/src/HHBase.h b/src/HHBase.h index 63faedb..b94a5a4 100644 --- a/src/HHBase.h +++ b/src/HHBase.h @@ -4,7 +4,6 @@ #include "HHRobot.h" #include "Subsystems/Shooter.h" #include "Subsystems/Collector.h" -#include "Subsystems/Compressor.h" #include "Subsystems/Sonar.h" #include "Subsystems/Dashboard.h" #include @@ -12,9 +11,7 @@ class HHRobot; class HHShooter; class HHCollector; -class HHCompressor; class HHSonar; -class JoystickController; class HHBase : public IterativeRobot{ private: HHRobot* hHBot; diff --git a/src/HHRobot.cpp b/src/HHRobot.cpp index bc2b772..0d0b634 100644 --- a/src/HHRobot.cpp +++ b/src/HHRobot.cpp @@ -5,9 +5,9 @@ HHRobot::HHRobot(): drive(new WCDrive(6,1,1,1,2,1,3,2,1,2,2,2,3)), driveStick(new Extreme3dPro(1)), shootStick(new Extreme3dPro(2)), + compressor(new AirCompressor(2,5,1,3)), shooter(new HHShooter()), collector(new HHCollector()), - compressorSystem(new HHCompressor()), dashboard(new HHDashboard()){ //sonar(new HHSonar()){} driveTable=NetworkTable::GetTable("ZaphodDrive"); @@ -24,8 +24,7 @@ void HHRobot::Init(){ //Put table values initally to avoid annoying refreshing shooterTable->PutNumber("Target Shooter Angle",90); shooterTable->PutNumber("Current Shooter Angle",-420); - timer->Start(); - compressorSystem->StartCompressor(); + compressor->StartCompressor(); } bool HHRobot::CheckJoystickValues(){ float x=driveStick->GetJoystickAxis("x"); @@ -44,7 +43,7 @@ void HHRobot::UpdateDashboard(){ void HHRobot::RunAuto(){ timer->Reset(); int step,time; - compressorSystem->ExtendCollector(); + //CollectorExtend //TODO I have no idea what rate this loop runs at so we are going to have to fine tune the times //Drive for 51 inches/cm/units (or time) if(step==2){ @@ -72,16 +71,10 @@ void HHRobot::RunAuto(){ //Main function used to handle periodic tasks on the robot void HHRobot::Handler(){ double targetAngle = shooterTable->GetNumber("Target Shooter Angle"); - bool allowCompressing = true; //Periodic tasks that should be run by every loop shooter->UpdateShooterPosition(targetAngle); driveStick->handler(); shootStick->handler(); - if(timer->Get()-lastTime>=0.5f){ - // Update compressor when current time-last time is more than .5 seconds - lastTime=timer->Get(); - compressorSystem->CompressorSystemPeriodic(allowCompressing); - } collector->UpdateCollector(shooter->isShooting,shooter->GetAngle()); //TODO Fix whatever the heck is wrong with this drive->Update(6,driveStick->GetJoystickAxis("z")+driveStick->GetJoystickAxis("x"),driveStick->GetJoystickAxis("y")); @@ -102,10 +95,10 @@ void HHRobot::Handler(){ collector->CollectorStop(); } if(driveStick->GetJoystickButton(COLLECTOR_EXTEND)){ - compressorSystem->ExtendCollector(); + //TODO extend collector } if(driveStick->GetJoystickButton(COLLECTOR_RETRACT)){ - compressorSystem->RetractCollector(); + //TODO retract collector } if(shootStick->GetJoystickButton(SHOOTER_ANGLE_ONE)){ targetAngle=100; diff --git a/src/HHRobot.h b/src/HHRobot.h index d4d9c9e..27ebe2c 100644 --- a/src/HHRobot.h +++ b/src/HHRobot.h @@ -4,10 +4,10 @@ #include "HHBase.h" #include "lib/drive/WCDrive.h" #include "lib/controller/Controller.h" +#include "lib/pneumatics/Compressor.h" #include "Definitions.h" class HHShooter; class HHCollector; -class HHCompressor; class HHDashboard; class HHRobot; class HHSonar; @@ -15,10 +15,10 @@ class HHRobot{ private: WCDrive *drive; Extreme3dPro *driveStick, *shootStick; + AirCompressor *compressor; NetworkTable *driveTable, *shooterTable, *collectorTable; HHShooter *shooter; HHCollector *collector; - HHCompressor *compressorSystem; HHDashboard *dashboard; HHSonar *sonar; Timer *timer; diff --git a/src/Subsystems/Compressor.cpp b/src/Subsystems/Compressor.cpp deleted file mode 100644 index 5e149e1..0000000 --- a/src/Subsystems/Compressor.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "Compressor.h" -HHCompressor::HHCompressor(){ - compressor=new Compressor(COMPRESSOR_GAUGE_SIDECAR, COMPRESSOR_GAUGE, COMPRESSOR_RELAY_SIDECAR, COMPRESSOR_RELAY); - solenoid1=new Solenoid(COMPRESSOR_SOLENOID_ONE); - solenoid2=new Solenoid(COMPRESSOR_SOLENOID_TWO); - compressing=false; -} -void HHCompressor::CompressorSystemPeriodic(bool compressorEnabled){ - switch(e_CollectorSolenoidState){ - case EXTENDED: - solenoid1->Set(false); - solenoid2->Set(true); - break; - case RETRACTED: - solenoid1->Set(true); - solenoid2->Set(false); - break; - case IDLE: - break; - default: - break; - } - if(compressorEnabled){ - printf("Compressor is enabled\n"); - if(compressing&&compressor->GetPressureSwitchValue()==1){ - // It is compressing, but the pressure is too high - printf("Condition 1"); - StopCompressor(); - }else if(!compressing&&compressor->GetPressureSwitchValue()==0){ - // It is not compressing and the pressure isn't too high - printf("Condition 2"); - StartCompressor(); - } - }else{ - printf("Condition 3"); - if(compressing){ - // If the compressor is not enabled, but it's still compressing - printf("Condition 4"); - StopCompressor(); - } - } - e_CollectorSolenoidState=IDLE; -} -void HHCompressor::ExtendCollector(){ - e_CollectorSolenoidState=EXTENDED; -} -void HHCompressor::RetractCollector(){ - e_CollectorSolenoidState=RETRACTED; -} -void HHCompressor::StopCompressor(){ - printf("Stopping compressor\n"); - compressor->Stop(); - compressing=false; -} -void HHCompressor::StartCompressor(){ - printf("Starting compressor\n"); - compressor->Start(); - compressing=true; -} -// vim: ts=2:sw=2:et diff --git a/src/lib/pneumatics/Compressor.cpp b/src/lib/pneumatics/Compressor.cpp new file mode 100644 index 0000000..442c981 --- /dev/null +++ b/src/lib/pneumatics/Compressor.cpp @@ -0,0 +1,47 @@ +#include "Compressor.h" +AirCompressor::AirCompressor(uint8_t compressorGauge, uint8_t compressorRelay){ + compressor = new Compressor(compressorGauge,compressorRelay); + timer = new Timer(); + lastTime=0; + compressing=false; +} +AirCompressor::AirCompressor(uint8_t compressorGaugeSidecar, uint8_t compressorGauge, uint8_t compressorRelaySidecar, uint8_t compressorRelay){ + compressor = new Compressor(compressorGaugeSidecar, compressorGauge, compressorRelaySidecar, compressorRelay); + timer = new Timer(); + lastTime=0; + compressing=false; +} +void AirCompressor::CompressorSystemPeriodic(){ + bool compressorEnabled; + if(timer->Get()-lastTime>=0.5f){ + // Update compressor when current time-last time is more than .5 seconds + lastTime=timer->Get(); + compressorEnabled=true; + } + if(compressorEnabled){ + if(compressing&&compressor->GetPressureSwitchValue()==1){ + // It is compressing, but the pressure is too high + StopCompressor(); + }else if(!compressing&&compressor->GetPressureSwitchValue()==0){ + // It is not compressing and the pressure isn't too high + StartCompressor(); + } + }else{ + if(compressing){ + // If the compressor is not enabled, but it's still compressing + StopCompressor(); + } + } + e_CollectorSolenoidState=IDLE; +} +void AirCompressor::StopCompressor(){ + printf("Stopping compressor\n"); + compressor->Stop(); + compressing=false; +} +void AirCompressor::StartCompressor(){ + printf("Starting compressor\n"); + compressor->Start(); + compressing=true; +} +// vim: ts=2:sw=2:et diff --git a/src/Subsystems/Compressor.h b/src/lib/pneumatics/Compressor.h similarity index 54% rename from src/Subsystems/Compressor.h rename to src/lib/pneumatics/Compressor.h index 53c6d7f..63c71b3 100644 --- a/src/Subsystems/Compressor.h +++ b/src/lib/pneumatics/Compressor.h @@ -1,10 +1,11 @@ #include -#include "../Definitions.h" #include -class HHCompressor{ +class AirCompressor{ private: Compressor *compressor; - Solenoid *solenoid1, *solenoid2; + //Timer used for keeping time? + Timer *timer; + double lastTime; bool compressing; public: enum{ @@ -12,10 +13,9 @@ class HHCompressor{ RETRACTED, IDLE }e_CollectorSolenoidState; - HHCompressor(); - void CompressorSystemPeriodic(bool compressorEnabled); - void ExtendCollector(); - void RetractCollector(); + explicit AirCompressor(uint8_t,uint8_t); + AirCompressor(uint8_t,uint8_t,uint8_t,uint8_t); + void CompressorSystemPeriodic(); void StopCompressor(); void StartCompressor(); };