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:
parent
aaeae5fd11
commit
7b24f4914e
@ -4,7 +4,6 @@
|
|||||||
#include "HHRobot.h"
|
#include "HHRobot.h"
|
||||||
#include "Subsystems/Shooter.h"
|
#include "Subsystems/Shooter.h"
|
||||||
#include "Subsystems/Collector.h"
|
#include "Subsystems/Collector.h"
|
||||||
#include "Subsystems/Compressor.h"
|
|
||||||
#include "Subsystems/Sonar.h"
|
#include "Subsystems/Sonar.h"
|
||||||
#include "Subsystems/Dashboard.h"
|
#include "Subsystems/Dashboard.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -12,9 +11,7 @@
|
|||||||
class HHRobot;
|
class HHRobot;
|
||||||
class HHShooter;
|
class HHShooter;
|
||||||
class HHCollector;
|
class HHCollector;
|
||||||
class HHCompressor;
|
|
||||||
class HHSonar;
|
class HHSonar;
|
||||||
class JoystickController;
|
|
||||||
class HHBase : public IterativeRobot{
|
class HHBase : public IterativeRobot{
|
||||||
private:
|
private:
|
||||||
HHRobot* hHBot;
|
HHRobot* hHBot;
|
||||||
|
@ -5,9 +5,9 @@ HHRobot::HHRobot():
|
|||||||
drive(new WCDrive(6,1,1,1,2,1,3,2,1,2,2,2,3)),
|
drive(new WCDrive(6,1,1,1,2,1,3,2,1,2,2,2,3)),
|
||||||
driveStick(new Extreme3dPro(1)),
|
driveStick(new Extreme3dPro(1)),
|
||||||
shootStick(new Extreme3dPro(2)),
|
shootStick(new Extreme3dPro(2)),
|
||||||
|
compressor(new AirCompressor(2,5,1,3)),
|
||||||
shooter(new HHShooter()),
|
shooter(new HHShooter()),
|
||||||
collector(new HHCollector()),
|
collector(new HHCollector()),
|
||||||
compressorSystem(new HHCompressor()),
|
|
||||||
dashboard(new HHDashboard()){
|
dashboard(new HHDashboard()){
|
||||||
//sonar(new HHSonar()){}
|
//sonar(new HHSonar()){}
|
||||||
driveTable=NetworkTable::GetTable("ZaphodDrive");
|
driveTable=NetworkTable::GetTable("ZaphodDrive");
|
||||||
@ -24,8 +24,7 @@ void HHRobot::Init(){
|
|||||||
//Put table values initally to avoid annoying refreshing
|
//Put table values initally to avoid annoying refreshing
|
||||||
shooterTable->PutNumber("Target Shooter Angle",90);
|
shooterTable->PutNumber("Target Shooter Angle",90);
|
||||||
shooterTable->PutNumber("Current Shooter Angle",-420);
|
shooterTable->PutNumber("Current Shooter Angle",-420);
|
||||||
timer->Start();
|
compressor->StartCompressor();
|
||||||
compressorSystem->StartCompressor();
|
|
||||||
}
|
}
|
||||||
bool HHRobot::CheckJoystickValues(){
|
bool HHRobot::CheckJoystickValues(){
|
||||||
float x=driveStick->GetJoystickAxis("x");
|
float x=driveStick->GetJoystickAxis("x");
|
||||||
@ -44,7 +43,7 @@ void HHRobot::UpdateDashboard(){
|
|||||||
void HHRobot::RunAuto(){
|
void HHRobot::RunAuto(){
|
||||||
timer->Reset();
|
timer->Reset();
|
||||||
int step,time;
|
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
|
//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)
|
//Drive for 51 inches/cm/units (or time)
|
||||||
if(step==2){
|
if(step==2){
|
||||||
@ -72,16 +71,10 @@ void HHRobot::RunAuto(){
|
|||||||
//Main function used to handle periodic tasks on the robot
|
//Main function used to handle periodic tasks on the robot
|
||||||
void HHRobot::Handler(){
|
void HHRobot::Handler(){
|
||||||
double targetAngle = shooterTable->GetNumber("Target Shooter Angle");
|
double targetAngle = shooterTable->GetNumber("Target Shooter Angle");
|
||||||
bool allowCompressing = true;
|
|
||||||
//Periodic tasks that should be run by every loop
|
//Periodic tasks that should be run by every loop
|
||||||
shooter->UpdateShooterPosition(targetAngle);
|
shooter->UpdateShooterPosition(targetAngle);
|
||||||
driveStick->handler();
|
driveStick->handler();
|
||||||
shootStick->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());
|
collector->UpdateCollector(shooter->isShooting,shooter->GetAngle());
|
||||||
//TODO Fix whatever the heck is wrong with this
|
//TODO Fix whatever the heck is wrong with this
|
||||||
drive->Update(6,driveStick->GetJoystickAxis("z")+driveStick->GetJoystickAxis("x"),driveStick->GetJoystickAxis("y"));
|
drive->Update(6,driveStick->GetJoystickAxis("z")+driveStick->GetJoystickAxis("x"),driveStick->GetJoystickAxis("y"));
|
||||||
@ -102,10 +95,10 @@ void HHRobot::Handler(){
|
|||||||
collector->CollectorStop();
|
collector->CollectorStop();
|
||||||
}
|
}
|
||||||
if(driveStick->GetJoystickButton(COLLECTOR_EXTEND)){
|
if(driveStick->GetJoystickButton(COLLECTOR_EXTEND)){
|
||||||
compressorSystem->ExtendCollector();
|
//TODO extend collector
|
||||||
}
|
}
|
||||||
if(driveStick->GetJoystickButton(COLLECTOR_RETRACT)){
|
if(driveStick->GetJoystickButton(COLLECTOR_RETRACT)){
|
||||||
compressorSystem->RetractCollector();
|
//TODO retract collector
|
||||||
}
|
}
|
||||||
if(shootStick->GetJoystickButton(SHOOTER_ANGLE_ONE)){
|
if(shootStick->GetJoystickButton(SHOOTER_ANGLE_ONE)){
|
||||||
targetAngle=100;
|
targetAngle=100;
|
||||||
|
@ -4,10 +4,10 @@
|
|||||||
#include "HHBase.h"
|
#include "HHBase.h"
|
||||||
#include "lib/drive/WCDrive.h"
|
#include "lib/drive/WCDrive.h"
|
||||||
#include "lib/controller/Controller.h"
|
#include "lib/controller/Controller.h"
|
||||||
|
#include "lib/pneumatics/Compressor.h"
|
||||||
#include "Definitions.h"
|
#include "Definitions.h"
|
||||||
class HHShooter;
|
class HHShooter;
|
||||||
class HHCollector;
|
class HHCollector;
|
||||||
class HHCompressor;
|
|
||||||
class HHDashboard;
|
class HHDashboard;
|
||||||
class HHRobot;
|
class HHRobot;
|
||||||
class HHSonar;
|
class HHSonar;
|
||||||
@ -15,10 +15,10 @@ class HHRobot{
|
|||||||
private:
|
private:
|
||||||
WCDrive *drive;
|
WCDrive *drive;
|
||||||
Extreme3dPro *driveStick, *shootStick;
|
Extreme3dPro *driveStick, *shootStick;
|
||||||
|
AirCompressor *compressor;
|
||||||
NetworkTable *driveTable, *shooterTable, *collectorTable;
|
NetworkTable *driveTable, *shooterTable, *collectorTable;
|
||||||
HHShooter *shooter;
|
HHShooter *shooter;
|
||||||
HHCollector *collector;
|
HHCollector *collector;
|
||||||
HHCompressor *compressorSystem;
|
|
||||||
HHDashboard *dashboard;
|
HHDashboard *dashboard;
|
||||||
HHSonar *sonar;
|
HHSonar *sonar;
|
||||||
Timer *timer;
|
Timer *timer;
|
||||||
|
@ -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
|
|
47
src/lib/pneumatics/Compressor.cpp
Normal file
47
src/lib/pneumatics/Compressor.cpp
Normal 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
|
@ -1,10 +1,11 @@
|
|||||||
#include <WPILib.h>
|
#include <WPILib.h>
|
||||||
#include "../Definitions.h"
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
class HHCompressor{
|
class AirCompressor{
|
||||||
private:
|
private:
|
||||||
Compressor *compressor;
|
Compressor *compressor;
|
||||||
Solenoid *solenoid1, *solenoid2;
|
//Timer used for keeping time?
|
||||||
|
Timer *timer;
|
||||||
|
double lastTime;
|
||||||
bool compressing;
|
bool compressing;
|
||||||
public:
|
public:
|
||||||
enum{
|
enum{
|
||||||
@ -12,10 +13,9 @@ class HHCompressor{
|
|||||||
RETRACTED,
|
RETRACTED,
|
||||||
IDLE
|
IDLE
|
||||||
}e_CollectorSolenoidState;
|
}e_CollectorSolenoidState;
|
||||||
HHCompressor();
|
explicit AirCompressor(uint8_t,uint8_t);
|
||||||
void CompressorSystemPeriodic(bool compressorEnabled);
|
AirCompressor(uint8_t,uint8_t,uint8_t,uint8_t);
|
||||||
void ExtendCollector();
|
void CompressorSystemPeriodic();
|
||||||
void RetractCollector();
|
|
||||||
void StopCompressor();
|
void StopCompressor();
|
||||||
void StartCompressor();
|
void StartCompressor();
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user