2
0
mirror of https://github.com/team2059/Zaphod synced 2025-01-07 22:14:14 -05:00

Added shooter angle limits, sonar auto driving, and a base for autonomous

This commit is contained in:
Adam Long 2014-10-07 06:33:29 -04:00
parent 94ddbfea89
commit b9b25144b6
10 changed files with 67 additions and 6 deletions

5
src/Auto/AutoMain.cpp Normal file
View File

@ -0,0 +1,5 @@
#include "AutoMain.h"
HHAuto::HHAuto(){
}

6
src/Auto/AutoMain.h Normal file
View File

@ -0,0 +1,6 @@
#include <WPILib.h>
#include "../Definitions.h"
class HHAuto{
public:
HHAuto();
};

View File

@ -65,6 +65,11 @@
#define COLLECTOR_OUTTAKE 2 #define COLLECTOR_OUTTAKE 2
#define COLLECTOR_EXTEND 9 #define COLLECTOR_EXTEND 9
#define COLLECTOR_RETRACT 10 #define COLLECTOR_RETRACT 10
#define SHOOTER_ANGLE_ONE 3
#define SHOOTER_ANGLE_TWO 4
#define SHOOTER_ANGLE_THREE 5
#define SHOOTER_ANGLE_FOUR 6
#define DRIVE_FOR_DISTANCE 11
//Drive threshold definitions //Drive threshold definitions

View File

@ -31,7 +31,9 @@ void HHBase::DisabledContinuous(){}
void HHBase::AutonomousContinuous(){} void HHBase::AutonomousContinuous(){}
void HHBase::TeleopContinuous(){} void HHBase::TeleopContinuous(){}
void HHBase::DisabledPeriodic(){} void HHBase::DisabledPeriodic(){}
void HHBase::AutonomousPeriodic(){} void HHBase::AutonomousPeriodic(){
hHBot->RunAuto();
}
void HHBase::TeleopPeriodic(){ void HHBase::TeleopPeriodic(){
hHBot->Handler(); hHBot->Handler();
} }

View File

