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

Added an alternative method for autonomus because the other one failed?

This commit is contained in:
Adam Long 2014-03-06 23:45:13 +00:00
parent 00b7d80479
commit 3d62cd0a83

View File

@ -1,4 +1,3 @@
//TODO
//Add a button on joystick that activates "auto" to drive to 40 inches away and another to shoot when at 40 inches away (use the little joystick on both drive and shooter stick) //Add a button on joystick that activates "auto" to drive to 40 inches away and another to shoot when at 40 inches away (use the little joystick on both drive and shooter stick)
//Sonar in auto: drive till 40in away (dashboard value) and shoot //Sonar in auto: drive till 40in away (dashboard value) and shoot
#include "WPILib.h" #include "WPILib.h"
@ -11,12 +10,10 @@ class RobotDemo : public SimpleRobot
{ {
RobotDrive myRobot; RobotDrive myRobot;
float potVal, multiplier, throttle; float potVal, multiplier, throttle;
bool collectorExtended, shooting, compressing; bool collectorExtended, shooting, compressing, allowCompressing;
float upLimit; float upLimit;
Joystick Rstick, Lstick; Joystick Rstick, Lstick;
Solenoid collectorSole1, collectorSole2; Solenoid collectorSole1, collectorSole2;
//Do we need this? TODO - Austen
Relay collectorSpike;
Compressor compressor; Compressor compressor;
Jaguar Left1, Left2, Left3, Right1, Right2, Right3, RightArmMotor1, RightArmMotor2, LeftArmMotor1, LeftArmMotor2, CollectorMotor1; Jaguar Left1, Left2, Left3, Right1, Right2, Right3, RightArmMotor1, RightArmMotor2, LeftArmMotor1, LeftArmMotor2, CollectorMotor1;
AnalogChannel armPot; AnalogChannel armPot;
@ -50,8 +47,6 @@ public:
Right1(2,1), Right1(2,1),
Right2(2,2), Right2(2,2),
Right3(2,3), Right3(2,3),
//Spikes
collectorSpike(2, 7),
//Shooter Motors //Shooter Motors
LeftArmMotor1(1, 4), LeftArmMotor1(1, 4),
LeftArmMotor2(1, 5), LeftArmMotor2(1, 5),
@ -69,6 +64,7 @@ public:
compressor.Start(); compressor.Start();
shooting = false; shooting = false;
compressing = true; compressing = true;
allowCompressing = true;
throttle=0; throttle=0;
} }
void DashboardSetup() { void DashboardSetup() {
@ -88,14 +84,19 @@ public:
SmartDashboard::PutNumber("AutoPower",0.455f); SmartDashboard::PutNumber("AutoPower",0.455f);
SmartDashboard::PutNumber("AutoAngle",130.0f); SmartDashboard::PutNumber("AutoAngle",130.0f);
SmartDashboard::PutNumber("AutoCorrection",0.06f); SmartDashboard::PutNumber("AutoCorrection",0.06f);
SmartDashboard::PutNumber("Inital Drive Timeout", 2);
SmartDashboard::PutNumber("First Shot Start", 2.5);
SmartDashboard::PutNumber("First Shot Stop", 3);
SmartDashboard::PutNumber("Reverse direction start",3.5);
SmartDashboard::PutNumber("Reverse direction stop",5.5);
//Shooter presets //Shooter presets
SmartDashboard::PutNumber("ShortRange",0.465f); //Power for the shooter when against the low goal SmartDashboard::PutNumber("ShortRange",0.465f); //Power for the shooter when against the low goal
SmartDashboard::PutNumber("ShooterButtonPower10",0.605f); SmartDashboard::PutNumber("ShooterButtonPower10",0.605f);
SmartDashboard::PutNumber("ShooterButtonPower7",1.0f); SmartDashboard::PutNumber("ShooterButtonPower7",1.0f);
SmartDashboard::PutNumber("ShooterButtonPower8",0.5f); SmartDashboard::PutNumber("ShooterButtonPower8",0.5f);
//Bool switches //Bool switches
SmartDashboard::PutBoolean("OneBallAuto",true); SmartDashboard::PutBoolean("OneBallAuto",false);
SmartDashboard::PutBoolean("Use Ultrasonic",false); SmartDashboard::PutBoolean("Use Ultrasonic",true);
SmartDashboard::PutBoolean("Daniel Mode",false); SmartDashboard::PutBoolean("Daniel Mode",false);
SmartDashboard::PutBoolean("CollectorState",false); SmartDashboard::PutBoolean("CollectorState",false);
SmartDashboard::PutBoolean("Compressor Enabled", allowCompressing); SmartDashboard::PutBoolean("Compressor Enabled", allowCompressing);
@ -240,16 +241,19 @@ public:
int commandIndex=0; int commandIndex=0;
int averageAmount=5; int averageAmount=5;
int i=0; int i=0;
int cur=0; int c=0;
int averageAmount=5; float initalDriveTimeout=(SmartDashboard::GetNumber("Inital Drive Timeout"))*200;
float shooterMaxAngle=125; //The maximum angle that the arm can shoot to during all of auto //Incase the wall ultrasonic fails, there will be a timeout that will force the motors to stop after a given time.
float shooterDelay = 2; //The amount of time in seconds between the inital drive time and the shooter firing float startShootingFirst=(SmartDashboard::GetNumber("First Shot Start"))*200;
float shooterDuration = .5;//The amount of time in seconds that the shooter motors will be moving //The time when the shooter motors will begin to fire the ball
shooterDelay = (shooterDelay*200); //Do math to figure out the times to start the shooting float stopShootingFirst=(SmartDashboard::GetNumber("First Shot Stop"))*200;
float sampleCount=12; //The time when the shooter motors will stop (set power to 0)
float avgRight=0; float getSecondBallStart=(SmartDashboard::GetNumber("Reverse direction start"))*200;
float curDist; //The time to start when getting the second ball
float thisIsATest; float getSecondBallStop=(SmartDashboard::GetNumber("Reverse direction stop"))*200;
//The time to stop when getting the second ball
float power=SmartDashboard::GetNumber("AutoPower");
//The power the shooter will use (in a percent)
compressing=false; compressing=false;
collectorSole1.Set(false); collectorSole1.Set(false);
collectorSole2.Set(true); collectorSole2.Set(true);
@ -259,96 +263,26 @@ public:
BallRight.Set(0); BallRight.Set(0);
SmartDashboard::PutBoolean("CollectorState",true); SmartDashboard::PutBoolean("CollectorState",true);
while(IsEnabled()&&IsAutonomous()) { while(IsEnabled()&&IsAutonomous()) {
int x=SmartDashboard::GetNumber("AutoDistance"); //int x=SmartDashboard::GetNumber("AutoDistance");
int y=SmartDashboard::GetNumber("AutoYValue"); //int y=SmartDashboard::GetNumber("AutoYValue");
float power=SmartDashboard::GetNumber("AutoPower"); //int angle=SmartDashboard::GetNumber("AutoAngle");
int angle=SmartDashboard::GetNumber("AutoAngle"); //float correction=SmartDashboard::GetNumber("AutoCorrection");
float correction=SmartDashboard::GetNumber("AutoCorrection"); if(i-c==0){ //The first statement to check for. Will run at start because i-c will be 0 (shouldn't need to be changed)
if(SmartDashboard::GetBoolean("OneBallAuto")){ if(voltToDistance(WallSonicLeft.GetAverageVoltage(),true)>=40.0f){ //Particular only to the first drive step
setMotorValue(6, 1, 1);
if(i<200+x) {
//Forward .5s
driveRobot(-1.0f,correction);
shootRobot(0.0f);
}else if(i>=200+x&&i<=400+x){
//Wait
driveRobot(0.0f, 0.0f);
shootRobot(0.0f);
} else if(i>400+x&&i<500+x&&angle>=potToDegrees(armPot.GetAverageVoltage())) {
//Shoot
driveRobot(0.0f, 0.0f);
shootRobot(power);
} else if(i>400+x&&i<500+x&&angle<=potToDegrees(armPot.GetAverageVoltage())) {
//Wait
driveRobot(0.0f, 0.0f);
shootRobot(0.0f);
} else if(i>=500) {
//Kill robit
driveRobot(0.0f, 0.0f);
shootRobot(0.0f);
}
}else if(SmartDashboard::GetBoolean("Use Ultrasonic")){
if(voltToDistance(WallSonicLeft.GetAverageVoltage(),true)>=40.0f){
driveRobot(1.0f,correction); driveRobot(1.0f,correction);
}else{
driveRobot(0.0f,0.0f);
} }
}else{ if(c==initalDriveTimeout){ //Acts as the else (ie: motor stopping, etc)
if(i<1700+3*x+2*y){ driveRobot(0.0f,0.0f);
setMotorValue(6, 1, 1); i=1; //Could be added to the dashboard as a step custimization thing (basically 'i' is the next step to run)
c=0; //Reset the timer
} }
} }
if(i-c==1&&c>startShootingFirst){ //The next 'step' in auto, shooting the motors when startShootingFirst is true if(i-c==1&&c>startShootingFirst){ //The next 'step' in auto, shooting the motors when startShootingFirst is true
shootRobot(power); shootRobot(power);
if(c==stopShootingFirst){ //Stop the motors when the end time is reached if(c==stopShootingFirst){ //Stop the motors when the end time is reached
shootRobot(0.0f); shootRobot(0.0f);
}else if(i>=200+x&&i<=400+x){ i=2; //Run step 2 next
//Wait c=0;
driveRobot(0.0f, 0.0f);
shootRobot(0.0f);
} else if(i>400+x&&i<500+x&&angle>=potToDegrees(armPot.GetAverageVoltage())) {
//Shoot
driveRobot(0.0f, 0.0f);
shootRobot(power);
} else if(i>400+x&&i<500+x&&angle<=potToDegrees(armPot.GetAverageVoltage())) {
//Wait
driveRobot(0.0f, 0.0f);
shootRobot(0.0f);
} else if(i>500+x&&i<700+2*x+y) {
//Drive backward 1s, Collect ball
if(40.0f<=potToDegrees(armPot.GetAverageVoltage())){
shootRobot(-0.30f);
}
driveRobot(0.6f,correction);
shootRobot(0.0f);
} else if(i>=700+2*x+y&&i<=1300+2*x+y){
//Wait
driveRobot(0.0f,0.0f);
shootRobot(0.0f);
} else if(i>1300+2*x+y&&i<1500+3*x+2*y) {
//Drive forward 1s
driveRobot(-1.0f,correction);
shootRobot(0.0f);
} else if(i>=1500+3*x+2*y&&i<=1600+3*x+2*y){
//Wait
driveRobot(0.0f,0.0f);
shootRobot(0.0f);
} else if(i>1600+3*x+2*y&&i<1700+3*x+2*y&&/*120*/angle>=potToDegrees(armPot.GetAverageVoltage())){
//Shoot
driveRobot(0.0f,0.0f);
shootRobot(power);
} else if(i>1600+3*x+2*y&&i<1700+3*x+2*y&&/*120*/angle<=potToDegrees(armPot.GetAverageVoltage())){
//Wait
driveRobot(0.0f,0.0f);
shootRobot(0.0f);
} else if(i>1700+3*x+2*y&&40.0f<=potToDegrees(armPot.GetAverageVoltage())) {
//Stop robot after auto, let down shooter
driveRobot(0.0f,0.0f);
shootRobot(-0.15);
} else if(i>1700+3*x+2*y&&40.0f>=potToDegrees(armPot.GetAverageVoltage())) {
//Stop all motors
driveRobot(0.0f,0.0f);
shootRobot(0.0f);
} }
} }
// if(i-c==2&&c>getSecondBallStart){ // if(i-c==2&&c>getSecondBallStart){