Minimal working example for RViz marker publishing
Does anyone know of a complete minimal working example to publish a marker that can be visualised in RViz
written in Python
?
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
Does anyone know of a complete minimal working example to publish a marker that can be visualised in RViz
written in Python
?
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)
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.
For future readers: This wasn't working for me, I was getting the error For frame [/map]: Frame [/map] does not exist
. After spending probably way too long on this, I realized that /map
indeed does not exist in the tf tree (run rosrun tf view_frames
to get a pdf of the tree) - but map
IS in the tree. I changed the frame_id
to map
and then it worked.
TLRD: If your getting For frame [/map]: Frame [/map] does not exist
try changing marker.header.frame_id = "/map"
to marker.header.frame_id = "map"
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.
Asked: 2021-03-11 05:22:53 -0500
Seen: 6,718 times
Last updated: Mar 11 '21
Creating a rosbag from images and imu data using bag.write
[SOLVED] rviz not showing 16 bits-per-pixel, single channel depth images
Multiple problems when configuring MiR200 with ur5 using MoveIt in Gazebo
Python2 and Python3 interoperability
rospy types of message subfields
Display sonar datapoints in rviz for amcl
AttributeError's when running Python scripts