Periodic Activity

Hi all, I have an periodic activity running on my app. and I'd like to
change it's period during execution time in order to set an PWM on my
board. Is it possible?

Thanks,
Breno

Periodic Activity

On Fri, Nov 27, 2009 at 14:16, <breno [..] ...> wrote:
> Hi all, I have an periodic activity running on my app. and I'd like to
> change it's period during execution time in order to set an PWM on my
> board. Is it possible?

Hi Breno,

The best way to do this is to use an RTT::Activity, which can change
its frequency during run-time (RTT 1.10). Unfortunately (as discussed
earlier on this list), you need to change the frequency of the
underlying thread, instead of on the activity object itself. From
within a TaskContext, write:

this->getActivity()->thread()->setPeriod( new_period_in_sec );

Would that work for you ?

Peter

Periodic Activity

> On Fri, Nov 27, 2009 at 14:16, <breno [..] ...> wrote:
>> Hi all, I have an periodic activity running on my app. and I'd like to
>> change it's period during execution time in order to set an PWM on my
>> board. Is it possible?
>
> Hi Breno,
>
> The best way to do this is to use an RTT::Activity, which can change
> its frequency during run-time (RTT 1.10). Unfortunately (as discussed
> earlier on this list), you need to change the frequency of the
> underlying thread, instead of on the activity object itself. From
> within a TaskContext, write:
>
>

> this->getActivity()->thread()->setPeriod( new_period_in_sec );
> 

>
> Would that work for you ?
>
> Peter
>

Hi, thanks for your support!!!

I did an simple example in order to test some commands from API.

I'm posting my code below, I hope you get it through. If you have any
suggestion to do it in a better way let me know, please.

CODE START:

class AtividadePeriodica
: public Activity
{
protected:

public :AtividadePeriodica()
: Activity(1,5)
{
}

void initialized() {
// Your algorithm for periodic execution goes inhere
log(Info) << "Initialized" <<endlog();
}
void step() {
// Your algorithm for periodic execution goes inhere
log(Info) << "Step" < }

};

class World
: public RTT::TaskContext
{
protected:
Method

void changeperiod(double period)
{
activity->setPeriod(period);
}

private:
AtividadePeriodica * activity;

public:World(std::string name)
: TaskContext(name, PreOperational),
Changer("Change", &World::changeperiod, this)
{

activity = new AtividadePeriodica();

assert( Changer.ready() );

this->methods()->addMethod(&Changer,"Method","Period","New Period");
}

bool configureHook()
{
Logger::In in("World");
// Lookup the Hello component.

//activity->setActivity( new Activity( 5, 5 ));
activity->start();

return true;

}
void updateHook()
{
activity->stop();

}

};

CODE FINISH

So then, when i call the method Change from World Browser I can change the
period. I realized also that it takes some noticeable time to get it done,
I mean, to change the period effectively.

I'm using RTT 1.10.0

Case you have any sgg,

Thanks

Breno

Periodic Activity

On Mon, Nov 30, 2009 at 19:26, <breno [..] ...> wrote:
>> On Fri, Nov 27, 2009 at 14:16,  <breno [..] ...> wrote:
>>> Hi all, I have an periodic activity running on my app. and I'd like to
>>> change it's period during execution time in order to set an PWM on my
>>> board. Is it possible?
>>
>> Hi Breno,
>>
>> The best way to do this is to use an RTT::Activity, which can change
>> its frequency during run-time (RTT 1.10). Unfortunately (as discussed
>> earlier on this list), you need to change the frequency of the
>> underlying thread, instead of on the activity object itself. From
>> within a TaskContext, write:
>>
>>

>> this->getActivity()->thread()->setPeriod( new_period_in_sec );
>> 

>>
>> Would that work for you ?
>>
>> Peter
>>
>
>
> Hi, thanks for your support!!!
>
> I did an simple example in order to test some commands from API.
>
> I'm posting my code below, I hope you get it through. If you have any
> suggestion to do it in a better way let me know, please.

The code below is not what we had in mind. Most users don't override Activity or
implement ActivityInterface. All your code goes into updateHook() etc.
It *is* possible
as you write it, but it beats the purpose of having updateHook().
Also, the stop() in updateHook()
is very suspect, I would at least expect it in stopHook().

What you had to do was:

class MyTask : public TaskContext
{
protected:
        Method<void(double)> Changer;
 
        void changeperiod(double period)
                 {
                         this->getActivity()->thread()->setPeriod(period);
                 }
public:
     MyTask() : TaskContext("MyTask"),
        Changer("Change", &World::changeperiod, this)
    {
           this->methods()->addMethod(&Changer,"Method","Period","New Period");
           this->setActivity( new Activity(ORO_SCHED_RT,5) ); // priority=5
    }
 
    void updateHook()
    {
                // your code for periodic execution goes here.
    }
};

On some operating systems, the new period is only picked up after the
sleeping is done. So you get most of the time a delay of 1 'old'
sample. We probably can improve this in the fosi/Thread.cpp
implementation.

Peter

Periodic Activity

> On Mon, Nov 30, 2009 at 19:26, <breno [..] ...> wrote:
>>> On Fri, Nov 27, 2009 at 14:16,  <breno [..] ...> wrote:
>>>> Hi all, I have an periodic activity running on my app. and I'd like to
>>>> change it's period during execution time in order to set an PWM on my
>>>> board. Is it possible?
>>>
>>> Hi Breno,
>>>
>>> The best way to do this is to use an RTT::Activity, which can change
>>> its frequency during run-time (RTT 1.10). Unfortunately (as discussed
>>> earlier on this list), you need to change the frequency of the
>>> underlying thread, instead of on the activity object itself. From
>>> within a TaskContext, write:
>>>
>>>

>>> this->getActivity()->thread()->setPeriod( new_period_in_sec );
>>> 

>>>
>>> Would that work for you ?
>>>
>>> Peter
>>>
>>
>>
>> Hi, thanks for your support!!!
>>
>> I did an simple example in order to test some commands from API.
>>
>> I'm posting my code below, I hope you get it through. If you have any
>> suggestion to do it in a better way let me know, please.
>
> The code below is not what we had in mind. Most users don't override
> Activity or
> implement ActivityInterface. All your code goes into updateHook() etc.
> It *is* possible
> as you write it, but it beats the purpose of having updateHook().
> Also, the stop() in updateHook()
> is very suspect, I would at least expect it in stopHook().
>
> What you had to do was:
>
>
> class MyTask : public TaskContext
> {
> protected:
>         Method<void(double)> Changer;
>
>         void changeperiod(double period)
>                  {
>                          this->getActivity()->thread()->setPeriod(period);
>                  }
> public:
>      MyTask() : TaskContext("MyTask"),
>         Changer("Change", &World::changeperiod, this)
>     {
>            this->methods()->addMethod(&Changer,"Method","Period","New
> Period");
>            this->setActivity( new Activity(ORO_SCHED_RT,5) ); //
> priority=5
>     }
>
>     void updateHook()
>     {
>                 // your code for periodic execution goes here.
>     }
> };
>
> 

>
> On some operating systems, the new period is only picked up after the
> sleeping is done. So you get most of the time a delay of 1 'old'
> sample. We probably can improve this in the fosi/Thread.cpp
> implementation.
>
> Peter
>
Absolutely perfect!!! Thanks a lot for all observations!

Breno