Ask Your Question
0

One-line object declaration in rospy

asked 2017-10-31 19:56:27 -0500

Ravi Joshi gravatar image

Hi, Is it possible to declare Marker from visualization_msgs.msg in one line? Below is my code:

from std_msgs.msg import ColorRGBA
from visualization_msgs.msg import Marker

red   = ColorRGBA(0.98, 0.30, 0.30, 1.00)
fixed_frame = 'base'

my_marker = Marker()
my_marker.id  = 0
my_marker.ns = 'my_marker'
my_marker.color = red
my_marker.action = Marker.ADD
my_marker.type = Marker.LINE_STRIP
my_marker.scale.x = float(line_width)
my_marker.header.stamp = time
my_marker.header.frame_id = fixed_frame

I am using ROS Indigo in Ubuntu 14.04 LTS PC.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-10-31 21:10:41 -0500

Ed Venator gravatar image

According to this page on the wiki, you can use in-order or keyword arguments to initialize the values during construction. Your code would then look like this:

from geometry_msgs.msg import Pose
from std_msgs.msg import ColorRGBA, Header
from visualization_msgs.msg import Marker

red   = ColorRGBA(0.98, 0.30, 0.30, 1.00)
fixed_frame = 'base'
my_marker = Marker(id  = 0,
                   ns = 'my_marker',
                   color = red,
                   action = Marker.ADD,
                   type = Marker.LINE_STRIP,
                   scale = Pose(x=float(line_width)),
                   header = Header(stamp = time, frame_id = fixed_frame))

If you're generating a lot of markers, you might want to look at David Lu!!'s easy_markers package.

edit flag offensive delete link more

Comments

2

Which really doesn't look that different from the "multi-line" initialisation style :)

gvdhoorn gravatar image gvdhoorn  ( 2017-11-01 03:38:17 -0500 )edit

Yeah, it's not really better.

Ed Venator gravatar image Ed Venator  ( 2017-11-01 19:06:03 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-10-31 19:56:27 -0500

Seen: 106 times

Last updated: Oct 31 '17