Hi,
I want to implement a new EEHook function that send events to my component
FSM.
I wrote a file with the hook function:
local target_in = rttlib.port_clone_conn(detection:getPort("target"))
rtt.getTC():addPort(target_in)
function target_detection()
local fs, target = target_in:read()
if fs == "NewData" then
rtt.logl("Warning", "Target detected " .. tostring(target))
rfsm.send_events(fsm, 'e_abort')
report_out:write("CIBLE_LOCALISEE")
end
return true
end
And then in my component script, I have done:
tc:exec_file("hooks.lua")
ee_td_hook = rtt.EEHook('target_detection')
ee_td_hook:enable()
Creating my component works.
When I write something in the 'target' port, the 'if' part of
target_detection raises an error:
> tgt:write(state)
> 7.310 [ Warning][rttlua-gnulinux::main()] Target detected
{phi=0,cpt=0,h=0,ax=0,ts_rem_alt=0,q=0,p=0,wp=0,ts_rem_nav=0,theta=0,ts=0,ay=0,r=0,phase=0,ts_rem_gps=0,ts_ref=0,az=0,y=0,x=0,id=0,z=0,vz=0,psi=0,vx=0,vy=0}
7.310 [ ERROR ][rttlua-gnulinux::main()] LuaComponent 'HiDDeN': error
calling function target_detection:
/home/lesire/work/orocos/rFSM/utils.lua:371: table index is nil
This error comes from the rfsm.send_events function.
What am I doing wrong?
Charles.
RTTLua: EEHook and rFSM
Hi Charles,
On Tue, Jun 19, 2012 at 06:22:05PM +0200, Charles Lesire-Cabaniols wrote:
>
> I want to implement a new EEHook function that send events to my component FSM.
>
> I wrote a file with the hook function:
>
> local target_in = rttlib.port_clone_conn(detection:getPort("target"))
> rtt.getTC():addPort(target_in)
> function target_detection()
> local fs, target = target_in:read()
> if fs == "NewData" then
> rtt.logl("Warning", "Target detected " .. tostring(target))
> rfsm.send_events(fsm, 'e_abort')
> report_out:write("CIBLE_LOCALISEE")
> end
> return true
> end
>
> And then in my component script, I have done:
>
> tc:exec_file("hooks.lua")
Who is tc? The current component? If yes, why don't you just put the
target_detection code in the updateHook?
> ee_td_hook = rtt.EEHook('target_detection')
> ee_td_hook:enable()
The original usecase of EEHook was to piggyback an rFSM running in a
Lua Service on a C++ component, though I don't see why it should not
work directly on a component.
> Creating my component works.
> When I write something in the 'target' port, the 'if' part of target_detection
> raises an error:
>
> > tgt:write(state)
> > 7.310 [ Warning][rttlua-gnulinux::main()] Target detected {phi=0,cpt=0,h=0,ax
> =0,ts_rem_alt=0,q=0,p=0,wp=0,ts_rem_nav=0,theta=0,ts=0,ay=0,r=0,phase=
> 0,ts_rem_gps=0,ts_ref=0,az=0,y=0,x=0,id=0,z=0,vz=0,psi=0,vx=0,vy=0}
> 7.310 [ ERROR ][rttlua-gnulinux::main()] LuaComponent 'HiDDeN': error calling
> function target_detection: /home/lesire/work/orocos/rFSM/utils.lua:371: table
> index is nil
Which rFSM commit are you on? (git show --stat HEAD)
> This error comes from the rfsm.send_events function.
How do you infer that?
> What am I doing wrong?
No clue so far...
Markus
RTTLua: EEHook and rFSM
2012/6/19 Markus Klotzbuecher <markus [dot] klotzbuecher [..] ...>
> Hi Charles,
>
> On Tue, Jun 19, 2012 at 06:22:05PM +0200, Charles Lesire-Cabaniols wrote:
> >
> > I want to implement a new EEHook function that send events to my
> component FSM.
> >
> > I wrote a file with the hook function:
> >
> > local target_in = rttlib.port_clone_conn(detection:getPort("target"))
> > rtt.getTC():addPort(target_in)
> > function target_detection()
> > local fs, target = target_in:read()
> > if fs == "NewData" then
> > rtt.logl("Warning", "Target detected " .. tostring(target))
> > rfsm.send_events(fsm, 'e_abort')
> > report_out:write("CIBLE_LOCALISEE")
> > end
> > return true
> > end
> >
> > And then in my component script, I have done:
> >
> > tc:exec_file("hooks.lua")
>
> Who is tc? The current component? If yes, why don't you just put the
> target_detection code in the updateHook?
>
tc is effectively the LuaComponent I am creating.
This design comes from the time I was entending an existing component...
now this component is completely in Lua, I could hence try to move all
functions to the update hook part.
>
> > ee_td_hook = rtt.EEHook('target_detection')
> > ee_td_hook:enable()
>
> The original usecase of EEHook was to piggyback an rFSM running in a
> Lua Service on a C++ component, though I don't see why it should not
> work directly on a component.
>
> > Creating my component works.
> > When I write something in the 'target' port, the 'if' part of
> target_detection
> > raises an error:
> >
> > > tgt:write(state)
> > > 7.310 [ Warning][rttlua-gnulinux::main()] Target detected
> {phi=0,cpt=0,h=0,ax
> > =0,ts_rem_alt=0,q=0,p=0,wp=0,ts_rem_nav=0,theta=0,ts=0,ay=0,r=0,phase=
> > 0,ts_rem_gps=0,ts_ref=0,az=0,y=0,x=0,id=0,z=0,vz=0,psi=0,vx=0,vy=0}
> > 7.310 [ ERROR ][rttlua-gnulinux::main()] LuaComponent 'HiDDeN': error
> calling
> > function target_detection: /home/lesire/work/orocos/rFSM/utils.lua:371:
> table
> > index is nil
>
> Which rFSM commit are you on? (git show --stat HEAD)
>
899c754c05cbbf2611d1b1c8f42593a96ece90fc
>
> > This error comes from the rfsm.send_events function.
>
> How do you infer that?
>
Commenting the rfsm.send_events line cause no error.
>
> > What am I doing wrong?
>
> No clue so far...
>
> Markus
>
>
>
RTTLua: EEHook and rFSM
On Tue, Jun 19, 2012 at 09:50:49PM +0200, Charles Lesire-Cabaniols wrote:
>
>
> 2012/6/19 Markus Klotzbuecher <markus [dot] klotzbuecher [..] ...>
>
> Hi Charles,
>
> On Tue, Jun 19, 2012 at 06:22:05PM +0200, Charles Lesire-Cabaniols wrote:
> >
> > I want to implement a new EEHook function that send events to my
> component FSM.
> >
> > I wrote a file with the hook function:
> >
> > local target_in = rttlib.port_clone_conn(detection:getPort("target"))
> > rtt.getTC():addPort(target_in)
> > function target_detection()
> > local fs, target = target_in:read()
> > if fs == "NewData" then
> > rtt.logl("Warning", "Target detected " .. tostring(target))
> > rfsm.send_events(fsm, 'e_abort')
> > report_out:write("CIBLE_LOCALISEE")
> > end
> > return true
> > end
> >
> > And then in my component script, I have done:
> >
> > tc:exec_file("hooks.lua")
>
> Who is tc? The current component? If yes, why don't you just put the
> target_detection code in the updateHook?
>
>
> tc is effectively the LuaComponent I am creating.
> This design comes from the time I was entending an existing component... now
> this component is completely in Lua, I could hence try to move all functions to
> the update hook part.
Ok, still what you try seems ok.
> > ee_td_hook = rtt.EEHook('target_detection')
> > ee_td_hook:enable()
>
> The original usecase of EEHook was to piggyback an rFSM running in a
> Lua Service on a C++ component, though I don't see why it should not
> work directly on a component.
>
> > Creating my component works.
> > When I write something in the 'target' port, the 'if' part of
> target_detection
> > raises an error:
> >
> > > tgt:write(state)
> > > 7.310 [ Warning][rttlua-gnulinux::main()] Target detected {phi=0,cpt=
> 0,h=0,ax
> > =0,ts_rem_alt=0,q=0,p=0,wp=0,ts_rem_nav=0,theta=0,ts=0,ay=0,r=0,phase=
> > 0,ts_rem_gps=0,ts_ref=0,az=0,y=0,x=0,id=0,z=0,vz=0,psi=0,vx=0,vy=0}
> > 7.310 [ ERROR ][rttlua-gnulinux::main()] LuaComponent 'HiDDeN': error
> calling
> > function target_detection: /home/lesire/work/orocos/rFSM/utils.lua:371:
> table
> > index is nil
>
> Which rFSM commit are you on? (git show --stat HEAD)
>
>
> 899c754c05cbbf2611d1b1c8f42593a96ece90fc
Thanks.
> > This error comes from the rfsm.send_events function.
>
> How do you infer that?
>
>
> Commenting the rfsm.send_events line cause no error.
Ok, It seems that the 'fsm' arg to send_events is nil. You omit the
code where fsm comes from, hence could you verify that value
(ie. print("fsm:", fsm) before the send_events?
Markus
RTTLua: EEHook and rFSM
2012/6/19 Markus Klotzbuecher <markus [dot] klotzbuecher [..] ...>
> On Tue, Jun 19, 2012 at 09:50:49PM +0200, Charles Lesire-Cabaniols wrote:
> >
> >
> > 2012/6/19 Markus Klotzbuecher <markus [dot] klotzbuecher [..] ...>
> >
> > Hi Charles,
> >
> > On Tue, Jun 19, 2012 at 06:22:05PM +0200, Charles Lesire-Cabaniols
> wrote:
> > >
> > > I want to implement a new EEHook function that send events to my
> > component FSM.
> > >
> > > I wrote a file with the hook function:
> > >
> > > local target_in =
> rttlib.port_clone_conn(detection:getPort("target"))
> > > rtt.getTC():addPort(target_in)
> > > function target_detection()
> > > local fs, target = target_in:read()
> > > if fs == "NewData" then
> > > rtt.logl("Warning", "Target detected " .. tostring(target))
> > > rfsm.send_events(fsm, 'e_abort')
> > > report_out:write("CIBLE_LOCALISEE")
> > > end
> > > return true
> > > end
> > >
> > > And then in my component script, I have done:
> > >
> > > tc:exec_file("hooks.lua")
> >
> > Who is tc? The current component? If yes, why don't you just put the
> > target_detection code in the updateHook?
> >
> >
> > tc is effectively the LuaComponent I am creating.
> > This design comes from the time I was entending an existing component...
> now
> > this component is completely in Lua, I could hence try to move all
> functions to
> > the update hook part.
>
> Ok, still what you try seems ok.
>
> > > ee_td_hook = rtt.EEHook('target_detection')
> > > ee_td_hook:enable()
> >
> > The original usecase of EEHook was to piggyback an rFSM running in a
> > Lua Service on a C++ component, though I don't see why it should not
> > work directly on a component.
> >
> > > Creating my component works.
> > > When I write something in the 'target' port, the 'if' part of
> > target_detection
> > > raises an error:
> > >
> > > > tgt:write(state)
> > > > 7.310 [ Warning][rttlua-gnulinux::main()] Target detected
> {phi=0,cpt=
> > 0,h=0,ax
> > >
> =0,ts_rem_alt=0,q=0,p=0,wp=0,ts_rem_nav=0,theta=0,ts=0,ay=0,r=0,phase=
> > > 0,ts_rem_gps=0,ts_ref=0,az=0,y=0,x=0,id=0,z=0,vz=0,psi=0,vx=0,vy=0}
> > > 7.310 [ ERROR ][rttlua-gnulinux::main()] LuaComponent 'HiDDeN':
> error
> > calling
> > > function target_detection:
> /home/lesire/work/orocos/rFSM/utils.lua:371:
> > table
> > > index is nil
> >
> > Which rFSM commit are you on? (git show --stat HEAD)
> >
> >
> > 899c754c05cbbf2611d1b1c8f42593a96ece90fc
>
> Thanks.
>
> > > This error comes from the rfsm.send_events function.
> >
> > How do you infer that?
> >
> >
> > Commenting the rfsm.send_events line cause no error.
>
> Ok, It seems that the 'fsm' arg to send_events is nil. You omit the
> code where fsm comes from, hence could you verify that value
> (ie. print("fsm:", fsm) before the send_events?
>
Effectively, I have tried to directly call target_detection from updateHook
instead of using EEHook.
I first encountered the same issue.
When passing 'fsm' as an argument of the function, it works.
fsm is declared local in the file that defines my component hooks. Code
snippet of component.lua:
require ...
local tc = rtt.getTC()
local fsm
function configureHook()
...
fsm = rfsm.init(rfsm.load("fsm.lua"))
...
end
function updateHook()
...
target_detection(fsm)
...
end
The EEHook part was previously in configureHook, tried before and after the
rfsm.init call.
>
> Markus
>
RTTLua: EEHook and rFSM
On Wed, Jun 20, 2012 at 08:11:54AM +0200, Charles Lesire-Cabaniols wrote:
>
>
> 2012/6/19 Markus Klotzbuecher <markus [dot] klotzbuecher [..] ...>
>
> On Tue, Jun 19, 2012 at 09:50:49PM +0200, Charles Lesire-Cabaniols wrote:
> >
> >
> > 2012/6/19 Markus Klotzbuecher <markus [dot] klotzbuecher [..] ...>
> >
> > Hi Charles,
> >
> > On Tue, Jun 19, 2012 at 06:22:05PM +0200, Charles Lesire-Cabaniols
> wrote:
> > >
> > > I want to implement a new EEHook function that send events to my
> > component FSM.
> > >
> > > I wrote a file with the hook function:
> > >
> > > local target_in = rttlib.port_clone_conn(detection:getPort
> ("target"))
> > > rtt.getTC():addPort(target_in)
> > > function target_detection()
> > > local fs, target = target_in:read()
> > > if fs == "NewData" then
> > > rtt.logl("Warning", "Target detected " .. tostring(target))
> > > rfsm.send_events(fsm, 'e_abort')
> > > report_out:write("CIBLE_LOCALISEE")
> > > end
> > > return true
> > > end
> > >
> > > And then in my component script, I have done:
> > >
> > > tc:exec_file("hooks.lua")
> >
> > Who is tc? The current component? If yes, why don't you just put the
> > target_detection code in the updateHook?
> >
> >
> > tc is effectively the LuaComponent I am creating.
> > This design comes from the time I was entending an existing component...
> now
> > this component is completely in Lua, I could hence try to move all
> functions to
> > the update hook part.
>
> Ok, still what you try seems ok.
>
> > > ee_td_hook = rtt.EEHook('target_detection')
> > > ee_td_hook:enable()
> >
> > The original usecase of EEHook was to piggyback an rFSM running in a
> > Lua Service on a C++ component, though I don't see why it should not
> > work directly on a component.
> >
> > > Creating my component works.
> > > When I write something in the 'target' port, the 'if' part of
> > target_detection
> > > raises an error:
> > >
> > > > tgt:write(state)
> > > > 7.310 [ Warning][rttlua-gnulinux::main()] Target detected {phi=
> 0,cpt=
> > 0,h=0,ax
> > > =0,ts_rem_alt=0,q=0,p=0,wp=0,ts_rem_nav=0,theta=0,ts=0,ay=0,r=
> 0,phase=
> > > 0,ts_rem_gps=0,ts_ref=0,az=0,y=0,x=0,id=0,z=0,vz=0,psi=0,vx=0,vy=0}
> > > 7.310 [ ERROR ][rttlua-gnulinux::main()] LuaComponent 'HiDDeN':
> error
> > calling
> > > function target_detection: /home/lesire/work/orocos/rFSM/
> utils.lua:371:
> > table
> > > index is nil
> >
> > Which rFSM commit are you on? (git show --stat HEAD)
> >
> >
> > 899c754c05cbbf2611d1b1c8f42593a96ece90fc
>
> Thanks.
>
> > > This error comes from the rfsm.send_events function.
> >
> > How do you infer that?
> >
> >
> > Commenting the rfsm.send_events line cause no error.
>
> Ok, It seems that the 'fsm' arg to send_events is nil. You omit the
> code where fsm comes from, hence could you verify that value
> (ie. print("fsm:", fsm) before the send_events?
>
>
> Effectively, I have tried to directly call target_detection from updateHook
> instead of using EEHook.
> I first encountered the same issue.
>
> When passing 'fsm' as an argument of the function, it works.
>
> fsm is declared local in the file that defines my component hooks. Code snippet
> of component.lua:
These are the intricacies of lexical scoping in the context of
exec_file. If you declare a variable local the scope is only the
calling context of exec_file. Hence, the fsm variable below will be
garbage collected some time after the call finishes. But when you pass
it as an argument to target_detection you are creating a closure that
references fsm and hence prevents garbage collection. If you don't
care about this, the easiest solution is to make fsm (and tc) global.
> require ...
>
> local tc = rtt.getTC()
> local fsm
>
> function configureHook()
> ...
> fsm = rfsm.init(rfsm.load("fsm.lua"))
> ...
> end
>
> function updateHook()
> ...
> target_detection(fsm)
> ...
> end
>
> The EEHook part was previously in configureHook, tried before and after the
> rfsm.init call.
Does this fix you problem?
Markus