Writing an image listener on android device; need debugging tips (why running out of memory?)
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 ...