In the Robot Operating System (ROS), what is the main purpose of a node?
Think about how ROS breaks down robot software into smaller parts.
A ROS node is a process that performs computation and communicates with other nodes to build a robot system. It does not store data permanently or provide GUIs by default.
Consider two ROS nodes both publishing messages to the same topic. What is the expected behavior?
Think about how ROS topics handle multiple publishers.
ROS topics allow multiple nodes to publish messages. Subscribers receive all messages from all publishers in the order they arrive.
Arrange the following ROS node lifecycle states in the correct order from startup to shutdown:
- Inactive
- Active
- Unconfigured
- Finalized
Think about the node starting unconfigured, then becoming active, then shutting down.
The ROS node lifecycle starts at Unconfigured, then moves to Inactive, then Active, and finally Finalized when shutting down.
Given the following ROS Python node code, what will be printed to the console?
import rclpy from rclpy.node import Node class SimpleNode(Node): def __init__(self): super().__init__('simple_node') self.counter = 0 self.timer = self.create_timer(0.5, self.timer_callback) def timer_callback(self): self.counter += 1 self.get_logger().info(f'Count: {self.counter}') if self.counter == 3: self.destroy_timer(self.timer) rclpy.init() node = SimpleNode() rclpy.spin(node) rclpy.shutdown()
Look at how the counter increments and when the timer is destroyed.
The timer callback runs every 0.5 seconds, increments counter, prints it, and stops after count 3 by destroying the timer.
Consider this ROS Python node snippet that tries to publish messages:
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class Talker(Node):
def __init__(self):
super().__init__('talker')
self.publisher_ = self.create_publisher(String, 'chatter', 10)
self.timer = self.create_timer(1.0, self.timer_callback)
def timer_callback(self):
msg = String()
msg.data = 'Hello ROS'
self.publisher_.publish(msg)
rclpy.init()
node = Talker()
rclpy.spin(node)
rclpy.shutdown()Which modification below will cause a runtime error when running this node?
Think about what types ROS publishers accept for messages.
ROS publishers require a valid message type class. Using 'int' instead of a ROS message type causes a runtime error.
