Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   CodeProblem (http://www.chiefdelphi.com/forums/showthread.php?t=134659)

AnnaliseDonavan 15-02-2015 20:25

CodeProblem
 
I run the code and the Driver station accepts it and allows it to run but when I press the buttons nothing happens? Pleas help ASAP


package org.usfirst.frc.team4284.robot;



import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.buttons.Button;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* 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 Robot extends IterativeRobot {
RobotDrive Drive;
Joystick drivestick;
Joystick joystick;
int autoLoopCounter;

/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {

Jaguar FL = new Jaguar (5);
Jaguar BL = new Jaguar (2);
Jaguar FR = new Jaguar (3);
Jaguar BR = new Jaguar (4);
Drive = new RobotDrive(FL,BL,FR,BR);
drivestick = new Joystick(0);
joystick = new Joystick(1);


}

/**
* This function is run once each time the robot enters autonomous mode
*/
public void autonomousInit() {
autoLoopCounter = 0;
}

/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
/*if(autoLoopCounter < 100) //Check if we've completed 100 loops (approximately 2 seconds)
{
Drive.drive(-0.5, 0.0); // drive forwards half speed
autoLoopCounter++;
} else {
Drive.drive(0.0, 0.0); // stop robot
} */
}

/**
* This function is called once each time the robot enters tele-operated mode
*/
public void teleopInit(){

}

/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
Drive.arcadeDrive(drivestick);

Button button1 = new JoystickButton(joystick, 1),
button2 = new JoystickButton(joystick, 2),
button3 = new JoystickButton(joystick, 3),
button4 = new JoystickButton(joystick, 4),
button5 = new JoystickButton(joystick, 5),
button6 = new JoystickButton(joystick, 6),
button7 = new JoystickButton(joystick, 7),
button8 = new JoystickButton(joystick, 8),
button9 = new JoystickButton(joystick, 9),
button10 = new JoystickButton(joystick, 10),
button11 = new JoystickButton(joystick , 11);


button1.whenPressed(new ElevatorOff());
button2.whenPressed(new ElevatorOn());
button3.whenPressed(new ElevatorReverse());
button4.whenPressed(new ArmsOut());
button5.whenPressed(new ArmsIn());
button6.whenPressed(new ArmsVerticalIn());
button7.whenPressed(new ArmsVarticalOut());
button8.whenPressed(new BlueLightShow());
button9.whenPressed(new LigthShowOn());
button10.whenPressed(new RedLightShow());
button11.whenPressed(new LightShowEnd());




}



/**
* This function is called periodically during test mode
*/
public void testPeriodic() {
LiveWindow.run();


}

}


package org.usfirst.frc.team4284.robot;
import edu.wpi.first.wpilibj.Talon;

import edu.wpi.first.wpilibj.command.Command;

public class ArmsIn extends Command {

@Override
protected void initialize() {
// TODO Auto-generated method stub

}

@Override
protected void execute() {
Talon LeftArm = new Talon(9);
Talon RightArm = new Talon(8);

LeftArm.set(1);
RightArm.set(-1);
try {
Thread.sleep(500); //stop for 1/2 second
} catch(InterruptedException ex) { // allows for interruption of the sleep period
Thread.currentThread().interrupt();
}

LeftArm.set(0);
RightArm.set(0);


}

@Override
protected boolean isFinished() {
// TODO Auto-generated method stub
return false;
}

@Override
protected void end() {
// TODO Auto-generated method stub

}

@Override
protected void interrupted() {
// TODO Auto-generated method stub

}

}



package org.usfirst.frc.team4284.robot;
import edu.wpi.first.wpilibj.Talon;

import edu.wpi.first.wpilibj.command.Command;

