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

Revision history [back]

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!

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!works! The power of Android UI and ROS!