rttlua and vector parameters

I have an Orocos component with a method that takes an vector input:
void SetReference(const std::vector<double>& val);

When using the Deployer (or an ops script), I can make a call to that method via:
> var array ref = array(1.0, 1.0, 10.0)
= { [1, 1, 10 ], size = 3, capacity = 3 }
> SimpleController.SetReference(ref)
ref[0] = 1.000000
ref[1] = 1.000000
ref[2] = 10.000000
= (void)
But, when I try using rttlua (or a lua script), I get the following error:
> ref = {1.0, 1.0, 10.0}
> simpleController:SetReference(ref)
/opt/ros/diamondback/stacks/orocos_toolchain_ros/ocl/bin/rttlua-xenomai: ...acks/orocos_toolchain_ros/ocl/lua/modules/rttlib.lua:538: __lua_todsb: can't convert lua table to float64[] variable
stack traceback: [C]:
in function 'call' ...acks/orocos_toolchain_ros/ocl/lua/modules/rttlib.lua:538: in function 'SetReference'
lua_deploy.lua:103: in main chunk
[C]: ?

So, how do I send a vector input to a component's method from rttlua?

--
Dustin Gooding
NASA/JSC Robotics

rttlua and vector parameters

Hi Dustin,

On Tue, Sep 20, 2011 at 04:39:29PM +0200, Gooding, Dustin R. (JSC-ER411) wrote:
> I have an Orocos component with a method that takes an vector input:
> void SetReference(const std::vector<double>& val);
>
> When using the Deployer (or an ops script), I can make a call to that method
> via:
> > var array ref = array(1.0, 1.0, 10.0)
> = { [1, 1, 10 ], size = 3, capacity = 3 }
> > SimpleController.SetReference(ref)
> ref[0] = 1.000000
> ref[1] = 1.000000
> ref[2] = 10.000000
> = (void)
> But, when I try using rttlua (or a lua script), I get the following error:
> > ref = {1.0, 1.0, 10.0}
> > simpleController:SetReference(ref)

You are calling an operation with a table. Currently there is no automatic
conversion from tables to RTT types, so you have to do it manually:

ref=rtt.Variable("array")
ref:resize(3)
ref:fromtab{1,1,10}

print(ref) -- prints {1,1,10}
simpleController:SetReference(ref) -- should work now.

> /opt/ros/diamondback/stacks/orocos_toolchain_ros/ocl/bin/rttlua-xenomai:
> ...acks/orocos_toolchain_ros/ocl/lua/modules/rttlib.lua:538: __lua_todsb: can't
> convert lua table to float64[] variable
> stack traceback: [C]:
> in function 'call' ...acks/orocos_toolchain_ros/ocl/lua/modules/rttlib.lua:538:
> in function 'SetReference'
> lua_deploy.lua:103: in main chunk
> [C]: ?
>
> So, how do I send a vector input to a component's method from rttlua?

Does above work for you?
Markus

rttlua and vector parameters

On Sep 20, 2011, at 10:03 AM, Markus Klotzbuecher wrote:

> Hi Dustin,
>
> On Tue, Sep 20, 2011 at 04:39:29PM +0200, Gooding, Dustin R. (JSC-ER411) wrote:
>> I have an Orocos component with a method that takes an vector input:
>> void SetReference(const std::vector<double>& val);
>>
>> When using the Deployer (or an ops script), I can make a call to that method
>> via:
>>> var array ref = array(1.0, 1.0, 10.0)
>> = { [1, 1, 10 ], size = 3, capacity = 3 }
>>> SimpleController.SetReference(ref)
>> ref[0] = 1.000000
>> ref[1] = 1.000000
>> ref[2] = 10.000000
>> = (void)
>> But, when I try using rttlua (or a lua script), I get the following error:
>>> ref = {1.0, 1.0, 10.0}
>>> simpleController:SetReference(ref)
>
> You are calling an operation with a table. Currently there is no automatic
> conversion from tables to RTT types, so you have to do it manually:
>
> ref=rtt.Variable("array")
> ref:resize(3)
> ref:fromtab{1,1,10}
>
> print(ref) -- prints {1,1,10}
> simpleController:SetReference(ref) -- should work now.
>
>> /opt/ros/diamondback/stacks/orocos_toolchain_ros/ocl/bin/rttlua-xenomai:
>> ...acks/orocos_toolchain_ros/ocl/lua/modules/rttlib.lua:538: __lua_todsb: can't
>> convert lua table to float64[] variable
>> stack traceback: [C]:
>> in function 'call' ...acks/orocos_toolchain_ros/ocl/lua/modules/rttlib.lua:538:
>> in function 'SetReference'
>> lua_deploy.lua:103: in main chunk
>> [C]: ?
>>
>> So, how do I send a vector input to a component's method from rttlua?
>
> Does above work for you?
> Markus
>

Thank you, Markus. Yes it does.

-dustin