More conceptual questions about the tasks

Hi,

as I can read (and understand) in the component builder's manual, there are
some functions that must be implemented in a task: configureHook, startHook,
updateHook, stopHook and cleanHook.

In general I understand configureHook, startHook, stopHook and cleanHook. But
I have some doubts about he updateHook. In the documentation and the examples
there's this comment:

// Your algorithm for periodic execution goes inhere

also I understand that this function is called in a periodic task every cicle
that it needs it. So, a periodic task of 0.01 it will be called 100 times in
a second.

In the examples, (deployment/Plant.cpp) there's no "time" consuming code. Some
calculations, and no more important. In taskstate/TaskState.cpp a simple
while :
....
while ( !rwbufPort.empty() )
rwbufPort.Pop( value );

....

so as I understand, in a periodic task, I put my periodic stuff here and the
task will execute this code every period. Ok.

But, .... in the nonPeriodic task? In my case, I need to execute an infinite
loop of a listen function of a socket. So, I launch the recvfrom , wait till
the message is received and then write it to a port.

Now I'm in a point that I don't understand what I have to put. In a "normal"
application I would create a thread with a infinite loop (for(;;)) in the way
that always would be listening. But with task?
Have I to implement something like this?

void updateHook() {
while(1) {
size = recvfrom(udpSocket, mesg, MAX_MESG_SIZE, 0,
(struct sockaddr *)&clientName, &clientLength);
if(size!=0){
analise(mesg,data);
write(data)
}
}
}

for example,

or I must put while is outside the function?

Thanks in advance,

best regards,

Leo

More conceptual questions about the tasks

On Dec 13, 2007 4:47 PM, Leopold Palomo-Avellaneda <lepalom [..] ...> wrote:
[...]
> so as I understand, in a periodic task, I put my periodic stuff here and the
> task will execute this code every period. Ok.
>
> But, .... in the nonPeriodic task? In my case, I need to execute an infinite
> loop of a listen function of a socket. So, I launch the recvfrom , wait till
> the message is received and then write it to a port.
>
> Now I'm in a point that I don't understand what I have to put. In a "normal"
> application I would create a thread with a infinite loop (for(;;)) in the way
> that always would be listening. But with task?
> Have I to implement something like this?
>
> void updateHook() {
> while(1) {
> size = recvfrom(udpSocket, mesg, MAX_MESG_SIZE, 0,
> (struct sockaddr *)&clientName, &clientLength);
> if(size!=0){
> analise(mesg,data);
> write(data)
> }
> }
> }

No, you should use the loop function for this case. See

- trunk/ocl/hardware/krypton/ for an example.
-
-

Unfortunately, as you probably have noticed, nobody ever get's that
far in the component builders manual. And note the misleading title
of that section :-).

ps1. You might file a bug for this, or even better, provide a patch to
the docs once you understood how things are working. Maintaining the
documentation is a huge job!
ps2. Looking at the API docs of TaskContext, I feel that the amount of
member functions has grown to a number that a mere mortal (Peter, you
are not a mere mortal :-) simply cannot cope with. Some people would
use the term featuritis for this, but IMO this is also something we
have to address for 2.0

regards, and thanks for your valuable feedback

Klaas

More conceptual questions about the tasks

A Dijous 13 Desembre 2007, Klaas Gadeyne va escriure:
> On Dec 13, 2007 4:47 PM, Leopold Palomo-Avellaneda <lepalom [..] ...> wrote:
> [...]
>
> > so as I understand, in a periodic task, I put my periodic stuff here and
> > the task will execute this code every period. Ok.
> >
> > But, .... in the nonPeriodic task? In my case, I need to execute an
> > infinite loop of a listen function of a socket. So, I launch the recvfrom
> > , wait till the message is received and then write it to a port.
> >
> > Now I'm in a point that I don't understand what I have to put. In a
> > "normal" application I would create a thread with a infinite loop
> > (for(;;)) in the way that always would be listening. But with task?
> > Have I to implement something like this?
> >
> > void updateHook() {
> > while(1) {
> > size = recvfrom(udpSocket, mesg, MAX_MESG_SIZE, 0,
> > (struct sockaddr *)&clientName,
> > &clientLength); if(size!=0){
> > analise(mesg,data);
> > write(data)
> > }
> > }
> > }
>
> No, you should use the loop function for this case. See
>
> - trunk/ocl/hardware/krypton/ for an example.
> -
> >1TaskCore.html#fc5559f81613fc0ac9f9717c996610ca> -
> >nents-manual.html#id2746938>
>
> Unfortunately, as you probably have noticed, nobody ever get's that
> far in the component builders manual. And note the misleading title
> of that section :-).

ummm, I begin to be so confussed. I read:

[Note] Note
In older Orocos versions, 'Activities' were named 'Tasks'.

but in some parts of the manual they are referring as tasks. So, Task =
Activity no? Really, now I'm lost.