public class ArmsOut extends Command {

@Override
protected void initialize() {
// TODO Auto-generated method stub

}

@Override
protected void execute() {

Talon RightArm = new Talon(9);
Talon LeftArm = new Talon(8);

LeftArm.set(-1);
RightArm.set(1);
try {
Thread.sleep(500); //stop for 1/2 second
} catch(InterruptedException ex) { // allows for interruption of the sleep period
Thread.currentThread().interrupt();
}

LeftArm.set(0);
RightArm.set(0);
// TODO Auto-generated method stub

}

@Override
protected boolean isFinished() {
// TODO Auto-generated method stub
return false;
}

@Override
protected void end() {
// TODO Auto-generated method stub

}

@Override
protected void interrupted() {
// TODO Auto-generated method stub

}

}




package org.usfirst.frc.team4284.robot;

import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.command.Command;

public class ArmsVarticalOut extends Command {

@Override
protected void initialize() {
// TODO Auto-generated method stub

}

@Override
protected void execute() {
Talon In_Out = new Talon(7);
Talon In__Out = new Talon(0);


In_Out.set(-1);
In__Out.set(-1);
try {
Thread.sleep(500); //stop for 1/2 second
} catch(InterruptedException ex) { // allows for interruption of the sleep period
Thread.currentThread().interrupt();
}
In_Out.set(0);
In__Out.set(0);
// TODO Auto-generated method stub

}

@Override
protected boolean isFinished() {
// TODO Auto-generated method stub
return false;
}

@Override
protected void end() {
// TODO Auto-generated method stub

}

@Override
protected void interrupted() {
// TODO Auto-generated method stub

}

}



package org.usfirst.frc.team4284.robot;

import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.command.Command;

public class ArmsVerticalIn extends Command {

@Override
protected void initialize() {
// TODO Auto-generated method stub

}

@Override
protected void execute() {

Talon In_Out = new Talon (7);
Talon In__Out = new Talon(0);


In_Out.set(1);
In__Out.set(1);
try {
Thread.sleep(500); //stop for 1/2 second
} catch(InterruptedException ex) { // allows for interruption of the sleep period
Thread.currentThread().interrupt();
}
In_Out.set(0);
In__Out.set(0);

}

@Override
protected boolean isFinished() {
// TODO Auto-generated method stub
return false;
}

@Override
protected void end() {
// TODO Auto-generated method stub

}

@Override
protected void interrupted() {
// TODO Auto-generated method stub

}

}



package org.usfirst.frc.team4284.robot;

import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.command.Command;

public class BlueLightShow extends Command {

@Override
protected void initialize() {
// TODO Auto-generated method stub

}

@Override
protected void execute() {
// TODO Auto-generated method stub
Relay relay1 = new Relay(0);
Relay relay2 = new Relay(1);
relay1.set(Relay.Value.kOn);
relay2.set(Relay.Value.kOff);

}

@Override
protected boolean isFinished() {
// TODO Auto-generated method stub
return false;
}

@Override
protected void end() {
// TODO Auto-generated method stub

}

@Override
protected void interrupted() {
// TODO Auto-generated method stub

}

}

package org.usfirst.frc.team4284.robot;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.command.Command;

public class ElevatorOff extends Command {

@Override
protected void initialize() {
// TODO Auto-generated method stub

}

@Override
protected void execute() {
// TODO Auto-generated method stub
Jaguar Elevator1 = new Jaguar(5);
Jaguar Elevator2 = new Jaguar(0);


Elevator1.set(0);
Elevator2.set(0);

}

@Override
protected boolean isFinished() {
// TODO Auto-generated method stub
return false;
}

@Override
protected void end() {
// TODO Auto-generated method stub

}

@Override
protected void interrupted() {
// TODO Auto-generated method stub

}

}


package org.usfirst.frc.team4284.robot;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.command.Command;

public class ElevatorOn extends Command {

@Override
protected void initialize() {
// TODO Auto-generated method stub

}

@Override
protected void execute() {
// TODO Auto-generated method stub
Jaguar Elevator1 = new Jaguar(5);
Jaguar Elevator2 = new Jaguar(0);

Elevator1.set(.25);
Elevator2.set(.25);


}

@Override
protected boolean isFinished() {
return false;
}

@Override
protected void end() {


}

@Override
protected void interrupted() {

}

}


