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

Moved the compressor code the lib/pnumatics and updated the old code to work with it

This commit is contained in:
Adam Long 2014-12-28 20:40:47 +00:00
parent aaeae5fd11
commit 7b24f4914e
6 changed files with 61 additions and 84 deletions

View File

@ -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 <string>
@ -12,9 +11,7 @@
class HHRobot;
class HHShooter;
class HHCollector;
class HHCompressor;
class HHSonar;
class JoystickController;
class HHBase : public IterativeRobot{
private:
HHRobot* hHBot;

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -1,10 +1,11 @@
#include <WPILib.h>
#include "../Definitions.h"
#include <time.h>
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();
};