Performance: ROS node concept
This concept affects the communication efficiency and responsiveness of a ROS-based robotic system.
from threading import Thread def sensor_callback(data): Thread(target=process_and_publish, args=(data,)).start() def process_and_publish(data): result = complex_processing(data) publish_result(result) rospy.Subscriber('sensor_topic', SensorMsg, sensor_callback) rospy.spin()
def sensor_callback(data): # Heavy computation inside callback result = complex_processing(data) publish_result(result) rospy.Subscriber('sensor_topic', SensorMsg, sensor_callback) rospy.spin()
| Pattern | CPU Usage | Message Latency | Responsiveness | Verdict |
|---|---|---|---|---|
| Heavy processing in callback | High CPU blocking | High latency | Low responsiveness | [X] Bad |
| Offload processing to thread | Balanced CPU usage | Low latency | High responsiveness | [OK] Good |
import rospy
rospy.init_node('talker')
rospy.loginfo('Node started')
import rospy
rospy.init_node('listener')
rospy.spinPass the test and this pattern moves unknown