الدرس 2.2 · الكود والأرقام⏱ 12 دقيقة
الفصل 2: الصورة اللي بتعالجها عمرها كام؟ ومين ييجي متأخر يلاقي إيه؟
تجربة: depth والمتأخر والاختلاف
كاميرا 30 Hz والمعالجة 100 ms، وخريطة اتبعتت مرة.
- depth 1 / 10 / 100: عمر الصورة 28 ms و 324 ms و 3.3 ثانية.
- الخريطة: volatile ماوصلتش، و transient_local في 1 ms.
- best effort → reliable: صفر رسايل.
الشرح بالتفصيل
from rclpy.qos import QoSProfile, ReliabilityPolicy as Rel, DurabilityPolicy as Dur
# (1) كاميرا 30 Hz، والمعالجة 100 ms: الصورة عمرها كام لما نبدأ نعالجها؟
q = QoSProfile(depth=depth, reliability=Rel.RELIABLE)
def on(m): ages.append(time.time() - m.data); time.sleep(0.100) # «معالجة الصورة»
sub.create_subscription(Float64, "frame", on, q)
# (2) الخريطة اتبعتت مرة واحدة، والـ planner اشتغل بعدها بثانيتين
q = QoSProfile(depth=1, reliability=Rel.RELIABLE, durability=dur) # VOLATILE ولا TRANSIENT_LOCAL
# (3) الـ publisher والـ subscriber مختلفين في الـ reliability
pub.create_publisher(Float64, "x", QoSProfile(depth=10, reliability=pr))
sub.create_subscription(Float64, "x", cb, QoSProfile(depth=10, reliability=sr))
النتيجة المتوقعة (من الكتاب):
camera 30 Hz, processing 100 ms, depth 1: frame age median 28 ms · max 124 ms · processed 107/352 camera 30 Hz, processing 100 ms, depth 10: frame age median 324 ms · max 397 ms · processed 109/354 camera 30 Hz, processing 100 ms, depth 100: frame age median 3313 ms · max 3434 ms · processed 111/354 map published once, planner starts 2 s later, volatile : never got the map map published once, planner starts 2 s later, transient_local: got the map after 1 ms pub reliable → sub reliable : 199 of ~200 messages pub best_effort → sub best_effort : 199 of ~200 messages pub reliable → sub best_effort : 199 of ~200 messages [WARN] [s]: New publisher discovered on topic 'x', offering incompatible QoS. No messages will be received from it. Last incompatible policy: RELIABILITY pub best_effort → sub reliable : 0 of ~200 messages
- الـ depth: المعالجة بتلحق 10 صور في الثانية بس، فالـ 20 التانيين لازم يترموا في كل الحالات. السؤال بس: نرمي الجديد ولا القديم؟ الـ depth الكبير بيرمي الجديد عمليًا: بيخلّي طابور قديم، ونفضل نعالج صور عمرها 3 ثواني. ده نفس درس «آخر صورة» في الجزء 8 الفصل 4، بس هنا بسطر واحد:
depth=1. - الخريطة: بـ
VOLATILEاللي جه متأخر مايعرفش إن فيه خريطة أصلًا، وهيستنى للأبد. بـTRANSIENT_LOCALوصلته في ملّي ثانية. والاتنين لازم يتفقوا (الـ publisher والـ subscriber). - الاختلاف: subscriber عايز
RELIABLEمن publisherBEST_EFFORT= ولا رسالة، وتحذير واحد في الـ log. ده من أشهر أسباب «الـ topic موجود بس مفيش داتا»: كتير من drivers الحساسات بتبعتBEST_EFFORT(الـ «sensor data» profile). العكس شغال: الـ publisher بيدّي أكتر من المطلوب.
🤖 جرّبها على روبوت كامل في روبو سيم: الـ LiDAR بيبعت /scan بـ BEST_EFFORT: غيّر الـ QoS في الكود لـ 10 (RELIABLE) وشوف الـ node مش بتستقبل حاجة، وجرّب ros2 topic info /scan -v.
ملاحظة«الـ topic موجود بس مفيش داتا»؟ شوف ros2 topic info -v.

