Ask Your Question
0

Minimal working example for RViz marker publishing

asked 2021-03-11 05:22:53 -0500

Py gravatar image

Does anyone know of a complete minimal working example to publish a marker that can be visualised in RViz written in Python?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2021-03-11 06:11:07 -0500

Roberto Z. gravatar image

This is a minimal working example of a ROS node in Python with a Rviz marker publisher:

#! /usr/bin/env python

import rospy
from visualization_msgs.msg import Marker

rospy.init_node('rviz_marker')

marker_pub = rospy.Publisher("/visualization_marker", Marker, queue_size = 2)

marker = Marker()

marker.header.frame_id = "/map"
marker.header.stamp = rospy.Time.now()

# set shape, Arrow: 0; Cube: 1 ; Sphere: 2 ; Cylinder: 3
marker.type = 2
marker.id = 0

# Set the scale of the marker
marker.scale.x = 1.0
marker.scale.y = 1.0
marker.scale.z = 1.0

# Set the color
marker.color.r = 0.0
marker.color.g = 1.0
marker.color.b = 0.0
marker.color.a = 1.0

# Set the pose of the marker
marker.pose.position.x = 0
marker.pose.position.y = 0
marker.pose.position.z = 0
marker.pose.orientation.x = 0.0
marker.pose.orientation.y = 0.0
marker.pose.orientation.z = 0.0
marker.pose.orientation.w = 1.0

while not rospy.is_shutdown():
  marker_pub.publish(marker)
  rospy.rostime.wallsleep(1.0)
edit flag offensive delete link more

Comments

That's really great, just what I needed! My next task is to colour code each marker according to a sensor value like a heat map. Any ideas how I'd achieve this?

Py gravatar image Py  ( 2021-03-15 14:27:49 -0500 )edit

I am glad that this resolved your question. To change to color of one marker use the attribute .color , it is shown above. For a heatmap it seems to me that you need many markers. Take a look at visualization_msgs/MarkerArray message. It is a bit broad subject to discuss here in details.

Roberto Z. gravatar image Roberto Z.  ( 2021-03-15 14:48:28 -0500 )edit
1

answered 2021-03-11 06:00:38 -0500

Ranjit Kathiriya gravatar image

updated 2021-03-11 06:13:50 -0500

Hello @Py,

Just take a look at the link below might be you can get help from this python code.

You can publish transformation(tf2) of each markers by sendTransform() function.

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: 2021-03-11 05:22:53 -0500

Seen: 227 times

Last updated: Mar 11