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

Dynamic information flow between ROSJAVA nodes and ROSActivity

asked 2013-02-18 12:55:14 -0500

updated 2014-01-28 17:15:18 -0500

ngrennan gravatar image

Hi All,

When using ROSJAVA with android I'd like to pass information from the ROSActivity gui to the ros_node implementing nodeMain. Is there a way to do this without using the normal ROS message traffic?

If there is, how is it done?

cheers

Peter

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2013-02-19 10:31:25 -0500

damonkohler gravatar image

There's a lot of options here. You're basically asking how to write a multi-threaded Activity. This tutorial seems to cover a lot of the various concepts:

http://www.vogella.com/articles/AndroidBackgroundProcessing/article.html

edit flag offensive delete link more

Comments

I looked at the handlers type of processing but in the tutorial, it mentioned that it must be run in the same scope as the main activity. I attribute my failure to the fact that I'm trying to update a handler inside my class and therefore out of scope. What method do you recommend?

PeterMilani gravatar image PeterMilani  ( 2013-03-01 14:41:33 -0500 )edit
1

answered 2013-03-05 02:05:28 -0500

updated 2013-03-05 02:08:19 -0500

Based off Damon's answer, I applied the transfer of information between threads by using an application class as described in his link and elaborated here

To use the application class which contains the data I wanted to transfer. I created a global instance in the mainActivity onCreate() method, then I created my node classes, passing the instance of the application to them like this:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rApplication = (ROSApplication)getApplicationContext();
        interfacenode= new cartesian_interface_node(rApplication);
        statusupdate = (TextView) findViewById(R.id.textView1);
    }

After the in the init() method after all the nodes had been set running by the nodeMainExecutor, I passed to a function called loop() and placed the following code.

protected void loop()
{
    while (true)
    {
        runOnUiThread(new Runnable() {
            public void run() {
                statusupdate.setText(rApplication.Status);
            }
        });

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

there's probably a more correct way to implement the loop other than the while loop, but it is effective and the update to ui works! The power of Android UI and ROS!

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-18 12:55:14 -0500

Seen: 893 times

Last updated: Mar 05 '13