|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
||||
|
||||
|
Porting to Java: enums, clocks, and multi-files
I was porting some code to Java (a new ZomB interface), and have come across only a few small snags:
1. How do you do enum's? I am getting "enums are not supported in source 1.3 use src 5 to enable" and my switch statement is not working either 2. What is the equivalent of the C++ GetClock() which returns seconds since boot. Currently i am using Timer.getUsClock() / 1000000f but it is kinda bulky 3. Can you turn off the error that classes need to be in their own files? I am hoping I can have a single file for a bunch of public classes |
|
#2
|
|||
|
|||
|
Re: Porting to Java: enums, clocks, and multi-files
Quote:
|
|
#3
|
|||
|
|||
|
Re: Porting to Java: enums, clocks, and multi-files
enums:
sunspotfrcsdk/lib/WPILibJ/enum.txt: Code:
//Going to use this pattern for enumeration classes, since they are otherwise unsupported
//The typesafe enum pattern
public class Suit {
public final int value;
protected static final int CLUBS_VAL = 0;
protected static final int DIAMONDS_VAL = 1;
protected static final int HEARTS_VAL = 2;
protected static final int SPADES_VAL = 3;
public static final Suit CLUBS = new Suit(CLUBS_VAL);
public static final Suit DIAMONDS = new Suit(DIAMONDS_VAL);
public static final Suit HEARTS = new Suit(HEARTS_VAL);
public static final Suit SPADES = new Suit(SPADES_VAL);
private Suit(int value){
this.value = value;
}
}
Classes in one file: Don't. Trust me, I know where you're coming from, I was there once. You're trying to program in some other language. Wrap your mind around Java, and then, this will seem stupid. However, you may be interested to know that you can define sub-classes, which are all in the same file. |
|
#4
|
||||
|
||||
|
Re: Porting to Java: enums, clocks, and multi-files
Quote:
Ok, how would one make a jar/zip/dll/whateverstaticlibrarysarecalledinjava to house multiple classes in netbeans then? I'm going for the fewest files possible |
|
#5
|
||||||
|
||||||
|
Re: Porting to Java: enums, clocks, and multi-files
Java 1.4 and earlier does not support enums, unfortunately. See the following presentation for more things that are "missing" http://www.usfirst.org/uploadedFiles...FRCKickoff.pdf
Last edited by Joe Ross : 01-06-2010 at 15:28. |
|
#6
|
|||
|
|||
|
Re: Porting to Java: enums, clocks, and multi-files
Quote:
Once you've got you're JAR file made, to `link' your program against it (in NetBeans, anyway) right-click on your project, select properties. From that window select the ``Java Sources Classpath'' category. You should see where the WPILIBJ JAR is already added. Click ``Add JAR/Folder...'', and find your jar. |
|
#7
|
||||
|
||||
|
Re: Porting to Java: enums, clocks, and multi-files
Quote:
|
|
#8
|
||||
|
||||
|
Re: Porting to Java: enums, clocks, and multi-files
I can't seem to get the jar to compile into a robot sample with the add jar method.
Quote:
Code:
init:
No to.jar.file specified.
Using "suite\RobotTemplate_1.0.0.jar"
Deleting directory C:\Documents and Settings\*\My Documents\NetBeansProjects\RobotTemplate\build
clean:
Created dir: C:\Documents and Settings\*\My Documents\NetBeansProjects\RobotTemplate\build
Compiling 1 source file to C:\Documents and Settings\*\My Documents\NetBeansProjects\RobotTemplate\build
C:\Documents and Settings\*\My Documents\NetBeansProjects\RobotTemplate\src\edu\wpi\first\wpilibj\templates\RobotTemplate.java:11: package org.thecatattack.System451.Communication.Dashboard does not exist
import org.thecatattack.System451.Communication.Dashboard.*;
C:\Documents and Settings\*\My Documents\NetBeansProjects\RobotTemplate\src\edu\wpi\first\wpilibj\templates\RobotTemplate.java:23: cannot find symbol
symbol : class ZomBDashboard
location: class edu.wpi.first.wpilibj.templates.RobotTemplate
ZomBDashboard zomB = ZomBDashboard.getInstance(ZomBModes.TCP);
^
C:\Documents and Settings\*\My Documents\NetBeansProjects\RobotTemplate\src\edu\wpi\first\wpilibj\templates\RobotTemplate.java:23: cannot find symbol
symbol : variable ZomBModes
location: class edu.wpi.first.wpilibj.templates.RobotTemplate
ZomBDashboard zomB = ZomBDashboard.getInstance(ZomBModes.TCP);
^
C:\Documents and Settings\*\My Documents\NetBeansProjects\RobotTemplate\src\edu\wpi\first\wpilibj\templates\RobotTemplate.java:23: cannot find symbol
symbol : variable ZomBDashboard
location: class edu.wpi.first.wpilibj.templates.RobotTemplate
ZomBDashboard zomB = ZomBDashboard.getInstance(ZomBModes.TCP);
^
4 errors
C:\Documents and Settings\*\sunspotfrcsdk\ant\compile.xml:48: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 1 second)
|
|
#9
|
|||
|
|||
|
Re: Porting to Java: enums, clocks, and multi-files
Looks like the jarfile containing the ZomB classes isn't on your compilation classpath. From the looks of things, simply adding the file via NetBeans like explained above doesn't do anything to the build process (as noted by the dialog). So while the editor's validation may have passed, compilation still failed.
To be honest, I have no idea what the suggested method for adding libraries is for FRC dev. I assume it involves modifying the build file, but so much of that is included from elsewhere it'd be a pain to find the proper place. Your best/easiest bet, as far as I know, is to copy the source files you need directly into the source for your project and compile the whole thing at once. Assuming the library (ZomB in this case) is simple enough, it won't be pretty, but it should work. But... if there's a better way, I'd be happy to hear it! Edit: after looking at the ZomB guide, it looks like copying the ZomB source files is the recommended thing to do. Last edited by timothyb89 : 06-06-2010 at 07:10. |
|
#10
|
||||
|
||||
|
Re: Porting to Java: enums, clocks, and multi-files
Quote:
About your edit, I am the ZomB creator, and am making more advanced bindings that are 8 file monsters, and copying the source was the way to do it for the old 1 file bindings, although it appears it also will be what you need to do now as well. |
|
#11
|
||||
|
||||
|
Re: Porting to Java: enums, clocks, and multi-files
Quote:
For #1, use (and repeat for each enum type Code:
public static final <Insert Type Here> eVar1 = new <Insert Type Here>(ctor vars...){
<override/implement any methods here>
};
Code:
public static final int sVar1 = 1; public static final String sVar1_str = "Foo"; 3.) Everyone else has pretty much hit is spot on. |
|
#12
|
||||
|
||||
|
Re: Porting to Java: enums, clocks, and multi-files
Quote:
Code:
public boolean CanSend()
{
return (this.lasttime+(1/this.currentHz)<=GetClock()) && this.IsAnyConnected();
}
public void ResetCounter()
{
this.lasttime=GetClock();
}
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Labview and Java | chsrobotics3283 | NI LabVIEW | 3 | 13-03-2010 21:36 |
| **FIRST EMAIL**/Java and Orbit Balls *****JAVA DISCUSSION*** | Pjohn1959 | Programming | 37 | 31-08-2009 15:55 |
| Real time clocks, out of the question? | evan_wilson | Programming | 23 | 27-02-2007 09:29 |
| porting camera code to 2005 bot controller | dwc309 | Programming | 6 | 28-02-2006 19:16 |
| pic: Elgin Clocks Car at FIRST Party | dez250 | Extra Discussion | 17 | 13-07-2005 17:09 |