[ros-users] roslua: creating messages with subtypes
Markus Klotzbuecher
markus.klotzbuecher at mech.kuleuven.be
Mon Feb 21 16:32:21 UTC 2011
Dear List,
I just gave roslua a try and its working quite nicely. One smaller
problem I noticed is when printing some array types:
$ lua -lroslua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> twist = roslua.get_msgspec("geometry_msgs/Twist")
> t=twist:instantiate()
> t:print()
geometry_msgs/Twist
/home/mk/src/git/lua/roslua/src/roslua/msg_spec.lua:53: attempt to call method 'find' (a nil value)
stack traceback:
/home/mk/src/git/lua/roslua/src/roslua/msg_spec.lua:53: in function 'is_array_type'
/home/mk/src/git/lua/roslua/src/roslua/message.lua:259: in function 'print_value'
/home/mk/src/git/lua/roslua/src/roslua/message.lua:285: in function 'print'
stdin:1: in main chunk
[C]: ?
>
Secondly I wondered if there is a more compact way to create messages
which contain submessages. For instance to create and fill a
"geometry_msgs/Twist" I did the following:
local Vector3=roslua.get_msgspec("geometry_msgs/Vector3")
local m = p.msgspec:instantiate() -- geometry_msgs/Twist message
local vec3lin = Vector3:instantiate()
local vec3ang = Vector3:instantiate()
vec3lin.values.x=x
vec3lin.values.y=y
vec3lin.values.z=z
vec3ang.values.x=xang
vec3ang.values.y=yang
vec3ang.values.z=zang
m.values.linear = vec3lin
m.values.angular = vec3ang
Before that I tried
m.values.linear.x = x
m.values.linear.y = y
...
but this didn't work.
Thanks in advance!
Markus
More information about the ros-users
mailing list