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

ROS Subscriber in Android

asked 2018-05-24 03:33:15 -0500

MarkusHHN gravatar image

updated 2018-05-24 10:34:24 -0500

gvdhoorn gravatar image

I would like to make a Subscriber on my Android-Application which can subscribe the batterydata from the robotino. These Data should be displayed on the apply. In this project i have two nodes which the predecessor make it. In one of then they subscribe the camera an, which I use the source code to hope they working for my extra function, but they show nothing. Here my Sourcecode for the subscription

@Override
public void onStart(ConnectedNode connectedNode) {
 // Battery Subscriber
    battery_subscriber = connectedNode.newSubscriber(GraphName.of(topic_basename + "battery_status"), std_msgs.Float64._TYPE);
    battery_subscriber.addMessageListener(new MessageListener<std_msgs.Float64>() {
        @Override
        public void onNewMessage(Float64 message) {
            batterystatus = callable.call(message);
        }
    });                                                                                                                                                                            public Float64 getBatterystatus() { return batterystatus;
}

In my MainActivity I call the "getBatterystatus" to receive the data from the battery:

    pTextBatteryStatus = (TextView) findViewById(R.id.robot_battery);
    pTextBatteryStatus.setText(String.valueOf(NodeTeleopPublisher.getBatterystatus()));

I publish some data but my app is crashing all the time. My Question is: How make a simple Subscriber for my Android-Application?


Edit: Thank you for your answer. I hope that is the errorlog what are your need. The app crash doesnt make some error. I think the problem is the part from the messageListener.

05-24 15:03:03.659 28077-28077/? E/HAL: load: couldn't find symbol HMI
05-24 15:03:03.660 28077-28077/? E/memtrack: Couldn't load memtrack module (Invalid argument)
05-24 15:03:03.660 28077-28077/? E/android.os.Debug: failed to load memtrack module: -22
05-24 15:03:03.708 28077-28077/? E/HAL: load: id=fm != hmi->id=fm
05-24 15:03:03.708 28077-28077/? E/fm_if.c: find the id:fm and begins to open the devices
05-24 15:03:04.954 28092-28092/? E/HAL: load: couldn't find symbol HMI
05-24 15:03:04.955 28092-28092/? E/memtrack: Couldn't load memtrack module (Invalid argument)
05-24 15:03:04.955 28092-28092/? E/android.os.Debug: failed to load memtrack module: -22
05-24 15:03:05.003 28092-28092/? E/HAL: load: id=fm != hmi->id=fm
05-24 15:03:05.003 28092-28092/? E/fm_if.c: find the id:fm and begins to open the devices
05-24 15:03:05.785 27146-27174/? E/ExternalAccountType: Unsupported attribute readOnly
05-24 15:03:05.785 27146-27174/? E/CSP_ExceptionCapture: Unsupported attribute readOnly
05-24 15:03:05.901 5459-5497/? E/LogCollectService: Level = 256
05-24 15:03:11.144 28104-28104/? E/HAL: load: couldn't find symbol HMI
05-24 15:03:11.144 28106-28106/? E/HAL: load: couldn't find symbol HMI
05-24 15:03:11.144 28106-28106/? E/memtrack: Couldn't load memtrack module (Invalid argument)
05-24 15:03:11.144 28104-28104/? E/memtrack: Couldn't load memtrack module (Invalid argument)
05-24 15:03:11.144 28106-28106/? E/android.os.Debug: failed to load memtrack module: -22
05-24 15:03:11.144 28104-28104/? E/android.os.Debug: failed to load memtrack module: -22
05-24 15:03:11.202 28106-28106/? E/HAL: load: id=fm != hmi->id=fm
05-24 15:03:11.202 28104-28104/? E/HAL: load: id=fm != hmi->id=fm
05-24 15 ...
(more)
edit retag flag offensive close merge delete

Comments

can you copy the error that is making the application crash here? How are you executing the node that has that code? The code of the node looks alright (see https://github.com/rosjava/rosjava_co... ).

jubeira gravatar image jubeira  ( 2018-05-24 07:23:56 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-05-24 07:29:52 -0500

jubeira gravatar image

updated 2018-05-24 08:44:57 -0500

Hi! Can you update the question with the error that's making the app crash? Try debugging your app with ADB (see here for reference, you can see exactly what's going on with your app with it).

The code for the node looks OK. How are you executing it? Have you taken a look at https://github.com/rosjava/android_co... Perhaps that can give you a hint.

I'd say the error is somewhere else. Use ADB and take a closer look to the error messages.

EDIT: note that you can copy the code in your question, not as an answer, please take into account that this is not a forum.

I just saw this line. What is this doing?

batterystatus = callable.call(message);

You should make batteryStatus just a plain double, and do

batteryStatus = message.getData();

edit flag offensive delete link more

Comments

i change the code and it isnt crashing but I dont received any data from the Subscriber.

MarkusHHN gravatar image MarkusHHN  ( 2018-05-24 08:57:48 -0500 )edit

Try adding some logs to the callback. Use https://github.com/rosjava/rosjava_co... as a reference; log the value you get in the callback. Use rostopic info to check that the node has actually subscribed

jubeira gravatar image jubeira  ( 2018-05-24 09:08:00 -0500 )edit

okay thanks i received the data but i cant pass over the data from the node to the RosActivity.

MarkusHHN gravatar image MarkusHHN  ( 2018-05-24 09:35:03 -0500 )edit

ok, we are getting there then. What if you log the value you get outside the node instead of setting it directly? What is NodeTeleopPublisher.getBatteryStatus returning?

jubeira gravatar image jubeira  ( 2018-05-24 09:41:59 -0500 )edit

The NodeTeleopPublisher.getBatterystatus is zero. I checked the value "batterystatus" in the methode which is zero too. Do you know what is the problem?

MarkusHHN gravatar image MarkusHHN  ( 2018-05-28 03:52:43 -0500 )edit

Is your whole code public? perhaps if I can take a quick look at all of it I can give you more help. Are you printing the value that you are getting inside the callback? Is it something different from 0?

jubeira gravatar image jubeira  ( 2018-05-28 10:19:41 -0500 )edit

No this whole code was made from a student on my university. I must make a additional function for the application. In the onNewMessage method i get the data, but in the getBetterystatus method i get zero.

MarkusHHN gravatar image MarkusHHN  ( 2018-05-29 03:09:29 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2018-05-24 03:33:15 -0500

Seen: 711 times

Last updated: May 24 '18