Re: Task communication

Peter Soetens <[email protected]> Fri, 24 Feb 2006 17:45:09 +0100
Newsgroups gmane.science.robotics.orocos.user
Organization FMTC
Message-ID <[email protected]>
On Friday 24 February 2006 16:27, [email protected] wrote:
> 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?

Due to the confusion between the 'CoreLib' task (which is actually an 
'Activity', see <http://www.fmtc.be/orocos-bugzilla/show_bug.cgi?id=31> )
and the 'Task Context' (which is actually closer to a 'component' ), I'm not 
sure what you want. Since the program below "works", I'll assume that you 
want to use the full 'Task Context' facilities of Orocos to exchange data.

When using the 'to be released' Orocos 0.22.0 version, I'd change your program 
to the file in attachment. Now, since the 'DataFlow Interface' is not yet 
integrated with the TaskContext (see 
<http://www.fmtc.be/orocos-bugzilla/show_bug.cgi?id=22> ), the resulting 
program does not change much yet. This 'DataFlow' integration effort would 
'upgrade' the 'addPeer' methods to 'data flow connectors' such that connected 
tasks automatically find each other's data.

The reason why the 'TaskContext' is not fully functional is that it was first 
only a 'helper' class for the Orocos 'Control Kernel' components. Now it 
grows to get its own 'component' interface, such that it takes over these 
'Control Kernel' Components, and hopefully, we can skip the Control Kernel 
altogether, only using 'robot control components' which are in effect 
TaskContexts. (See also a draft document here about using TaskContexts: 
<http://people.mech.kuleuven.be/~psoetens/orocos/doc/latest/orocos-task-context.html> )

Take a look at the attachment, and start from that file to add functionality 
as described in the document above.

With kind regards,
Peter

>
> 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);
> }
>
> _______________________________________________
> Orocos mailing list
> [email protected]
> http://lists.mech.kuleuven.be/mailman/listinfo/orocos

-- 
Peter Soetens -- FMTC -- <http://www.fmtc.be>

_______________________________________________
Orocos mailing list
[email protected]
http://lists.mech.kuleuven.be/mailman/listinfo/orocos
task-test.cpp (text/x-c++src, 1.6 KB)
/**
 * Compile with:

g++  task-test.cpp  -o task-test -I/usr/local/orocos/include  -L/usr/local/orocos/lib -lorocos-gnulinux  -lpthread -lreadline -lxerces-c 

 */


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

using namespace std;
using namespace ORO_CoreLib;
using namespace ORO_Execution;

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

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

    bool startup() {
        return(true);
    }

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

    void shutdown() {
    }
};

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

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

    bool startup() {
        return( true );
    }

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

    }

    void shutdown() {
    }
};

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

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

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

    TaskBrowser browser( &taskGet );

    browser.loop();

    return(0);
}