Using Multiple Languages

I was wondering whether it would be worth using multiple language on a robot. Since I am no expert, I am wondering whether it is a good idea to use multiple languages on the robot. Our robot is to be programmed in Java. However, I would like to use C for offboard vision because it is very easy to get everything set up and to program OpenCV.

Other than that, does anyone know how to get Java running with OpenCV?

Thanks, and Happy Holidays/Happy KickOff!

The cRIO can only support one language image at a time, which can be changed via the cRIO Imaging Tool. However, you could also run an interpreted language like Python or another scripting language with a runtime written in whatever language the cRIO is imaged in. Other than that, there shouldn’t be a problem using multiple languages since the cRIO and the coprocessor are two separate systems.

I’m not familiar with OpenCV as it pertains to Java. I’m sure someone else can point you in the right direction.

I’ve been looking into using another language on the robot along side Java as well, primarily for autonomous scripting. What I’ve found is that since FRC currently uses a Java ME environment (the Squawk JVM is J2ME CLDC 1.1), disappointingly most of the new cool JVM-backed languages are not compatible (such as Scala, Clojure, JRuby, etc). There are a couple of J2ME implementations of Lua floating around, but I was not able to get any of them working for FRC. It seems folks have more success with this from the C++ side of things with projects like RobotPy and Greyhound Lua. However, both of these are intended as a full replacement, not to be mixed and matched with C++ [citation needed].

There is always the possibility of writing your own scripting language, which would probably be a beneficial experience in and of itself. Additionally, Team 4334 created a scripting language called Gordian designed specifically for FRC; you might want to check it out.

As was already stated, using a different language on the driver station or whatever you are using for vision processing will be fine.

Thanks. I was looking at a comparison between just sticking with one language, sticking with one language, but making some exceptions, and allowing every language, even if it is as old as Forth!

I know that almost every software giant, like Google, Microsoft and Facebook (IDK about Apple, so I won’t comment), use multiple languages to do their processes. Google has most of it’s code written in Java, but uses quite a bit of python interleaved.

Our team has, for this year, stuck to using just Java, because our mentor’s told us that it is the “best” language. While it isn’t a bad language (I like Java, actually), There are some places where I think it is impractical to use Java. In this case, I am thinking solely about OpenCV. It is probably one of the most feature-packed CV library, but installing the Java connector seems like rocket science. Not only that, but SoCs typically have crappy JVMs, making it a hassle to run the code. OpenCV, for example, is written in C. That means that the Java interpreter needs to run the binaries continuously. In the case where you have limited resources like RAM, that seems quite impractical, the same reason why a Raspberry Pi + Minecraft Server don’t always work out well, if you are a typical gamer!

Typically, linking multiple languages isn’t the easiest thing to do. However, in this case, the cRIO is the i2C host server and the Pi is the i2C slave, obeying the instructions of the cRIO!

On a full-blown Debian system, I noticed that the JVM takes quite a bit of time to launch. It takes 1-5 minutes for Minecraft, Vanilla, to load on my MacBook. I think the reason why I get such load speeds is because the DSP of my Pi isn’t powerful enough to max out my Hard Disk, another reason why I shouldn’t waste my money buying an SSD for the Pi! That’s why when you go on my site, when the chrome bar is moving backwards slowly, the HDD is being read, and the site is being generated/downloaded as the circle turns around!

This is just what I have noticed when programming.

Both Java and LabVIEW can call a C library. With Java, you would use JNA. With LabVIEW, you would use Call Library Function.

We have never used different programming languages on the robot. We have used Java on the robot, and a LabVIEW dashboard to do vision processing.

The choice as to whether to use multiple programming languages should be carefully considered. It significantly increases the complexity of your program. You can’t afford to have only a single person that knows part of your code, so you need multiple people able to use both languages. Often I see a project use different languages because one person is an expert in one language and doesn’t want to learn the language that everyone else is using. This doesn’t end well.

When is it ok to use multiple languages? Here’s a few rules of thumb:
When each language has clear benefits in a particular area, and a common language has significant detractors in those areas.
When everyone agrees that multiple languages are better.
When multiple people can work with multiple languages.
When there is a clear segmentation (for example, different processors).
When the interface between the languages is well defined and the amount of information to be shared is minimal.
When there is lots of time for troubleshooting.

Here’s one project designed to run LUA alongside C++. http://www.chiefdelphi.com/forums/showthread.php?t=106532&highlight=lua

What does this mean?

In my experience it hasn’t been worth the effort to try and do multiple languages on a single device in FIRST. I’ve found that with a little file IO and a few switches there’s practically no need to do any code changes to autonomous. If I’m drawn to using another language for more than auton I might as well write the whole thing in that language.

However multiple languages on different devices is much less of an issue. For example a robot written in C++ or LabVIEW and a dashboard in Java can work well together, or a microcontroller with code written in XYZ communicating with a robot written in ABC aren’t that difficult. Once you’re communicating over the network to a separate device the difficulty of using a different language only comes from needing to be proficient in two languages.

tl;dr Is there a better way to accomplish what you want to accomplish with multiple languages on one device? Different devices mean multiple languages isn’t really a big deal.

We do not use multiple languages on our robot, but in our team. Our cRio is labview, computer vision is c or c++ (mentors encourage c++, for college studies)-whichever the student prefers, and our scouting system is in c#. I personally like the variety. It allows for a more well rounded programmer. If you don’t enjoy labview, you can try out C++, C# or just plain old C. We have a mentor that learned labview through FIRST many many years ago, another is an electrical engineer that has been learning c++ with the rest of the students, and we have another mentor who develops code in c# for a living, so we have support in all three.

I think I’d rephrase this original question.

Do you have a problem that warrants bringing in an additional tool?

A computer language is a tool. Carrying multiple tools around and being proficient in them is useful and not uncommon. Using them simultaneously is far different and far harder than one at a time.

Getting to the details, mixing languages can really complicate things if the fundamentals of data types, memory ownership and lifetime aren’t well understood and controlled. There are other issues too, like knowing which tool a particular error code was produced by. Basically, different design philosophies within the language and the libraries can make this much harder.

As others have mentioned, a safer way to do this is to isolate the tools to different computers, perhaps at sub-team boundaries.

Did you have a specific problem in mind?
Greg McKaskle

[/quote]

I’m still wondering what it means.

Firstly, modern OpenCV uses C++. Yes, the OpenCV docs for Java integration are here for a CLI and here for Eclipse.

While vision processing is nice, its useless unless you can communicate the results back to the cRIO. You should focus on designing the mechanism by which you want the two systems to pass information back and forth. If that leads you to write both in the same language, great. If you end up using C++ and Java, great. (Assuming you’re open to using multiple languages, of course; if you only know Java, that’s a different case.) Making your code simple and reliable is much more important than what language it uses.

I don’t quite understand what you mean. All that Java should do is reference the precompiled binaries, making execution faster.