Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Unable to get multiple Topic follow along android_core/android_tutorial_pubsub #320

Open
longduong11311 opened this issue May 25, 2020 · 1 comment

Comments

@longduong11311
Copy link

longduong11311 commented May 25, 2020

I try get 3 Topic based on android_tutorial_pubsub instead of 1 topic is "/chatter".
Purpose is get multiple Topic to display monitor telephone. But I have issue this unable to get data at the same time. i only get 1 topic. Help me!
My code:

package org.ros.android.android_tutorial_pubsub;
import android.os.Bundle;
import org.ros.android.MessageCallable;
import org.ros.android.RosActivity;
import org.ros.android.view.RosTextView;
import org.ros.node.ConnectedNode;
import org.ros.node.NodeConfiguration;
import org.ros.node.NodeMainExecutor;
import org.ros.node.topic.Subscriber;
import std_msgs.String;

/**

public class MainActivity extends RosActivity {
// create
private RosTextView<std_msgs.String> rosPreArm;
private RosTextView<std_msgs.String> rosBattery;
private RosTextView<std_msgs.String> rosMode;
protected NodeMainExecutor nodeMainExecutor;

public MainActivity() {
// The RosActivity constructor configures the notification title and ticker
// messages.
super("Pubsub Tutorial", "Pubsub Tutorial");
}

@SuppressWarnings("unchecked")
@OverRide
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

rosPreArm = (RosTextView<std_msgs.String>) findViewById(R.id.prearm);
rosPreArm.setTopicName("/hp/StatusPreArm");
rosPreArm.setMessageType(std_msgs.String._TYPE);
rosPreArm.setMessageToStringCallable(new MessageCallable<java.lang.String, String>() {
  @Override
  public java.lang.String call(String message) {
    return message.getData();
  }
});

rosBattery = (RosTextView<std_msgs.String>) findViewById(R.id.battery);
rosBattery.setTopicName("/hp/StatusBattery");
rosBattery.setMessageType(std_msgs.String._TYPE);
rosBattery.setMessageToStringCallable(new MessageCallable<java.lang.String, String>() {
  @Override
  public java.lang.String call(String message) {
    return message.getData();
  }
});

rosMode = (RosTextView<std_msgs.String>) findViewById(R.id.mode);
rosMode.setTopicName("/hp/StatusMode");
rosMode.setMessageType(std_msgs.String._TYPE);
rosMode.setMessageToStringCallable(new MessageCallable<java.lang.String, String>() {
  @Override
  public java.lang.String call(String message) {
    return message.getData();
  }
});

}

@OverRide
protected void init(NodeMainExecutor nodeEx) {
nodeMainExecutor = nodeEx;

NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(getRosHostname());
nodeConfiguration.setMasterUri(getMasterUri());
nodeMainExecutor.execute(rosPreArm, nodeConfiguration);

}

protected void Battery(){
NodeConfiguration nodeConfiguration1 = NodeConfiguration.newPublic(getRosHostname());
nodeConfiguration1.setMasterUri(getMasterUri());
nodeMainExecutor.execute(rosBattery, nodeConfiguration1);
}

protected void Mode(){
NodeConfiguration nodeConfiguration2 = NodeConfiguration.newPublic(getRosHostname());
nodeConfiguration2.setMasterUri(getMasterUri());
nodeMainExecutor.execute(rosMode, nodeConfiguration2);
}
}

And, I have issue is get message like:
In file msg have:
StatusType.msg (string PreArm, string Battery, string Mode, string Armed) and multiple file like GPSType.msg, AttitudeType.msg, ..., created by me.
I want to get message in android instead of get Topic. Help me!

@arpit999
Copy link

You need to define the other two RosTextView in init. As per you code, I can only see that you define one.

add below lines in your init method

nodeMainExecutor.execute(rosPreArm, nodeConfiguration);
nodeMainExecutor.execute(rosBattery , nodeConfiguration);
nodeMainExecutor.execute(rosMode, nodeConfiguration);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants