RASG RViz Marker Publisher API Reference
rviz_marker_publisher.publisher module
The main module for the rviz_marker_publisher.
- class rviz_marker_publisher.publisher.RvizMarkerPublisher(node: rclpy.node.Node, fixed_frame: str = 'map', callback_group: rclpy.callback_groups.CallbackGroup = None, default_qos_profile: rclpy.qos.QoSProfile = None, **config_dict)
Bases:
objectA publisher of visualization objects including Markers, MarkerArray and Pointcloud2.
The class manages the topics, marker publish, and other functionality that facilitates the use of visualization in a ROS2 application.
- activate_topic(topic: str, message_cls: type, qos_profile: rclpy.qos.QoSProfile | None = None) None
Activate a topic by creating a publisher to associated with the given message class on the given topic.
- Parameters:
topic (str) – the new topic
message_cls (type) – the message class associated with the publisher
qos_profile (QoSProfile, optional) – the QoSProfile of the publisher, defaults to None (the default QoSProfile)
- Raises:
ValueError – the topic is already used
- audit_rviz_subscriptions() dict[str, list] | None
Audit the rviz node and query the topic subscription.
- Returns:
a dictionary containing key value pairs of (topic name, list of message type names) or None if the query failed.
- Return type:
dict[str, list] or None
- deactivate_topic(topic: str) None
Deactivate the topic and destroy the associated publisher.
- Parameters:
topic (str) – the topic to be deactivated
- delete_all_objects_by_topics(topics_list: list | str | None = None) None
Attempt to clear old objects by sending DELETE_ALL messages to the topics.
- Parameters:
topics_list (list[str], optional) – the list of topics to send DELETE_ALL messages, defaults to None (the default topics)
frame_id (str, optional) – the frame id, defaults to the default the fixed_frame variable of this object
- delete_cached_objects_by_topics(topics_list: list | str | None = None) None
Delete all objects from rviz, optionally only the topics in the topics_list.
- Parameters:
topics_list (list, optional) – the topics included, defaults to None (all default topics)
- delete_marker_by_id(name: str, id: int) None
Delete marker by its name and id.
- Parameters:
name (str) – the namespace of the marker
id (int) – the id of the marker
- delete_object(the_object: visualization_msgs.msg.Marker | visualization_msgs.msg.MarkerArray | sensor_msgs.msg.PointCloud2) None
Delete the object from the visualization.
- Parameters:
the_object (Marker, MarkerArray or PointCloud2) – the object
- publish(the_object: visualization_msgs.msg.Marker | visualization_msgs.msg.MarkerArray | sensor_msgs.msg.PointCloud2, topic: str | None = None, delay: float = 0, update_stamp: bool = True) visualization_msgs.msg.Marker | visualization_msgs.msg.MarkerArray | sensor_msgs.msg.PointCloud2
Add an once-only marker, which is to be published only once.
- Parameters:
marker – A marker to be published only once
delay – The delay
- Returns:
The marker
- publish_and_cache(the_object: visualization_msgs.msg.Marker | visualization_msgs.msg.MarkerArray | sensor_msgs.msg.PointCloud2, topic: str | None = None, pub_tf: bool = False, update_stamp: bool = True) visualization_msgs.msg.Marker | visualization_msgs.msg.MarkerArray | sensor_msgs.msg.PointCloud2
Publish an object to rviz and again if auto-refresh is True.
- Parameters:
the_object – A object to be published
topic – the topic to publish to
pub_tf – if True, the pose of the marker is published as a tf frame
- Returns:
The mrker
- publish_cached_objects_now() None
Publish the cached objects once now.
- publish_custom_tf(frame_id: str, parent_frame_id: str, pose: geometry_msgs.msg.Pose, static_tf: bool = False, linked_marker: visualization_msgs.msg.Marker | None = None) None
Add a custom transform to the rviz visualizer, which is broadcast regularly.
- Parameters:
frame_id – the name of the transform
pose – the pose of the transform, which may be coming from the Pose of the Marker object
parent_frame – the parent frame
static_tf – publish this transform to static_tf once
linked_marker – link this transform to the pose of a Marker and so when the pose of the Marker is updated so is this transform
- rviz_marker_publisher.publisher.create_arrow_marker(name: str, id: int, xyz1: list, xyz2: list, frame_id: str | None = None, arrow_head_length: float = 0.05, arrow_shaft_diameter: float = 0.1, arrow_head_diameter: float = 0.1, rgba: list | None = None, lifetime: float = 0) visualization_msgs.msg.Marker
Create a marker for displaying an arrow.
- Parameters:
name – the name space of the marker
id – the id of the marker
xyz1 – the first point of the arrow
xyz2 – the second point of the arrow
frame_id – the reference frame, defaults to None (the default fixed_frame)
arrow_head_length – the length of the arrow head, defaults to 0.05
arrow_width – the width of the arrow shaft, defaults to 0.1
arrow_height – the height of the arrow shaft, defaults to 0.1
rgba – the colour and alpha value, defaults to None
lifetime – the duration that the marker is displayed, defaults to 0 (indefinte)
- Returns:
the Marker object
- rviz_marker_publisher.publisher.create_arrow_marker_from_xyzrpy(name: str, id: int, xyzrpy: list, frame_id: str | None = None, arrow_length: float = 0.5, arrow_shaft_diameter: float = 0.1, arrow_head_diameter: float = 0.1, rgba: list | None = None, lifetime: float = 0) visualization_msgs.msg.Marker
Create a marker for displaying an arrow.
- Parameters:
name – the name space of the marker
id – the id of the marker
xyzrpy – the pose of the arrow as a list of 6
frame_id – the reference frame, defaults to None (the default fixed_frame)
arrow_length – the length of the arrow, defaults to 0.5
arrow_shaft_diameter – the diameter of the arrow shaft, defaults to 0.1
arrow_head_diameter – the diameter of the arrow head, defaults to 0.1
rgba – the colour and alpha value, defaults to None
lifetime – the duration that the marker is displayed, defaults to 0 (indefinte)
- Returns:
the Marker object
- rviz_marker_publisher.publisher.create_axisplane_marker(name: str, id: int, bbox2d: list, offset: float, frame_id: str | None = None, axes: str = 'xy', plane_thickness: float = 0.005, rgba: list | None = None, lifetime: float = 0) visualization_msgs.msg.Marker
Create a marker for displaying a 2D region as a plane.
- Parameters:
name – the name space of the marker
id – the id of the marker
bbox2d – a bounding box as a list [min_x, min_y, max_x, max_y]
offset – the z value where the plane is display
referencframe_ide_frame – the reference frame, defaults to None (the default fixed_frame)
axes – a string representing the axes where the bounding box lies, defaults to ‘xy’
plane_thickness – the thickness of the plane to be displayed, defaults to 0.005
rgba – the colour and alpha value, defaults to None
lifetime – the duration that the marker is displayed, defaults to 0 (indefinte)
- Returns:
the Marker object
- rviz_marker_publisher.publisher.create_cube_marker_from_bbox(name: str, id: int, bbox3d: list, frame_id: str | None = None, rgba: list | None = None, lifetime: float = 0) visualization_msgs.msg.Marker
Create a marker for displaying a 3D box defined by the min xyz and max xyz that aligns with the axes of the reference frame.
- Parameters:
name – the name space of the marker
id – the id of the marker
bbox3d – a bounding box as a 6-list [min_x, min_y, min_z, max_x, max_y, max_z]
frame_id – the reference frame, defaults to None (the default fixed_frame)
rgba – the colour and alpha value, defaults to None
lifetime – the duration that the marker is displayed, defaults to 0 (indefinte)
- Returns:
the Marker object
- rviz_marker_publisher.publisher.create_cube_marker_from_xyzrpy(name: str, id: int, xyzrpy: list, frame_id: str | None = None, scale: float | list = 0.5, rgba: list | None = None, lifetime: float = 0) visualization_msgs.msg.Marker
Create a marker for displaying a 3D box defined by both the position (xyz) and orientation (rpy) with respect to the axes of the reference frame.
- Parameters:
name – the name space of the marker
id – the id of the marker
bbox3d – a bounding box as a list [min_x, min_y, min_z, max_x, max_y, max_z]
frame_id – the reference frame, defaults to None (the default fixed_frame)
rgba – the colour and alpha value, defaults to None
lifetime – the duration that the marker is displayed, defaults to 0 (indefinte)
- Returns:
the Marker object
- rviz_marker_publisher.publisher.create_cylinder_marker(name: str, id: int, xyzrpy: list, frame_id: str | None = None, scale: float | list = (0.1, 0.1, 0.2), rgba: list | None = None, lifetime: float = 0) visualization_msgs.msg.Marker
Create a marker for displaying a cylinder.
- Parameters:
name – the name space of the marker
id – the id of the marker
xyzrpy – the pose of the cylinder
frame_id – the reference frame, defaults to None (the default fixed_frame)
scale – the scale of the cylinder as a list of 3 numbers representing radius in x and y direction and the height
rgba – the colour and alpha value, defaults to None
lifetime – the duration that the marker is displayed, defaults to 0 (indefinte)
- Returns:
the Marker object
- rviz_marker_publisher.publisher.create_line_marker(name: str, id: int, xyz1: list, xyz2: list, frame_id: str | None = None, line_width: float = 0.01, rgba: list | None = None, lifetime: float = 0) visualization_msgs.msg.Marker
Create a marker for displaying a line.
- Parameters:
name – the name space of the marker
id – the id of the marker
xyz1 – the first point of the line
xyz2 – the second point of the line
frame_id – the reference frame, defaults to None (the default fixed_frame)
line_width – the width of the line, defaults to 0.01
rgba – the colour and alpha value, defaults to None
lifetime – the duration that the marker is displayed, defaults to 0 (indefinte)
- Returns:
the Marker object
- rviz_marker_publisher.publisher.create_marker_array(markers_list: list[visualization_msgs.msg.Marker]) visualization_msgs.msg.MarkerArray
Create a MarkerArray from a list of markers.
- Parameters:
markers_list (list[Marker]) – a list of Marker objects
- Returns:
a MarkerArray populated with the input parameter markers
- Return type:
MarkerArray
- rviz_marker_publisher.publisher.create_mesh_marker(name: str, id: int, resource_uri: str, xyzrpy: list, frame_id: str | None = None, scale: list | float = 0.5, rgba: list | None = None, lifetime: float = 0) visualization_msgs.msg.Marker
Create a marker for displaying a mesh object.
- Parameters:
name – the name space of the marker
id – the id of the marker
resource_uri – the full path to the resource containing a binary STL or DAE file or using protocols such as file://, package://, or http://
xyzrpy – the pose of the text as a list of 6
frame_id – the reference frame, defaults to None (the default fixed_frame)
scale – the scale factor of the mesh object, defaults to [1, 1, 1]
rgba – the colour and alpha value, defaults to None
lifetime – the duration that the marker is displayed, defaults to defaults to None (indefinte)
- Returns:
the Marker object
- rviz_marker_publisher.publisher.create_path_marker(name: str, id: int, xyzlist: list, frame_id: str | None = None, line_width: float = 0.01, rgba: list | None = None, lifetime: float = 0) visualization_msgs.msg.Marker
Create a marker for displaying a path of multiple waypoints.
- Parameters:
name – the name space of the marker
id – the id of the marker
xyzlist – a list of points (xyz, Pose or PoseStamped) defining the path
frame_id – the reference frame, defaults to None (the default fixed_frame)
line_width – the width of the line, defaults to 0.01
rgba – the colour and alpha value, defaults to None
lifetime – the duration that the marker is displayed, defaults to 0 (indefinte)
- Returns:
the Marker object
- rviz_marker_publisher.publisher.create_pointcloud_from_image(image_bgr: numpy.ndarray, xyz: list = (0, 0, 0), pixel_physical_size: float = 0.005, frame_id: str | None = None, opacity: float = 1.0, depth_array: numpy.ndarray | None = None) sensor_msgs.msg.PointCloud2
Create a PointCloud2 for displaying a OpenCV image (color or greyscale).
- Parameters:
image_bgr – the image to be displayed, type numpy ndarray
xyz – the position of the bottom left hand corner of the image, defaults to (0, 0, 0)
pixel_physical_size – the length of each pixel in x, y, defaults to [0.005, 0.005], and optionally the third value in the list for z scaling factor
frame_id – the reference frame, defaults to None (the default fixed_frame)
opacity – the opacity of the displayed image, defaults to 1.0
depth_array – optionally a numpy ndarray of exact the same shape as the image indicating the depth, defaults to None
- Returns:
the PointCloud2 object
- rviz_marker_publisher.publisher.create_sphere_marker(name: str, id: int, xyzrpy: list, frame_id: str | None = None, scale: float | list = 0.2, rgba: list | None = None, lifetime: float = 0) visualization_msgs.msg.Marker
Create a marker for displaying a sphere.
- Parameters:
name – the name space of the marker
id – the id of the marker
xyzrpy – the position of the sphere
frame_id – the reference frame, defaults to None (the default fixed_frame)
scale – the scale of the sphere as a list of 3 scales or a number, defaults to 0.2
rgba – the colour and alpha value, defaults to None
lifetime – the duration that the marker is displayed, defaults to 0 (indefinte)
- Returns:
the Marker object
- rviz_marker_publisher.publisher.create_text_marker(name: str, id: int, text: str, xyzrpy: list, frame_id: str | None = None, scale: list | float = 0.5, rgba: list | None = None, lifetime: float = 0) visualization_msgs.msg.Marker
Create a marker for displaying a text.
- Parameters:
name – the name space of the marker
id – the id of the marker
text – a string to be displayed
xyzrpy – the pose of the text as a list of 6
frame_id – the reference frame, defaults to None (the default fixed_frame)
scale – the size of the text, defaults to 0.5
rgba – the colour and alpha value, defaults to None
lifetime – the duration that the marker is displayed, defaults to 0 (indefinte)
- Returns:
the Marker object
- rviz_marker_publisher.publisher.move_marker(marker: visualization_msgs.msg.Marker, xyz_offset: list) None
Update the position of a marker by the given position offset as a 3-tuple [dx, dy, dz].
- Parameters:
marker (Marker) – the Marker object of which the pose is to be udpated
xyz_offset (list) – the displacement to be applied to the Marker object in a 3-tuple [dx, dy, dz] format
- rviz_marker_publisher.publisher.spin_in_thread(node: rclpy.node.Node) None
Create a threaded executor and spin it in a thread. Designed for the demo examples.
- rviz_marker_publisher.publisher.update_marker_xyzrpy(marker: visualization_msgs.msg.Marker, xyzrpy: list) None
Update the pose of a marker by a xyyrpy list.
- Parameters:
marker (Marker) – the Marker object of which the pose is to be udpated
xyzrpy (list) – the new Marker object pose in a 6-tuple xyzrpy format, each value can be a float or None (which retains the existing value)