Rosanswers logo

New to ROS

I have a robot moving around a room. Receive data from the laser scan obtaining a cloud point in the camera's frame and I want to extract significant lines to finally obtain a "linear-model" of the map.

To publish the lines I use Markers and publish them to a topic.

I want to represent the map on Rviz while the robot is moving. This is the way I publish the markers on each iteration:

msg = Marker()
msg.header.stamp = rospy.Time.now()
msg.header.frame_id = frame
msg.ns = ns
msg.id = marker_id
msg.type = msg.LINE_LIST
msg.action = msg.ADD
msg.pose.position.x = 0.0
msg.pose.position.y = 0.0
msg.pose.position.z = 0.0
msg.pose.orientation.x = 0.0
msg.pose.orientation.y = 0.0
msg.pose.orientation.z = 0.0
msg.pose.orientation.w = 1.0
msg.scale.x = 0.01
msg.scale.y = 0.0
msg.scale.z = 0.0
msg.color.r = color[0]
msg.color.g = color[1]
msg.color.b = color[2]
msg.color.a = 1.0
for i in range(lines.shape[0]):
    msg.points.append(Point(lines[i, 0], lines[i, 1], 0))
    msg.points.append(Point(lines[i, 2], lines[i, 3], 0))
# Publish

Rviz only shows the last Markers received. I tried to save all lines and send it in every iteration but on every iteration the robot is in a diferent position so the data is in a diferent frame. I think that should be possible to make Rviz not clean the lasts Markers just to see it all time.

Thanks a lot

Originally posted by RogerPi on ROS Answers with karma: 36 on 2016-12-01

Post score: 0


1 Answer 1


Rosanswers logo

I believe you're overwriting them every time because you're using the same marker id. If you increment the marker id each time, then you'll be adding a new marker each time rather than modifying the existing marker each time. You can control how long each will stay by using the lifetime field or by explicitly publishing a Marker message with the same marker id and the action delete.

If you look at the marker message, the actions ADD and MODIFY have been merged. Really it should be something like SET, where that actually means "set contents for this marker id".

Originally posted by William with karma: 17335 on 2016-12-01

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by RogerPi on 2016-12-02:
Thanks! It worked fine!!!


Your Answer

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