diff --git a/src/HHRobot.cpp b/src/HHRobot.cpp index 09d49c3..9f8c7a4 100644 --- a/src/HHRobot.cpp +++ b/src/HHRobot.cpp @@ -7,9 +7,7 @@ HHRobot::HHRobot(): compressorSystem(new HHCompressor()), dashboard(new HHDashboard()), sonar(new HHSonar()){ - //comment } -//Functions to get sonar values and return as INCH values bool HHRobot::checkJoystickValues(){ float x=ControlSystem->rightJoystickAxisValues[1]; float y=ControlSystem->rightJoystickAxisValues[2]; diff --git a/src/Subsystems/Sonar.cpp b/src/Subsystems/Sonar.cpp index 7993985..e97685f 100644 --- a/src/Subsystems/Sonar.cpp +++ b/src/Subsystems/Sonar.cpp @@ -9,6 +9,59 @@ HHSonar::HHSonar(){ AnalogChannel backLeftA=new AnalogChannel(SONAR_BACK_LEFT_ANA); AnalogChannel backRightA=new AnalogChannel(SONAR_BACK_RIGHT_ANA); } -float HHSonar::getInches(const char* from){ - return 10.9f; +float HHSonar::getInches(std::string from){ + switch(from){ + case "FRONT": + frontLeftD->Set(1); + float x=(frontLeftA->GetAverageVoltage()/0.00488f)/2.54f; + frontLeftD->Set(0); + //TODO: Delay + frontRightD->Set(1); + float y=(frontRightA->GetAverageVoltage()/0.00488f)/2.54f; + frontRightD->Set(0); + //TODO: Delay + return (x+y)/2; + break; + case "BACK": + backLeftD->Set(1); + float x=(backLeftA->GetAverageVoltage()/0.00488f)/2.54f; + backLeftD->Set(0); + //TODO: Delay + backRightD->Set(1); + float y=(backRightA->GetAverageVoltage()/0.00488f)/2.54f; + backRightD->Set(0); + //TODO: Delay + return (x+y)/2; + break; + case "FRONTLEFT": + frontLeftD->Set(1); + float x=(frontLeftA->GetAverageVoltage()/0.00488f)/2.54f; + frontLeftD->Set(0); + //TODO: Delay + return x; + break; + case "FRONTRIGHT": + frontRightD->Set(1); + float x=(frontRightA->GetAverageVoltage()/0.00488f)/2.54f; + frontRightD->Set(0); + //TODO: Delay + return x; + break; + case "BACKLEFT": + backLeftD->Set(1); + float x=(backLeftA->GetAverageVoltage()/0.00488f)/2.54f; + backLeftD->Set(0); + //TODO: Delay + return x; + break; + case "BACKRIGHT": + backRightD->Set(1); + float x=(backRightA->GetAverageVoltage()/0.00488f)/2.54f; + backRightD->Set(0); + //TODO: Delay + return x; + break; + default: + break; + } } diff --git a/src/Subsystems/Sonar.h b/src/Subsystems/Sonar.h index 35e2b67..3063b27 100644 --- a/src/Subsystems/Sonar.h +++ b/src/Subsystems/Sonar.h @@ -7,5 +7,5 @@ class HHSonar{ public: HHSonar(); //from is (in string form) "FRONT", "BACK", "FRONTLEFT", "FRONTRIGHT"... - float getInches(const char* from); + float getInches(std::string from); };