Bird
Raised Fist0
ROSframework~20 mins

cmd_vel topic for velocity commands 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
🎖️
cmd_vel Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a ROS node publishes zero velocity on cmd_vel?

In a robot controlled by ROS, the cmd_vel topic is used to send velocity commands. What is the robot's behavior when a node publishes a message with all velocity values set to zero on cmd_vel?

ROS
geometry_msgs/Twist msg = new geometry_msgs/Twist();
msg.linear.x = 0.0;
msg.linear.y = 0.0;
msg.linear.z = 0.0;
msg.angular.x = 0.0;
msg.angular.y = 0.0;
msg.angular.z = 0.0;
publisher.publish(msg);
AThe robot ignores the message and continues previous motion.
BThe robot moves forward at a default speed.
CThe robot stops moving immediately and holds its position.
DThe robot rotates in place at a default angular velocity.
Attempts:
2 left
💡 Hint

Think about what zero velocity means for movement commands.

📝 Syntax
intermediate
2:00remaining
Which ROS Python code snippet correctly publishes a forward velocity on cmd_vel?

Choose the correct Python code snippet that publishes a forward linear velocity of 1.0 m/s on the cmd_vel topic using ROS.

A
pub = rospy.Publisher('cmd_vel', Twist)
msg = Twist()
msg.linear.y = 1.0
pub.publish(msg)
B
pub = rospy.Publisher('cmd_vel', Twist, queue_size=10)
msg = Twist()
msg.linear.x = 1.0
pub.publish(msg)
C
pub = rospy.Publisher('cmd_vel', Twist, queue_size=10)
msg = Twist()
msg.angular.z = 1.0
pub.publish(msg)
D
pub = rospy.Publisher('cmd_vel', Twist, queue_size=10)
msg = Twist()
msg.linear.x = '1.0'
publish(msg)
Attempts:
2 left
💡 Hint

Check the topic name, message type, and correct field for forward velocity.

state_output
advanced
2:00remaining
What is the robot's angular velocity after publishing this cmd_vel message?

Given the following ROS message published on cmd_vel, what is the robot's angular velocity around the z-axis?

ROS
geometry_msgs/Twist msg = new geometry_msgs/Twist();
msg.linear.x = 0.5;
msg.angular.z = -0.3;
publisher.publish(msg);
A0.3 radians per second (counter-clockwise rotation)
B0 radians per second (no rotation)
C-0.5 radians per second (clockwise rotation)
D-0.3 radians per second (clockwise rotation)
Attempts:
2 left
💡 Hint

Remember the sign convention for angular.z in ROS.

🔧 Debug
advanced
2:00remaining
Why does this ROS node fail to move the robot when publishing to cmd_vel?

Consider this ROS Python snippet intended to move the robot forward. Why does the robot not move?

ROS
import rospy
from geometry_msgs.msg import Twist

rospy.init_node('move_robot')
pub = rospy.Publisher('cmd_vel', Twist, queue_size=10)
msg = Twist()
msg.linear.x = 1.0
# Missing loop or sleep
pub.publish(msg)
AThe message is published only once before the node shuts down, so the robot stops immediately.
BThe message has incorrect data types causing a runtime error.
CThe topic name 'cmd_vel' is misspelled, so no commands are received.
DThe Twist message is missing angular velocity fields, causing the robot to ignore it.
Attempts:
2 left
💡 Hint

Think about how ROS nodes and message publishing work over time.

🧠 Conceptual
expert
3:00remaining
How does the cmd_vel topic integrate with robot safety and control layers in ROS?

In a typical ROS robot system, the cmd_vel topic is used to send velocity commands. Which statement best describes how cmd_vel interacts with safety and control layers?

A<code>cmd_vel</code> is the final command topic; safety layers subscribe to it and override or stop commands if needed before sending to motors.
B<code>cmd_vel</code> directly controls motor drivers without any intermediate safety checks.
CSafety layers publish to <code>cmd_vel</code> to enable movement after verifying sensor data.
D<code>cmd_vel</code> is only used for simulation and ignored on real robots.
Attempts:
2 left
💡 Hint

Consider how safety is enforced in robot control pipelines.

Practice

(1/5)
1. What is the main purpose of the /cmd_vel topic in ROS?
easy
A. To configure robot hardware settings
B. To receive sensor data from the robot
C. To send velocity commands to control robot movement
D. To log robot status messages

Solution

  1. Step 1: Understand the role of /cmd_vel topic

    The /cmd_vel topic is used to send velocity commands to the robot.
  2. Step 2: Identify what velocity commands control

    Velocity commands control the robot's movement, including linear and angular velocities.
  3. Final Answer:

    To send velocity commands to control robot movement -> Option C
  4. Quick Check:

    /cmd_vel controls robot movement = A [OK]
