ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

publishing marker points python

asked 2015-11-13 13:41:13 -0600

leovetto gravatar image

I have some problems publishing markers in a python node to visualize them on rViz. I have a node that calculates some static points and I want to visualize them (like a path). I also have a robot moving and I want to drop some marks when it reaches some points. I don't want to make an infinite cycle to visualize them, otherwise the rest of the code will not go on. Here is a method that I wrote to visualize the points in the path and it worked sometimes, now I don't know why does never appear anything on rViz:

def print_points(self, points, frame):
    rate = rospy.Rate(5)
    triplePoints = []
     #transform from x,y points to x,y,z points
    for (x,y) in points:
        p = Point() 
        p.x = x
        p.y = y
        p.z = 0
        triplePoints.append(p)

    iterations = 0
    while not rospy.is_shutdown() and iterations <= 10:
        pub = rospy.Publisher(frame, Marker, queue_size = 100)
        marker = Marker()
        marker.header.frame_id = "/map"

        marker.type = marker.POINTS
        marker.action = marker.ADD
        marker.pose.orientation.w = 1

        marker.points = triplePoints;
        t = rospy.Duration()
        marker.lifetime = t
        marker.scale.x = 0.4
        marker.scale.y = 0.4
        marker.scale.z = 0.4
        marker.color.a = 1.0
        marker.color.r = 1.0

        pub.publish(marker)
        iterations += 1
        rate.sleep()

As you can see I tried to use the lifetime and 0 should mean infinite time. I also published the points more times because I've seen that sometimes rviz needed 2-3 times to receive the points. Now it doesn't work anymore.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-11-16 03:38:35 -0600

Mehdi. gravatar image

Did you do an echo on your published topic to see if something is actually published?

I think you should declare your publisher once at the beginning of your program. I had experienced some problems before when there wasn't enough time between publisher declaration and publishing and nothing was actually published. So in your initializer function define this publisher

def __init__(self):
        self.pub = rospy.Publisher(frame, Marker, queue_size = 100)

and then in your function

self.pub.publish(marker)

if it still doesn't work, try

def __init__(self):
        self.pub = rospy.Publisher(frame, Marker, queue_size = 100)
        rospy.sleep(1)
edit flag offensive delete link more

Question Tools

Stats

Asked: 2015-11-13 13:41:13 -0600

Seen: 7,982 times

Last updated: Nov 16 '15