Quote:
Originally Posted by curtis0gj
I have setup the limit switch program with the suggestions but I am attempting to setup reverse for the victors. Also I am trying to setup the same if statement layout for my relays does this look okay?
Code:
public class Robot extends SampleRobot {
RobotDrive robot;
Joystick stick;
Joystick xbox;
Relay spike1;
Relay spike2;
Victor victor1;
Victor victor2;
DigitalInput limit;
boolean limitPressed = false;
public Robot() {
robot = new RobotDrive(0, 1);
stick = new Joystick(1);
xbox = new Joystick(0);
spike1 = new Relay(0);
spike2 = new Relay(1);
limit = new DigitalInput(4);
victor1 = new Victor(4);
victor2 = new Victor(5);
}
public void operatorControl() {
while (isOperatorControl() && isEnabled()) {
stick.getThrottle();
robot.arcadeDrive(stick.getY(), stick.getX());
limitPressed = limit.get(); //Do I want this out side of my while operator control loop?
System.out.println("limitPressed=" + limitPressed); //Read the RoboRIO log for some values before you go all out on your motors.
if(limitPressed) {
victor1.set(0);
victor2.set(0);
} else if (xbox.getRawButton(4)) {
victor1.set(1);
victor2.set(1);
} else {
victor1.set(0);
victor1.set(0);
}
if(xbox.getRawButton(1)) {
victor1.set(-1);
victor1.set(-1);
} else {
victor1.set(0);
victor2.set(0);
}
if(xbox.getRawButton(3)) {
spike1.set(Relay.Value.kForward);
spike2.set(Relay.Value.kForward);
} else {
spike1.set(Relay.Value.kOff);
spike2.set(Relay.Value.kOff);
}
if(xbox.getRawButton(2)) {
spike1.set(Relay.Value.kReverse);
spike2.set(Relay.Value.kReverse);
} else {
spike1.set(Relay.Value.kOff);
spike2.set(Relay.Value.kOff);
}
}
}
|
The relays look good. In addition to double victor1's which have already been pointed out, consider the effect of pushing buttons 1 and 4 at the same time - you'll oscillate between full speed forward and full speed reverse. It's probably not a big deal, as your driver shouldn't be pushing them both at the same time anyways, but I personally like to prevent that sort of situation. Using some fairly simple logic, you can reduce everything dealing with the victors to a single if/else-if/else block. Something like:
Code:
if ()//the conditions you want it to go up
{
//go up
}
else if ()//the conditions you want it to go down
{
//go down
}
else
{
//stop
}
You can set up the conditionals using the AND (&&) operator, the OR (||) operator, and the not (!). For example, to say "when button 4 is pressed and the limit switch is not pressed", you would do "xbox.getRawButton(4) || !limitPressed". Figuring out how to use logic like this is a very powerful tool while programming!