2014-03-08 17:10:33 -05:00
|
|
|
//Includes{{{
|
2014-02-22 18:14:01 -05:00
|
|
|
#include "WPILib.h"
|
|
|
|
#include "SmartDashboard/SmartDashboard.h"
|
2014-02-15 10:47:49 -05:00
|
|
|
#include <iostream>
|
|
|
|
#include <math.h>
|
2014-02-19 22:25:03 -05:00
|
|
|
#include <sstream>
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-02-15 10:47:49 -05:00
|
|
|
class RobotDemo : public SimpleRobot
|
|
|
|
{
|
2014-03-08 17:10:33 -05:00
|
|
|
//Declarations{{{
|
2014-02-15 10:47:49 -05:00
|
|
|
RobotDrive myRobot;
|
2014-03-27 22:55:34 -04:00
|
|
|
bool collectorExtended,shooting,compressing,allowCompressing;
|
|
|
|
float upLimit,throttle;
|
|
|
|
Joystick Rstick,Lstick;
|
|
|
|
Solenoid collectorSole1,collectorSole2;
|
2014-02-16 20:09:11 -05:00
|
|
|
Compressor compressor;
|
2014-03-27 22:55:34 -04:00
|
|
|
Jaguar Left1,Left2,Left3,Right1,Right2,Right3,RightArmMotor1,RightArmMotor2,LeftArmMotor1,LeftArmMotor2,CollectorMotor1;
|
|
|
|
AnalogChannel armPot,BallSonicLeft,BallSonicRight,WallSonicLeft,WallSonicRight;
|
|
|
|
DigitalOutput BallLeft,BallRight,WallLeft,WallRight;
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-02-15 10:47:49 -05:00
|
|
|
public:
|
|
|
|
RobotDemo():
|
2014-03-08 17:10:33 -05:00
|
|
|
//Initializations{{{
|
2014-02-15 10:47:49 -05:00
|
|
|
//Joysticks
|
|
|
|
Rstick(1),
|
|
|
|
Lstick(2),
|
|
|
|
//Pot
|
2014-02-16 20:09:11 -05:00
|
|
|
armPot(6),
|
2014-02-15 10:47:49 -05:00
|
|
|
//Ultrasonic
|
|
|
|
BallSonicLeft(1),
|
|
|
|
BallSonicRight(2),
|
|
|
|
WallSonicLeft(3),
|
|
|
|
WallSonicRight(4),
|
2014-02-22 18:14:01 -05:00
|
|
|
BallLeft(1,4),
|
|
|
|
WallLeft(1,5),
|
|
|
|
BallRight(2,4),
|
|
|
|
WallRight(2,5),
|
2014-02-15 10:47:49 -05:00
|
|
|
//Compressor
|
2014-03-27 22:55:34 -04:00
|
|
|
compressor(2,5,1,1),
|
2014-02-26 23:02:49 -05:00
|
|
|
//Solenoids
|
2014-02-15 10:47:49 -05:00
|
|
|
collectorSole1(1),
|
|
|
|
collectorSole2(2),
|
2014-03-02 15:32:51 -05:00
|
|
|
//Drive Motors
|
|
|
|
Left1(1,1),
|
|
|
|
Left2(1,2),
|
|
|
|
Left3(1,3),
|
|
|
|
Right1(2,1),
|
|
|
|
Right2(2,2),
|
|
|
|
Right3(2,3),
|
2014-02-15 10:47:49 -05:00
|
|
|
//Shooter Motors
|
2014-03-27 22:55:34 -04:00
|
|
|
LeftArmMotor1(1,4),
|
|
|
|
LeftArmMotor2(1,5),
|
|
|
|
RightArmMotor1(2,4),
|
|
|
|
RightArmMotor2(2,5),
|
2014-02-15 10:47:49 -05:00
|
|
|
//Collector Motor
|
2014-03-27 22:55:34 -04:00
|
|
|
CollectorMotor1(1,6),
|
|
|
|
myRobot(Left1,Left2,Right1,Right2){
|
|
|
|
GetWatchdog().SetEnabled(false);
|
|
|
|
}
|
|
|
|
//}}}
|
2014-03-08 17:10:33 -05:00
|
|
|
//RobotInit{{{
|
2014-03-27 22:55:34 -04:00
|
|
|
void RobotInit(){
|
2014-02-15 10:47:49 -05:00
|
|
|
DashboardSetup();
|
2014-03-27 22:55:34 -04:00
|
|
|
upLimit=130.0;
|
2014-02-15 10:47:49 -05:00
|
|
|
compressor.Start();
|
2014-03-27 22:55:34 -04:00
|
|
|
shooting=false;
|
|
|
|
compressing=true;
|
|
|
|
allowCompressing=true;
|
2014-03-16 19:13:54 -04:00
|
|
|
throttle=(-Lstick.GetRawAxis(4)+1)/2;
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
|
|
|
//DashboardSetup{{{
|
2014-03-27 22:55:34 -04:00
|
|
|
void DashboardSetup(){
|
|
|
|
SmartDashboard::PutNumber("Throttle",throttle);
|
|
|
|
SmartDashboard::PutNumber("upLimit",120.0f);
|
|
|
|
SmartDashboard::PutNumber("armPot",potToDegrees(armPot.GetAverageVoltage()));
|
|
|
|
SmartDashboard::PutNumber("Log Level",1.0f);
|
2014-03-02 17:39:45 -05:00
|
|
|
//Ultrasonic
|
2014-03-27 22:55:34 -04:00
|
|
|
SmartDashboard::PutNumber("Wall Left",voltToDistance(WallSonicLeft.GetAverageVoltage(),true));
|
|
|
|
SmartDashboard::PutNumber("Wall Right",voltToDistance(WallSonicRight.GetAverageVoltage(),true));
|
|
|
|
SmartDashboard::PutNumber("Ball Left",voltToDistance(BallSonicLeft.GetAverageVoltage()));
|
|
|
|
SmartDashboard::PutNumber("Ball Right",voltToDistance(BallSonicRight.GetAverageVoltage()));
|
2014-03-02 15:32:51 -05:00
|
|
|
//Autonomous values
|
2014-03-14 16:28:20 -04:00
|
|
|
SmartDashboard::PutNumber("AutoSpeed",0.95f);
|
|
|
|
SmartDashboard::PutNumber("Auto Distance",65.0f);
|
2014-03-13 21:31:51 -04:00
|
|
|
SmartDashboard::PutNumber("Collector Speed",1.0f);
|
2014-03-15 15:43:47 -04:00
|
|
|
SmartDashboard::PutNumber("AutoPower",0.46f);
|
2014-03-14 14:47:10 -04:00
|
|
|
SmartDashboard::PutNumber("AutoCorrection",0.032f);
|
2014-03-13 21:31:51 -04:00
|
|
|
SmartDashboard::PutNumber("Initial Drive Delay",2.0f);
|
2014-03-27 22:55:34 -04:00
|
|
|
SmartDashboard::PutNumber("Inital Drive Timeout",4.5f);
|
|
|
|
SmartDashboard::PutNumber("First Shot Start",0.5f);
|
|
|
|
SmartDashboard::PutNumber("First Shot Stop",1.0f);
|
2014-03-08 17:10:33 -05:00
|
|
|
SmartDashboard::PutNumber("Reverse direction start",0.0f);
|
|
|
|
SmartDashboard::PutNumber("Reverse direction stop",2.5f);
|
2014-03-27 22:55:34 -04:00
|
|
|
SmartDashboard::PutNumber("Second Drive Start",1.0f);
|
|
|
|
SmartDashboard::PutNumber("Second Drive Timeout",2.5f);
|
|
|
|
SmartDashboard::PutNumber("Second Shot Start",0.5f);
|
|
|
|
SmartDashboard::PutNumber("Second Shot Stop",1.0f);
|
2014-03-06 21:10:08 -05:00
|
|
|
SmartDashboard::PutNumber("Autonomous step",0.0f);
|
2014-03-27 22:55:34 -04:00
|
|
|
SmartDashboard::PutNumber("Autonomous sequence",2.0f);
|
2014-03-02 17:39:45 -05:00
|
|
|
//Shooter presets
|
|
|
|
SmartDashboard::PutNumber("ShortRange",0.465f); //Power for the shooter when against the low goal
|
2014-02-28 15:25:38 -05:00
|
|
|
SmartDashboard::PutNumber("ShooterButtonPower10",0.605f);
|
|
|
|
SmartDashboard::PutNumber("ShooterButtonPower7",1.0f);
|
|
|
|
SmartDashboard::PutNumber("ShooterButtonPower8",0.5f);
|
2014-03-02 17:39:45 -05:00
|
|
|
//Bool switches
|
2014-03-31 15:06:14 -04:00
|
|
|
SmartDashboard::PutBoolean("HalfPower",false);
|
2014-03-06 18:45:13 -05:00
|
|
|
SmartDashboard::PutBoolean("OneBallAuto",false);
|
|
|
|
SmartDashboard::PutBoolean("Use Ultrasonic",true);
|
2014-02-26 23:02:49 -05:00
|
|
|
SmartDashboard::PutBoolean("Daniel Mode",false);
|
2014-03-01 11:54:04 -05:00
|
|
|
SmartDashboard::PutBoolean("CollectorState",false);
|
2014-03-27 22:55:34 -04:00
|
|
|
SmartDashboard::PutBoolean("Compressor Enabled",allowCompressing);
|
|
|
|
SmartDashboard::PutBoolean("Compressor Running",compressing);
|
2014-03-06 21:10:08 -05:00
|
|
|
SmartDashboard::PutBoolean("Ignore Pot",false);
|
2014-03-06 18:44:23 -05:00
|
|
|
//Battery voltage
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
|
|
|
//updateDashboard{{{
|
2014-03-27 22:55:34 -04:00
|
|
|
void updateDashboard(){
|
|
|
|
SmartDashboard::PutNumber("Throttle",throttle);
|
|
|
|
SmartDashboard::PutNumber("armPot",potToDegrees(armPot.GetAverageVoltage()));
|
|
|
|
SmartDashboard::PutNumber("Wall Left",voltToDistance(WallSonicLeft.GetAverageVoltage(),true));
|
|
|
|
SmartDashboard::PutNumber("Wall Right",voltToDistance(WallSonicRight.GetAverageVoltage(),true));
|
|
|
|
SmartDashboard::PutNumber("Ball Left",voltToDistance(BallSonicLeft.GetAverageVoltage()));
|
|
|
|
SmartDashboard::PutNumber("Ball Right",voltToDistance(BallSonicRight.GetAverageVoltage()));
|
|
|
|
SmartDashboard::PutNumber("upLimit",upLimit);
|
|
|
|
SmartDashboard::PutBoolean("Compressor Running",compressing);
|
|
|
|
allowCompressing=SmartDashboard::GetBoolean("Compressor Enabled");
|
|
|
|
if(upLimit > 167){
|
|
|
|
upLimit=167;
|
2014-02-16 20:09:11 -05:00
|
|
|
}
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-03-27 22:55:34 -04:00
|
|
|
//shootRobot{{{
|
|
|
|
void shootRobot(float power=0){
|
|
|
|
setMotorValue(4,1,cvt(power));
|
|
|
|
setMotorValue(5,1,cvt(power));
|
|
|
|
setMotorValue(4,2,cvt(-power));
|
|
|
|
setMotorValue(5,2,cvt(-power));
|
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-03-27 22:55:34 -04:00
|
|
|
//driveRobot{{{
|
|
|
|
void driveRobot(float x,float y){
|
|
|
|
if(y>1.0f){
|
|
|
|
y=1.0f;
|
|
|
|
}else if(y!=0.0f&&y<-1.0f){
|
|
|
|
y=-1.0f;
|
2014-03-08 17:10:33 -05:00
|
|
|
}
|
2014-03-27 22:55:34 -04:00
|
|
|
int leftPower=((y+x)/2+1)*127+1;
|
|
|
|
int rightPower=((y-x)/2+1)*127+1;
|
2014-03-31 15:06:14 -04:00
|
|
|
if(SmartDashboard::GetBoolean("HalfPower")){
|
|
|
|
leftPower/=2;
|
|
|
|
rightPower/=2;
|
|
|
|
}
|
2014-03-27 22:55:34 -04:00
|
|
|
setMotorValue(1,1,leftPower);
|
|
|
|
setMotorValue(2,1,leftPower);
|
|
|
|
setMotorValue(3,1,leftPower);
|
|
|
|
setMotorValue(1,2,rightPower);
|
|
|
|
setMotorValue(2,2,rightPower);
|
|
|
|
setMotorValue(3,2,rightPower);
|
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
|
|
|
//voltToDistance{{{
|
2014-03-27 22:55:34 -04:00
|
|
|
float voltToDistance(float a,bool wall=false){
|
|
|
|
if(wall){
|
|
|
|
return (a/0.00488f)/2.54f;
|
|
|
|
}else{
|
|
|
|
return (a/0.000976562f)/25.4f;
|
2014-02-19 22:25:03 -05:00
|
|
|
}
|
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
|
|
|
//potToDegrees{{{
|
2014-04-02 19:42:21 -04:00
|
|
|
float potToDegrees(float a) {
|
|
|
|
float max = -.0003948;
|
|
|
|
float min = 5.0245547;
|
|
|
|
float b = a - max;
|
|
|
|
min = min - max; // ~5.0027
|
|
|
|
max = max - max; //=0
|
|
|
|
return 300 - ((b + max) * (300 / min));
|
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
|
|
|
//cvt{{{
|
2014-03-27 22:55:34 -04:00
|
|
|
int cvt(float input){
|
2014-02-17 15:04:40 -05:00
|
|
|
return input * 127.0f + 128;
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
|
|
|
//setMotorValue{{{
|
2014-03-27 22:55:34 -04:00
|
|
|
void setMotorValue(int motor,int subwayStation=1,int value=127){
|
2014-03-31 22:40:15 -04:00
|
|
|
if(subwayStation==1){
|
2014-03-08 17:10:33 -05:00
|
|
|
//subwayStation1{{{
|
2014-03-27 22:55:34 -04:00
|
|
|
switch(motor){
|
|
|
|
case 1:
|
|
|
|
Left1.SetRaw(value);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
Left2.SetRaw(value);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
Left3.SetRaw(value);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
LeftArmMotor1.SetRaw(value);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
LeftArmMotor2.SetRaw(value);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
CollectorMotor1.SetRaw(value);
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
break;
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-03-31 22:40:15 -04:00
|
|
|
}else if(subwayStation==2){
|
2014-03-08 17:10:33 -05:00
|
|
|
//subwayStation2{{{
|
2014-03-27 22:55:34 -04:00
|
|
|
switch(motor){
|
|
|
|
//Shooter motors
|
|
|
|
case 1:
|
|
|
|
Right1.SetRaw(value);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
Right2.SetRaw(value);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
Right3.SetRaw(value);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
RightArmMotor1.SetRaw(value);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
RightArmMotor2.SetRaw(value);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
break;
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-04-02 13:55:12 -04:00
|
|
|
//runCompressor{{{
|
2014-04-03 15:13:42 -04:00
|
|
|
void runCompressor(int i, int refreshInterval){
|
|
|
|
if(i%refreshInterval==0&compressing&compressor.GetPressureSwitchValue()==1){
|
2014-04-02 13:55:12 -04:00
|
|
|
compressing=false;
|
2014-04-02 17:45:42 -04:00
|
|
|
compressor.Stop();
|
2014-04-02 13:55:12 -04:00
|
|
|
}
|
2014-04-03 15:13:42 -04:00
|
|
|
if(i%refreshInterval==0&!compressing&compressor.GetPressureSwitchValue()==0){
|
2014-04-02 13:55:12 -04:00
|
|
|
compressing=true;
|
2014-04-02 17:45:42 -04:00
|
|
|
compressor.Start();
|
2014-04-02 13:55:12 -04:00
|
|
|
}
|
2014-04-02 20:00:46 -04:00
|
|
|
}
|
2014-04-02 13:55:12 -04:00
|
|
|
//}}}
|
2014-04-03 17:17:28 -04:00
|
|
|
//{{{updateJoystick
|
|
|
|
bool* updateJoystick(int joystick){
|
|
|
|
if(joystick==1){
|
|
|
|
for(i=1,i<=12,i++){
|
|
|
|
state[joystick][i] = Lstick.GetRawButton(i);
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
if(joystick==2){
|
|
|
|
for(i=1,i<=12,i++){
|
|
|
|
state[joystick][i] = Rstick.GetRawButton(i);
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
2014-03-08 17:10:33 -05:00
|
|
|
//Autonomous{{{
|
2014-03-27 22:55:34 -04:00
|
|
|
void Autonomous(){
|
2014-03-08 17:10:33 -05:00
|
|
|
//Initializations{{{
|
2014-02-15 10:47:49 -05:00
|
|
|
myRobot.SetSafetyEnabled(false);
|
2014-02-22 18:14:01 -05:00
|
|
|
int i=0;
|
2014-03-06 18:45:13 -05:00
|
|
|
int c=0;
|
2014-03-06 19:54:28 -05:00
|
|
|
float power=SmartDashboard::GetNumber("AutoPower");
|
|
|
|
float correction=SmartDashboard::GetNumber("AutoCorrection");
|
2014-03-06 20:23:07 -05:00
|
|
|
int currentStep=0;
|
2014-02-26 15:50:12 -05:00
|
|
|
compressing=false;
|
|
|
|
collectorSole1.Set(false);
|
|
|
|
collectorSole2.Set(true);
|
2014-02-22 18:14:01 -05:00
|
|
|
WallLeft.Set(1);
|
2014-02-26 15:50:12 -05:00
|
|
|
BallLeft.Set(0);
|
|
|
|
WallRight.Set(1);
|
2014-02-22 18:14:01 -05:00
|
|
|
BallRight.Set(0);
|
2014-03-01 11:54:04 -05:00
|
|
|
SmartDashboard::PutBoolean("CollectorState",true);
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-03-27 22:55:34 -04:00
|
|
|
while(IsEnabled()&&IsAutonomous()){
|
2014-03-31 15:06:14 -04:00
|
|
|
if(!SmartDashboard::GetBoolean("HalfPower")){
|
2014-03-31 20:28:08 -04:00
|
|
|
if(SmartDashboard::GetNumber("Autonomous sequence")==0){
|
|
|
|
//Autonomous0{{{
|
|
|
|
//Drive{{{
|
|
|
|
if(currentStep==0){
|
|
|
|
if(voltToDistance(WallSonicLeft.GetAverageVoltage(),true)>=SmartDashboard::GetNumber("Auto Distance")){
|
|
|
|
driveRobot(-1.0f,correction);
|
|
|
|
}else{
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
}
|
|
|
|
if(c==SmartDashboard::GetNumber("Inital Drive Timeout")*200){
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
currentStep++;
|
|
|
|
c=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
//Shoot{{{
|
|
|
|
if(currentStep==1&&c>SmartDashboard::GetNumber("First Shot Start")*200){
|
|
|
|
if(SmartDashboard::GetBoolean("Ignore Pot")||upLimit>=potToDegrees(armPot.GetAverageVoltage())){
|
|
|
|
shootRobot(power);
|
|
|
|
}else{
|
|
|
|
shootRobot(0.0f);
|
|
|
|
}
|
|
|
|
setMotorValue(6, 1, 1);
|
|
|
|
if(c==(SmartDashboard::GetNumber("First Shot Stop"))*200){
|
|
|
|
shootRobot(0.0f);
|
|
|
|
setMotorValue(6, 1, 0);
|
|
|
|
currentStep++;
|
|
|
|
c=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
//Lower Shooter{{{
|
|
|
|
if(currentStep==2&&c>SmartDashboard::GetNumber("Reverse direction start")*200){
|
|
|
|
if(40.0f<=potToDegrees(armPot.GetAverageVoltage())){
|
|
|
|
shootRobot(-0.3f);
|
|
|
|
}else{
|
|
|
|
shootRobot(0.0f);
|
|
|
|
}
|
|
|
|
if(c==(3.0f)*200){
|
|
|
|
shootRobot(0.0f);
|
|
|
|
currentStep++;
|
|
|
|
c=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
//}}}
|
|
|
|
}else if(SmartDashboard::GetNumber("Autonomous sequence")==1){
|
|
|
|
//Autonomous1{{{
|
|
|
|
//Drive{{{
|
|
|
|
if(currentStep==0){
|
|
|
|
if(voltToDistance(WallSonicLeft.GetAverageVoltage(),true)>=SmartDashboard::GetNumber("Auto Distance")){
|
|
|
|
driveRobot(-1.0f,correction);
|
|
|
|
}else{
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
}
|
|
|
|
if(c==SmartDashboard::GetNumber("Inital Drive Timeout")*200){
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
currentStep++;
|
|
|
|
c=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
//Shoot{{{
|
|
|
|
if(currentStep==1&&c>SmartDashboard::GetNumber("First Shot Start")*200){
|
|
|
|
if(SmartDashboard::GetBoolean("Ignore Pot")||upLimit>=potToDegrees(armPot.GetAverageVoltage())){
|
|
|
|
shootRobot(power);
|
|
|
|
}else{
|
|
|
|
shootRobot(0.0f);
|
|
|
|
}
|
|
|
|
setMotorValue(6, 1, 1);
|
|
|
|
if(c==(SmartDashboard::GetNumber("First Shot Stop"))*200){
|
|
|
|
shootRobot(0.0f);
|
|
|
|
setMotorValue(6, 1, 0);
|
|
|
|
currentStep++;
|
|
|
|
c=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
//Drive Backwards{{{
|
|
|
|
if(currentStep==2&&c>SmartDashboard::GetNumber("Reverse direction start")*200){
|
|
|
|
driveRobot(1.0f,correction);
|
|
|
|
if(40.0f<=potToDegrees(armPot.GetAverageVoltage())){
|
|
|
|
shootRobot(-0.2f);
|
|
|
|
}else{
|
|
|
|
shootRobot(0.0f);
|
|
|
|
}
|
|
|
|
if(c==(SmartDashboard::GetNumber("Reverse direction stop"))*200){
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
shootRobot(0.0f);
|
|
|
|
currentStep++;
|
|
|
|
c=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
//Drive{{{
|
|
|
|
if(currentStep==3&&c>SmartDashboard::GetNumber("Second Drive Start")*200){
|
|
|
|
if(voltToDistance(WallSonicLeft.GetAverageVoltage(),true)>=SmartDashboard::GetNumber("Auto Distance")){
|
|
|
|
driveRobot(-1.0f,correction);
|
|
|
|
}else{
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
}
|
|
|
|
if(c==(SmartDashboard::GetNumber("Inital Drive Timeout"))*200){
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
currentStep++;
|
|
|
|
c=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
//Shoot{{{
|
|
|
|
if(currentStep==4&&c>(SmartDashboard::GetNumber("Second Shot Start"))*200){
|
|
|
|
if(SmartDashboard::GetBoolean("Ignore Pot")||upLimit>=potToDegrees(armPot.GetAverageVoltage())){
|
|
|
|
shootRobot(power);
|
|
|
|
}else{
|
|
|
|
shootRobot(0.0f);
|
|
|
|
}
|
|
|
|
setMotorValue(6, 1, 1);
|
|
|
|
if(c==(SmartDashboard::GetNumber("First Shot Stop"))*200){
|
|
|
|
shootRobot(0.0f);
|
|
|
|
setMotorValue(6, 1, 0);
|
|
|
|
currentStep++;
|
|
|
|
c=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
//}}}
|
|
|
|
}else if(SmartDashboard::GetNumber("Autonomous sequence")==2){
|
|
|
|
//Autonomous2{{{
|
|
|
|
//Drive{{{
|
|
|
|
if(currentStep==0&&c>SmartDashboard::GetNumber("Initial Drive Delay")*200){
|
|
|
|
setMotorValue(6, 1, SmartDashboard::GetNumber("Collector Speed"));
|
|
|
|
if(voltToDistance(WallSonicLeft.GetAverageVoltage(),true)>=SmartDashboard::GetNumber("Auto Distance")){
|
|
|
|
driveRobot(-1*(SmartDashboard::GetNumber("AutoSpeed")),correction);
|
|
|
|
}else{
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
}
|
|
|
|
if(c==SmartDashboard::GetNumber("Inital Drive Timeout")*200){
|
|
|
|
setMotorValue(6, 1, 0);
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
currentStep++;
|
|
|
|
c=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
//Release Ball{{{
|
|
|
|
if(currentStep==1){
|
|
|
|
setMotorValue(6, 1, 102);
|
|
|
|
if(c==50){
|
|
|
|
currentStep++;
|
|
|
|
c=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
//Shoot{{{
|
|
|
|
if(currentStep==2&&c>SmartDashboard::GetNumber("First Shot Start")*200){
|
|
|
|
if(SmartDashboard::GetBoolean("Ignore Pot")||upLimit>=potToDegrees(armPot.GetAverageVoltage())){
|
|
|
|
shootRobot(power);
|
|
|
|
}else{
|
|
|
|
shootRobot(0.0f);
|
|
|
|
}
|
|
|
|
if(c==SmartDashboard::GetNumber("First Shot Stop")*200){
|
|
|
|
shootRobot(0.0f);
|
|
|
|
setMotorValue(6, 1, 0);
|
|
|
|
currentStep++;
|
|
|
|
c=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
//Lower Shooter{{{
|
|
|
|
if(currentStep==3){
|
|
|
|
if(40.0f<=potToDegrees(armPot.GetAverageVoltage())){
|
|
|
|
shootRobot(-0.3f);
|
|
|
|
}else{
|
|
|
|
shootRobot(0.0f);
|
|
|
|
}
|
|
|
|
if(c==1*200){
|
|
|
|
shootRobot(0.0f);
|
|
|
|
currentStep++;
|
|
|
|
c=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
//Collect Ball{{{
|
|
|
|
if(currentStep==4&&c>SmartDashboard::GetNumber("Second Shot Start")){
|
|
|
|
setMotorValue(6, 1, 1);
|
|
|
|
if(c==SmartDashboard::GetNumber("Second Shot Stop")*200){
|
|
|
|
setMotorValue(6, 1, 0);
|
|
|
|
currentStep++;
|
|
|
|
c=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
//Shoot{{{
|
|
|
|
if(currentStep==5&&c>(SmartDashboard::GetNumber("Second Shot Start"))*200){
|
|
|
|
if(SmartDashboard::GetBoolean("Ignore Pot")||upLimit>=potToDegrees(armPot.GetAverageVoltage())){
|
|
|
|
shootRobot(power);
|
|
|
|
}else{
|
|
|
|
shootRobot(0.0f);
|
|
|
|
}
|
|
|
|
setMotorValue(6, 1, 1);
|
|
|
|
if(c==(SmartDashboard::GetNumber("First Shot Stop"))*200){
|
|
|
|
setMotorValue(6, 1, 0);
|
|
|
|
shootRobot(0.0f);
|
|
|
|
currentStep++;
|
|
|
|
c=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
//}}}
|
|
|
|
}
|
|
|
|
SmartDashboard::PutNumber("Autonomous step", currentStep);
|
|
|
|
updateDashboard();
|
2014-03-08 17:10:33 -05:00
|
|
|
//Compressor{{{
|
2014-04-02 13:55:12 -04:00
|
|
|
if(SmartDashboard::GetBoolean("Compressor Enabled")){
|
2014-04-02 17:44:42 -04:00
|
|
|
runCompressor(i,100);
|
2014-02-16 20:09:11 -05:00
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-02-19 22:25:03 -05:00
|
|
|
i++;
|
2014-03-06 18:44:23 -05:00
|
|
|
c++;
|
2014-03-08 17:10:33 -05:00
|
|
|
Wait(0.005f);
|
2014-02-22 18:14:01 -05:00
|
|
|
}
|
2014-03-27 22:55:34 -04:00
|
|
|
compressing=false;
|
2014-02-15 10:47:49 -05:00
|
|
|
compressor.Stop();
|
|
|
|
}
|
2014-04-02 19:37:26 -04:00
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
|
|
|
//Teleop{{{
|
2014-03-27 22:55:34 -04:00
|
|
|
void OperatorControl(){
|
2014-03-08 17:10:33 -05:00
|
|
|
//Initializations{{{
|
2014-02-15 10:47:49 -05:00
|
|
|
myRobot.SetSafetyEnabled(false);
|
2014-03-27 22:55:34 -04:00
|
|
|
int i=0;
|
2014-02-15 10:47:49 -05:00
|
|
|
collectorSole1.Set(true);
|
|
|
|
collectorSole2.Set(false);
|
2014-03-27 22:55:34 -04:00
|
|
|
compressing=false;
|
2014-03-01 11:54:04 -05:00
|
|
|
SmartDashboard::PutBoolean("CollectorState",false);
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-03-31 22:40:15 -04:00
|
|
|
while(IsEnabled()&&IsOperatorControl()){
|
2014-03-08 17:10:33 -05:00
|
|
|
//Joystick{{{
|
2014-03-13 21:08:11 -04:00
|
|
|
//Throttle values{{{
|
2014-02-28 15:25:38 -05:00
|
|
|
if(Lstick.GetRawButton(9)==1){
|
2014-03-27 22:55:34 -04:00
|
|
|
throttle=(-Lstick.GetRawAxis(4)+1)/2;
|
2014-02-28 15:25:38 -05:00
|
|
|
}else if(Lstick.GetRawButton(10)){
|
2014-03-27 22:55:34 -04:00
|
|
|
throttle=SmartDashboard::GetNumber("ShooterButtonPower10");
|
2014-02-28 15:25:38 -05:00
|
|
|
}else if(Lstick.GetRawButton(7)){
|
2014-03-27 22:55:34 -04:00
|
|
|
throttle=SmartDashboard::GetNumber("ShooterButtonPower7");
|
2014-02-28 15:25:38 -05:00
|
|
|
}else if(Lstick.GetRawButton(8)){
|
2014-03-27 22:55:34 -04:00
|
|
|
throttle=SmartDashboard::GetNumber("ShooterButtonPower8");
|
2014-02-28 15:25:38 -05:00
|
|
|
}
|
2014-03-13 20:11:00 -04:00
|
|
|
//}}}
|
|
|
|
//Shooter upLimit{{{
|
2014-02-27 14:42:10 -05:00
|
|
|
if(Lstick.GetRawButton(3)){
|
2014-02-27 17:10:36 -05:00
|
|
|
upLimit=100.0f;
|
2014-02-27 14:42:10 -05:00
|
|
|
}
|
|
|
|
if(Lstick.GetRawButton(4)){
|
2014-02-27 17:10:36 -05:00
|
|
|
upLimit=120.0f;
|
2014-02-27 14:42:10 -05:00
|
|
|
}
|
|
|
|
if(Lstick.GetRawButton(5)){
|
2014-02-27 17:10:36 -05:00
|
|
|
upLimit=90.0f;
|
2014-02-27 14:42:10 -05:00
|
|
|
}
|
|
|
|
if(Lstick.GetRawButton(6)){
|
2014-02-27 17:10:36 -05:00
|
|
|
upLimit=130.0f;
|
2014-02-27 14:42:10 -05:00
|
|
|
}
|
2014-03-13 20:11:00 -04:00
|
|
|
//}}}
|
2014-03-27 22:55:34 -04:00
|
|
|
if(Lstick.GetRawButton(1)==1){
|
2014-03-08 17:10:33 -05:00
|
|
|
//Shoot{{{
|
2014-03-27 22:55:34 -04:00
|
|
|
shooting=true;
|
|
|
|
setMotorValue(6,1,1);
|
2014-03-31 22:40:15 -04:00
|
|
|
if(collectorExtended==false){
|
2014-03-27 22:55:34 -04:00
|
|
|
shooting=false;
|
2014-03-06 21:10:08 -05:00
|
|
|
}
|
2014-03-31 22:41:42 -04:00
|
|
|
//shootRobot(throttle);
|
|
|
|
//TODO: test this code, we don't know if it works, but if it does not, run this code: ^
|
2014-03-31 22:40:15 -04:00
|
|
|
if(collectorExtended==true&&(SmartDashboard::GetBoolean("Ignore Pot")||upLimit>=potToDegrees(armPot.GetAverageVoltage()))){
|
2014-03-27 22:55:34 -04:00
|
|
|
shooting=true;
|
2014-03-06 21:10:08 -05:00
|
|
|
shootRobot(throttle);
|
2014-03-27 22:55:34 -04:00
|
|
|
setMotorValue(6,1,1);
|
2014-03-13 21:19:42 -04:00
|
|
|
}else{
|
2014-03-27 22:55:34 -04:00
|
|
|
shooting=false;
|
2014-03-13 21:19:42 -04:00
|
|
|
shootRobot(0.0f);
|
2014-03-27 22:55:34 -04:00
|
|
|
setMotorValue(6,1,0);
|
2014-03-06 21:10:08 -05:00
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-03-27 22:55:34 -04:00
|
|
|
}else if(Lstick.GetRawButton(2)==1){
|
2014-03-08 17:10:33 -05:00
|
|
|
//Lower Shooter{{{
|
2014-03-27 22:55:34 -04:00
|
|
|
shooting=false;
|
2014-03-06 18:44:23 -05:00
|
|
|
shootRobot(-0.1f);
|
2014-03-31 22:40:15 -04:00
|
|
|
if(collectorExtended==true){
|
2014-03-06 21:10:08 -05:00
|
|
|
shootRobot(-0.1f);
|
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-03-27 22:55:34 -04:00
|
|
|
}else{
|
2014-03-08 17:10:33 -05:00
|
|
|
//Stop Shooting{{{
|
2014-03-27 22:55:34 -04:00
|
|
|
shooting=false;
|
2014-04-02 19:37:26 -04:00
|
|
|
shootRobot(0.0f);
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-03-27 22:55:34 -04:00
|
|
|
if(Rstick.GetRawButton(9)==1){
|
2014-03-08 17:10:33 -05:00
|
|
|
//Extend Collector{{{
|
2014-03-01 11:54:04 -05:00
|
|
|
SmartDashboard::PutBoolean("CollectorState",true);
|
2014-03-27 22:55:34 -04:00
|
|
|
collectorExtended=true;
|
2014-02-15 10:47:49 -05:00
|
|
|
collectorSole1.Set(false);
|
|
|
|
collectorSole2.Set(true);
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-03-27 22:55:34 -04:00
|
|
|
}else if(Rstick.GetRawButton(10)==1){
|
2014-03-08 17:10:33 -05:00
|
|
|
//Retract Collector{{{
|
2014-03-01 11:54:04 -05:00
|
|
|
SmartDashboard::PutBoolean("CollectorState",false);
|
2014-03-27 22:55:34 -04:00
|
|
|
collectorExtended=false;
|
2014-02-15 10:47:49 -05:00
|
|
|
collectorSole1.Set(true);
|
|
|
|
collectorSole2.Set(false);
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//Collector Motor{{{
|
2014-04-03 16:58:02 -04:00
|
|
|
if(Lstick.GetRawButton(11)==1&&50<=potToDegrees(armPot.GetAverageVoltage())){
|
2014-03-27 22:55:34 -04:00
|
|
|
setMotorValue(6,1,1);
|
|
|
|
}else if(Lstick.GetRawButton(12)==1){
|
|
|
|
setMotorValue(6,1,255);
|
|
|
|
}else if(!shooting){
|
|
|
|
setMotorValue(6,1,0);
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
|
|
|
//}}}
|
|
|
|
//Driving{{{
|
|
|
|
if(Rstick.GetRawButton(1)){
|
|
|
|
if(voltToDistance(WallSonicLeft.GetAverageVoltage(),true)>=40.0f){
|
|
|
|
driveRobot(1.0f,SmartDashboard::GetNumber("AutoCorrection"));
|
|
|
|
}else{
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
}
|
|
|
|
}else{
|
2014-03-27 22:55:34 -04:00
|
|
|
if(SmartDashboard::GetBoolean("Daniel Mode")){
|
2014-03-08 17:10:33 -05:00
|
|
|
driveRobot(-Rstick.GetY(),Rstick.GetZ()+Rstick.GetX());
|
2014-03-27 22:55:34 -04:00
|
|
|
}else{
|
2014-03-08 17:10:33 -05:00
|
|
|
driveRobot(Rstick.GetY(),Rstick.GetZ()+Rstick.GetX());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
//Compressor{{{
|
|
|
|
if(SmartDashboard::GetBoolean("Compressor Enabled")){
|
2014-04-02 17:44:42 -04:00
|
|
|
runCompressor(i,100);
|
2014-03-08 17:10:33 -05:00
|
|
|
}
|
|
|
|
//}}}
|
|
|
|
updateDashboard();
|
2014-02-15 10:47:49 -05:00
|
|
|
i++;
|
|
|
|
Wait(0.005f);
|
|
|
|
}
|
2014-03-27 22:55:34 -04:00
|
|
|
compressing=false;
|
2014-03-08 17:10:33 -05:00
|
|
|
compressor.Stop();
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-03-08 17:10:33 -05:00
|
|
|
//}}}
|
2014-03-13 20:11:00 -04:00
|
|
|
//Test{{{
|
2014-03-27 22:55:34 -04:00
|
|
|
void Test(){
|
2014-03-31 22:40:15 -04:00
|
|
|
int i=0;
|
|
|
|
while(IsEnabled()&&IsTest()){
|
|
|
|
i++;
|
|
|
|
Wait(0.005f);
|
|
|
|
}
|
2014-03-13 20:11:00 -04:00
|
|
|
}
|
|
|
|
//}}}
|
2014-02-15 10:47:49 -05:00
|
|
|
};
|
|
|
|
START_ROBOT_CLASS(RobotDemo);
|