Programming with Java?

Hi,

Our computer science department teaches Java to students. We’re trying to integrate some robotics with the Object-oriented curriculum.

I’m curious to know if there is any way to have the students play with Microchip’s microcontrollers and Java language, in order to program the robot…?

What are the limitations?

Hmmm, interesting idea. I do quite a lot of Java programming as part of my phd project. The problem is you have to end up with a hex file that Microchip can understand. You definitely couldn’t load up a java program directly, since it is interpreted. Just not something the RC can do. C++ might work, but probably not. I will look into it, but I just don’t think there is an easy way to do it.

Try looking at this site:
https://jvex-robotics.dev.java.net/VEXController.html

I believe the Vex controller and the FRC PIC are the same. Perhaps for project programming purposes the Vex would be the way to go. Anyone have any experience with this?

EDIT:
Actually the JCX is the part you should look at. I think the idea is if you want to use a Microchip controller, bet it Vex or FRC and you want to use Java, then you need to have a seperate processor to program Java to, and that feeds back to the microchip controller.

http://www.jcx.systronix.com/

You have to keep in mind the nature of the user processor that is given to us - it is a PIC18F8722, which is 10MHz and has about 3900 bytes of static RAM. Java is one of the most bloated of all languages, especially in its implementations. You need very large class libraries for Java to run on any platform, and that just can’t happen with the amount of program and data memory on the PIC18F. The code is very simple (IMO) as it is, and adding classes and interfaces and whatnot on top of it really defeats the purpose.

I also believe that the object-oriented paradigm really doesn’t fit into robotics very well - it’s a very functional kind of work, where flow control is far more important than encapsulation and abstraction. Your students would benefit more from learning C and lower-level constructs to give them a more well-rounded approach to programming in general.

The most effective way to use Java with the IFI equipment would be to build a framework that runs on a PC with a serial interface to the robot controller. The framework would have to handle the IO.

The PC can send motor commands directly to the RC and the RC can send telemetry back to the PC. There will be some latency but it would be an interesting project.

If you really want to program a microcontroller using an object oriented language you might have to skip using the PICs all together. I know certain microcontrollers and DSPs do have the capability of being programed in C++.

I also believe that the object-oriented paradigm really doesn’t fit into robotics very well - it’s a very functional kind of work, where flow control is far more important than encapsulation and abstraction.

I have to disagree with you. Certain paradigms can get by with a functional abstraction while others are object oriented from the get go. It all depends on what you want the robot to do.

I actually think that at the level we do programming for FIRST, Java could be a good language. It handles events and exceptions very cleanly from the programmer’s standpoint, so you can focus on making a good algorithm. Event and exception handling is a critical part of programming any autonomous robot.

Java is a slow language, but the speed of decision making for FIRST robots isn’t really that fast. You shouldn’t use Java if you absolutely have to make the decision about how to position control surfaces in less than 2 milliseconds in order to keep the plane from flipping over. But if you don’t care whether it takes 3 milliseconds or 15 milliseconds to compute a series of angles, Java is fine in terms of speed.

But the microcontrollers we have are just too slow to be able to effectively program them in Java unless you created an environment to compile Java into object code rather than into Java byte codes. Something like the xCode tools on the Mac, in which you can use Java to create OS X native Cocoa applications.

If you are just looking for an environment to do robotics in Java, try looking the Intelli-Brain robots by RidgeSoft. (www.ridgesoft.com) They are nice little programmable (in Java) robots which can be extensively configured. You can even run the CMU cam on them.

I don’t agree about the size of Java. I have used a JVM in the past that runs on the LEGO RIS controller (which has WAY less horsepower and memory than the FIRST controller) and it was quite usable. Of course it was a minimized system without a lot of the bells and whistles of regular Java (which you don’t need for this application anyway). It also showed me that the OO paradigm is very applicable to robotics. The ability to abstract common attributes of, for instance, sensors and then derive from them can be very useful.

The issues in this case are: 1. I don’t think there is a JVM available for the PIC processors used, and 2. Many of the great features of Java like multi-threading just aren’t possible in this environment because we have to turn control over to the master processor, then wait for it to call our routines again. But things like event and exception handling, as mentioned before, would be very useful.

Great discussion! Keep it coming.

Having a different language to use on the controllers would be great. (Python would be my choice. :wink: ) But again, capabilities limit what can be run natively.

Some parts (eg, interrupts) still need to be written in C. And there’s enough intricacies in the architecture that you have to be cautious everywhere else, too. (Get a value from a structure out of an array: ~30 words of instructions.)

Personally, I’d say start with lowering the bar on C. Maybe I’ll work on a set of tools to handle a laptop on the robot.

EDIT: I wouldn’t worry much about advanced features. How many students use them on PCs?

You might have better luck using something like a mini-itx board, a dc-dc power supply, and an interface board of some sort. (parallel port?) Of course, most of the work in a system like that is with the electronics itself, which is what makes the VEX systems so great for education.

Of course, I think a computer science class wouldn’t be hurt by learning a bit of C. Most of the syntax is the same as Java, and if the teacher is really worried about it, he could write default code to start from, so that students put their algorithms into one function.

The bottom line is that you aren’t going to get any “real” interpreted language support until the IFI Robot Controllers use a 32-bit ARM core. This would open the door to Microsoft’s .NET Micro Framework or Java, along with a lot of other languages.