cRIOs are fairly expensive and we don’t get new ones each year, so in order to continue demo-ing our old robots, we want to try to compile code into a JAR and run the program output through an Arduino or something instead. In particular, we want a standalone implementation of the CAN protocol so that we can at least run motors.
Since the cRIO doesn’t do any of the work of compiling, it seems like it should be possible to extract the relevant source files from the SunSPOT FRC SDK and put them in a new vanilla Java project. However, nearly all the files from edu.wpi.blahblahblah end up importing from com.sun.blahblahblah and all the packages under com.sun are missing in sunspotfrcsdk/lib/wpilibj/src and their corresponding .class files are missing from sunspotfrcsdk/lib/wpilibj/build, so I can’t even decompile them to get the actual source. (But everything does show up in javadoc.)
If I create a Simple Robot project using the Netbeans module, then I can import these missing classes, but if I navigate to source, Netbeans auto-generates the missing code instead since no source can be found. However, many of the the generated files are incomplete or incorrect, so they don’t help. Adding the JAR files from the modules directory to classpath also does not help.
Has anyone tried messing with this, and if so, can they tell me where I can find the missing files or if there is a better solution?
The problem is that the WPILibJ libraries are tied to the cRIO hardware. For every cRIO hardware call, you would need to replace it with a call to the equivalent feature in your new platform. For example, in the PWM class, rather then calling the FPGA function to generate a PWM signal, you’d need to replace it with the generate PWM command on the Arduino. When you’ve done this will all the source, I expect that there won’t be any calls left to com.sun., as well as edu.wpi.first.wpilibj.fpga.. In addition, the communication protocol is handled by a compiled library which edu.wpi.first.wpilibj.communication.* references. You’d need to re-implement all of that also, based on reverse engineering the communication protocol. There are probably other things you need to do as well.
The Jaguar CAN protocol specs are included in the Jaguar SDK. You will need to program the jaguars to the stock firmware, rather then the FRC firmware. This is because the FRC firmware runs in a “trusted” mode for which the protocol is not released.
@joelg236: Those are the same files I have in the SDK. I just noticed that if you look at what they import, many of them end up importing from a class/classes in com.sun that do not appear in the SDK and are not included by default. I was just wondering where the sources for those were located. (Presumably, they’re located in one of the compiled libraries.)
@Joe: Yeah, we discovered that FIRST hides the communication protocol. We’re considering reverse engineering it as an alternative to what I’m trying to do right now.
I discovered that instead of trying to reconstruct the relevant classes, there is a suite directory containing a JAR that I could add to classpath. That library contains the same files that Joel and I have, but everything is functional.
To clarify what we’re trying to do with the Arduino: We’re not running anything on the Arduino itself. The idea was that we could possibly replace the cRIO with a combination of a laptop running the code and an Arduino on the robot passing the output to the relevant devices.
Current status: After adding the suite JAR file to the classpath of a vanilla Java project, I can import the CANJaguar class, create a CANJaguar variable, initialize it, and set its speed without any compiler errors. I’m just having trouble instantiating it at runtime, since I’m trying to communicate over USB-to-Serial, and that requires something in addition to the usual
CANJaguar jaguar = new CANJaguar(2);