2014-02-22 18:14:01 -05:00
|
|
|
//Sonar code
|
|
|
|
#include "WPILib.h"
|
|
|
|
#include "SmartDashboard/SmartDashboard.h"
|
2014-02-27 14:42:10 -05:00
|
|
|
//#include "Command.h"
|
2014-02-15 10:47:49 -05:00
|
|
|
#include <iostream>
|
|
|
|
#include <math.h>
|
2014-02-16 20:09:11 -05:00
|
|
|
#include <vector>
|
2014-02-19 22:25:03 -05:00
|
|
|
#include <sstream>
|
2014-02-15 10:47:49 -05:00
|
|
|
class RobotDemo : public SimpleRobot
|
|
|
|
{
|
|
|
|
RobotDrive myRobot;
|
2014-02-17 15:04:40 -05:00
|
|
|
float potVal, multiplier, servoXState, servoYState, throttle, ServoXJoyPos, ServoYJoyPos;
|
2014-02-22 18:14:01 -05:00
|
|
|
int lastToggle;
|
|
|
|
int collectorSpeed;
|
2014-02-26 15:50:12 -05:00
|
|
|
bool collectorExtended, toggleCollector, shooting, compressing;
|
2014-02-16 20:09:11 -05:00
|
|
|
float DownSpeed, downLimit, upLimit;
|
2014-02-26 15:50:12 -05:00
|
|
|
//string cmd;
|
2014-02-15 10:47:49 -05:00
|
|
|
Joystick Rstick, Lstick;
|
|
|
|
Servo Servo1, Servo2;
|
|
|
|
Solenoid collectorSole1, collectorSole2;
|
|
|
|
DigitalInput pneumaticLS, shootTopLS, shootBottomLS;
|
|
|
|
Relay collectorSpike, lightingSpike;
|
2014-02-16 20:09:11 -05:00
|
|
|
Compressor compressor;
|
2014-02-17 15:04:40 -05:00
|
|
|
Jaguar Left1, Left2, Left3, Right1, Right2, Right3, RightArmMotor1, RightArmMotor2, LeftArmMotor1, LeftArmMotor2, CollectorMotor1;
|
2014-02-15 10:47:49 -05:00
|
|
|
AnalogChannel armPot;
|
2014-02-22 18:14:01 -05:00
|
|
|
//Ultrasonic
|
2014-02-17 15:04:40 -05:00
|
|
|
AnalogChannel BallSonicLeft, BallSonicRight, WallSonicLeft, WallSonicRight;
|
2014-02-22 18:14:01 -05:00
|
|
|
DigitalOutput BallLeft, BallRight, WallLeft, WallRight;
|
2014-02-26 23:02:49 -05:00
|
|
|
//DigitalInput ballLimit;
|
2014-02-15 10:47:49 -05:00
|
|
|
public:
|
|
|
|
RobotDemo():
|
2014-02-26 23:02:49 -05:00
|
|
|
//Limit Switches
|
|
|
|
//TODO
|
|
|
|
//ballLimit(),
|
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-02-26 23:02:49 -05:00
|
|
|
compressor(2, 5, 1, 1),
|
|
|
|
//Solenoids
|
2014-02-15 10:47:49 -05:00
|
|
|
collectorSole1(1),
|
|
|
|
collectorSole2(2),
|
|
|
|
//Limit switches
|
|
|
|
pneumaticLS(1),
|
|
|
|
shootTopLS(2),
|
|
|
|
shootBottomLS(3),
|
|
|
|
//Driver Motors
|
2014-02-17 15:04:40 -05:00
|
|
|
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
|
|
|
//Servos
|
2014-02-17 15:04:40 -05:00
|
|
|
Servo1(1, 7),
|
|
|
|
Servo2(1, 8),
|
2014-02-15 10:47:49 -05:00
|
|
|
//Spikes
|
2014-02-17 15:04:40 -05:00
|
|
|
collectorSpike(2, 7),
|
|
|
|
lightingSpike(2, 8),
|
2014-02-15 10:47:49 -05:00
|
|
|
//Shooter Motors
|
2014-02-17 15:04:40 -05:00
|
|
|
LeftArmMotor1(1, 4),
|
|
|
|
LeftArmMotor2(1, 5),
|
|
|
|
RightArmMotor1(2, 4),
|
|
|
|
RightArmMotor2(2, 5),
|
2014-02-15 10:47:49 -05:00
|
|
|
//Collector Motor
|
2014-02-22 18:14:01 -05:00
|
|
|
CollectorMotor1(1, 6),
|
|
|
|
myRobot(Left1, Left2, Right1, Right2) {
|
|
|
|
GetWatchdog().SetEnabled(false);
|
|
|
|
}
|
2014-02-15 10:47:49 -05:00
|
|
|
void RobotInit() {
|
|
|
|
//Initializing robot
|
|
|
|
lastToggle = 0;
|
|
|
|
DashboardSetup();
|
|
|
|
servoXState = 90;
|
|
|
|
servoYState = 90;
|
|
|
|
multiplier = 1.0f;
|
2014-02-16 20:09:11 -05:00
|
|
|
downLimit = 40;
|
2014-02-27 17:10:36 -05:00
|
|
|
upLimit = 130.0;
|
2014-02-15 10:47:49 -05:00
|
|
|
compressor.Start();
|
2014-02-16 20:09:11 -05:00
|
|
|
shooting = false;
|
2014-02-15 10:47:49 -05:00
|
|
|
compressing = true;
|
2014-02-17 15:04:40 -05:00
|
|
|
toggleCollector = false;
|
2014-02-19 22:25:03 -05:00
|
|
|
throttle=0;
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
|
|
|
void DashboardSetup() {
|
|
|
|
SmartDashboard::PutNumber("Throttle", throttle);
|
2014-02-27 14:42:10 -05:00
|
|
|
SmartDashboard::PutNumber("downLimit", 35.0f);
|
|
|
|
SmartDashboard::PutNumber("upLimit", 120.0f);
|
|
|
|
SmartDashboard::PutNumber("DownSpeed", 0.1f);
|
2014-02-26 15:50:12 -05:00
|
|
|
//SmartDashboard::PutString("Auto", cmd);
|
2014-02-17 15:04:40 -05:00
|
|
|
SmartDashboard::PutNumber("collectorSpeed", 127);
|
2014-02-16 20:09:11 -05:00
|
|
|
SmartDashboard::PutNumber("armPot", potToDegrees(armPot.GetAverageVoltage()));
|
2014-02-19 22:25:03 -05:00
|
|
|
SmartDashboard::PutNumber("Log Level", 1);
|
2014-02-15 10:47:49 -05:00
|
|
|
//Ultrasonic
|
2014-02-22 18:14:01 -05: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-02-26 15:50:12 -05:00
|
|
|
SmartDashboard::PutBoolean("Use Ultrasonic",false);
|
2014-02-26 23:02:49 -05:00
|
|
|
SmartDashboard::PutBoolean("Daniel Mode",false);
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
|
|
|
void updateDashboard() {
|
|
|
|
SmartDashboard::PutNumber("Throttle", throttle);
|
|
|
|
collectorSpeed = SmartDashboard::GetNumber("collectorSpeed");
|
2014-02-16 20:09:11 -05:00
|
|
|
SmartDashboard::PutNumber("armPot", potToDegrees(armPot.GetAverageVoltage()));
|
2014-02-22 18:14:01 -05: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-02-15 10:47:49 -05:00
|
|
|
DownSpeed = SmartDashboard::GetNumber("DownSpeed");
|
2014-02-16 20:09:11 -05:00
|
|
|
downLimit = SmartDashboard::GetNumber("downLimit");
|
2014-02-27 17:10:36 -05:00
|
|
|
SmartDashboard::PutNumber("upLimit",upLimit);
|
2014-02-26 23:02:49 -05:00
|
|
|
if(downLimit < 35) {
|
2014-02-16 20:09:11 -05:00
|
|
|
downLimit = 35;
|
|
|
|
}
|
2014-02-26 23:02:49 -05:00
|
|
|
if(upLimit > 167) {
|
2014-02-16 20:09:11 -05:00
|
|
|
upLimit = 167;
|
|
|
|
}
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-02-19 22:25:03 -05:00
|
|
|
void shootRobot(float power=0, bool override=false) {
|
2014-02-26 15:50:12 -05:00
|
|
|
override=true;
|
2014-02-19 22:25:03 -05:00
|
|
|
//Needs a limit to help the driver aim
|
|
|
|
//In this case its checking that we are no more than 15 degrees off
|
|
|
|
//The override is in place in case an ultrasonic becomes damaged and we are unable to validate the distance through software
|
2014-02-22 18:14:01 -05:00
|
|
|
float averageAtan = atan((abs(voltToDistance(BallSonicLeft.GetAverageVoltage()) - voltToDistance(BallSonicRight.GetAverageVoltage())))/20.0f)*360.0f/(2.0f*3.141592653589793f);
|
2014-02-26 23:02:49 -05:00
|
|
|
if(override==true) {
|
2014-02-19 22:25:03 -05:00
|
|
|
setMotorValue(4, 1, cvt(power));
|
|
|
|
setMotorValue(5, 1, cvt(power));
|
|
|
|
setMotorValue(4, 2, cvt(-power));
|
|
|
|
setMotorValue(5, 2, cvt(-power));
|
2014-02-26 23:02:49 -05:00
|
|
|
} else if(averageAtan<=30.0f&&(voltToDistance(WallSonicLeft.GetAverageVoltage(),true))<=100&&(voltToDistance(WallSonicRight.GetAverageVoltage(),true))<=100) {
|
2014-02-19 22:25:03 -05:00
|
|
|
setMotorValue(4, 1, cvt(power));
|
|
|
|
setMotorValue(5, 1, cvt(power));
|
|
|
|
setMotorValue(4, 2, cvt(-power));
|
|
|
|
setMotorValue(5, 2, cvt(-power));
|
|
|
|
}
|
2014-02-26 23:02:49 -05:00
|
|
|
if(averageAtan>=16.0f&&(voltToDistance(WallSonicLeft.GetAverageVoltage(),true))<=100&&(voltToDistance(WallSonicRight.GetAverageVoltage(),true))) {
|
|
|
|
//printf/smartdashboard: warning
|
2014-02-19 22:25:03 -05:00
|
|
|
setMotorValue(4, 1, cvt(power));
|
|
|
|
setMotorValue(5, 1, cvt(power));
|
|
|
|
setMotorValue(4, 2, cvt(-power));
|
|
|
|
setMotorValue(5, 2, cvt(-power));
|
|
|
|
}
|
2014-02-22 18:14:01 -05:00
|
|
|
//Allow shooting regardless of the angle or distance
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-02-26 23:02:49 -05:00
|
|
|
void logMsg(std::string message, int level) {
|
|
|
|
if((int)SmartDashboard::GetNumber("Log Level") % level == 0) {
|
2014-02-22 18:14:01 -05:00
|
|
|
printf((message+"\n").c_str());
|
2014-02-17 15:04:40 -05:00
|
|
|
}
|
|
|
|
}
|
2014-02-19 22:25:03 -05:00
|
|
|
void driveRobot(float x, float y) {
|
2014-02-26 23:02:49 -05:00
|
|
|
if(y>1.0f) {
|
2014-02-19 22:25:03 -05:00
|
|
|
y=1.0f;
|
2014-02-26 23:02:49 -05:00
|
|
|
} else if(y!=0.0f&&y<-1.0f) {
|
2014-02-19 22:25:03 -05:00
|
|
|
y=-1.0f;
|
|
|
|
}
|
|
|
|
int leftPower = ((y+x)/2+1)*127+1;
|
|
|
|
int rightPower = ((y-x)/2+1)*127+1;
|
|
|
|
//logMsg("leftPower: "+toString<int>(leftPower),3);
|
|
|
|
//logMsg("rightPower: "+toString<int>(rightPower),3);
|
|
|
|
//logMsg("JoyX: "+toString<float>(Rstick.GetX()),3);
|
|
|
|
//logMsg("JoyY: "+toString<float>(Rstick.GetY()),3);
|
2014-02-17 15:04:40 -05: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-02-15 10:47:49 -05:00
|
|
|
}
|
2014-02-26 23:02:49 -05:00
|
|
|
template<typename numbertype> string toString(numbertype a) {
|
2014-02-19 22:25:03 -05:00
|
|
|
//TODO
|
|
|
|
stringstream ss;
|
|
|
|
ss<<a;
|
|
|
|
string s = ss.str();
|
|
|
|
return s;
|
|
|
|
}
|
2014-02-22 18:14:01 -05:00
|
|
|
float voltToDistance(float a,bool wall=false) {
|
2014-02-26 23:02:49 -05:00
|
|
|
if(wall) {
|
2014-02-22 18:14:01 -05:00
|
|
|
return (a / 0.00488f) / 2.54f;
|
2014-02-26 23:02:49 -05:00
|
|
|
} else {
|
2014-02-22 18:14:01 -05:00
|
|
|
return (a / 0.000976562f) / 25.4f;
|
2014-02-19 22:25:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
float potToDegrees(float a) {
|
2014-02-16 20:09:11 -05:00
|
|
|
float max = -.0003948;
|
|
|
|
float min = 5.0245547;
|
2014-02-17 15:04:40 -05:00
|
|
|
float b = a - max;
|
|
|
|
min = min - max; // ~5.0027
|
|
|
|
max = max - max; //=0
|
|
|
|
return 300 - ((b + max) * (300 / min));
|
2014-02-16 20:09:11 -05:00
|
|
|
}
|
2014-02-15 10:47:49 -05: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-02-17 15:04:40 -05:00
|
|
|
void setMotorValue(int motor, int subwayStation = 1, int value = 127) {
|
2014-02-26 23:02:49 -05:00
|
|
|
if(subwayStation == 1) {
|
|
|
|
switch(motor) {
|
|
|
|
//Drive motors
|
|
|
|
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-02-26 23:02:49 -05:00
|
|
|
} else if(subwayStation == 2) {
|
|
|
|
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:
|
|
|
|
Servo1.SetAngle(value);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
Servo2.SetAngle(value);
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
break;
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-22 18:14:01 -05:00
|
|
|
void Test() {
|
|
|
|
}
|
2014-02-15 10:47:49 -05:00
|
|
|
void Autonomous() {
|
|
|
|
myRobot.SetSafetyEnabled(false);
|
2014-02-26 15:50:12 -05:00
|
|
|
int avgDist;
|
2014-02-22 18:14:01 -05:00
|
|
|
int commandIndex=0;
|
|
|
|
int i=0;
|
|
|
|
int cur=0;
|
|
|
|
int averageAmount=5;
|
2014-02-26 15:50:12 -05:00
|
|
|
float initalDriveTime=1.4; //The amount of time in seconds that we will drive forward at the start of the match
|
|
|
|
float shooterMaxAngle=125; //The maximum angle that the arm can shoot to during all of auto
|
2014-02-27 14:42:10 -05:00
|
|
|
float shooterDelay = 2; //The amount of time in seconds between the inital drive time and the shooter firing
|
2014-02-26 15:50:12 -05:00
|
|
|
float shooterDuration = .5;//The amount of time in seconds that the shooter motors will be moving
|
2014-02-27 14:42:10 -05:00
|
|
|
shooterDelay = (shooterDelay*200); //Do math to figure out the times to start the shooting
|
2014-02-26 15:50:12 -05:00
|
|
|
float sampleCount=12;
|
2014-02-22 18:14:01 -05:00
|
|
|
float avgLeft=0;
|
|
|
|
float avgRight=0;
|
|
|
|
float curDist;
|
2014-02-26 15:50:12 -05:00
|
|
|
float thisIsATest;
|
|
|
|
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-02-26 23:02:49 -05:00
|
|
|
while(IsEnabled()&&IsAutonomous()) {
|
2014-02-27 17:10:36 -05:00
|
|
|
//Drive initial amount of time
|
|
|
|
//if(i<=initalDriveTime*200) {
|
|
|
|
setMotorValue(6, 1, 1);
|
|
|
|
if(SmartDashboard::GetBoolean("Use Ultrasonic")){
|
|
|
|
}else{
|
|
|
|
if(i<100) {
|
|
|
|
//Forward .5s
|
|
|
|
driveRobot(-1.0f,0.0f);
|
|
|
|
shootRobot(0.0f, true);
|
|
|
|
}else if(i>=100&&i<=200){//zero
|
|
|
|
driveRobot(0.0f, 0.0f);
|
|
|
|
shootRobot(0.0f, true);
|
|
|
|
} else if(i>700&&i<800&&/*120*/95.0f>=potToDegrees(armPot.GetAverageVoltage())) {
|
|
|
|
//Shoot .45 power
|
2014-02-27 12:17:40 -05:00
|
|
|
driveRobot(0.0f, 0.0f);
|
2014-02-27 14:42:10 -05:00
|
|
|
shootRobot(0.45f, true);
|
2014-02-27 17:10:36 -05:00
|
|
|
} else if(i>700&&i<800&&/*120*/95.0f<=potToDegrees(armPot.GetAverageVoltage())) {
|
|
|
|
driveRobot(0.0f, 0.0f);
|
|
|
|
shootRobot(0.0f, true);
|
|
|
|
} else if(i>800&&i<960&&40.0f<=potToDegrees(armPot.GetAverageVoltage())) {
|
|
|
|
//Lower shooter .15 power
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
shootRobot(-0.15f, true);
|
|
|
|
} else if(i>800&&i<960&&40.0f>=potToDegrees(armPot.GetAverageVoltage())) {
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
shootRobot(0.0f, true);
|
|
|
|
} else if(i>=970&&i<=980) {//zero
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
shootRobot(0.0f, true);
|
|
|
|
} else if(i>980&&i<1080) {
|
|
|
|
//Drive backward .5s
|
|
|
|
//Collect ball
|
|
|
|
driveRobot(1.0f,0.0f);
|
|
|
|
shootRobot(0.0f,true);
|
|
|
|
}else if(i>=1080&&i<=1280){//zero
|
|
|
|
//Collect ball
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
shootRobot(0.0f,true);
|
|
|
|
} else if(i>1280&&i<1380) {
|
|
|
|
//Drive forward .5s
|
|
|
|
driveRobot(-1.0f,0.0f);
|
|
|
|
shootRobot(0.0f,true);
|
|
|
|
} else if(i>=1380&&i<=1580){//zero
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
shootRobot(0.0f,true);
|
|
|
|
} else if(i>1660&&i<1760&&/*120*/95.0f>=potToDegrees(armPot.GetAverageVoltage())){
|
|
|
|
//Shoot at .45 power
|
2014-02-27 14:42:10 -05:00
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
shootRobot(0.45f,true);
|
2014-02-27 17:10:36 -05:00
|
|
|
} else if(i>1660&&i<1760&&/*120*/95.0f<=potToDegrees(armPot.GetAverageVoltage())){
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
shootRobot(0.0f,true);
|
|
|
|
} else if(i>1760&&40.0f>=potToDegrees(armPot.GetAverageVoltage())) {
|
|
|
|
//Stop robot after auto, let down shooter
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
shootRobot(-0.15f,true);
|
|
|
|
} else if(i>1760&&40.0f<=potToDegrees(armPot.GetAverageVoltage())) {
|
|
|
|
//Stop all motors
|
|
|
|
driveRobot(0.0f,0.0f);
|
|
|
|
shootRobot(0.0f,true);
|
2014-02-26 23:02:49 -05:00
|
|
|
}
|
2014-02-27 17:10:36 -05:00
|
|
|
}
|
2014-02-16 20:09:11 -05:00
|
|
|
updateDashboard();
|
2014-02-26 23:02:49 -05:00
|
|
|
if(i % 100 == 0 && compressing && compressor.GetPressureSwitchValue() == 1) {
|
2014-02-16 20:09:11 -05:00
|
|
|
compressor.Stop();
|
|
|
|
compressing = false;
|
2014-02-19 22:25:03 -05:00
|
|
|
logMsg("Stopping the compressor",2);
|
2014-02-16 20:09:11 -05:00
|
|
|
}
|
2014-02-26 23:02:49 -05:00
|
|
|
if(i % 100 == 0 && !compressing && compressor.GetPressureSwitchValue() == 0) {
|
2014-02-16 20:09:11 -05:00
|
|
|
compressor.Start();
|
2014-02-17 15:04:40 -05:00
|
|
|
compressing = true;
|
2014-02-19 22:25:03 -05:00
|
|
|
logMsg("Starting the compressor",2);
|
2014-02-16 20:09:11 -05:00
|
|
|
}
|
|
|
|
Wait(0.005f);
|
2014-02-19 22:25:03 -05:00
|
|
|
i++;
|
2014-02-22 18:14:01 -05:00
|
|
|
cur++;
|
|
|
|
}
|
2014-02-27 17:10:36 -05:00
|
|
|
i=0;
|
2014-02-17 15:04:40 -05:00
|
|
|
compressing = false;
|
2014-02-15 10:47:49 -05:00
|
|
|
compressor.Stop();
|
|
|
|
}
|
|
|
|
void OperatorControl() {
|
|
|
|
myRobot.SetSafetyEnabled(false);
|
2014-02-17 15:04:40 -05:00
|
|
|
int i = 0;
|
2014-02-22 18:14:01 -05:00
|
|
|
int cur=0;
|
|
|
|
bool swap=false;
|
2014-02-15 10:47:49 -05:00
|
|
|
collectorSole1.Set(true);
|
|
|
|
collectorSole2.Set(false);
|
2014-02-17 15:04:40 -05:00
|
|
|
compressing = false;
|
2014-02-19 22:25:03 -05:00
|
|
|
logMsg("Starting Teleop",1);
|
2014-02-26 23:02:49 -05:00
|
|
|
while(IsEnabled() && IsOperatorControl()) {
|
|
|
|
if(cur==50) {
|
2014-02-22 18:14:01 -05:00
|
|
|
cur=0;
|
|
|
|
WallLeft.Set(swap?1:0);
|
|
|
|
BallRight.Set(swap?1:0);
|
|
|
|
WallRight.Set(swap?0:1);
|
|
|
|
BallRight.Set(swap?0:1);
|
|
|
|
swap=!swap;
|
|
|
|
}
|
2014-02-19 22:25:03 -05:00
|
|
|
throttle = (-Lstick.GetRawAxis(4)+1)/2;
|
2014-02-26 23:02:49 -05:00
|
|
|
if(SmartDashboard::GetBoolean("Daniel Mode")) {
|
2014-02-26 15:50:12 -05:00
|
|
|
driveRobot(-Rstick.GetY(),Rstick.GetZ()+Rstick.GetX());
|
2014-02-26 23:02:49 -05:00
|
|
|
} else {
|
2014-02-26 15:50:12 -05:00
|
|
|
driveRobot(Rstick.GetY(),Rstick.GetZ()+Rstick.GetX());
|
|
|
|
}
|
2014-02-15 10:47:49 -05:00
|
|
|
//Log things
|
2014-02-26 23:02:49 -05:00
|
|
|
if(i % 200 == 0) {
|
2014-02-19 22:25:03 -05:00
|
|
|
//logMsg(toString(compressor.GetPressureSwitchValue()),2);
|
|
|
|
//logMsg("armPot value: "+toString(armPot.GetAverageVoltage(),11));
|
|
|
|
//logMsg("Converted armPot value: "+toString(armPot.GetAverageVoltage(),11));
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-02-26 23:02:49 -05:00
|
|
|
if(i % 100 == 0 && compressing && compressor.GetPressureSwitchValue() == 1) {
|
2014-02-15 10:47:49 -05:00
|
|
|
compressor.Stop();
|
|
|
|
compressing = false;
|
2014-02-19 22:25:03 -05:00
|
|
|
logMsg("Stopping the compressor",2);
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-02-26 23:02:49 -05:00
|
|
|
if(i % 100 == 0 && !compressing && compressor.GetPressureSwitchValue() == 0) {
|
2014-02-15 10:47:49 -05:00
|
|
|
compressor.Start();
|
2014-02-17 15:04:40 -05:00
|
|
|
compressing = true;
|
2014-02-19 22:25:03 -05:00
|
|
|
logMsg("Starting the compressor... again",2);
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
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-02-27 17:10:36 -05:00
|
|
|
updateDashboard();
|
2014-02-26 23:02:49 -05:00
|
|
|
if(Lstick.GetRawButton(1)==1&&(upLimit>=potToDegrees(armPot.GetAverageVoltage()))) {
|
2014-02-15 10:47:49 -05:00
|
|
|
//Move arm motors based on throttle
|
2014-02-26 23:02:49 -05:00
|
|
|
if(collectorExtended == false) {
|
2014-02-17 15:04:40 -05:00
|
|
|
shooting = false;
|
2014-02-19 22:25:03 -05:00
|
|
|
logMsg("Collector is NOT extended, not going to fire",17);
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-02-19 22:25:03 -05:00
|
|
|
if(collectorExtended == true) {
|
2014-02-16 20:09:11 -05:00
|
|
|
shooting = true;
|
2014-02-19 22:25:03 -05:00
|
|
|
logMsg("Firing",13);
|
|
|
|
logMsg("Collector is extended, going to fire",17);
|
|
|
|
shootRobot(throttle, false);
|
2014-02-17 15:04:40 -05:00
|
|
|
setMotorValue(6, 1, 1);
|
2014-02-16 20:09:11 -05:00
|
|
|
}
|
2014-02-19 22:25:03 -05:00
|
|
|
} else if(Lstick.GetRawButton(1)==1&&(upLimit<=potToDegrees(armPot.GetAverageVoltage()))) {
|
2014-02-16 20:09:11 -05:00
|
|
|
shooting = false;
|
2014-02-19 22:25:03 -05:00
|
|
|
logMsg("Stopping shooter motor",13);
|
|
|
|
logMsg("Stopping collector motor",17);
|
|
|
|
shootRobot(0, true);
|
2014-02-26 23:02:49 -05:00
|
|
|
} else if(Lstick.GetRawButton(2)==1) {
|
2014-02-15 10:47:49 -05:00
|
|
|
//Reverse the arm motors
|
2014-02-16 20:09:11 -05:00
|
|
|
shooting = false;
|
2014-02-26 23:02:49 -05:00
|
|
|
if(collectorExtended == false) {
|
2014-02-19 22:25:03 -05:00
|
|
|
logMsg("Collector is not extended, not going to fire",17);
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-02-26 23:02:49 -05:00
|
|
|
if(collectorExtended == true) {
|
2014-02-19 22:25:03 -05:00
|
|
|
shootRobot(-DownSpeed, false);
|
|
|
|
logMsg("Collector is extended, going to fire",17);
|
2014-02-26 23:02:49 -05:00
|
|
|
}
|
|
|
|
} else {
|
2014-02-17 15:04:40 -05:00
|
|
|
shooting = false;
|
2014-02-15 10:47:49 -05:00
|
|
|
//Stop all motors
|
2014-02-19 22:25:03 -05:00
|
|
|
shootRobot(0, true);
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-02-26 23:02:49 -05:00
|
|
|
if(Rstick.GetRawButton(9)==1) {
|
2014-02-15 10:47:49 -05:00
|
|
|
collectorExtended = true;
|
|
|
|
collectorSole1.Set(false);
|
|
|
|
collectorSole2.Set(true);
|
2014-02-26 23:02:49 -05:00
|
|
|
} else if(Rstick.GetRawButton(10)==1) {
|
2014-02-15 10:47:49 -05:00
|
|
|
collectorExtended = false;
|
|
|
|
collectorSole1.Set(true);
|
|
|
|
collectorSole2.Set(false);
|
|
|
|
}
|
2014-02-26 23:02:49 -05:00
|
|
|
if(Lstick.GetRawButton(11)==1) {
|
2014-02-17 15:04:40 -05:00
|
|
|
setMotorValue(6, 1, 1);
|
2014-02-26 23:02:49 -05:00
|
|
|
} else if(Lstick.GetRawButton(12)==1) {
|
2014-02-17 15:04:40 -05:00
|
|
|
setMotorValue(6, 1, 255);
|
2014-02-26 23:02:49 -05:00
|
|
|
} else if(!shooting) {
|
2014-02-19 22:25:03 -05:00
|
|
|
setMotorValue(6, 1, 0);
|
2014-02-15 10:47:49 -05:00
|
|
|
}
|
2014-02-22 18:14:01 -05:00
|
|
|
cur++;
|
2014-02-15 10:47:49 -05:00
|
|
|
i++;
|
|
|
|
Wait(0.005f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
START_ROBOT_CLASS(RobotDemo);
|