package org.usfirst.frc.team4284.robot;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.command.Command;

public class ElevatorReverse extends Command {

@Override
protected void initialize() {
// TODO Auto-generated method stub

}

@Override
protected void execute() {
// TODO Auto-generated method stub
Jaguar Elevator1 = new Jaguar(5);
Jaguar Elevator2 = new Jaguar(0);

Elevator1.set(-.25);
Elevator2.set(-.25);


}

@Override
protected boolean isFinished() {
// TODO Auto-generated method stub
return false;
}

@Override
protected void end() {
// TODO Auto-generated method stub

}

@Override
protected void interrupted() {
// TODO Auto-generated method stub

}

}


package org.usfirst.frc.team4284.robot;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.command.Command;

public class LightShowEnd extends Command {

@Override
protected void initialize() {
// TODO Auto-generated method stub

}

@Override
protected void execute() {
// TODO Auto-generated method stub
Relay relay1 = new Relay(0);
Relay relay2 = new Relay(1);
relay1.set(Relay.Value.kOff);
relay2.set(Relay.Value.kOff);


}

@Override
protected boolean isFinished() {
// TODO Auto-generated method stub
return false;
}

@Override
protected void end() {
// TODO Auto-generated method stub

}

@Override
protected void interrupted() {
// TODO Auto-generated method stub

}

}

package org.usfirst.frc.team4284.robot;

import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.command.Command;

public class LigthShowOn extends Command {

@Override
protected void initialize() {
// TODO Auto-generated method stub

}

@Override
protected void execute() {
// TODO Auto-generated method stub

Relay relay1 = new Relay(0);
Relay relay2 = new Relay(1);

relay1.set(Relay.Value.kReverse);
relay2.set(Relay.Value.kOn);
try {
Thread.sleep(5000); //stop for 1/2 second
} catch(InterruptedException ex) { // allows for interruption of the sleep period
Thread.currentThread().interrupt();
}
//Turn on lights Blue and Green)
relay1.set(Relay.Value.kOn);
relay2.set(Relay.Value.kReverse);
try {
Thread.sleep(5000); //stop for 1/2 second
} catch(InterruptedException ex) { // allows for interruption of the sleep period
Thread.currentThread().interrupt();
}
// Turns on blue and red lights
relay1.set(Relay.Value.kOn);
relay2.set(Relay.Value.kForward);
try {
Thread.sleep(5000); //stop for 1/2 second
} catch(InterruptedException ex) { // allows for interruption of the sleep period
Thread.currentThread().interrupt();
}
relay1.set(Relay.Value.kReverse);
relay2.set(Relay.Value.kOn);


}

@Override
protected boolean isFinished() {
// TODO Auto-generated method stub
return false;
}

@Override
protected void end() {
// TODO Auto-generated method stub

}

@Override
protected void interrupted() {
// TODO Auto-generated method stub

}

}


package org.usfirst.frc.team4284.robot;
import edu.wpi.first.wpilibj.Relay;

import edu.wpi.first.wpilibj.command.Command;

public class RedLightShow extends Command {

@Override
protected void initialize() {
// TODO Auto-generated method stub

}

@Override
protected void execute() {
// TODO Auto-generated method stub
Relay relay1 = new Relay(0);
Relay relay2 = new Relay(1);
relay2.set(Relay.Value.kForward);
relay1.set(Relay.Value.kReverse);

}

@Override
protected boolean isFinished() {
// TODO Auto-generated method stub
return false;
}

@Override
protected void end() {
// TODO Auto-generated method stub

}

@Override
protected void interrupted() {
// TODO Auto-generated method stub

}

}



Please and thank you

legts 15-02-2015 21:37

Re: CodeProblem
 
Quote:

