Ask Your Question
0

How to draw a line strip in RViz using python?

asked 2020-09-17 17:46:15 -0500

efglow gravatar image

I've been trying to add a blue line strip and 4 yellow spheres to Rviz. I see the yellow spheres, but I cannot get the line strip to appear. I've tried publishing the line_strip by itself and as part of a marker_array, but the lines still do not appear. Below is my code, where I generate the 4 spherical markers (marker_array) and 10 points in the linestrip (marker2). I am getting no errors in running the node or rendering in Rviz. I am using ROS Noetic with Ubuntu 20.04. Sorry, I'm very new to ROS. Thanks in advance.

!/usr/bin/env python3

import roslib; roslib.load_manifest('visualization_marker_tutorials') from visualization_msgs.msg import Marker from visualization_msgs.msg import MarkerArray from geometry_msgs.msg import Point import rospy import math

topic = 'visualization_marker_array' publisher = rospy.Publisher(topic, MarkerArray)

rospy.init_node('register')

markerArray = MarkerArray()

count = 0 MARKERS_MAX = 4 xpos = 0

Make the yellow spheres

for i in range(MARKERS_MAX): marker = Marker() marker.id = count marker.lifetime = rospy.Duration() marker.header.frame_id = "/neck" marker.type = marker.SPHERE marker.action = marker.ADD marker.scale.x = 0.2 marker.scale.y = 0.2 marker.scale.z = 0.2 marker.color.a = 1.0 marker.color.r = 1.0 marker.color.g = 1.0 marker.color.b = 0.0 marker.pose.orientation.w = 1.0 marker.pose.position.x = 0 + xpos marker.pose.position.y = 0 marker.pose.position.z = 0 markerArray.markers.append(marker) xpos += 1 count += 1

Make the line strip

marker2 = Marker() marker2.id = count marker2.lifetime = rospy.Duration() marker2.header.frame_id = "/neck" marker2.type = marker.LINE_STRIP marker2.action = marker.ADD marker2.scale.x = 0.4 marker2.color.a = 1.0 marker2.color.b = 1.0 marker2.pose.orientation.w=1.0 marker2.pose.position.x = 0 marker2.pose.position.y = 0 marker2.pose.position.z = 0 p = Point() marker2.points=[] for i in range(10): p.x = i/2 p.y = i*math.sin(i/3) p.z = 0 marker2.points.append(p) markerArray.markers.append(marker2) #add linestrip to markerArray

Give time for connection to be made between nodes since only publishing once

rospy.sleep(20)

Publish the MarkerArray

publisher.publish(markerArray)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-09-18 16:54:30 -0500

efglow gravatar image

I figured it out. I needed to declare a new p = Point() every time inside the for loop rather than just once outside of it.

edit flag offensive delete link more

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: 2020-09-17 17:38:12 -0500

Seen: 981 times

Last updated: Sep 18 '20