0
$\begingroup$

Rosanswers logo

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.


Originally posted by ravijoshi on ROS Answers with karma: 1744 on 2017-10-31

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Ed Venator with karma: 1185 on 2017-10-31

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by gvdhoorn on 2017-11-01:
Which really doesn't look that different from the "multi-line" initialisation style :)

Comment by Ed Venator on 2017-11-01:
Yeah, it's not really better.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.