android_core 0.1.0 documentation

Getting started

«  Building   ::   Contents

Getting started

Before diving into ROS enabled Android application development, you should be familiar with rosjava and Android application development in general. Note that any information regarding command-line adt and eclipse development is depracating - we have moved early to a gradle-android studio environment.

Creating a new Android application

Refer to the RosWiki for tutorials.

Using RosActivity

The RosActivity class is the base class for all of your ROS enabled Android applications. Let’s consider the following example from the android_tutorial_pubsub package. In this example, we create a Publisher and a Subscriber that will exchange “Hello, World” messages.

On line 14, we extend RosActivity. When our activity starts, the RosActivity super class will:

On line 22 we call the super constructor with two strings that become the title and ticker message of an Android notification. The user may tap on the notification to shut down all ROS nodes associated with the application.

Lines 28-30 should look familiar to Android developers. We load the activity layout and get a reference to our RosTextView (more on that later).

On line 42 we define the abstract method RosActivity.init. This is where we kick off our NodeMains and other business logic.

And that’s it. RosActivity handles the rest of the application’s lifecycle management including:

Nodes and Views

The android_core stack provides a number of Android Views which implement NodeMain. For example, let’s look at the implementation of RosTextView. The intent of this view is to display the textual representation of published messages.

The view is configured with a topic name, message type, and a MessageCallable. On line 40, in the NodeMain.onStart method, we create a new Subscriber for the configured topic and message type.

When a new message arrives, we either use the configured callable to transform the incoming message to a string (line 49), or we use the default toString() method if no callable was configured (line 56). We then set the text of the view to the string representation of the incoming message.

As with any other NodeMain, the RosTextView must be executed by the NodeMainExecutor. In the Using RosActivity example, we execute it in RosActivity.init and use the it to display incoming messages from the Talker node.

«  Building   ::   Contents