@ -5,7 +5,9 @@ HHRobot::HHRobot():
shooter(new HHShooter()), shooter(new HHShooter()),
collector(new HHCollector()), collector(new HHCollector()),
compressorSystem(new HHCompressor()), compressorSystem(new HHCompressor()),
dashboard(new HHDashboard()){ dashboard(new HHDashboard()),
autoseq(new HHAuto()),
sonar(new HHSonar()){
} }
bool HHRobot::CheckJoystickValues(){ bool HHRobot::CheckJoystickValues(){
float x=ControlSystem->rightJoystickAxisValues[1]; float x=ControlSystem->rightJoystickAxisValues[1];
@ -36,12 +38,24 @@ void HHRobot::DriveRobot(float x, float y){
void HHRobot::UpdateDashboard(){ void HHRobot::UpdateDashboard(){
dashboard->PutFloatValue("Shooting Power", ControlSystem->throttle); dashboard->PutFloatValue("Shooting Power", ControlSystem->throttle);
} }
void HHRobot::RunAuto(){
int step, time;
if(step == 0 && time < 200){
compressorSystem->ExtendCollector();
collector->CollectBallAtSpeed(50);
}
else{
step = 1;
}
time++;
}
//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(){
int targetAngle;
//Periodic tasks that should be run by every loop //Periodic tasks that should be run by every loop
ControlSystem->UpdateJoysticks(); ControlSystem->UpdateJoysticks();
shooter->UpdateShooterPosition(); shooter->UpdateShooterPosition(targetAngle);
//TODO Need to implement a timing system to not break the spike (this function doesn't run the compressor at the moment) //TODO Need to implement a timing system to not break the spike (this function doesn't run the compressor at the moment)
compressorSystem->CompressorSystemPeriodic(); compressorSystem->CompressorSystemPeriodic();
collector->UpdateCollector(shooter->isShooting, shooter->GetAngle()); collector->UpdateCollector(shooter->isShooting, shooter->GetAngle());
@ -65,5 +79,25 @@ void HHRobot::Handler(){
if(ControlSystem->rightJoystickValues[COLLECTOR_RETRACT]) { if(ControlSystem->rightJoystickValues[COLLECTOR_RETRACT]) {
compressorSystem->RetractCollector(); compressorSystem->RetractCollector();
} }
if(ControlSystem->leftJoystickValues[SHOOTER_ANGLE_ONE]){
targetAngle = 100;
}
if(ControlSystem->leftJoystickValues[SHOOTER_ANGLE_TWO]){
targetAngle = 120;
}
if(ControlSystem->leftJoystickValues[SHOOTER_ANGLE_THREE]){
targetAngle = 90;
}
if(ControlSystem->leftJoystickValues[SHOOTER_ANGLE_FOUR]){
targetAngle = 130;
}
if(ControlSystem->rightJoystickValues[DRIVE_FOR_DISTANCE]){
if(sonar->GetInches("FRONTLEFT") >= 40){
DriveRobot(0,-.5);
}
else{
DriveRobot(0,0);
}
}
} }
// vim: ts=2:sw=2:et // vim: ts=2:sw=2:et

View File

@ -2,6 +2,7 @@
#define __ZAPHOD_ROBOT_H__ #define __ZAPHOD_ROBOT_H__
#include <WPILib.h> #include <WPILib.h>
#include "HHBase.h" #include "HHBase.h"
#include "Auto/AutoMain.h"
#include "Definitions.h" #include "Definitions.h"
class JoystickController; class JoystickController;
class HHShooter; class HHShooter;
@ -9,6 +10,7 @@ class HHCollector;
class HHCompressor; class HHCompressor;
class HHDashboard; class HHDashboard;
class HHRobot; class HHRobot;
class HHSonar;
class HHRobot{ class HHRobot{
private: private:
Jaguar *right1, *right2, *right3, *left1, *left2, *left3; Jaguar *right1, *right2, *right3, *left1, *left2, *left3;
@ -17,12 +19,15 @@ class HHRobot{
HHCollector *collector; HHCollector *collector;
HHCompressor *compressorSystem; HHCompressor *compressorSystem;
HHDashboard *dashboard; HHDashboard *dashboard;
HHAuto *autoseq;
HHSonar *sonar;
public: public:
HHRobot(); HHRobot();
bool CheckJoystickValues(); bool CheckJoystickValues();
void DriveRobot(float,float); void DriveRobot(float,float);
void UpdateDashboard(); void UpdateDashboard();
void Handler(); void Handler();
void RunAuto();
}; };
#endif #endif
// vim: ts=2:sw=2:et // vim: ts=2:sw=2:et

View File

@ -19,6 +19,9 @@ void HHCollector::UpdateCollector(bool shooting, float angle){
collectorMotor->Set(0); collectorMotor->Set(0);
} }
} }
void HHCollector::CollectBallAtSpeed(float speed){
collectorMotor->Set(speed);
}
void HHCollector::CollectBall(){ void HHCollector::CollectBall(){
collectorMotor->Set(1); collectorMotor->Set(1);
} }

View File

@ -11,6 +11,7 @@ class HHCollector{
STOP STOP
}e_CollectorState; }e_CollectorState;
void UpdateCollector(bool, float); void UpdateCollector(bool, float);
void CollectBallAtSpeed(float speed);
void CollectBall(); void CollectBall();
void ReleaseBall(); void ReleaseBall();
void SpinWithShot(float); void SpinWithShot(float);

View File

@ -47,14 +47,14 @@ void HHShooter::ShootRaw(float power){
shooterRight2->SetRaw(int(FloatToPWM(-power))); shooterRight2->SetRaw(int(FloatToPWM(-power)));
} }
//Should be run in a loop //Should be run in a loop
void HHShooter::UpdateShooterPosition(){ void HHShooter::UpdateShooterPosition(int angle){
if(e_ShooterState == IDLE_PRESHOT){ if(e_ShooterState == IDLE_PRESHOT){
isShooting=false; isShooting=false;
StopShooter(); StopShooter();
} }
if(e_ShooterState == FIRING){ if(e_ShooterState == FIRING){
isShooting=true; isShooting=true;
ShootForAngle(shootingPower,110); ShootForAngle(shootingPower,angle);
} }
if(e_ShooterState == IDLE_POSTSHOT){ if(e_ShooterState == IDLE_POSTSHOT){
isShooting=false; isShooting=false;

View File

@ -19,7 +19,7 @@ class HHShooter{
void ShootRaw(float); void ShootRaw(float);
void Lower(float); void Lower(float);
void StopShooter(); void StopShooter();
void UpdateShooterPosition(); void UpdateShooterPosition(int);
float FloatToPWM(float input); float FloatToPWM(float input);
float GetAngle(); float GetAngle();
}; };