Hello,
In the off season our team has been experimenting with Java, and i recently rewrote our Java code to function more efficiently. Unfortunately, With this new code, absolutely nothing works. The Robot does not drive and nothing runs. If i run the old code, then everything works, so it is a software issue. Also, i do not know why but i keep getting a robot drive not running fast enough error with the new code. Here is both the old and new code:
NEW CODE:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Timer;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the SimpleRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the manifest file in the resource
* directory.
*/
public class RobotTemplate extends SimpleRobot {
/**
* This function is called once each time the robot enters autonomous mode.
*/
//Declare drive base, jaguars and compressor
RobotDrive myBase = new RobotDrive(1, 2);
Joystick joystick = new Joystick(1);
Jaguar shootingFront = new Jaguar(3);
Jaguar shootingBack = new Jaguar(4);
Jaguar push = new Jaguar(6);
Jaguar roll = new Jaguar(5);
Compressor compressor = new Compressor(1,1);
Solenoid solenoidPistonOut = new Solenoid(1);
Solenoid solenoidPistonIn = new Solenoid(2);
DigitalInput topMicro = new DigitalInput(1);
DigitalInput bottomMicro = new DigitalInput(2);
double shooterMotorFront = 0;
double shooterMotorBack = 0;
double pushMotor = 0;
double rollMotor = 0;
double xStick = 0;
double yStick = 0;
boolean pistonOut = false;
boolean pistonIn = false;
public void runMotor() {
shootingFront.set(shooterMotorFront);
shootingBack.set(shooterMotorBack);
push.set(pushMotor);
roll.set(rollMotor);
solenoidPistonIn.set(pistonIn);
solenoidPistonOut.set(pistonOut);
}
public void autonomous() {
int state = 1;
int c = 0;
switch(state) {
case 1:
shooterMotorFront = 0.8;
shooterMotorBack = 0.8;
Timer.delay(3);
state = 2;
break;
case 2:
pistonIn = false;
pistonOut = true;
Timer.delay(1);
state = 3;
break;
case 3:
pistonOut = false;
pistonIn = true;
Timer.delay(1);
state = 4;
break;
case 4:
if (c == 1) {
while(topMicro.get() == true) {
rollMotor = 0.4;
}
state = 2;
}
else if(c == 2) {
while(bottomMicro.get() == true) {
rollMotor = 0.4;
}
state = 2;
}
else if (c == 3) {
state = 5;
}
break;
case 5:
shooterMotorFront = 0;
shooterMotorBack = 0;
state = 0;
break;
}
}
/**
* This function is called once each time the robot enters operator control.
*/
public void operatorControl() {
myBase.setSafetyEnabled(true);
int state = 0;
int c = 0;
double zStick;
double map_zStick;
compressor.start();
while (isOperatorControl() && isEnabled()) {
if (joystick.getRawButton(6) == true) {
state = 0;
}
if (joystick.getRawButton(3)) {
state = 8;
}
myBase.arcadeDrive(0.5, 0.5);
switch(state) {
case 0:
//Get Throttle and map it to a value from 0 to 1
zStick = joystick.getAxis(Joystick.AxisType.kZ);
map_zStick = (zStick+1)/2;
//Get x-Axis and map it based on throttle
xStick = joystick.getAxis(Joystick.AxisType.kX);
xStick = xStick * map_zStick * (-1);
//Get y-Axis and map it based on throttle
yStick = joystick.getAxis(Joystick.AxisType.kY);
yStick = yStick * map_zStick * (-1);
if (joystick.getRawButton(2) == true) {
state = 1;
}
break;
case 1:
int i =0;
while(i<3) {
rollMotor = 0.4;
if (topMicro.get() == true) {
i++;
}
}
state = 2;
break;
case 2:
//Get Throttle and map it to a value from 0 to 1
zStick = joystick.getAxis(Joystick.AxisType.kZ);
map_zStick = (zStick+1)/2;
//Get x-Axis and map it based on throttle
xStick = joystick.getAxis(Joystick.AxisType.kX);
xStick = xStick * map_zStick * (-1);
//Get y-Axis and map it based on throttle
yStick = joystick.getAxis(Joystick.AxisType.kY);
yStick = yStick * map_zStick * (-1);
myBase.arcadeDrive(yStick, xStick);
if (joystick.getRawButton(2) == true) {
state = 3;
}
break;
case 3:
shooterMotorFront = 0.8;
shooterMotorBack = 0.8;
Timer.delay(3);
state = 4;
break;
case 4:
pistonIn = false;
pistonOut = true;
Timer.delay(1);
state = 5;
break;
case 5:
pistonOut = false;
pistonIn = true;
Timer.delay(1);
state = 6;
break;
case 6:
if (c == 1) {
while(topMicro.get() == true) {
rollMotor = 0.4;
}
state = 4;
}
else if(c == 2) {
while(bottomMicro.get() == true) {
rollMotor = 0.4;
}
state = 4;
}
else if (c == 3) {
state = 7;
}
break;
case 7:
shooterMotorFront = 0;
shooterMotorBack = 0;
state = 0;
break;
case 8:
long end = System.currentTimeMillis() + 10000;
while(System.currentTimeMillis() < end) {
yStick = 0.6;
}
state = 9;
break;
case 9:
if (joystick.getRawButton(11) == true) {
state = 0;
}
break;
}
Timer.delay(0.01);
runMotor();
}
compressor.stop();
}
/**
* This function is called once each time the robot enters test mode.
*/
public void test() {
}
}
OLD CODE:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Timer;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the SimpleRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the manifest file in the resource
* directory.
*/
public class RobotTemplate extends SimpleRobot {
/**
* This function is called once each time the robot enters autonomous mode.
*/
//Declare drive base, jaguars and compressor
RobotDrive myBase = new RobotDrive(1, 2);
Joystick joystick = new Joystick(1);
Jaguar shootingFront = new Jaguar(3);
Jaguar shootingBack = new Jaguar(4);
Jaguar push = new Jaguar(6);
Jaguar roll = new Jaguar(5);
Compressor compressor = new Compressor(1,1);
Solenoid solenoidPistonOut = new Solenoid(1);
Solenoid solenoidPistonIn = new Solenoid(2);
double shooterMotorFront;
double shooterMotorBack;
double pushMotor;
double rollMotor;
boolean pistonOut = false;
boolean pistonIn = false;
public void runMotor() {
shootingFront.set(shooterMotorFront);
shootingBack.set(shooterMotorBack);
push.set(pushMotor);
roll.set(rollMotor);
solenoidPistonIn.set(pistonIn);
solenoidPistonOut.set(pistonOut);
}
public void autonomous() {
}
/**
* This function is called once each time the robot enters operator control.
*/
public void operatorControl() {
myBase.setSafetyEnabled(true);
boolean kTriggerButton=false;
boolean kTopButton=false;
boolean button3=false;
compressor.start();
while (isOperatorControl() && isEnabled()) {
//Get Throttle and map it to a value from 0 to 1
double zStick = joystick.getAxis(Joystick.AxisType.kZ);
double map_zStick = (zStick+1)/2;
//Get x-Axis and map it based on throttle
double xStick = joystick.getAxis(Joystick.AxisType.kX);
xStick = xStick * map_zStick * (-1);
//Get y-Axis and map it based on throttle
double yStick = joystick.getAxis(Joystick.AxisType.kY);
yStick = yStick * map_zStick * (-1);
//Set Robot Drive to mapped Joystick Values
myBase.arcadeDrive(yStick, xStick);
//Check Trigger and set Shooting Motors accordingly
if(joystick.getButton(Joystick.ButtonType.kTrigger)==true && kTriggerButton==false) {
shooterMotorFront = -0.8;
shooterMotorBack = -0.8;
kTriggerButton=true;
}
else if(joystick.getButton(Joystick.ButtonType.kTrigger)==false && kTriggerButton==true) {
shooterMotorFront = 0;
shooterMotorBack = 0;
kTriggerButton=false;
}
//Check button 2 and set pushing motor accordingly
if(joystick.getButton(Joystick.ButtonType.kTop)==true && kTopButton==false) {
pushMotor = 0.8;
kTopButton=true;
}
else if(joystick.getButton(Joystick.ButtonType.kTop)==false && kTopButton==true) {
pushMotor = 0;
kTopButton=false;
}
//Check Buton 3 an set top wheel accordingly
if(joystick.getRawButton(3)==true && button3==false) {
rollMotor = 0.4;
button3=true;
}
else if(joystick.getRawButton(3)==false && button3==true) {
rollMotor = 0;
button3=false;
}
if (joystick.getRawButton(4)) {
pistonOut = true;
}
else if (joystick.getRawButton(5)) {
pistonIn = true;
}
else {
pistonOut = false;
pistonIn = false;
}
Timer.delay(0.01);
runMotor();
}
compressor.stop();
}
/**
* This function is called once each time the robot enters test mode.
*/
public void test() {
}
}
Any help would be greatly appreciated!
Sasha
Team Melbourne
FRC #4529