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

How would I take multiple values from a subscriber to output to RosTextViews?

asked 2019-06-27 09:22:10 -0500

AmanjotG gravatar image

So I'm making a Ros-Android App to get the gps position of the robot using the ublox gps package on the robot. I've got my RosTextViews set up for longitude, latitute, altitude and heading. So do I create multiple NodeConfigurations and execute each RosTextView or can this be done with just nodeMainExecutor?

public class MainActivity extends RosActivity {
private RosTextView<sensor_msgs.NavSatFix> latitudeTextView;
private TextView longitudeTextView;
private TextView headerTextView;
private TextView altitudeTextView;

protected MainActivity() {
    super("gpsPoseApp", "gpsPoseApp");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    latitudeTextView = findViewById(R.id.latitudeTxtView);
    longitudeTextView = findViewById(R.id.longitudeTxtView);
    altitudeTextView = findViewById(R.id.altitudeTxtView);
    headerTextView = findViewById(R.id.headerTextView);
    processSubscribers();
}

public void processSubscribers(){
    latitudeTextView.setTopicName("/ublox_gps_node/fix");
    latitudeTextView.setMessageToStringCallable(new MessageCallable<String, NavSatFix>() {
        @Override
        public String call(NavSatFix navSatFix) {
            return String.valueOf(navSatFix.getLatitude());
        }
    });
}

@Override
protected void init(NodeMainExecutor nodeMainExecutor) {

    NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(InetAddressFactory.newNonLoopback().getHostAddress());
    nodeConfiguration.setMasterUri(getMasterUri());
    nodeMainExecutor.execute(latitudeTextView, nodeConfiguration);

}

}

edit retag flag offensive close merge delete

Comments

I'm not sure if I understand the question. The standard approach would be using one text view for each of them. You can use the same NodeConfiguration object AFAIK.

jubeira gravatar image jubeira  ( 2019-07-04 12:10:11 -0500 )edit

I've tried that way but the problem is that the callables are all strings. When I receive the navSatFix messages, they're doubles. I then convert them to string using either String.valueOf(navSatFix.getLatitude()) or Double.toString(navSatFix.getLatitude()). When I output to the RosTextView, I just get a blank box.

AmanjotG gravatar image AmanjotG  ( 2019-07-04 12:24:05 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2019-07-04 13:39:21 -0500

AmanjotG gravatar image

I solved the issue I was having. It was because of this:

E/UpdatePublisherRunnable: java.lang.RuntimeException: java.net.UnknownHostException: Unable to resolve host "amanjot-precision-3520": No address associated with hostname

Once I set the HOSTNAME, IP and URI explicitly, I was able to receive the messages and display them to the RosTextView.

edit flag offensive delete link more
0

answered 2019-07-04 12:32:07 -0500

jubeira gravatar image

updated 2019-07-04 13:11:35 -0500

Have you checked the standard pubsub tutorial?

From what I can see, you need to specify the message type to the ROS text view: https://github.com/rosjava/android_co.... Other than that, the message callable looks OK.

You could also use a single node that parses the whole NavSatFix message and builds a single string representation out of it.

EDIT: Yes, the problem probably is that the Android device is not solving the hostname. Try using ROS_IPenvironment variable on the publisher side. See http://wiki.ros.org/ROS/NetworkSetup and https://github.com/rosjava/android_co... for reference.

edit flag offensive delete link more

Comments

I've done the first part and I still get a blank textview. Publishing data works fine from the app but subscribing to data doesn't work at all from the robot. I've even tried the listener way of subscribing by having another class that extends AbstractNodeMain and subscribes from there. From that class, I just get 0.0 instead of an actual latitude value.

Do you think it has anything to do with getting a java.lang.RuntimeException for not being able to resolve host "": No address associated with hostname even though the master uri is correctly set?

AmanjotG gravatar image AmanjotG  ( 2019-07-04 12:58:34 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-06-27 09:22:10 -0500

Seen: 133 times

Last updated: Jul 04 '19