ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Writing an image listener on android device; need debugging tips (why running out of memory?)

asked 2012-04-05 16:18:37 -0500

amigo gravatar image

updated 2012-04-06 06:32:19 -0500

I'm trying to write an app that can receive sensor_msgs/Image messages on an android device. I've modelled the code after android_tutorial_pubsub:

import org.ros.address.InetAddressFactory;
import org.ros.android.BitmapFromImage;
import org.ros.android.RosActivity;
import org.ros.android.views.RosImageView;
import org.ros.node.NodeConfiguration;
import org.ros.node.NodeMainExecutor;

import android.os.Bundle;

public class MainActivity extends RosActivity {
        private RosImageView<sensor_msgs.image> rosImageView;

        public MainActivity() {
                super("Android App", "Android App");
        }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                rosImageView = (RosImageView<sensor_msgs.image>)findViewById(R.id.imageView1);
                rosImageView.setTopicName("/camera/rgb/image_color");
                rosImageView.setMessageType("sensor_msgs/Image");
                rosImageView.setMessageToBitmapCallable(new BitmapFromImage());
        }

        @Override
        protected void init(NodeMainExecutor nodeMainExecutor) {
                NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(InetAddressFactory.newNonLoopback().getHostName());
                nodeConfiguration.setMasterUri(getMasterUri());
                nodeMainExecutor.execute(rosImageView, nodeConfiguration.setNodeName("myapp/image_listener"));
        }

        @Override
        protected void onDestroy() {
                super.onDestroy();
        }
}

I am able to connect to the ROS master just fine:

~$ rosnode list
/myapp/image_listener
/rosout

It is properly subscribed:

~$ rostopic info /camera/rgb/image_color 
Type: sensor_msgs/Image

Publishers: None

Subscribers: 
 * /myapp/image_listener (http://192.168.0.116:50285)

When I use rosbag play on a bag file, it shows the publisher:

~$ rostopic info /camera/rgb/image_color 
Type: sensor_msgs/Image

Publishers: 
 * /play_1333677784320867515 (http://192.168.0.119:44669/)

Subscribers: 
 * /myapp/image_listener (http://192.168.0.116:50285)

But that's the end of good behavior. The image does not appear in the image view. Here is my res/layout/main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <org.ros.android.views.RosImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

</LinearLayout>

Before I start rosbag play, I am able to exit the app and re-enter no problem. Once the publishing starts, the app is pretty much frozen.

roswtf doesn't tell me anything interesting (I ran rosbag a second time, so the play node number is different).

~/ros_workspace/android_core/android_image_listener$ roswtf
Loaded plugin tf.tfwtf
No package or stack in context
================================================================================
Static checks summary:

No errors or warnings
================================================================================
Beginning tests of your ROS graph. These may take awhile...
analyzing graph...
... done analyzing graph
running graph rules...
... done running graph rules

Online checks summary:

Found 2 warning(s).
Warnings are things that may be just fine, but are sometimes at fault

WARNING Node [/myapp/image_listener] is not connected to anything
WARNING The following nodes are unexpectedly connected:
 * /play_1333678178991195080->/rosout (/rosout)
 * unknown (http://192.168.0.116:50933/)->/rosout (/rosout)

logcat gives me a bunch of (nonstop):

D/dalvikvm( 3678): GC_CONCURRENT freed 2048K, 25% free 34961K/46599K, paused 2ms+4ms
D/dalvikvm( 3678): GC_CONCURRENT freed 2048K, 25% free 34961K/46599K, paused 2ms+4ms
D/dalvikvm( 3678): GC_CONCURRENT freed 2048K, 25% free 34961K/46599K, paused 2ms+4ms
D/dalvikvm( 3678): GC_CONCURRENT freed 2048K, 25% free 34961K/46599K, paused 2ms+4ms

and I can get in logcat (after running rosbag a few times):

E/dalvikvm-heap( 3678): Out of memory on ...
(more)
edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2012-04-06 10:35:00 -0500

damonkohler gravatar image

Please file an issue and attach a sample bag file that will cause the error. I'll try to reproduce it: http://code.google.com/p/rosjava/issues/list

edit flag offensive delete link more
0

answered 2012-04-05 21:56:56 -0500

Lorenz gravatar image

The exception is caused by message deserialization. Android devices have a very limited amount of memory so I guess the image that you are transmitting is just too big. Try with a smaller image, maybe you need to write something like an image downsampling node.

edit flag offensive delete link more

Comments

I actually got the same code to work using the same bag file a few days ago before I got the latest rosjava_core and android_core. I just downgraded rosjava_core and android_core and verified again that it does work on the older versions. So I don't think it's the image size.

amigo gravatar image amigo  ( 2012-04-06 05:50:32 -0500 )edit
0

answered 2014-12-15 11:17:36 -0500

r2doesinc gravatar image

Perhaps try the CompressedImage message type. I have been using this type with no issues.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2012-04-05 16:18:37 -0500

Seen: 2,582 times

Last updated: Dec 15 '14