Bird
Raised Fist0
ROSframework~10 mins

Marker display for custom visualization in ROS - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Concept Flow - Marker display for custom visualization
Create Marker Object
Set Marker Properties
Publish Marker to Topic
RViz Subscribes to Topic
RViz Displays Marker
Update Marker Properties (optional)
Publish Updated Marker
RViz Updates Display
The flow shows creating a marker, setting its properties, publishing it to a ROS topic, and RViz subscribing and displaying it. Updates follow the same publish-subscribe cycle.
Execution Sample
ROS
marker = Marker()
marker.header.frame_id = "map"
marker.type = Marker.SPHERE
marker.pose.position.x = 1.0
marker.scale.x = 0.2
publisher.publish(marker)
This code creates a sphere marker at position x=1.0 in the 'map' frame and publishes it for RViz to display.
Execution Table
StepActionMarker Property SetPublish StatusRViz Display
1Create Marker ObjectNoneNot PublishedNo Display
2Set frame_id to 'map'frame_id='map'Not PublishedNo Display
3Set type to SPHEREtype=SPHERENot PublishedNo Display
4Set position x=1.0pose.position.x=1.0Not PublishedNo Display
5Set scale x=0.2scale.x=0.2Not PublishedNo Display
6Publish markerAll properties setPublishedMarker appears as sphere at x=1.0
7Update position x=2.0pose.position.x=2.0Not PublishedMarker at x=1.0
8Publish updated markerUpdated positionPublishedMarker moves to x=2.0
9EndNo changesNo further publishDisplay stable at x=2.0
💡 Execution stops after publishing updated marker and RViz displays it; no further updates.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5After Step 6After Step 7After Step 8Final
marker.header.frame_id'''map''map''map''map''map''map''map''map'
marker.typeNoneNoneSPHERESPHERESPHERESPHERESPHERESPHERESPHERE
marker.pose.position.x0.00.00.01.01.01.02.02.02.0
marker.scale.x0.00.00.00.00.20.20.20.20.2
publishedFalseFalseFalseFalseFalseTrueFalseTrueTrue
Key Moments - 3 Insights
Why doesn't the marker appear in RViz before publishing?
Because RViz only shows markers that are published to the topic. Until step 6, the marker is created and properties set but not published, so RViz has no data to display.
What happens if you update marker properties but don't publish again?
RViz will continue showing the last published marker. Changes in properties are not visible until the updated marker is published again, as seen between steps 7 and 8.
Why do we need to set the frame_id property?
frame_id tells RViz which coordinate frame to use for the marker's position. Without it, RViz cannot place the marker correctly in the 3D space.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the marker's position x after step 4?
A0.0
B1.0
C2.0
DNot set yet
💡 Hint
Check the 'Marker Property Set' column at step 4 in the execution table.
At which step does RViz first display the marker?
AStep 6
BStep 5
CStep 7
DStep 8
💡 Hint
Look for the first 'Published' status and marker appearance in the 'RViz Display' column.
If you change the scale.x property after step 6 but do not publish again, what will RViz show?
AMarker with new scale
BNo marker
CMarker with old scale
DError in RViz
💡 Hint
Refer to the key moment about updating properties without publishing.
Concept Snapshot
Marker display in ROS:
- Create Marker object
- Set frame_id, type, pose, scale
- Publish marker to a topic
- RViz subscribes and displays marker
- Update properties and re-publish to change display
- frame_id is essential for correct placement
Full Transcript
This visual execution shows how to display a custom marker in ROS using the Marker message. First, a Marker object is created. Then, properties like frame_id, type (e.g., sphere), position, and scale are set. The marker is published to a ROS topic. RViz listens to this topic and displays the marker accordingly. If you update the marker's properties, you must publish again for RViz to update the display. The frame_id property is crucial because it tells RViz the coordinate frame to use for positioning the marker. Without publishing, changes are not visible in RViz. This step-by-step trace helps beginners understand the flow from code to visualization.

Practice

(1/5)
1. What is the main purpose of using markers in ROS visualization tools like RViz?
easy
A. To control the robot's movement directly
B. To send commands to the robot's motors
C. To draw shapes in 3D space to help visualize robot data
D. To store robot configuration files

Solution

  1. Step 1: Understand marker usage in ROS

    Markers are used to create visual shapes like arrows, cubes, or spheres in RViz to represent data.
  2. Step 2: Differentiate markers from control commands

    Markers do not control robot movement or store files; they only help visualize data.
  3. Final Answer:

    To draw shapes in 3D space to help visualize robot data -> Option C
  4. Quick Check:

    Markers visualize data = B [OK]
Hint: Markers show shapes for visualization, not control [OK]
Common Mistakes:
  • Thinking markers control robot movement
  • Confusing markers with configuration files
  • Assuming markers send commands to motors
2. Which of the following is the correct way to set the type of a marker to a sphere in ROS using the visualization_msgs/Marker message?
easy
A. marker.type = visualization_msgs::Marker::SPHERE;
B. marker.type = visualization_msgs::Marker::CUBE;
C. marker.type = visualization_msgs::Marker::LINE_STRIP;
D. marker.type = visualization_msgs::Marker::TEXT_VIEW_FACING;

Solution

  1. Step 1: Identify marker type constants

    ROS defines marker types like CUBE, SPHERE, LINE_STRIP, TEXT_VIEW_FACING as constants in visualization_msgs::Marker.
  2. Step 2: Match sphere type

    The constant for a sphere is visualization_msgs::Marker::SPHERE.
  3. Final Answer:

    marker.type = visualization_msgs::Marker::SPHERE; -> Option A
  4. Quick Check:

    SPHERE type constant = A [OK]
Hint: Use Marker::SPHERE constant to set sphere type [OK]
Common Mistakes:
  • Using CUBE instead of SPHERE
  • Confusing LINE_STRIP with sphere
  • Using text marker type for shapes
3. Given the following ROS Python code snippet, what will be the color of the marker displayed in RViz?
marker.color.r = 0.0
marker.color.g = 1.0
marker.color.b = 0.0
marker.color.a = 0.5
medium
A. Opaque red
B. Fully transparent (invisible)
C. Opaque blue
D. Semi-transparent green

Solution

  1. Step 1: Analyze RGB color values

    Red = 0.0, Green = 1.0, Blue = 0.0 means pure green color.
  2. Step 2: Check alpha (opacity) value

    Alpha = 0.5 means 50% transparency, so semi-transparent.
  3. Final Answer:

    Semi-transparent green -> Option D
  4. Quick Check:

    Green=1 and alpha=0.5 = D [OK]
Hint: Alpha <1 means transparency; RGB sets color [OK]
Common Mistakes:
  • Ignoring alpha and assuming opaque
  • Mixing up RGB values for color
  • Thinking alpha=0.5 means fully transparent
4. You wrote this ROS C++ code to publish a marker, but the marker does not appear in RViz. What is the likely error?
visualization_msgs::Marker marker;
marker.header.frame_id = "map";
marker.type = visualization_msgs::Marker::SPHERE;
marker.action = visualization_msgs::Marker::ADD;
marker.pose.position.x = 1.0;
marker.pose.position.y = 2.0;
marker.pose.position.z = 0.0;
marker.scale.x = 0.5;
marker.scale.y = 0.5;
marker.scale.z = 0.5;
marker.color.r = 1.0;
marker.color.g = 0.0;
marker.color.b = 0.0;
marker.color.a = 1.0;
marker_pub.publish(marker);
medium
A. Incorrect marker type used
B. Missing setting of marker.header.stamp to current time
C. Scale values are too small to see
D. Color alpha is zero making it invisible

Solution

  1. Step 1: Check marker header completeness

    ROS markers require header.stamp to be set to current time for RViz to display them properly.
  2. Step 2: Verify other parameters

    Marker type, scale, and color are valid and visible; alpha is 1.0 (opaque).
  3. Final Answer:

    Missing setting of marker.header.stamp to current time -> Option B
  4. Quick Check:

    Header stamp missing = A [OK]
Hint: Always set header.stamp to ros::Time::now() [OK]
Common Mistakes:
  • Forgetting to set header.stamp
  • Using zero alpha making marker invisible
  • Assuming scale too small to see
5. You want to display multiple markers at different positions using a single ROS publisher. Which approach correctly updates and publishes markers to show all of them in RViz?
hard
A. Publish each marker separately with unique IDs and the same topic
B. Publish only the last marker repeatedly, ignoring others
C. Publish markers with the same ID to overwrite previous ones
D. Publish markers without setting frame_id to avoid errors

Solution

  1. Step 1: Understand marker IDs and topics

    Each marker must have a unique ID to be displayed simultaneously on the same topic.
  2. Step 2: Avoid overwriting markers

    Publishing markers with the same ID overwrites previous ones, so unique IDs are needed.
  3. Final Answer:

    Publish each marker separately with unique IDs and the same topic -> Option A
  4. Quick Check:

    Unique IDs per marker = C [OK]
Hint: Use unique IDs for each marker on one topic [OK]
Common Mistakes:
  • Using same ID for multiple markers
  • Publishing only one marker and expecting all to show
  • Not setting frame_id causing display errors