ROS 1 and ROS 2 are tools that help robots talk to each other and work together. Knowing the difference helps you pick the right one for your robot projects.
ROS 1 vs ROS 2 overview
ROS 1 and ROS 2 are not code syntax but different versions of the Robot Operating System framework.
ROS 1 uses a centralized master node to manage communication.
ROS 2 uses a decentralized system based on DDS for better performance and flexibility.
roscore before running nodes.# ROS 1 example: Starting a talker node
roscore
rosrun beginner_tutorials talker.py# ROS 2 example: Starting a talker node
ros2 run demo_nodes_cpp talkerThis ROS 1 node sends a message every second to the 'chatter' topic.
# ROS 1 talker node in Python import rospy from std_msgs.msg import String def talker(): rospy.init_node('talker', anonymous=True) pub = rospy.Publisher('chatter', String, queue_size=10) rate = rospy.Rate(1) # 1hz while not rospy.is_shutdown(): hello_str = "hello world" rospy.loginfo(hello_str) pub.publish(hello_str) rate.sleep() if __name__ == '__main__': try: talker() except rospy.ROSInterruptException: pass
ROS 2 improves on ROS 1 by removing the single point of failure (the master node).
ROS 2 supports multiple platforms like Windows and real-time systems better than ROS 1.
Many ROS 1 packages are not directly compatible with ROS 2 and may need porting.
ROS 1 is older and simpler but has limitations in scalability and real-time support.
ROS 2 is newer, more flexible, and designed for modern robot needs.
Choosing between them depends on your project requirements and hardware.
Practice
ROS 1 and ROS 2?Solution
Step 1: Understand ROS 1 characteristics
ROS 1 is the original version, simpler but limited in real-time and scalability.Step 2: Understand ROS 2 improvements
ROS 2 was designed to fix these limits, adding real-time support and better scalability.Final Answer:
ROS 1 is older and simpler, while ROS 2 supports real-time and better scalability. -> Option AQuick Check:
ROS 1 simpler, ROS 2 modern and scalable = A [OK]
- Thinking ROS 2 is older than ROS 1
- Believing ROS 1 has better real-time support
- Assuming both versions have identical features
Solution
Step 1: Identify ROS 2 communication method
ROS 2 uses DDS, a middleware standard, for flexible and scalable communication.Step 2: Check other options
TCP only or HTTP are not used as the main middleware in ROS 2.Final Answer:
ROS 2 uses DDS (Data Distribution Service) for flexible communication. -> Option BQuick Check:
ROS 2 middleware = DDS [OK]
- Confusing TCP with DDS
- Thinking ROS 2 lacks middleware
- Assuming HTTP is used for ROS 2 messages
node = Node('example_node')
node.create_publisher(String, 'topic', 10)What is a key difference in how this code behaves in ROS 1 vs ROS 2?
Solution
Step 1: Check ROS 1 publisher creation
ROS 1 usesrospy.Publisherorroscpp::Publisher, notcreate_publisher.Step 2: Check ROS 2 publisher creation
ROS 2 usescreate_publisherwith QoS settings for flexible communication.Final Answer:
ROS 1 does not supportcreate_publishermethod; ROS 2 does. -> Option DQuick Check:
ROS 2 uses create_publisher, ROS 1 does not [OK]
- Assuming ROS 1 has create_publisher method
- Thinking QoS is ignored in ROS 2
- Believing ROS 2 lacks publisher support
rclcpp::init. What is the likely cause?Solution
Step 1: Understand ROS 2 initialization
ROS 2 requires callingrclcpp::initbefore creating nodes to set up communication.Step 2: Check error cause
Missingrclcpp::initcauses runtime errors when nodes try to start.Final Answer:
You forgot to initialize the ROS 2 client library before creating nodes. -> Option CQuick Check:
Missing rclcpp::init means no ROS 2 initialization [OK]
- Confusing ROS 1 and ROS 2 initialization steps
- Assuming topic name causes this error
- Ignoring the need for client library init
Solution
Step 1: Identify real-time and platform needs
The project needs real-time control and multi-platform support including Windows and Linux.Step 2: Match requirements to ROS versions
ROS 2 supports real-time features and runs on Windows and Linux, unlike ROS 1 which is limited.Final Answer:
Choose ROS 2 because it supports real-time control and multi-platform compatibility. -> Option AQuick Check:
Real-time + multi-platform = ROS 2 [OK]
- Assuming ROS 1 supports Windows well
- Thinking ROS 2 lacks real-time features
- Believing ROS 2 only works on Linux
Ready to prove it?
Pass the test and this pattern moves unknown