Originally Posted by AnnaliseDonavan (Post 1444694)
Button button1 = new JoystickButton(joystick, 1),
button2 = new JoystickButton(joystick, 2),
button3 = new JoystickButton(joystick, 3),
button4 = new JoystickButton(joystick, 4),
button5 = new JoystickButton(joystick, 5),
button6 = new JoystickButton(joystick, 6),
button7 = new JoystickButton(joystick, 7),
button8 = new JoystickButton(joystick, 8),
button9 = new JoystickButton(joystick, 9),
button10 = new JoystickButton(joystick, 10),
button11 = new JoystickButton(joystick , 11);

I think I know what your problem is. If, and if being the key word, button1 works, then my theory is correct. When declaring buttons, you need to have then declared exactly as button1 is declared. Namely, having "Button" before the button name. Hope I helped!

Cyan 15-02-2015 21:43

Re: CodeProblem
 
Quote:

Originally Posted by legts (Post 1444726)
I think I know what your problem is. If, and if being the key word, button1 works, then my theory is correct. When declaring buttons, you need to have then declared exactly as button1 is declared. Namely, having "Button" before the button name. Hope I helped!

I don't believe this is the problem. Notice there are commas instead of semicolons at the end of each line; this should be the correct syntax.


As for AnnaliseDonavan, could you be more specific in your question? Also, which IDE do you use? Your code is relatively messy, so if you could show me one instance where your code does not work, you could troubleshoot through that pathway and follow example with the rest of the buttons.

legts 15-02-2015 21:45

Re: CodeProblem
 
Quote:

Originally Posted by Cyan (Post 1444735)
I don't believe this is the problem. Notice there are commas instead of semicolons at the end of each line; this should be the correct syntax.

I did not notice that before, thanks for pointing that out!

AnnaliseDonavan 15-02-2015 23:09

Re: CodeProblem
 
As for the needing of semi colons for this set up when I place semi colons it produces an error and when I looked up the correct way to do the button control this is what I found.

And I apologist I am new to coding but no one on my team knows how to code so we are lost. For the one instance currently all I have in the implementing stage is the buttons so that is all the is and it dose not work.

Cyan 16-02-2015 00:08

Re: CodeProblem
 
Try moving this code:
Code:

Button button1 = new JoystickButton(joystick, 1),
button2 = new JoystickButton(joystick, 2),
button3 = new JoystickButton(joystick, 3),
button4 = new JoystickButton(joystick, 4),
button5 = new JoystickButton(joystick, 5),
button6 = new JoystickButton(joystick, 6),
button7 = new JoystickButton(joystick, 7),
button8 = new JoystickButton(joystick, 8),
button9 = new JoystickButton(joystick, 9),
button10 = new JoystickButton(joystick, 10),
button11 = new JoystickButton(joystick , 11);

from Robot.teleopPeriodic() to Robot.robotInit(), and see if that leads to anything.

Oblarg 16-02-2015 00:12

Re: CodeProblem
 
I don't see any Scheduler.run() call in your teleop periodic code. Without that, there is nothing to call the commands that you have assigned to buttons.

om_nom_nom 16-02-2015 00:12

Re: CodeProblem
 
This may not solve much, but I suggest moving your button code into teleopInit(), otherwise you are creating buttons in a loop during teleop.

Also, have you tested your commands without the buttons? The issue may be that your commands are not working, not the buttons. To do this in Java, you can add
Code:

SmartDashboard.putData(new Command());
into your robotInit(). Then open up SmartDashboard from the driver station or a double-clicking on the program. You should see a button on the Dashboard after you compile that code. Click it to run, and click it again to cancel.

GeeTwo 16-02-2015 00:39

Re: CodeProblem
 
Quote:

Originally Posted by legts (Post 1444737)
I did not notice that before, thanks for pointing that out!

This is one of the important reasons to follow programming style conventions - that is, make your code look like programmers expect. In this case, the usual convention for objects is that the commas are only used if they are not being set. It's also common to keep columns aligned as you go down parallel code; this is why code is traditionally displayed in a fixed-width font. The usual style conventions would look like:
Code:

