Ask Your Question
0

How to check if the Pubsub tutorial is running correctly?

asked 2011-07-06 01:00:16 -0500

david gravatar image

updated 2011-07-06 06:16:20 -0500

mmwise gravatar image

Hi I'm trying to learn the following pubsub tutorial code fragment but apparently, is still not connecting to roscore running on pc yet. The program installs successfully but there is no sign of a successful roscore connection.

/*******************************************************************/

/*
 * Copyright (C) 2011 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.ros.tutorials.pubsub;

import org.ros.NodeConfiguration;
import org.ros.NodeRunner;
import org.ros.RosCore;
import org.ros.internal.node.address.InetAddressFactory;
import org.ros.rosjava.android.MessageCallable;
import org.ros.rosjava.android.views.RosTextView;

import android.app.Activity;
import android.os.Bundle;
/**
 * @author damonkohler@google.com (Damon Kohler)
 */

public class MainActivity extends Activity {

  private final NodeRunner nodeRunner;
  private RosCore rosCore;
  private RosTextView<org.ros.message.std_msgs.String> rosTextView;
  private Talker talker;

  public MainActivity() {
    super();
    nodeRunner = NodeRunner.createDefault();
  }

  @SuppressWarnings("unchecked")
  @Override

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    rosTextView = (RosTextView<org.ros.message.std_msgs.String>) findViewById(R.id.text);
    rosTextView.setTopicName("/chatter");
    rosTextView.setMessageClass(org.ros.message.std_msgs.String.class);
    rosTextView.setMessageToStringCallable(new MessageCallable<String, org.ros.message.std_msgs.String>() {
          @Override
          public String call(org.ros.message.std_msgs.String message) {
            return message.data;
          }
        });
  }


  @Override
  protected void onPause() {
    super.onPause();
    talker.shutdown();
    rosTextView.shutdown();
    rosCore.shutdown();
  }

  @Override
  protected void onResume() {
    super.onResume();
    try {
      rosCore = RosCore.createPublic(11311);
      NodeConfiguration nodeConfiguration = NodeConfiguration.createDefault();
      nodeConfiguration.setHost(InetAddressFactory.createNonLoopback().getHostAddress());
      nodeRunner.run(rosCore, nodeConfiguration);
      rosCore.awaitStart();
      nodeConfiguration.setMasterUri(rosCore.getUri());
      talker = new Talker();
      nodeRunner.run(talker, nodeConfiguration);
      nodeRunner.run(rosTextView, nodeConfiguration);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

}
/***********************End of Code*****************************/
edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2011-09-02 10:58:03 -0500

kwc gravatar image

no activity in > 1 month, closing

edit flag offensive delete link more
1

answered 2011-07-06 04:30:59 -0500

fergs gravatar image

You might want to check this other question - rosjava(android) pubsub tutorial. In particular, it looks like you need to run ADB.

edit flag offensive delete link more
0

answered 2011-07-06 03:02:26 -0500

seanarm gravatar image

Running a roscore provides your system with a /rosout. After running your roscore, type 'rosnode list' to verify this. Your sample node should automatically to the roscore. To verify this, run your node, then run 'rxgraph'. See the line connecting your node and rosout? That means it's connected to the roscore.

Also, in roscpp, when you start a node you might get one of two messages: 1. "core service [/rosout] found" -- meaning the node found the roscore 2. "starting new master (master configured for auto start)" -- meaning a new roscore was started

edit flag offensive delete link more

Comments

In fact, I am trying to communicate between the android phone and the host pc. Running the roscore on the pc is not a problem; i'm trying to get android to come and communicate with the roscore on the pc. The concept is quite clear-- to make the android connect to the roscore on the pc, but couldn't implement it with the codes details
david gravatar imagedavid ( 2011-07-06 03:25:57 -0500 )edit

I have exactly the same problem. Did you find a solution in the end?

noe_vb gravatar imagenoe_vb ( 2013-03-29 01:44:24 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-07-06 01:00:16 -0500

Seen: 1,481 times

Last updated: Sep 02 '11