2
0
mirror of https://github.com/team2059/Zaphod synced 2024-12-18 20:12:28 -05:00

Code now compiles. Completed refactorign of HHBase and Compressor. Continuing with refactoring. (Untested)

This commit is contained in:
Austen Adler 2014-06-10 20:29:12 -04:00
parent 9490e32ef6
commit 8478154307
5 changed files with 109 additions and 130 deletions

View File

@ -1,7 +1,7 @@
#include "HHBase.h" #include "HHBase.h"
ZaphodBase::HHBase(): HHBase::HHBase():
hHBot(new HHRobot()){ hHBot(new ZaphodRobot()){
printf("Done\n"); printf("Done\n");
} }
void HHBase::RobotInit(){ void HHBase::RobotInit(){

View File

@ -1,22 +1,21 @@
#ifndef __HH_BASE_H__ #ifndef __HH_BASE_H__
#define __HH_BASE_H__ #define __HH_BASE_H__
#include <WPILib.h> #include <WPILib.h>
#include "HHRobot.h" #include "ZaphodRobot.h"
#include "Subsystems/Controller.h" #include "Subsystems/Controller.h"
#include "Subsystems/Shooter.h" #include "Subsystems/Shooter.h"
#include "Subsystems/Collector.h" #include "Subsystems/Collector.h"
#include "Subsystems/Compressor.h" #include "Subsystems/Compressor.h"
#include "Subsystems/Dashboard.h" #include "Subsystems/Dashboard.h"
//Because this is the first header to be included, classes need to be declared here //Because this is the first header to be included, classes need to be declared here
class HHRobot; class ZaphodRobot;
class HHShooter; class HHShooter;
class HHCollector; class HHCollector;
class HHCompressor; class HHCompressor;
class JoystickController; class JoystickController;
class ZaphodBase : public IterativeRobot class HHBase : public IterativeRobot{
{
private: private:
HHRobot* hHBot; ZaphodRobot* hHBot;
public: public:
HHBase(); HHBase();
void RobotInit(); void RobotInit();

View File

@ -15,8 +15,8 @@ class HHCompressor
}e_CollectorSolenoidState; }e_CollectorSolenoidState;
HHCompressor(); HHCompressor();
void compressorSystemPeriodic(); void compressorSystemPeriodic();
void extendCollector(); void ExtendCollector();
void retractCollector(); void RetractCollector();
void startCompressing(); void StartCompressing();
void stopCompressing(); void StopCompressing();
}; };

View File