Also, in you example you are using rt commands, and I would like to no use it.
I have always understood that orocos is a middleware about it and I don't
have to take care about this kind of things. Are you talking that I need to
control by rt semaphores (#include )?

> ps1. You might file a bug for this, or even better, provide a patch to
> the docs once you understood how things are working. Maintaining the
> documentation is a huge job!

uffffffff, if we want that orocos could survive this have to be clear and not
misleading ...

> ps2. Looking at the API docs of TaskContext, I feel that the amount of
> member functions has grown to a number that a mere mortal (Peter, you
> are not a mere mortal :-) simply cannot cope with.

I agree, Peter is not a mere mortal. ;-)

> Some people would
> use the term featuritis for this, but IMO this is also something we
> have to address for 2.0

Ok, I will try to prepare a battery of questions for the next week.

> regards, and thanks for your valuable feedback

not very valuable at all ..... :-(

Regards,

Leo

More conceptual questions about the tasks

On Dec 13, 2007 11:16 PM, Leopold Palomo Avellaneda <lepalom [..] ...> wrote:
> A Dijous 13 Desembre 2007, Klaas Gadeyne va escriure:
> > On Dec 13, 2007 4:47 PM, Leopold Palomo-Avellaneda <lepalom [..] ...> wrote:
[...]
> > > >nents-manual.html#id2746938>
> >
[...]
> ummm, I begin to be so confussed. I read:
>
> [Note] Note
> In older Orocos versions, 'Activities' were named 'Tasks'.
>
> but in some parts of the manual they are referring as tasks. So, Task =
> Activity no? Really, now I'm lost.

That note can probably disappear, since the term 'old' denotes "really
old" and no one is aware of that anymore I guess.

IIRC (but please verify this, since it's more than a year ago since I
actually used this stuff)

- Peter uses the term "Task" to denote a TaskContext (I always found
the name TaskContext to be a "dragon", but maybe that's a matter of
taste).

- Each task(context) is via its execution engine (EE) connect to an
orocos Activity. You can (=have the possibility) link several
task(context)s to 1 EE, so different tasks can rely on a single
Activity to run their EE.

- Multiple activities (and hence tasks) can (but do not have to) be
runned in one OS thread [*].

[*] To make things even more confusing, e.g. in the xenomai native
skin you should read rt_task where I wrote OS thread.

> Also, in you example you are using rt commands, and I would like to no use it.
> I have always understood that orocos is a middleware about it and I don't
> have to take care about this kind of things. Are you talking that I need to
> control by rt semaphores (#include )?

No, in that case the krypton thing is a bad example (but it was the
first place that came to my mind when I was looking for an example
that used the loop() function). However, note that you will always
have code which depends on particular OS device driver code somewhere.

Klaas

More conceptual questions about the tasks

On Friday 14 December 2007 09:40:40 Klaas Gadeyne wrote:
> On Dec 13, 2007 11:16 PM, Leopold Palomo Avellaneda <lepalom [..] ...> wrote:
> > ummm, I begin to be so confussed. I read:
> >
> > [Note] Note
> > In older Orocos versions, 'Activities' were named 'Tasks'.
> >
> > but in some parts of the manual they are referring as tasks. So, Task =
> > Activity no? Really, now I'm lost.
>
> That note can probably disappear, since the term 'old' denotes "really
> old" and no one is aware of that anymore I guess.

I've removed that note from the manual.

>
> IIRC (but please verify this, since it's more than a year ago since I
> actually used this stuff)
>
> - Peter uses the term "Task" to denote a TaskContext (I always found
> the name TaskContext to be a "dragon", but maybe that's a matter of
> taste).

I've replaced most occurences of 'task' at the beginning with the
word 'component'. And added a note later that 'task' and 'component'
are equivalent in the manual.

>
> - Each task(context) is via its execution engine (EE) connect to an
> orocos Activity. You can (=have the possibility) link several
> task(context)s to 1 EE, so different tasks can rely on a single
> Activity to run their EE.
>
> - Multiple activities (and hence tasks) can (but do not have to) be
> runned in one OS thread [*].
>
> [*] To make things even more confusing, e.g. in the xenomai native
> skin you should read rt_task where I wrote OS thread.

That's all correct.

>
> > Also, in you example you are using rt commands, and I would like to no
> > use it. I have always understood that orocos is a middleware about it and
> > I don't have to take care about this kind of things. Are you talking that
> > I need to control by rt semaphores (#include )?

Please look at my previous mail about 'sockets' to find the correct example
when you want to have the equivalent of

for (;;) {
}

in updateHook(). I also added the example of that mail to the manual:

(the 'trigger()' code is not completely in place there)

I'll also extend the previous section 'task execution' with example code which
demonstrates the periodic and non-periodic cases more clearly.

Peter

More conceptual questions about the tasks

A Divendres 21 Desembre 2007, Peter Soetens va escriure:
> On Friday 14 December 2007 09:40:40 Klaas Gadeyne wrote:
> > On Dec 13, 2007 11:16 PM, Leopold Palomo Avellaneda <lepalom [..] ...>
wrote:
> > > ummm, I begin to be so confussed. I read:
> > >
> > > [Note] Note
> > > In older Orocos versions, 'Activities' were named 'Tasks'.
> > >
> > > but in some parts of the manual they are referring as tasks. So, Task =
> > > Activity no? Really, now I'm lost.
> >
> > That note can probably disappear, since the term 'old' denotes "really
> > old" and no one is aware of that anymore I guess.
>
> I've removed that note from the manual.

ok, thank's Peter.

> > IIRC (but please verify this, since it's more than a year ago since I
> > actually used this stuff)
> >
> > - Peter uses the term "Task" to denote a TaskContext (I always found
> > the name TaskContext to be a "dragon", but maybe that's a matter of
> > taste).
>
> I've replaced most occurences of 'task' at the beginning with the
> word 'component'. And added a note later that 'task' and 'component'
> are equivalent in the manual.

Ok,

> > - Each task(context) is via its execution engine (EE) connect to an
> > orocos Activity. You can (=have the possibility) link several
> > task(context)s to 1 EE, so different tasks can rely on a single
> > Activity to run their EE.
> >
> > - Multiple activities (and hence tasks) can (but do not have to) be
> > runned in one OS thread [*].
> >
> > [*] To make things even more confusing, e.g. in the xenomai native
> > skin you should read rt_task where I wrote OS thread.
>
> That's all correct.
> > > Also, in you example you are using rt commands, and I would like to no
> > > use it. I have always understood that orocos is a middleware about it
> > > and I don't have to take care about this kind of things. Are you
> > > talking that I need to control by rt semaphores (#include
> > > )?
>
> Please look at my previous mail about 'sockets' to find the correct example
> when you want to have the equivalent of
>
> for (;;) {
> }
>
> in updateHook(). I also added the example of that mail to the manual:
> >rocos-components-manual.html#id2621596> (the 'trigger()' code is not
> completely in place there)

?
are you saying that code doesn't go there? so, where?

> I'll also extend the previous section 'task execution' with example code
> which demonstrates the periodic and non-periodic cases more clearly.

Ok,

thanks.

Leo

More conceptual questions about the tasks

On Sunday 23 December 2007 00:48:16 Leopold Palomo Avellaneda wrote:
> A Divendres 21 Desembre 2007, Peter Soetens va escriure:
> >
> > Please look at my previous mail about 'sockets' to find the correct
> > example when you want to have the equivalent of
> >
> > for (;;) {
> > }
> >
> > in updateHook(). I also added the example of that mail to the manual:
> > > >/o rocos-components-manual.html#id2621596> (the 'trigger()' code is not
> > completely in place there)
>
> ?
> are you saying that code doesn't go there? so, where?

That's not what I meant. The code is correct, but the example is a bit overly
complex to demonstrate just the state changes. I'll add another example, just
demonstrating the use of trigger(), and simplify the error states example.

Peter

More conceptual questions about the tasks

A Divendres 14 Desembre 2007 09:40, Klaas Gadeyne va escriure:
> On Dec 13, 2007 11:16 PM, Leopold Palomo Avellaneda <lepalom [..] ...> wrote:
> > A Dijous 13 Desembre 2007, Klaas Gadeyne va escriure:
> > > On Dec 13, 2007 4:47 PM, Leopold Palomo-Avellaneda <lepalom [..] ...>
> > > wrote:
>
> [...]
>
> > > > > >ompo nents-manual.html#id2746938>
>
> [...]
>
> > ummm, I begin to be so confussed. I read:
> >
> > [Note] Note
> > In older Orocos versions, 'Activities' were named 'Tasks'.
> >
> > but in some parts of the manual they are referring as tasks. So, Task =
> > Activity no? Really, now I'm lost.
>
> That note can probably disappear, since the term 'old' denotes "really
> old" and no one is aware of that anymore I guess.

ok, I think that I should begin to fill some bugs about the documentation ....

> IIRC (but please verify this, since it's more than a year ago since I
> actually used this stuff)
> - Peter uses the term "Task" to denote a TaskContext (I always found
> the name TaskContext to be a "dragon", but maybe that's a matter of
> taste).

but in same parts of the documentations they use tasks not as taskcontext, I
think .....

> - Each task(context) is via its execution engine (EE) connect to an
> orocos Activity. You can (=have the possibility) link several
> task(context)s to 1 EE, so different tasks can rely on a single
> Activity to run their EE.

yes, create an activity and then "link" a task.

> - Multiple activities (and hence tasks) can (but do not have to) be
> runned in one OS thread [*].
>
> [*] To make things even more confusing, e.g. in the xenomai native
> skin you should read rt_task where I wrote OS thread.

uffffff I must read it again ...

> > Also, in you example you are using rt commands, and I would like to no
> > use it. I have always understood that orocos is a middleware about it and
> > I don't have to take care about this kind of things. Are you talking that
> > I need to control by rt semaphores (#include )?
>
> No, in that case the krypton thing is a bad example (but it was the
> first place that came to my mind when I was looking for an example
> that used the loop() function). However, note that you will always
> have code which depends on particular OS device driver code somewhere.

Ok,

thanks.

Regards,

Leo