Performance: Why topics enable decoupled communication
This concept affects how efficiently messages are passed between parts of a robot system without blocking or tight dependencies.
Node A publishes sensor data on a topic; multiple nodes subscribe and process data independently.Node A calls Node B's service directly and waits for response before continuing.| Pattern | Blocking | Coupling | Latency Impact | Verdict |
|---|---|---|---|---|
| Direct service calls | Yes, blocks caller | Tight coupling | High latency due to waiting | [X] Bad |
| Topic-based publish/subscribe | No, asynchronous | Loose coupling | Low latency with parallel processing | [OK] Good |
import rospy
from std_msgs.msg import String
def callback(msg):
print(f'Received: {msg.data}')
rospy.init_node('listener')
rospy.Subscriber('chatter', String, callback)
rospy.spin()Pass the test and this pattern moves unknown