Using port_clone_conn

Hi,

In the Supervisor I defined the following function (which is used as a
guard for the fsm):

above_force_thres=function()
msr = rttlib.port_clone_conn(CartImpCtrl:getPort("force_thres_ex"))
fs, tmp_force_thres_ex = msr:read()
print("tmp_force_thres_ex: ",tmp_force_thres_ex)
return tmp_force_thres_ex
end

This function is supposed to the check a boolean output port of a
CartesianImpedanceController component. The printing function is there just
for me to check the value of tmp_force_thres_ex online, and it shows that
this values remains false. However, when doing from the taskbrowser:

> msr = rttlib.port_clone_conn(CartImpCtrl:getPort("force_thres_ex"))
> fs, tmp_force_thres_ex = msr:read()
> =tmp_force_thres_ex

I can see that it does become true at some point. Why is my function not
properly working?

Thanks,

Bert

Using port_clone_conn

On Wed, Dec 12, 2012 at 3:50 PM, Bert Willaert
<bert [dot] willaert [..] ...> wrote:
> Hi,
>
> In the Supervisor I defined the following function (which is used as a guard
> for the fsm):
>
> above_force_thres=function()
> msr = rttlib.port_clone_conn(CartImpCtrl:getPort("force_thres_ex"))
> fs, tmp_force_thres_ex = msr:read()
> print("tmp_force_thres_ex: ",tmp_force_thres_ex)
> return tmp_force_thres_ex
> end
>
> This function is supposed to the check a boolean output port of a
> CartesianImpedanceController component. The printing function is there just
> for me to check the value of tmp_force_thres_ex online, and it shows that
> this values remains false. However, when doing from the taskbrowser:
>
>> msr = rttlib.port_clone_conn(CartImpCtrl:getPort("force_thres_ex"))
>> fs, tmp_force_thres_ex = msr:read()
>> =tmp_force_thres_ex
>
> I can see that it does become true at some point. Why is my function not
> properly working?

My guess is that you clone the port, but the odds that a write
happened between the clone and the read are very low.

You should create the port clone outside the function such that each
write will be 'stored' until you read it.

An alternative is to work with the ConnPolicy and let it initialize
the connection, but just cloning a port *every time* is very expensive
and might even be a memleak in lua environments.

Peter

Using port_clone_conn

On Wed, Dec 12, 2012 at 04:05:22PM +0100, Peter Soetens wrote:
> On Wed, Dec 12, 2012 at 3:50 PM, Bert Willaert
> <bert [dot] willaert [..] ...> wrote:
> > Hi,
> >
> > In the Supervisor I defined the following function (which is used as a guard
> > for the fsm):
> >
> > above_force_thres=function()
> > msr = rttlib.port_clone_conn(CartImpCtrl:getPort("force_thres_ex"))
> > fs, tmp_force_thres_ex = msr:read()
> > print("tmp_force_thres_ex: ",tmp_force_thres_ex)
> > return tmp_force_thres_ex
> > end
> >
> > This function is supposed to the check a boolean output port of a
> > CartesianImpedanceController component. The printing function is there just
> > for me to check the value of tmp_force_thres_ex online, and it shows that
> > this values remains false. However, when doing from the taskbrowser:
> >
> >> msr = rttlib.port_clone_conn(CartImpCtrl:getPort("force_thres_ex"))
> >> fs, tmp_force_thres_ex = msr:read()
> >> =tmp_force_thres_ex
> >
> > I can see that it does become true at some point. Why is my function not
> > properly working?
>
> My guess is that you clone the port, but the odds that a write
> happened between the clone and the read are very low.
>
> You should create the port clone outside the function such that each
> write will be 'stored' until you read it.
>
> An alternative is to work with the ConnPolicy and let it initialize
> the connection, but just cloning a port *every time* is very expensive
> and might even be a memleak in lua environments.

The way it is done above it is! Ports and Properties are _not_ garbage
collected, hence they must be destroyed in some way. See
http://www.orocos.org/wiki/orocos/toolchain/LuaCookbook#toc61

Markus