Button button1  = new JoystickButton(joystick,  1);
Button button2  = new JoystickButton(joystick,  2);
Button button3  = new JoystickButton(joystick,  3);
Button button4  = new JoystickButton(joystick,  4);
Button button5  = new JoystickButton(joystick,  5);
Button button6  = new JoystickButton(joystick,  6);
Button button7  = new JoystickButton(joystick,  7);
Button button8  = new JoystickButton(joystick,  8);
Button button9  = new JoystickButton(joystick,  9);
Button button10 = new JoystickButton(joystick, 10);
Button button11 = new JoystickButton(joystick, 11);

Following programming style conventions is nearly as important as following wiring color code conventions, and for exactly the same reason -- so that the guy (or gal) who comes behind you can easily figure out what you did. So far, it's not the law, or even in the FRC rules, but maybe it should be. Or maybe not -- do we really want code inspectors?

one_each 16-02-2015 10:22

Re: CodeProblem
 
Quote:

Originally Posted by Oblarg (Post 1444831)
I don't see any Scheduler.run() call in your teleop periodic code. Without that, there is nothing to call the commands that you have assigned to buttons.

This is the most likely cause of the problem. I would create a second project just to see what the default code does.

In the teleopPeriodic() method, you are creating Button objects then calling the whenPressed() methods. Next, the teleopPeriodic() ends and those objects go away (Garbage Collected). While this might work (I have not tested) if you add the Scheduler.run() call, it is a waste of time and effort for the roboRio.

Instead, I would recommend making the Button objects as member fields (just move the Button button1 ... ; statement outside of all methods) and moving the whenPressed() method calls to teleopInit(). Don't forget to add back the call to Scheduler.run()!

AnnaliseDonavan 17-02-2015 14:02

Re: CodeProblem
 
Okay so I tried moving the
Scheduler.run()
Button button1 = new JoystickButton(joystick, 1),
button2 = new JoystickButton(joystick, 2),
button3 = new JoystickButton(joystick, 3),
button4 = new JoystickButton(joystick, 4),
button5 = new JoystickButton(joystick, 5),
button6 = new JoystickButton(joystick, 6),
button7 = new JoystickButton(joystick, 7),
button8 = new JoystickButton(joystick, 8),
button9 = new JoystickButton(joystick, 9),
button10 = new JoystickButton(joystick, 10),
button11 = new JoystickButton(joystick , 11);
code to both outside of the whole code and the robot int and the program fails to recognize that

button1.whenPressed(new ElevatorOff());
button2.whenPressed(new ElevatorOn());
button3.whenPressed(new ElevatorReverse());
button4.whenPressed(new ArmsOut());
button5.whenPressed(new ArmsIn());
button6.whenPressed(new ArmsVerticalIn());
button7.whenPressed(new ArmsVarticalOut());
button8.whenPressed(new BlueLightShow());
button9.whenPressed(new LigthShowOn());
button10.whenPressed(new RedLightShow());
button11.whenPressed(new LightShowEnd());

is connected it comes up with a syntax error that the button1 - button11 is not defined.

legts 17-02-2015 15:35

Re: CodeProblem
 
If any of your commands require parameters then that could be why nothing is happening. As for declaring the buttons, that should be in the constructor of your OI file.

AnnaliseDonavan 17-02-2015 17:56

Re: CodeProblem
 
The Template I am using dose not have a OI section is there another way around it?

legts 17-02-2015 17:58

Re: CodeProblem
 
I don't know if it's possible to create one. You could try creating a new robot template to see if it has an OI and try to make one based off of that....

Oblarg 18-02-2015 01:34

Re: CodeProblem
 
Quote:

Originally Posted by legts (Post 1445848)
As for declaring the buttons, that should be in the constructor of your OI file.

You don't have to do it there, though. As long as they are declared somewhere before you enter your teleop periodic loop, it will work.


All times are GMT -5. The time now is 02:15.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi