|
| 1 | +Marker: Display types |
| 2 | +===================== |
| 3 | + |
| 4 | +**Goal:** This tutorial explains the basic Marker types and how to use them. |
| 5 | + |
| 6 | +**Tutorial level:** Intermediate |
| 7 | + |
| 8 | +**Time:** 15 Minutes |
| 9 | + |
| 10 | +.. contents:: Contents |
| 11 | + :depth: 2 |
| 12 | + :local: |
| 13 | + |
| 14 | + |
| 15 | +Background |
| 16 | +---------- |
| 17 | +The Markers display allows programmatic addition of various primitive shapes to the 3D view by sending a |
| 18 | +`visualization_msgs/msg/Marker <https://github.com/ros2/common_interfaces/blob/{DISTRO}/visualization_msgs/msg/Marker.msg>`_ or |
| 19 | +`visualization_msgs/msg/MarkerArray <https://github.com/ros2/common_interfaces/blob/{DISTRO}/visualization_msgs/msg/MarkerArray.msg>`_ message. |
| 20 | + |
| 21 | +.. image:: images/marker_overview.png |
| 22 | + |
| 23 | +.. |
| 24 | + This is a comment, the next line will be added to the file once the Markers-Sending-Basic-Shapes-CPP is merged to point to the start of the tutorial series. |
| 25 | + The :doc:`Marker: Sending Basic Shapes <../Markers-Sending-Basic-Shapes-CPP/Markers-Sending-Basic-Shapes-CPP>` that tutorial begins a series of tutorials on sending markers. |
| 26 | +
|
| 27 | +The Marker Message |
| 28 | +------------------ |
| 29 | +1 Example Usage (C++) |
| 30 | +^^^^^^^^^^^^^^^^^^^^^ |
| 31 | +First we will create a simple publisher node that publishes ``Marker`` messages from the ``visualization_messages`` package to the ``visualization_marker`` topic: |
| 32 | + |
| 33 | +.. code-block:: C++ |
| 34 | + |
| 35 | + auto marker_pub = node->create_publisher<visualization_msgs::msg::Marker>("visualization_marker", 1); |
| 36 | + |
| 37 | +After that it is as simple as filling out a `visualization_msgs/msg/Marker <https://github.com/ros2/common_interfaces/blob/{DISTRO}/visualization_msgs/msg/Marker.msg>`_ |
| 38 | +message and publishing it: |
| 39 | + |
| 40 | +.. code-block:: C++ |
| 41 | + |
| 42 | + visualization_msgs::msg::Marker marker; |
| 43 | + |
| 44 | + marker.header.frame_id = "/my_frame"; |
| 45 | + marker.header.stamp = rclcpp::Clock().now(); |
| 46 | + |
| 47 | + marker.ns = "basic_shapes"; |
| 48 | + marker.id = 0; |
| 49 | + |
| 50 | + marker.type = visualization_msgs::msg::Marker::SPHERE; |
| 51 | + |
| 52 | + marker.action = visualization_msgs::msg::Marker::ADD; |
| 53 | + |
| 54 | + marker.pose.position.x = 0; |
| 55 | + marker.pose.position.y = 0; |
| 56 | + marker.pose.position.z = 0; |
| 57 | + marker.pose.orientation.x = 0.0; |
| 58 | + marker.pose.orientation.y = 0.0; |
| 59 | + marker.pose.orientation.z = 0.0; |
| 60 | + marker.pose.orientation.w = 1.0; |
| 61 | + |
| 62 | + marker.scale.x = 1.0; |
| 63 | + marker.scale.y = 1.0; |
| 64 | + marker.scale.z = 1.0; |
| 65 | + |
| 66 | + marker.color.r = 0.0f; |
| 67 | + marker.color.g = 1.0f; |
| 68 | + marker.color.b = 0.0f; |
| 69 | + marker.color.a = 1.0; // Don't forget to set the alpha! |
| 70 | + |
| 71 | + // only if using a MESH_RESOURCE marker type: |
| 72 | + marker.mesh_resource = "package://pr2_description/meshes/base_v0/base.dae"; |
| 73 | + |
| 74 | + marker.lifetime = rclcpp::Duration::from_nanoseconds(0); |
| 75 | + |
| 76 | + marker_pub->publish(marker); |
| 77 | + |
| 78 | +There is also a `visualization_msgs/msg/MarkerArray <https://github.com/ros2/common_interfaces/blob/{DISTRO}/visualization_msgs/msg/MarkerArray.msg>`_ message, which lets you publish many markers at once. |
| 79 | + |
| 80 | +2 Message Parameters |
| 81 | +^^^^^^^^^^^^^^^^^^^^ |
| 82 | + |
| 83 | +The Marker message type is defined in `ROS 2 Common Interfaces <https://github.com/ros2/common_interfaces/tree/{DISTRO}/visualization_msgs/msg>_` package. |
| 84 | +The messages in this package include comments that are helpful in understanding each of the fields in the message. |
| 85 | + |
| 86 | +* ``ns``: |
| 87 | + |
| 88 | + Namespace for these markers. This plus the id form a unique identifier. |
| 89 | + |
| 90 | +* ``id``: |
| 91 | + |
| 92 | + Unique id assigned to this marker. It is your responsibility to keep these unique within your namespace. |
| 93 | + |
| 94 | +* ``type``: |
| 95 | + |
| 96 | + Type of marker (Arrow, Sphere, ...). The available types are specified in the message definition. |
| 97 | + |
| 98 | +* ``action``: |
| 99 | + |
| 100 | + 0 = add/modify, 1 = (deprecated), 2 = delete, 3 = deleteall |
| 101 | + |
| 102 | +* ``pose``: |
| 103 | + |
| 104 | + Pose marker, specified as x/y/z position and x/y/z/w quaternion orientation. |
| 105 | + |
| 106 | +* ``scale``: |
| 107 | + |
| 108 | + Scale of the marker. Applied before the position/orientation. A scale of [1, 1, 1] means the object will be 1m by 1m by 1m. |
| 109 | + |
| 110 | +* ``color``: |
| 111 | + |
| 112 | + Color of the object, specified as r/g/b/a, with values in the range of [0, 1]. The, `a` or alpha value, denotes the opacity of the marker with 1 indicating opaque and 0 indicating completely transparent. The default value is 0, or completely transparent. **You must set the a value of your marker to a non-zero value or it will be transparent by default!** |
| 113 | + |
| 114 | +* ``points``: |
| 115 | + |
| 116 | + Only used for markers of type ``Points``, ``Line strips``, and ``Line`` / ``Cube`` / ``Sphere`` -lists. |
| 117 | + It's also used for the Arrow type, if you want to specify the arrow start and end points. |
| 118 | + This entry represents a list of `geometry_msgs/Point` types for the center or each marker object you would like rendered. |
| 119 | + |
| 120 | +* ``colors``: |
| 121 | + |
| 122 | + This field is only used for markers that use the points member. This field specifies per-vertex color r/g/b/ color (no alpha yet) for each entry in `points`. |
| 123 | + |
| 124 | +* ``lifetime``: |
| 125 | + |
| 126 | + A `duration message value <https://docs.ros.org/en/ros2_packages/{DISTRO}/api/builtin_interfaces/interfaces/msg/Duration.html>`_ used to automatically delete the marker after this period of time. |
| 127 | + The countdown resets if another marker of the same ``namespace`` / ``id`` is received. |
| 128 | + |
| 129 | +* ``frame_locked``: |
| 130 | + |
| 131 | + Without the ``frame_locked`` parameter the marker will be placed based on the current transform and will stay there even if the given transform changes later. |
| 132 | + Setting this parameter tells RViz to retransform the marker to the new current location of the specified frame on every update cycle. |
| 133 | + |
| 134 | +* ``text``: |
| 135 | + |
| 136 | + The text string used for the ``TEXT_VIEW_FACING`` marker type |
| 137 | + |
| 138 | +* ``mesh_resource``: |
| 139 | + |
| 140 | + The resource location for the ``MESH_RESOURCE`` marker type. Can be any mesh type supported by RViz (``.stl`` or Ogre ``.mesh`` in 1.0, with the addition of COLLADA in 1.1). |
| 141 | + The format is the URI-form used by `resource_retriever <https://github.com/ros/resource_retriever/tree/{DISTRO}>`_, including the package:// syntax. |
| 142 | + |
| 143 | +3 Object types |
| 144 | +^^^^^^^^^^^^^^ |
| 145 | + |
| 146 | +.. _RVizMarkerObjectTypes: |
| 147 | + |
| 148 | +3.1 Arrow (ARROW=0) |
| 149 | +~~~~~~~~~~~~~~~~~~~ |
| 150 | + |
| 151 | +.. image:: images/ArrowMarker.png |
| 152 | + |
| 153 | +The arrow type provides two different ways of specifying where the arrow should begin/end: |
| 154 | + |
| 155 | +* ``Position/Orientation``: |
| 156 | + |
| 157 | + Pivot point is around the tip of its tail. Identity orientation points it along the +X axis. ``scale.x`` is the arrow length, ``scale.y`` is the arrow width and ``scale.z`` is the arrow height. |
| 158 | + |
| 159 | +* ``Start/End Points``: |
| 160 | + |
| 161 | + You can also specify a start/end point for the arrow, using the points member. If you put points into the points member, it will assume you want to do things this way. |
| 162 | + |
| 163 | + * The point at index 0 is assumed to be the start point, and the point at index 1 is assumed to be the end. |
| 164 | + * ``scale.x`` is the shaft diameter, and ``scale.y`` is the head diameter. If ``scale.z`` is not zero, it specifies the head length. |
| 165 | + |
| 166 | +3.2 Cube (CUBE=1) |
| 167 | +~~~~~~~~~~~~~~~~~ |
| 168 | + |
| 169 | +.. image:: images/CubeMarker.png |
| 170 | + |
| 171 | +Pivot point is at the center of the cube. |
| 172 | + |
| 173 | +3.3 Sphere (SPHERE=2) |
| 174 | +~~~~~~~~~~~~~~~~~~~~~ |
| 175 | + |
| 176 | +.. image:: images/SphereMarker.png |
| 177 | + |
| 178 | +Pivot point is at the center of the sphere. |
| 179 | + |
| 180 | +``scale.x`` is diameter in x direction, ``scale.y`` in y direction, ``scale.z`` in z direction. |
| 181 | +By setting these to different values you get an ellipsoid instead of a sphere. |
| 182 | + |
| 183 | +3.4 Cylinder (CYLINDER=3) |
| 184 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 185 | + |
| 186 | +.. image:: images/CylinderMarker.png |
| 187 | + |
| 188 | +Pivot point is at the center of the cylinder. |
| 189 | + |
| 190 | +``scale.x`` is diameter in x direction, ``scale.y`` in y direction, by setting these to different values you get an ellipse instead of a circle. |
| 191 | +Use ``scale.z`` to specify the height. |
| 192 | + |
| 193 | +3.5 Line Strip (LINE_STRIP=4) |
| 194 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 195 | + |
| 196 | +.. image:: images/LineStripMarker.png |
| 197 | + |
| 198 | +Line strips use the points member of the `visualization_msgs/msg/Marker <https://github.com/ros2/common_interfaces/blob/{DISTRO}/visualization_msgs/msg/Marker.msg>`_ message. |
| 199 | +It will draw a line between every two consecutive points, so 0-1, 1-2, 2-3, 3-4, 4-5... |
| 200 | + |
| 201 | +Line strips also have some special handling for scale: only ``scale.x`` is used and it controls the width of the line segments. |
| 202 | + |
| 203 | +Note that ``pose`` is still used (the points in the line will be transformed by them), and the lines will be correct relative to the ``frame id`` specified in the header. |
| 204 | + |
| 205 | +3.6 Line List (LINE_LIST=5) |
| 206 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 207 | + |
| 208 | +.. image:: images/LineListMarker.png |
| 209 | + |
| 210 | +Line lists use the points member of the `visualization_msgs/msg/Marker <https://github.com/ros2/common_interfaces/blob/{DISTRO}/visualization_msgs/msg/Marker.msg>`_ message. It will draw a line between each pair of points, so 0-1, 2-3, 4-5, ... |
| 211 | + |
| 212 | +Line lists also have some special handling for scale: only ``scale.x`` is used and it controls the width of the line segments. |
| 213 | + |
| 214 | +Note that ``pose`` is still used (the points in the line will be transformed by them), and the lines will be correct relative to the ``frame id`` specified in the header. |
| 215 | + |
| 216 | +3.7 Cube List (CUBE_LIST=6) |
| 217 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 218 | + |
| 219 | +.. image:: images/CubeListMarker.png |
| 220 | + |
| 221 | +A cube list is a list of cubes with all the same properties except their positions. |
| 222 | +Using this object type instead of a `visualization_msgs/msg/MarkerArray <https://github.com/ros2/common_interfaces/blob/{DISTRO}/visualization_msgs/msg/MarkerArray.msg>`_ allows RViz to batch-up rendering, |
| 223 | +which causes them to render much faster. |
| 224 | +The caveat is that they all must have the same scale. |
| 225 | + |
| 226 | +The ``points`` member of the `visualization_msgs/msg/Marker <https://github.com/ros2/common_interfaces/blob/{DISTRO}/visualization_msgs/msg/Marker.msg>`_ message is used for the position of each cube. |
| 227 | + |
| 228 | +3.8 Sphere List (SPHERE_LIST=7) |
| 229 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 230 | + |
| 231 | +.. image:: images/SphereListMarker.png |
| 232 | + |
| 233 | +A sphere list is a list of spheres with all the same properties except their positions. |
| 234 | +Using this object type instead of a `visualization_msgs/msg/MarkerArray <https://github.com/ros2/common_interfaces/blob/{DISTRO}/visualization_msgs/msg/MarkerArray.msg>`_ allows RViz to batch-up rendering, |
| 235 | +which causes them to render much faster. |
| 236 | +The caveat is that they all must have the same scale. |
| 237 | + |
| 238 | +The ``points`` member of the `visualization_msgs/msg/Marker <https://github.com/ros2/common_interfaces/blob/{DISTRO}/visualization_msgs/msg/Marker.msg>`_ message is used for the position of each sphere. |
| 239 | + |
| 240 | +Note that ``pose`` is still used (the ``points`` in the line will be transformed by them), and the lines will be correct relative to the ``frame id`` specified in the header. |
| 241 | + |
| 242 | +3.9 Points (POINTS=8) |
| 243 | +~~~~~~~~~~~~~~~~~~~~~ |
| 244 | + |
| 245 | +.. image:: images/PointsMarker.png |
| 246 | + |
| 247 | +Uses the ``points`` member of the `visualization_msgs/msg/Marker <https://github.com/ros2/common_interfaces/blob/{DISTRO}/visualization_msgs/msg/Marker.msg>`_ message. |
| 248 | + |
| 249 | +``Points`` have some special handling for scale: ``scale.x`` is point width, ``scale.y`` is point height |
| 250 | + |
| 251 | +Note that ``pose`` is still used (the ``points`` in the line will be transformed by them), and the lines will be correct relative to the ``frame id`` specified in the header. |
| 252 | + |
| 253 | +3.10 View-Oriented Text (TEXT_VIEW_FACING=9) |
| 254 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 255 | + |
| 256 | +.. image:: images/text_view_facing_marker.png |
| 257 | + |
| 258 | +This marker displays text in a 3D spot in the world. |
| 259 | +The text always appears oriented correctly for the RViZ user to see the included text. Uses the ``text`` field in the marker. |
| 260 | + |
| 261 | +Only ``scale.z`` is used. ``scale.z`` specifies the height of an uppercase "A". |
| 262 | + |
| 263 | +3.11 Mesh Resource (MESH_RESOURCE=10) |
| 264 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 265 | + |
| 266 | +.. image:: images/mesh_resource_marker.png |
| 267 | + |
| 268 | +Uses the ``mesh_resource`` field in the marker. |
| 269 | +Can be any mesh type supported by RViz (binary ``.stl`` or Ogre ``.mesh`` in 1.0, with the addition of COLLADA (``.dae``) in 1.1). |
| 270 | +The format is the URI-form used by `resource_retriever <https://github.com/ros/resource_retriever/tree/{DISTRO}>`_, including the ``package://`` syntax. |
| 271 | + |
| 272 | +An example of a mesh an its use is: |
| 273 | + |
| 274 | +.. code-block:: C++ |
| 275 | + |
| 276 | + marker.type = visualization_msgs::Marker::MESH_RESOURCE; |
| 277 | + marker.mesh_resource = "package://pr2_description/meshes/base_v0/base.dae"; |
| 278 | + |
| 279 | +Scale on a mesh is relative. |
| 280 | +A scale of (1.0, 1.0, 1.0) means the mesh will display as the exact size specified in the mesh file. |
| 281 | +A scale of (1.0, 1.0, 2.0) means the mesh will show up twice as tall, but the same width/depth. |
| 282 | + |
| 283 | +If the ``mesh_use_embedded_materials`` flag is set to true and the mesh is of a type which supports embedded materials (such as COLLADA), |
| 284 | +the material defined in that file will be used instead of the color defined in the marker. |
| 285 | + |
| 286 | +Since version [1.8], even when ``mesh_use_embedded_materials`` is true, |
| 287 | +if the marker ``color`` is set to anything other than ``r=0``, ``g=0``, ``b=0``, ``a=0`` the marker ``color`` and ``alpha`` will be used to tint the mesh with the embedded material. |
| 288 | + |
| 289 | +3.12 Triangle List (TRIANGLE_LIST=11) |
| 290 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 291 | + |
| 292 | +.. image:: images/triangle_list_marker.png |
| 293 | + |
| 294 | +Uses the points and optionally colors members. |
| 295 | +Every set of 3 points is treated as a triangle, so indices 0-1-2, 3-4-5, etc. |
| 296 | + |
| 297 | +Note that ``pose`` and ``scale`` are still used (the points in the line will be transformed by them), |
| 298 | +and the lines will be correct relative to the ``frame id`` specified in the header. |
| 299 | + |
| 300 | +4 Rendering Complexity Notes |
| 301 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 302 | +A single marker is always less expensive to render than many markers. |
| 303 | +For example, a single cube list can handle thousands of cubes, where we will not be able to render thousands of individual cube markers. |
0 commit comments