Task communication

[email protected] Fri, 24 Feb 2006 16:27:49 +0100
Newsgroups gmane.science.robotics.orocos.user
Message-ID <[email protected]>
Hello,

We had a long good chat with Herman today, but we are still
unclear about how to connect tasks. The documentation is not
completely clear on this point. I have made a small example
program that shows our intension. Basically, I just want to
exchange data between two tasks. What are the minimal
changes needed in my program to make it work?

Thanks,

Kasper Stoy, Ph.D.
Assistant Professor
University of Southern Denmark

#include <os/main.h>
#include <corelib/DataObjectInterfaces.hpp>
#include <corelib/TaskNonPreemptible.hpp>
#include <corelib/TaskNonRealTime.hpp>

using namespace std;
using namespace ORO_CoreLib;

class TaskGet : public RunnableInterface
{
public:
  DataObjectLockFree<double> *my_Do;

  TaskGet( DataObjectLockFree<double> *my_Do ) {
    this->my_Do = my_Do;
  };

  bool initialize() {
    return(true);
  }

  void step() {
    double contents;
    contents = my_Do->Get();
  }

  void finalize() {
  }
};

class TaskSet : public RunnableInterface
{
public:
  DataObjectLockFree<double> *my_Do;

  TaskSet( DataObjectLockFree<double> *my_Do ) {
    this->my_Do = my_Do;
  };

  bool initialize() {
    return( true );
  }

  void step() {
    double contents;
    my_Do->Set( 3.14 );

  }

  void finalize() {
  }
};

int ORO_main(int argc, char** argv)
{
  DataObjectLockFree<double> my_Do("MyData");

  TaskGet taskGet( &my_Do );
  TaskNonRealTime taskA( 0.1 );
  taskA.run( &taskGet );
  taskA.start();

  TaskSet taskSet( &my_Do );
  TaskNonPreemptible taskB( 0.1 );
  taskB.run( &taskSet );
  taskB.start();

  sleep(10);

  return(0);
}