Interactive markers let you control robots by moving markers in a 3D space. They make teleoperation easy and visual.
Interactive markers for teleoperation in ROS
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Syntax
ROS
interactive_markers::InteractiveMarkerServer server("marker_server"); // Create an interactive marker visualization_msgs::InteractiveMarker int_marker; int_marker.header.frame_id = "base_link"; int_marker.name = "my_marker"; int_marker.description = "Simple 6-DOF Control"; // Set marker pose int_marker.pose.position.x = 1.0; int_marker.pose.position.y = 0.0; int_marker.pose.position.z = 0.0; // Add controls to the marker visualization_msgs::InteractiveMarkerControl control; control.orientation.w = 1; control.orientation.x = 0; control.orientation.y = 0; control.orientation.z = 0; control.name = "move_z"; control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS; int_marker.controls.push_back(control); // Insert marker into server server.insert(int_marker); server.applyChanges();
You create an InteractiveMarkerServer to manage markers.
Each marker has a frame, name, pose, and controls for interaction.
Examples
ROS
// Create a simple interactive marker visualization_msgs::InteractiveMarker int_marker; int_marker.header.frame_id = "base_link"; int_marker.name = "marker1"; int_marker.description = "Move me"; // Add a move control visualization_msgs::InteractiveMarkerControl move_control; move_control.name = "move_xy"; move_control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_PLANE; move_control.orientation.w = 1; move_control.orientation.x = 0; move_control.orientation.y = 0; move_control.orientation.z = 0; int_marker.controls.push_back(move_control);
ROS
// Add a rotate control visualization_msgs::InteractiveMarkerControl rotate_control; rotate_control.name = "rotate_z"; rotate_control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS; rotate_control.orientation.w = 1; rotate_control.orientation.x = 0; rotate_control.orientation.y = 0; rotate_control.orientation.z = 0; int_marker.controls.push_back(rotate_control);
Sample Program
This program creates a simple interactive marker that you can drag in the XY plane. When moved, it prints the new position to the console.
ROS
#include <ros/ros.h> #include <interactive_markers/interactive_marker_server.h> #include <visualization_msgs/InteractiveMarker.h> #include <visualization_msgs/InteractiveMarkerFeedback.h> void processFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback) { ROS_INFO_STREAM("Marker moved to position: " << feedback->pose.position.x << ", " << feedback->pose.position.y << ", " << feedback->pose.position.z); } int main(int argc, char** argv) { ros::init(argc, argv, "simple_teleop_marker"); interactive_markers::InteractiveMarkerServer server("simple_marker_server"); visualization_msgs::InteractiveMarker int_marker; int_marker.header.frame_id = "base_link"; int_marker.name = "teleop_marker"; int_marker.description = "Drag to move robot"; int_marker.pose.position.x = 0; int_marker.pose.position.y = 0; int_marker.pose.position.z = 0; visualization_msgs::InteractiveMarkerControl move_control; move_control.name = "move_xy"; move_control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_PLANE; move_control.orientation.w = 1; move_control.orientation.x = 0; move_control.orientation.y = 0; move_control.orientation.z = 0; int_marker.controls.push_back(move_control); server.insert(int_marker, &processFeedback); server.applyChanges(); ros::spin(); return 0; }
Important Notes
Interactive markers require a running ROS master and RViz to visualize.
Use feedback callbacks to react when the marker moves.
Controls define how users can interact: move, rotate, or menu.
Summary
Interactive markers let you control robots visually and easily.
They work by adding controls to markers in 3D space.
Use feedback to handle user actions and update robot commands.
Practice
1. What is the main purpose of interactive markers in ROS teleoperation?
easy
Solution
Step 1: Understand interactive markers role
Interactive markers allow users to move and rotate markers in a 3D view to control robots easily.Step 2: Compare options with purpose
Only To visually control robots by moving markers in 3D space describes visual control via markers; others describe unrelated tasks.Final Answer:
To visually control robots by moving markers in 3D space -> Option AQuick Check:
Interactive markers = Visual robot control [OK]
Hint: Interactive markers let you move robot parts visually [OK]
Common Mistakes:
- Thinking markers are only for displaying data
- Confusing teleoperation with offline logging
- Assuming no user input is needed
2. Which ROS message type is commonly used to create an interactive marker for teleoperation?
easy
Solution
Step 1: Identify message type for interactive markers
The message type visualization_msgs/InteractiveMarker is designed to define interactive markers in ROS.Step 2: Eliminate unrelated message types
sensor_msgs/Image is for images, geometry_msgs/Twist for velocity commands, std_msgs/String for text messages, so they don't create interactive markers.Final Answer:
visualization_msgs/InteractiveMarker -> Option DQuick Check:
Interactive marker message = visualization_msgs/InteractiveMarker [OK]
Hint: Interactive markers use visualization_msgs/InteractiveMarker type [OK]
Common Mistakes:
- Choosing geometry_msgs/Twist which is for velocity commands
- Confusing image or string messages with markers
- Not knowing ROS message types
3. Given this snippet handling interactive marker feedback in ROS:
void processFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback) {
if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::POSE_UPDATE) {
geometry_msgs::Pose new_pose = feedback->pose;
// Update robot command with new_pose
}
}
What happens when the user moves the marker?medium
Solution
Step 1: Analyze feedback event type
The code checks if the event_type is POSE_UPDATE, which means the marker was moved or rotated.Step 2: Understand the effect of POSE_UPDATE
When POSE_UPDATE occurs, the new pose is extracted and used to update the robot command, so the robot moves accordingly.Final Answer:
The robot command updates with the marker's new pose -> Option AQuick Check:
POSE_UPDATE triggers robot command update [OK]
Hint: POSE_UPDATE means marker moved, update robot pose [OK]
Common Mistakes:
- Assuming marker resets automatically
- Ignoring the event_type check
- Thinking robot stops without command
4. You wrote this callback for interactive marker feedback but the robot does not move:
void feedbackCallback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback) {
if (feedback->event_type = visualization_msgs::InteractiveMarkerFeedback::POSE_UPDATE) {
// update robot command
}
}
What is the error?medium
Solution
Step 1: Check the if condition syntax
The condition uses '=' which assigns a value instead of '==' which compares values.Step 2: Understand effect of assignment in if
Assignment always returns true, so the condition is always true but does not properly check event_type, causing logic errors.Final Answer:
Using assignment '=' instead of comparison '==' in the if condition -> Option BQuick Check:
Use '==' to compare event_type, not '=' [OK]
Hint: Use '==' to compare, '=' assigns value [OK]
Common Mistakes:
- Confusing '=' and '==' in conditions
- Assuming missing return causes no movement
- Ignoring need to publish commands
5. You want to create an interactive marker that allows the user to rotate a robot arm joint only around the Z axis. Which control type and orientation should you use in your marker setup?
hard
Solution
Step 1: Identify control type for rotation
ROTATE_AXIS control allows rotation around a single axis, suitable for rotating a joint.Step 2: Set orientation to align with joint axis
To rotate around Z axis, set the control's orientation so its Z axis matches the joint's rotation axis.Final Answer:
Use a ROTATE_AXIS control with orientation set to align Z axis with the joint axis -> Option CQuick Check:
ROTATE_AXIS + Z orientation = rotate joint around Z [OK]
Hint: ROTATE_AXIS control with Z orientation rotates joint around Z [OK]
Common Mistakes:
- Using MOVE_PLANE which moves in a plane, not rotate
- Choosing BUTTON which is for clicks, not rotation
- Aligning control to wrong axis