@ -1,121 +1,105 @@
#include "ZaphodRobot.h" #include "ZaphodRobot.h"
#include "ZaphodBase.h" #include "HHBase.h"
ZaphodRobot::ZaphodRobot(): ZaphodRobot::ZaphodRobot():
ControlSystem(new JoystickController()), ControlSystem(new JoystickController()),
shooter(new ZaphodShooter()), shooter(new ZaphodShooter()),
collector(new ZaphodCollector()), collector(new ZaphodCollector()),
compressorSystem(new ZaphodCompressor()), compressorSystem(new HHCompressor()),
dashboard(new ZaphodDashboard()) dashboard(new ZaphodDashboard()){
{ left1=new Jaguar(DRIVE_LEFT_SIDECAR, DRIVE_LEFT_MOTOR_ONE);
left1 = new Jaguar(DRIVE_LEFT_SIDECAR, DRIVE_LEFT_MOTOR_ONE); left2=new Jaguar(DRIVE_LEFT_SIDECAR, DRIVE_LEFT_MOTOR_TWO);
left2 = new Jaguar(DRIVE_LEFT_SIDECAR, DRIVE_LEFT_MOTOR_TWO); left3=new Jaguar(DRIVE_LEFT_SIDECAR, DRIVE_LEFT_MOTOR_THREE);
left3 = new Jaguar(DRIVE_LEFT_SIDECAR, DRIVE_LEFT_MOTOR_THREE); right1=new Jaguar(DRIVE_RIGHT_SIDECAR, DRIVE_RIGHT_MOTOR_ONE);
right1 = new Jaguar(DRIVE_RIGHT_SIDECAR, DRIVE_RIGHT_MOTOR_ONE); right2=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);
right3 = new Jaguar(DRIVE_RIGHT_SIDECAR, DRIVE_RIGHT_MOTOR_ONE); frontSonarLeftD=new DigitalOutput(SONAR_LEFT_DIO_SIDECAR, SONAR_FRONT_LEFT_DIO);
frontSonarLeftD = new DigitalOutput(SONAR_LEFT_DIO_SIDECAR, SONAR_FRONT_LEFT_DIO); frontSonarRightD=new DigitalOutput(SONAR_RIGHT_DIO_SIDECAR, SONAR_FRONT_RIGHT_DIO);
frontSonarRightD = new DigitalOutput(SONAR_RIGHT_DIO_SIDECAR, SONAR_FRONT_RIGHT_DIO); rearSonarLeftD=new DigitalOutput(SONAR_LEFT_DIO_SIDECAR, SONAR_REAR_LEFT_DIO);
rearSonarLeftD = new DigitalOutput(SONAR_LEFT_DIO_SIDECAR, SONAR_REAR_LEFT_DIO); rearSonarRightD=new DigitalOutput(SONAR_RIGHT_DIO_SIDECAR, SONAR_REAR_RIGHT_DIO);
rearSonarRightD = new DigitalOutput(SONAR_RIGHT_DIO_SIDECAR, SONAR_REAR_RIGHT_DIO); frontSonarLeftA=new AnalogChannel(SONAR_FRONT_LEFT_ANA);
frontSonarLeftA = new AnalogChannel(SONAR_FRONT_LEFT_ANA); frontSonarRightA=new AnalogChannel(SONAR_FRONT_RIGHT_ANA);
frontSonarRightA = new AnalogChannel(SONAR_FRONT_RIGHT_ANA); rearSonarLeftA=new AnalogChannel(SONAR_REAR_LEFT_ANA);
rearSonarLeftA = new AnalogChannel(SONAR_REAR_LEFT_ANA); rearSonarRightA=new AnalogChannel(SONAR_REAR_RIGHT_ANA);
rearSonarRightA = new AnalogChannel(SONAR_REAR_RIGHT_ANA); }
}
//Functions to get sonar values and return as INCH values //Functions to get sonar values and return as INCH values
float ZaphodRobot::getFrontSonar(){
float ZaphodRobot::getFrontSonar() frontSonarLeftD->Set(1);
{ frontSonarLeftV=(frontSonarLeftA->GetAverageVoltage()/0.00488f)/2.54f;
frontSonarLeftD->Set(1); frontSonarLeftD->Set(0);
frontSonarLeftV = (frontSonarLeftA->GetAverageVoltage()/0.00488f)/2.54f; //Probably need some sort of delay here
frontSonarLeftD->Set(0); frontSonarRightD->Set(1);
//Probably need some sort of delay here frontSonarRightV=(frontSonarRightA->GetAverageVoltage()/0.00488f)/2.54f;
frontSonarRightD->Set(1); frontSonarRightD->Set(0);
frontSonarRightV = (frontSonarRightA->GetAverageVoltage()/0.00488f)/2.54f; //Returns the average (useful for throwing out useless readings)
frontSonarRightD->Set(0); return (frontSonarRightV+frontSonarLeftV)/2;
//Returns the average (useful for throwing out useless readings)
return (frontSonarRightV+frontSonarLeftV)/2;
} }
float ZaphodRobot::getRearSonar(){
float ZaphodRobot::getRearSonar() rearSonarLeftD->Set(1);
{ rearSonarLeftV=(rearSonarLeftA->GetAverageVoltage()/0.00488f)/2.54f;
rearSonarLeftD->Set(1); rearSonarLeftD->Set(0);
rearSonarLeftV = (rearSonarLeftA->GetAverageVoltage()/0.00488f)/2.54f; //Probably need some sort of delay here
rearSonarLeftD->Set(0); rearSonarRightD->Set(1);
//Probably need some sort of delay here rearSonarRightV=(rearSonarRightA->GetAverageVoltage()/0.00488f)/2.54f;
rearSonarRightD->Set(1); rearSonarRightD->Set(0);
rearSonarRightV = (rearSonarRightA->GetAverageVoltage()/0.00488f)/2.54f; //Returns the average (useful for throwing out useless readings)
rearSonarRightD->Set(0); return (rearSonarRightV+rearSonarLeftV)/2;
//Returns the average (useful for throwing out useless readings)
return (rearSonarRightV+rearSonarLeftV)/2;
} }
bool ZaphodRobot::checkJoystickValues(){
bool ZaphodRobot::checkJoystickValues() float x=ControlSystem->rightJoystickAxisValues[1];
{ float y=ControlSystem->rightJoystickAxisValues[2];
float x = ControlSystem->rightJoystickAxisValues[1]; if((-.1 < x && x < .1) && (-.1 < y && y < .1)) {
float y = ControlSystem->rightJoystickAxisValues[2]; dashboard->putBoolValue("Joysticks Valid", true);
if((-.1 < x && x < .1) && (-.1 < y && y < .1)) { return true;
dashboard->putBoolValue("Joysticks Valid", true); } else {
return true; dashboard->putBoolValue("Joysticks Valid", false);
} else { return true;
dashboard->putBoolValue("Joysticks Valid", false); return false;
return true; }
return false;
}
} }
void ZaphodRobot::driveRobot(float x, float y){
void ZaphodRobot::driveRobot(float x, float y) if(y>1.0f) {
{ y=1.0f;
if(y>1.0f) { } else if(y!=0.0f&&y<-1.0f) {
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;
float leftPower=((y+x)/2+1)*127+1; right1->SetRaw(int(rightPower));
float rightPower=((y-x)/2+1)*127+1; right2->SetRaw(int(rightPower));
right1->SetRaw(int(rightPower)); right3->SetRaw(int(rightPower));
right2->SetRaw(int(rightPower)); left1->SetRaw(int(leftPower));
right3->SetRaw(int(rightPower)); left2->SetRaw(int(leftPower));
left1->SetRaw(int(leftPower)); left3->SetRaw(int(leftPower));
left2->SetRaw(int(leftPower));
left3->SetRaw(int(leftPower));
} }
void ZaphodRobot::updateDashboard(){
void ZaphodRobot::updateDashboard() dashboard->putFloatValue("Shooting Power", ControlSystem->throttle);
{
dashboard->putFloatValue("Shooting Power", ControlSystem->throttle);
} }
//Main function used to handle periodic tasks on the robot //Main function used to handle periodic tasks on the robot
void ZaphodRobot::handler(){
void ZaphodRobot::handler() //Periodic tasks that should be run by every loop
{ ControlSystem->updateJoysticks();
//Periodic tasks that should be run by every loop shooter->updateShooterPosition();
ControlSystem->updateJoysticks(); //TODO Need to implement a timing system to not break the spike (this function doesn't run the compressor at the moment)
shooter->updateShooterPosition(); compressorSystem->compressorSystemPeriodic();
//TODO Need to implement a timing system to not break the spike (this function doesn't run the compressor at the moment) collector->updateCollector(shooter->isShooting, shooter->getAngle());
compressorSystem->compressorSystemPeriodic(); if(checkJoystickValues()) {
collector->updateCollector(shooter->isShooting, shooter->getAngle()); driveRobot(ControlSystem->rightJoystickAxisValues[3]+ControlSystem->rightJoystickAxisValues[1], -ControlSystem->rightJoystickAxisValues[2]);
if(checkJoystickValues()) { }
driveRobot(ControlSystem->rightJoystickAxisValues[3]+ControlSystem->rightJoystickAxisValues[1], -ControlSystem->rightJoystickAxisValues[2]); updateDashboard();
} //Button assignments to actions
updateDashboard(); if(ControlSystem->leftJoystickValues[SHOOTER_FIRE]) {
//Button assignments to actions shooter->startShootingSequence(ControlSystem->throttle);
if(ControlSystem->leftJoystickValues[SHOOTER_FIRE]) { }
shooter->startShootingSequence(ControlSystem->throttle); if(ControlSystem->rightJoystickValues[COLLECTOR_INTAKE]) {
} collector->collectBall();
if(ControlSystem->rightJoystickValues[COLLECTOR_INTAKE]) { }
collector->collectBall(); if(ControlSystem->rightJoystickValues[COLLECTOR_OUTTAKE]) {
} collector->releaseBall();
if(ControlSystem->rightJoystickValues[COLLECTOR_OUTTAKE]) { }
collector->releaseBall(); if(ControlSystem->rightJoystickValues[COLLECTOR_EXTEND]) {
} compressorSystem->extendCollector();
if(ControlSystem->rightJoystickValues[COLLECTOR_EXTEND]) { }
compressorSystem->extendCollector(); if(ControlSystem->rightJoystickValues[COLLECTOR_RETRACT]) {
} compressorSystem->retractCollector();
if(ControlSystem->rightJoystickValues[COLLECTOR_RETRACT]) { }
compressorSystem->retractCollector();
}
} }

View File

@ -1,19 +1,15 @@
#ifndef __ZAPHOD_ROBOT_H__ #ifndef __ZAPHOD_ROBOT_H__
#define __ZAPHOD_ROBOT_H__ #define __ZAPHOD_ROBOT_H__
#include <WPILib.h> #include <WPILib.h>
#include "ZaphodBase.h" #include "HHBase.h"
#include "Definitions.h" #include "Definitions.h"
class JoystickController; class JoystickController;
class ZaphodShooter; class ZaphodShooter;
class ZaphodCollector; class ZaphodCollector;
class ZaphodCompressor; class HHCompressor;
class ZaphodDashboard; class ZaphodDashboard;
class ZaphodRobot; class ZaphodRobot;
class ZaphodRobot{
class ZaphodRobot
{
private: private:
Jaguar *right1, *right2, *right3, *left1, *left2, *left3; Jaguar *right1, *right2, *right3, *left1, *left2, *left3;
DigitalOutput *frontSonarLeftD, *frontSonarRightD, *rearSonarLeftD, *rearSonarRightD; DigitalOutput *frontSonarLeftD, *frontSonarRightD, *rearSonarLeftD, *rearSonarRightD;
@ -21,7 +17,7 @@ class ZaphodRobot
JoystickController *ControlSystem; JoystickController *ControlSystem;
ZaphodShooter *shooter; ZaphodShooter *shooter;
ZaphodCollector *collector; ZaphodCollector *collector;
ZaphodCompressor *compressorSystem; HHCompressor *compressorSystem;
ZaphodDashboard *dashboard; ZaphodDashboard *dashboard;
public: public:
ZaphodRobot(); ZaphodRobot();