mirror of
https://github.com/team2059/Zaphod
synced 2025-01-07 22:14:14 -05:00
Added sonar code (doesn't work yet)
This commit is contained in:
parent
4972ee5e39
commit
47a6b9050b
@ -45,13 +45,13 @@
|
||||
//Ultrasonic (DIO, Analog, etc)
|
||||
#define SONAR_FRONT_RIGHT_DIO 4
|
||||
#define SONAR_FRONT_LEFT_DIO 4
|
||||
#define SONAR_REAR_LEFT_DIO 5
|
||||
#define SONAR_REAR_RIGHT_DIO 5
|
||||
#define SONAR_BACK_LEFT_DIO 5
|
||||
#define SONAR_BACK_RIGHT_DIO 5
|
||||
|
||||
#define SONAR_FRONT_RIGHT_ANA 2
|
||||
#define SONAR_FRONT_LEFT_ANA 1
|
||||
#define SONAR_REAR_LEFT_ANA 3
|
||||
#define SONAR_REAR_RIGHT_ANA 4
|
||||
#define SONAR_BACK_LEFT_ANA 3
|
||||
#define SONAR_BACK_RIGHT_ANA 4
|
||||
|
||||
//Joystick buttons
|
||||
|
||||
|
@ -6,12 +6,14 @@
|
||||
#include "Subsystems/Shooter.h"
|
||||
#include "Subsystems/Collector.h"
|
||||
#include "Subsystems/Compressor.h"
|
||||
#include "Subsystems/Sonar.h"
|
||||
#include "Subsystems/Dashboard.h"
|
||||
//Because this is the first header to be included, classes need to be declared here
|
||||
class HHRobot;
|
||||
class HHShooter;
|
||||
class HHCollector;
|
||||
class HHCompressor;
|
||||
class HHSonar;
|
||||
class JoystickController;
|
||||
class HHBase : public IterativeRobot{
|
||||
private:
|
||||
|
@ -5,45 +5,11 @@ HHRobot::HHRobot():
|
||||
shooter(new HHShooter()),
|
||||
collector(new HHCollector()),
|
||||
compressorSystem(new HHCompressor()),
|
||||
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);
|
||||
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);
|
||||
dashboard(new HHDashboard()),
|
||||
sonar(new HHSonar()){
|
||||
//comment
|
||||
}
|
||||
//Functions to get sonar values and return as INCH values
|
||||
float HHRobot::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 HHRobot::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 HHRobot::checkJoystickValues(){
|
||||
float x=ControlSystem->rightJoystickAxisValues[1];
|
||||
float y=ControlSystem->rightJoystickAxisValues[2];
|
||||
|
@ -8,6 +8,7 @@ class HHShooter;
|
||||
class HHCollector;
|
||||
class HHCompressor;
|
||||
class HHDashboard;
|
||||
class HHSonar;
|
||||
class HHRobot;
|
||||
class HHRobot{
|
||||
private:
|
||||
@ -19,6 +20,7 @@ class HHRobot{
|
||||
HHCollector *collector;
|
||||
HHCompressor *compressorSystem;
|
||||
HHDashboard *dashboard;
|
||||
HHSonar *sonar;
|
||||
public:
|
||||
HHRobot();
|
||||
float frontSonarLeftV, frontSonarRightV, rearSonarLeftV, rearSonarRightV;
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <WPILib.h>
|
||||
#include "../Definitions.h"
|
||||
|
||||
class HHCompressor{
|
||||
private:
|
||||
Compressor *compressor;
|
||||
|
14
src/Subsystems/Sonar.cpp
Normal file
14
src/Subsystems/Sonar.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include "Sonar.h"
|
||||
HHSonar::HHSonar(){
|
||||
DigitalOutput frontLeftD=new DigitalOutput(SONAR_LEFT_DIO_SIDECAR,SONAR_FRONT_LEFT_DIO);
|
||||
DigitalOutput frontRightD=new DigitalOutput(SONAR_RIGHT_DIO_SIDECAR,SONAR_FRONT_RIGHT_DIO);
|
||||
DigitalOutput backLeftD=new DigitalOutput(SONAR_LEFT_DIO_SIDECAR,SONAR_BACK_LEFT_DIO);
|
||||
DigitalOutput backRightD=new DigitalOutput(SONAR_RIGHT_DIO_SIDECAR,SONAR_BACK_RIGHT_DIO);
|
||||
AnalogChannel frontLeftA=new AnalogChannel(SONAR_FRONT_LEFT_ANA);
|
||||
AnalogChannel frontRightA=new AnalogChannel(SONAR_FRONT_RIGHT_ANA);
|
||||
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;
|
||||
}
|
11
src/Subsystems/Sonar.h
Normal file
11
src/Subsystems/Sonar.h
Normal file
@ -0,0 +1,11 @@
|
||||
#include <WPILib.h>
|
||||
#include "../Definitions.h"
|
||||
class HHSonar{
|
||||
private:
|
||||
DigitalOutput *frontLeftD,*frontRightD,*backLeftD,*backRightD;
|
||||
AnalogChannel *frontLeftA,*frontRightA,*backLeftA,*backRightA;
|
||||
public:
|
||||
HHSonar();
|
||||
//from is (in string form) "FRONT", "BACK", "FRONTLEFT", "FRONTRIGHT"...
|
||||
float getInches(const char* from);
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user