Go to Post Each poster can bring respect to the topic, whether agreeing with it or not. - JaneYoung [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-01-2012, 09:15 PM
Thundrio Thundrio is offline
Dedicated Racer
FRC #3673
 
Join Date: Feb 2011
Rookie Year: 2010
Location: The Internet
Posts: 67
Thundrio is on a distinguished road
A few syntax type questions

As I am going through the state of my teams code, I have a few questions I wanted to ask.

Also I am using iterativeRobot()

1) When I send a line to the driverstation using driverStationLCD(probably not the right syntax, but you know what I want), It displays the text, but does not update the values ever if they are changed in teleop(). I tried putting myLCD.updateLCD() at the bottom of my teleopPeriodic() function, but when I do netbeans says the myLCD variable is not created, even though I create it earlier where the output lines to the ds are. also to be clear, I have verified that the values are actually changing by using the Netconsole+System.out.println().

2) We are able to use the Microsoft Kinect to control the robot, and while we don't know if it will be used during competition, it will be a great way to demonstrate the robot. What I have done is split the teleoperated section of the code into two sections using an if statement like this:
if (isKinect == 1) {
// kinect enabled version of the code goes here
}
else
{
//normal code goes here
}
Right now all of my code is in 1 class file, although I would like to split it up into multiple files, to make it easier to read. it would then theoretically look like this:
if (isKinect == 1) {
run kinectcode.java;
}
else{
run normalcode.java;
}
However I have never worked with multiple files together, and so I am not sure how to do this.

3)right now I have shAUTOFIRE (one of my buttons) written using the .get() function (I believe it's a function), but I only want it run once, not for as long as it's held down.

I know that I could do this using a keyboard:
public void keyPressed(KeyEvent e) {
keyCode = e.getKeyCode();
swith (keyCode) {
case KeyEvent.VK_SPACEBAR:
//do autofire stuff
break;
}

however, I am at a loss as to what to do with the buttons. I looked at the API documentation and found the whenPressed() method, which seems like It should be similar as to what I do with the keyboard, but I don't know what to do.


Thank you for any and all help.
__________________
Interested in a new way of playing old games?
visit http://www.speedrunslive.com for a way to make single player games multiplayer!
visit http://www.zeldaspeedruns.com to open up a new world for zelda lovers!
pm me here or at zsr for more information!
Reply With Quote
  #2   Spotlight this post!  
Unread 02-01-2012, 09:48 PM
nickpeq nickpeq is offline
Turing-complete
FRC #1255 (Blarglefish)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Baytown, TX
Posts: 60
nickpeq is an unknown quantity at this point
Re: A few syntax type questions

Quote:
Originally Posted by Thundrio View Post
As I am going through the state of my teams code, I have a few questions I wanted to ask.

Also I am using iterativeRobot()

1) When I send a line to the driverstation using driverStationLCD(probably not the right syntax, but you know what I want), It displays the text, but does not update the values ever if they are changed in teleop(). I tried putting myLCD.updateLCD() at the bottom of my teleopPeriodic() function, but when I do netbeans says the myLCD variable is not created, even though I create it earlier where the output lines to the ds are. also to be clear, I have verified that the values are actually changing by using the Netconsole+System.out.println().

2) We are able to use the Microsoft Kinect to control the robot, and while we don't know if it will be used during competition, it will be a great way to demonstrate the robot. What I have done is split the teleoperated section of the code into two sections using an if statement like this:
if (isKinect == 1) {
// kinect enabled version of the code goes here
}
else
{
//normal code goes here
}
Right now all of my code is in 1 class file, although I would like to split it up into multiple files, to make it easier to read. it would then theoretically look like this:
if (isKinect == 1) {
run kinectcode.java;
}
else{
run normalcode.java;
}
However I have never worked with multiple files together, and so I am not sure how to do this.

3)right now I have shAUTOFIRE (one of my buttons) written using the .get() function (I believe it's a function), but I only want it run once, not for as long as it's held down.

I know that I could do this using a keyboard:
public void keyPressed(KeyEvent e) {
keyCode = e.getKeyCode();
swith (keyCode) {
case KeyEvent.VK_SPACEBAR:
//do autofire stuff
break;
}

however, I am at a loss as to what to do with the buttons. I looked at the API documentation and found the whenPressed() method, which seems like It should be similar as to what I do with the keyboard, but I don't know what to do.


Thank you for any and all help.
1) I would probably have to see the involved code. You might simply have a scope issue.

2) Java doesn't work quite that way. You can create seperate files for separate classes, and call methods from those classes, but you don't "run" any files except the main one. I would probably either make a new project for the Kinect-enabled version, or leave the code as it is on one java file. If it makes things more managable, move the kinect code into its own method elsewhere in the .java

3) If you mean you want something to run only once per button-press, do something this:

Code:
pressed = controller.getRawButton(buttonID);
if(pressed && !alreadyPressed)
     doStuffHere()
alreadyPressed = pressed;
Of course, you should initialize alreadyPressed in robotInit() and make pressed and alreadyPressed global variables.

Last edited by nickpeq : 02-01-2012 at 09:54 PM.
Reply With Quote
  #3   Spotlight this post!  
Unread 02-02-2012, 12:37 AM
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: A few syntax type questions

Quote:
Originally Posted by nickpeq View Post
1) I would probably have to see the involved code. You might simply have a scope issue.

2) Java doesn't work quite that way. You can create seperate files for separate classes, and call methods from those classes, but you don't "run" any files except the main one. I would probably either make a new project for the Kinect-enabled version, or leave the code as it is on one java file. If it makes things more managable, move the kinect code into its own method elsewhere in the .java

3) If you mean you want something to run only once per button-press, do something this:

Code:
pressed = controller.getRawButton(buttonID);
if(pressed && !alreadyPressed)
     doStuffHere()
alreadyPressed = pressed;
Of course, you should initialize alreadyPressed in robotInit() and make pressed and alreadyPressed global variables.
Also, if you want this to be used more than once, I suggest adding a timer to have a "buffer zone" between clicks. Since the crio is running fast, you probably will trigger it more than once and end up with the same state you started with (yes, I've run into this problem). Just check if the time since the last click has exceeded before changing the pressed state.
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 08:55 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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