Bird
Raised Fist0
ROSframework~20 mins

Marker display for custom visualization in ROS - Practice Problems & Coding Challenges

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
Challenge - 5 Problems
🎖️
Marker Visualization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What will this ROS Marker display code show in RViz?
Consider this ROS Python snippet that publishes a visualization marker. What shape and color will appear in RViz?
ROS
import rospy
from visualization_msgs.msg import Marker

rospy.init_node('marker_test')
pub = rospy.Publisher('visualization_marker', Marker, queue_size=10)
marker = Marker()
marker.header.frame_id = 'map'
marker.type = Marker.SPHERE
marker.action = 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
rate = rospy.Rate(1)
while not rospy.is_shutdown():
    marker.header.stamp = rospy.Time.now()
    pub.publish(marker)
    rate.sleep()
AA green cube of size 0.5 meters at position (1, 2, 0) in the 'map' frame.
BA red sphere of diameter 0.5 meters at position (1, 2, 0) in the 'map' frame.
CA blue arrow pointing along the x-axis at position (0, 0, 0) in the 'map' frame.
DNo marker will appear because the color alpha is zero.
Attempts:
2 left
💡 Hint
Check the marker type and color values carefully.
📝 Syntax
intermediate
1:30remaining
Which option fixes the syntax error in this ROS Marker message setup?
This code snippet tries to set a marker's scale but has a syntax error. Which option corrects it?
ROS
marker.scale.x = 1.0
marker.scale.y = 1.0
marker.scale.z = 1.0
marker.color.r = 0.0
marker.color.g = 1.0
marker.color.b = 0.0
marker.color.a = 1.0
marker.type = Marker.CUBE
marker.action = Marker.ADD
marker.pose.position.x = 0.0
marker.pose.position.y = 0.0
marker.pose.position.z = 0.0
marker.header.frame_id = 'base_link'
marker.header.stamp = rospy.Time.now()
pub.publish(marker)
AChange pub.publish(marker to pub.publish(marker))
BAdd a missing colon after pub.publish(marker)
CAdd a closing parenthesis at the end: pub.publish(marker)
DReplace pub.publish(marker with pub.publish(marker);
Attempts:
2 left
💡 Hint
Look carefully at the parentheses in the last line.
state_output
advanced
1:30remaining
What is the effect of changing marker.action to Marker.DELETE in this ROS Marker publisher?
Given a marker published repeatedly with action Marker.ADD, what happens if you publish the same marker with action Marker.DELETE?
ROS
marker.action = Marker.DELETE
pub.publish(marker)
AThe marker previously displayed with the same ID will be removed from RViz.
BPublishing with Marker.DELETE causes a runtime error.
CA new marker will appear at the origin with default shape.
DThe marker will change color to transparent but remain visible.
Attempts:
2 left
💡 Hint
Think about what DELETE action means for visualization markers.
🔧 Debug
advanced
2:00remaining
Why does this ROS Marker not appear in RViz despite publishing?
This code publishes a marker but nothing shows in RViz. What is the most likely cause?
ROS
marker = Marker()
marker.header.frame_id = 'map'
marker.type = Marker.CUBE
marker.action = Marker.ADD
marker.pose.position.x = 0
marker.pose.position.y = 0
marker.pose.position.z = 0
marker.scale.x = 1
marker.scale.y = 1
marker.scale.z = 1
marker.color.r = 0
marker.color.g = 0
marker.color.b = 1
marker.color.a = 0
marker.id = 0
marker.ns = 'test'
pub.publish(marker)
AThe frame_id 'map' is missing from the TF tree, so RViz can't place the marker.
BThe marker type CUBE is invalid and causes it not to render.
CThe marker scale values are zero, so the marker is invisible.
DThe alpha value is zero, making the marker fully transparent.
Attempts:
2 left
💡 Hint
Check the color alpha channel carefully.
🧠 Conceptual
expert
2:30remaining
How does the 'frame_id' in a ROS Marker affect its visualization in RViz?
Why is setting the correct 'frame_id' in a Marker message crucial for proper visualization in RViz?
AIt defines the coordinate frame in which the marker's position and orientation are interpreted, ensuring correct placement relative to other objects.
BIt sets the color scheme of the marker automatically based on the frame name.
CIt controls the marker's lifetime and how long it stays visible in RViz.
DIt determines the marker's shape and size by linking to predefined frame templates.
Attempts:
2 left
💡 Hint
Think about how RViz uses coordinate frames to place objects in 3D space.

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