Problem using environment variables in RosJava for Android

asked 2020-01-23 14:29:26 -0500

ielson gravatar image

Hey could someone please explain me how can I use environment variables on rosjava in android?

I'm trying to run the android_core pubsub example, but like some people, I'm having trouble using it at the emulator. At a real phone it works flawlessly, but at the emulator, I can see the nodes and the topics being created, but nothing comes at the topic after that and no error message is shown.

My problem is exactly the same as the one in this question (https://answers.ros.org/question/2236...), and I saw many answers (as @gdvhoorn in the link above) that say that the many times these kind of problems with the emulator are caused because of incorrect network configuration, so I have two questions:

1 - How can I set the values of the environment variables in an Android Emulator? I searched, but couldn't find a setter function, and when I go to the function definition it just returns me an EnvironmentVariables.class file that have the variables set like this:

public interface EnvironmentVariables {
    String ROS_MASTER_URI = "ROS_MASTER_URI";
    String ROS_IP = "ROS_IP";
    String ROS_HOSTNAME = "ROS_HOSTNAME";
    String ROS_NAMESPACE = "ROS_NAMESPACE";
    String ROS_ROOT = "ROS_ROOT";
    String ROS_PACKAGE_PATH = "ROS_PACKAGE_PATH";
}

And when I print these variables in the runtime, the only one that has changed is the Master URI, because of the nodeConfiguration.setMasterUri. So how can I change them to make it work in the emulator?

2 - How should I config my Environment Variables to make it possible for my computer to communicate with the emulator? The emulator runs on port localhost:5554, but when it runs, it creates a kind of brigde and sets the emulator own IP to 10.0.2.15 or 16 depending on the interface used, and host computer (where the roscore is running) to 10.0.2.2. But from the host computer I can't ping on 10.0.2.15 or 10.0.2.16 because they don't really exist. When the android app connnects, it shows the message: Registrar: MasterXmlRpcEndpoint URI: http://10.0.2.2:11311/ and that's right, because that's the address the emulator finds my computer, but the Publisher is registered at http://10.0.2.16:40719/ so when I'm able to change , as can be seen in the following message:

Registrar: Registering publisher: Publisher<PublisherDefinition<PublisherIdentifier<NodeIdentifier</android_gingerbread/ros_text_view, http://10.0.2.16:40719/>, TopicIdentifier</rosout>>, Topic<TopicIdentifier</rosout>, TopicDescription<rosgraph_msgs/Log, acffd30cd6b6de30f120938c17c593fb>>>>

But when my roscore try to find it, it won't be able to connect to it, because for my computer there's nothing with the IP 10.0.2.16 that my host computer can see. So, how should I config my Environment Variables to make it possible for my computer to communicate with the emulator?

I really need to use the emulator, because the project I'm working on will need 6 phones working together in ROS, so it makes really better if I can use the emulator. I have already some experience with ... (more)

edit retag flag offensive close merge delete