Hint: Remember: cmd_vel means command velocity for robot movement [OK]
Common Mistakes:
  • Confusing cmd_vel with sensor data topics
  • Thinking cmd_vel configures hardware
  • Assuming cmd_vel logs messages
2. Which message type is published on the /cmd_vel topic to control robot velocity?
easy
A. geometry_msgs/Twist
B. std_msgs/String
C. sensor_msgs/LaserScan
D. nav_msgs/Odometry

Solution

  1. Step 1: Identify the message type for velocity commands

    The /cmd_vel topic uses geometry_msgs/Twist messages to send velocity commands.
  2. Step 2: Confirm other message types are unrelated

    sensor_msgs/LaserScan is for laser data, std_msgs/String is generic text, and nav_msgs/Odometry is for position data.
  3. Final Answer:

    geometry_msgs/Twist -> Option A
  4. Quick Check:

    Velocity commands use Twist messages = C [OK]
Hint: Twist means linear + angular velocity message [OK]
Common Mistakes:
  • Choosing sensor or odometry messages instead of Twist
  • Confusing std_msgs/String as velocity message
3. Given this Python ROS publisher code snippet, what linear x velocity will the robot move at?
import rospy
from geometry_msgs.msg import Twist

rospy.init_node('move_robot')
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)
msg = Twist()
msg.linear.x = 0.5
msg.angular.z = 0.0
pub.publish(msg)
medium
A. 0.0 m/s
B. Undefined velocity
C. 1.0 m/s
D. 0.5 m/s

Solution

  1. Step 1: Check the linear velocity set in the message

    The code sets msg.linear.x = 0.5, which means forward velocity is 0.5 meters per second.
  2. Step 2: Confirm angular velocity does not affect linear speed

    msg.angular.z = 0.0 means no rotation, so linear speed remains 0.5 m/s.
  3. Final Answer:

    0.5 m/s -> Option D
  4. Quick Check:

    linear.x = 0.5 means speed 0.5 m/s [OK]
Hint: Look for msg.linear.x value for forward speed [OK]
Common Mistakes:
  • Confusing angular.z with linear.x velocity
  • Assuming default velocity if not set
  • Ignoring the published message values
4. What is wrong with this ROS Python code snippet that publishes velocity commands?
import rospy
from geometry_msgs.msg import Twist

rospy.init_node('move_robot')
pub = rospy.Publisher('/cmd_vel', Twist)
msg = Twist()
msg.linear.x = 1.0
pub.publish(msg)
medium
A. Twist message fields are incorrectly assigned
B. Missing queue_size parameter in Publisher initialization
C. Node initialization is missing
D. Publisher topic name is incorrect

Solution

  1. Step 1: Check Publisher initialization parameters

    The rospy.Publisher requires a queue_size parameter to avoid runtime warnings or errors.
  2. Step 2: Verify other parts of the code

    Node initialization is present, message fields are correctly assigned, and topic name /cmd_vel is correct.
  3. Final Answer:

    Missing queue_size parameter in Publisher initialization -> Option B
  4. Quick Check:

    Publisher needs queue_size argument = A [OK]
Hint: Always add queue_size when creating a Publisher [OK]
Common Mistakes:
  • Omitting queue_size causes errors
  • Thinking node initialization is missing
  • Assuming topic name is wrong
5. You want your robot to move forward at 0.3 m/s and rotate at 0.5 rad/s simultaneously using /cmd_vel. Which code snippet correctly publishes this combined velocity command in Python?
hard
A. msg.linear.x = 0.3 msg.angular.z = 0.5 pub.publish(msg)
B. msg.linear.y = 0.3 msg.angular.x = 0.5 pub.publish(msg)
C. msg.linear.x = 0.5 msg.angular.z = 0.3 pub.publish(msg)
D. msg.linear.z = 0.3 msg.angular.y = 0.5 pub.publish(msg)

Solution

  1. Step 1: Identify correct fields for forward and rotational velocity

    Forward movement uses linear.x, and rotation uses angular.z in geometry_msgs/Twist.
  2. Step 2: Match values to correct fields

    Set linear.x = 0.3 for forward speed and angular.z = 0.5 for rotation speed.
  3. Step 3: Verify other options use incorrect axes

    Options A, B, and C assign values to wrong axes or swap linear and angular values.
  4. Final Answer:

    msg.linear.x = 0.3 msg.angular.z = 0.5 pub.publish(msg) -> Option A
  5. Quick Check:

    Forward = linear.x, rotate = angular.z = D [OK]
Hint: Forward speed = linear.x, rotation = angular.z [OK]
Common Mistakes:
  • Using wrong linear or angular axes
  • Swapping linear and angular values
  • Setting velocities on unused axes