Java for Robotics

The task of programming a robot from scratch can be a daunting one. Having the right software tools and infrastructure to facilitate robot development is key to simplifying the process. This article explains how the Java programming language and platform provide a simple and easy to understand means for programming robots.

This article is based on Programming Robots, to be published in Spring 2013. It is being reproduced here by permission from Manning Publications. Manning early access books and ebooks are sold exclusively through Manning. Visit the book’s page for more information.

Author: Paul J. Perrone

Programming Robots There is a wide variety of programming languages traditionally used in developing software for robotics applications. In some cases, the programming languages are non-standard languages especially designed to work with a specific operating environment or target hardware platform. In other cases, the languages are designed to simply provide a high-level programming environment for robotics. Such a high-level programming approach for robotics provides some advantages in terms of readability and abstracting low-level details. However, use of highly specialized programming languages requires ramp-up time in learning its syntax, usually have limited portability across platforms, often have limited scalability, and have more limited third-party tool and software support than standard programming languages.

On the flip side, many standard programming languages, due to their more general-purpose applicability, have a lower-level programming syntax making them less readable for robotics applications than languages specifically designed for robotics. Such robot programming is performed at a low level using languages such as C, Basic, or various assembly languages. Frequently, these languages are employed due to the use of highly specialized hardware platforms initially programmed with that particular language. Another key reason is pre-existing academic programs or industrial applications that have leveraged highly specialized and legacy software libraries rooted in these languages.

In order for robotics to become more widely adoptable, more modern and widely adopted languages need to be leveraged. Enter the Java programming language. The Java programming language has grown to become the most commonly used programming language with a wealth of available software expertise worldwide and a wealth of available software components and tools. Java is the most popular programming language among skilled engineers and across courses and third party vendors with a significant percentage of the global market (www.tiobe.com). It is also the most requested language skill by employers (www.dice.com), and the most used programming language with nearly half of all developers using the language some of the time (www.evansdata.com). As of 2010, by Oracle’s count, there were over 6 million Java developers worldwide and over 850 million PCs with a Java platform installed (www.sun.com/java/everywhere). With such a foothold on desktops, use in multiple products, third-party library support, and developer mindshare, it’s sure to remain one of the most popular programming languages and platforms for a long time.

Java also is a high-level programming language with a simplicity in programming that appeals to programmers at various skill levels. Coding in Java, when done properly, can almost read like a novel and be self-descriptive as the example here illustrates:

HokeyPokeyBot myRobot = new HokeyPokeyBot();
myRobot.moveLeftFoot(1);
myRobot.moveLeftFoot(-1);
myRobot.moveLeftFoot(1);
myRobot.shakeLeftFoot();
myRobot.shakeBody();
myRobot.rotate(360);
myRobot.speak("That's what it's all about.");

Aside from its popularity and ease of programming as a language, Java is also a virtual machine platform offering portability across hardware and operating systems. As illustrated in figure 1, a programmer writes Java code in the Java programming language and uses Java software libraries that are interpreted and mapped by the virtual machine at runtime to underlying operating environment calls. Thus, programmers write once and run anywhere, as the Java slogan goes.

The Java language, virtual machine, libraries, and operating environmen

Figure 1. The Java language, virtual machine, libraries, and operating environment

But, how true is the write once run anywhere philosophy for robotics? It’s one thing to be able to write an application that runs on Windows as easily as it runs on Mac OSX and Linux. But these are standard operating system environments that have fairly widespread usage and have been around a while. What about microcontrollers and embedded environments? How easy is it to run Java there?

Seeing the need to apply Java across these varied environments, the folks within the Java community created a series of Java profiles. These include the following basic environments:

Java SE (Standard Edition) — Provides software libraries to run in most common operating system environments. Tailored for desktop, laptop, and PC motherboard hardware environments. Suitable for those robotics environments where by the application demands hardware with a reasonable amount of processing power and memory, ranging typically from a 6 to 18 square-inch footprint, can live with 15 to 120 second boot times, and don’t have an overwhelming need for deterministic real-time processing. For example, a basic hobby-grade robot navigation application may run in an SE environment, with Linux and a small footprint motherboard.

Java ME (Micro Edition) — Provides a minimalist subset of Java SE libraries to run in memory and processor constrained environments. Comes in a very constrained form known as Connected Limited Device Configuration (CLDC) and a form with more libraries known as Connected Device Configuration (CDC). CLDC is tailored for microcontroller and constrained embedded controller hardware environments. CDC is tailored for more capable embedded computer hardware environments. It’s suitable for those robotics environments where low-level feedback controls or real-time controls need to be implemented. It’s also useful when requiring faster boot times of a system. For example, an embedded controller in a teleoperated robotic ground vehicle for commercial deployment.

Java RTS (Real Time System) — Provides real-time determinism for Java environments. Currently limited to a real-time flavor of the Java SE platform that runs in a Solaris 10, SUSE Linux Enterprise, or Red Hat Enterprise operating environment. Given the operating system limitations at the time of this writing, Java RTS is mostly tailored for desktop and server-grade hardware environments. However, Java RTS also can run on a few fairly small-footprint embedded computers with a configuration of the operating systems listed. Robotics applications that demand real-time determinism, which can run in these larger footprint hardware environments and that don’t demand fast boot times are most appropriate venues for Java RTS. For example, a safety-critical robot controller performing mobile autonomous controls in a deterministic fashion inside of a car-sized unmanned ground vehicle (UGV).

Java EE (Enterprise Edition) — Provides a server-side programming environment for Java applications with a superset of the Java SE libraries. Software libraries for building Web server applications, connecting to databases, and integrating with back-end legacy systems are included in this profile. Java EE is tailored for server hardware environments. Suitable for those typically non-mobile applications of robotics requiring coarse-grained planning or multirobot coordination, for example, a robot route planning application looking at terrain data in a database.

JavaCard — Provides an extremely minimalist subset of Java SE libraries to run in highly constrained memory and processor environments. Tailored for smart cards and very limited micro-controller hardware environments. Suitable for those thumbnail or small rodent-sized robotics applications. For example, a mini-robot that roams around using touch sensors for avoiding things.

The scalable complexity of Java profiles to meet different operating needs

Figure 2. The scalable complexity of Java profiles to meet different operating needs

As you can see in figure 2, there is a scalable range of environments in which Java can run using these different profiles.

Summary

When people think of Java, they typically think of Java SE or Java EE grade applications. Indeed, Java runs in over 850 million PCs, but it also is running on over 2.1 billion mobile phones and handheld devices and in over 3.5 billion smart cards. With such traction across hardware platforms of all sizes and capabilities, we’re able to leverage this capability in robotics to meet the wide variety of hardware needs demanded by the field of robotics.

Related Posts:

One thought on “Java for Robotics

Comments are closed.